05-17-2013 04:19 PM
05-18-2013 04:29 AM
05-18-2013 10:19 PM
/**
* 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;
}
05-21-2013 05:55 AM
05-21-2013 11:55 AM
05-23-2013 09:47 AM
05-23-2013 12:21 PM
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);
}
05-28-2013 12:00 PM
05-30-2013 12:52 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.