/**
* Guardar el contenido del archivo
*/
public NodeRef guardarContenidoEnEspacio(final NodeRef espacioContenedor, final ActaRecepcion actaRecepcion, final Map<QName, Serializable> propiedades, final String usuario) throws ArchivoIncorrectoException {
final UserTransaction trx = serviceRegistry.getTransactionService().getUserTransaction();
NodeRef fileNodeRef = null;
try {
trx.begin();
final FileInfo fileInfo = fileFolderService.create(espacioContenedor, actaRecepcion.getCodigoProceso() + "_Acta_Recepción.pdf", ModeloActaRecepcion.TYPE_DOC);
fileNodeRef = fileInfo.getNodeRef();
setearPropiedadesProperties(fileNodeRef, actaRecepcion, propiedades, usuario);
final ContentWriter writer = contentService.getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);
writer.setEncoding("UTF-8");
writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
writer.putContent(new ByteArrayInputStream(actaRecepcion.getPdf()));
trx.commit();
} catch (FileExistsException fe) {
try {
trx.rollback();
} catch (Exception e1) {
}
LOG.error("El archivo " + actaRecepcion.getPdfPath() + "ya fue cargado anteriormente");
String name = actaRecepcion.getCodigoProceso().trim() + "_Acta_Recepción.pdf";
NodeRef node = nodeService.getChildByName(espacioContenedor, ContentModel.ASSOC_CONTAINS, name);
this.versionService = serviceRegistry.getVersionService();
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
versionService.createVersion(node, versionProperties);
setearPropiedadesProperties(node, actaRecepcion, propiedades, usuario);
ContentWriter writer = contentService.getWriter(node, ContentModel.PROP_CONTENT, true);
writer.setEncoding("UTF-8");
writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
writer.putContent(new ByteArrayInputStream(actaRecepcion.getPdf()));
} catch (Exception e) {
try {
trx.rollback();
} catch (Exception e1) {
}
throw new ArchivoIncorrectoException("Se produjo un error al cargar el archivo ");
}
return fileNodeRef;
}
transient private VersionService versionService;
this.versionService = serviceRegistry.getVersionService();
/**
* Fijar las propiedades del Documento
*/
private void setearPropiedadesProperties(final NodeRef fileNodeRef, final ActaRecepcion actaRecepcion, final Map<QName, Serializable> propiedades, final String currentUserName) {
final Map<QName, Serializable> propiedadesAutor = new HashMap<QName, Serializable>();
propiedadesAutor.put(ContentModel.PROP_AUTHOR, currentUserName);
nodeService.addAspect(fileNodeRef, ContentModel.ASPECT_AUTHOR, propiedadesAutor);
final Map<QName, Serializable> propiedadesBasicas = new HashMap<QName, Serializable>();
propiedadesBasicas.put(ContentModel.PROP_TITLE, "Titulo");
propiedadesBasicas.put(ContentModel.PROP_DESCRIPTION, "Descripcion");
nodeService.addAspect(fileNodeRef, ContentModel.ASPECT_TITLED, propiedadesBasicas);
nodeService.addProperties(fileNodeRef, propiedades);
}
Content from pre 2016 and from language groups that have been closed.
Content is read-only.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.