05-26-2014 10:24 AM
05-26-2014 10:39 AM
05-26-2014 11:18 AM
05-26-2014 11:27 AM
05-27-2014 01:40 AM
05-27-2014 03:14 AM
05-27-2014 03:30 AM
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException, WebScriptException
{
// AUTENTICATION
getAuthenticationService().authenticate(usuario, password);
// PATH WHERE BEGINS TO CREATE NODES
NodeRef nodeRef = serviceRegistry.getFileFolderService().resolveNamePath(repository.getCompanyHome(), pathInicial).getNodeRef();
// LIST OF PROPERTIES
Map properties = new HashMap();
properties.put(QName.createQName(Constantes.folder, Constants.numExpedienteProperty), numExpediente);
properties.put(QName.createQName(Constantes.folder, Constants.autorProperty), autor);
(…)
// CREATE THE FOLDERS OF THE PATH THAT NOT EXISTS
boolean newFolder = false;
StringTokenizer tokenizer = new StringTokenizer(path, "/");
while (tokenizer.hasMoreTokens()) {
if (!newFolder) {
List assocs = new ArrayList();
assocs = getNodeService().getChildAssocsByPropertyValue(nodeRef, QName.createQName(Constantes.folder, Constants.numExpedienteProperty), numExpediente);
if (existe) {
nodeRef = assocs.get(0).getChildRef();
} else {
newFolder = true;
}
}
if (newFolder) {
UserTransaction trx = serviceRegistry.getTransactionService().getNonPropagatingUserTransaction();
try {
trx.begin();
nodeRef = getNodeService().createNode(nodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), tipo, properties).getChildRef();
trx.commit();
} catch(Throwable e) {
trx.rollback();
logger.error("ERROR: " + e);
throw new WebScriptException(Status.STATUS_PROPERTIES_ERROR, e.getMessage());
}
}
} // while
UserTransaction trx = serviceRegistry.getTransactionService().getNonPropagatingUserTransaction();
try {
trx.begin();
// CREATE DOCUMENT NODE
nodeRef = getNodeService().createNode(nodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nameDoc), tipo, properties).getChildRef();
// DOCUMENT UPLOAD
InputStream myInputStream = getFileAsStream(pathDoc);
BufferedInputStream inputStream = new BufferedInputStream(myInputStream);
writer = getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(inputStream);
trx.commit();
} catch(Throwable e) {
trx.rollback();
logger.error("ERROR: " + e);
throw new WebScriptException(Status.STATUS_CREATE_ERROR, e.getMessage());
}
// POINTER AT THE PARENT NODE
NodeRef parent = getNodeService().getPrimaryParent(nodeRef).getParentRef();
UserTransaction trx = serviceRegistry.getTransactionService().getNonPropagatingUserTransaction();
try {
trx.begin();
// UPDATE PROPERTIES FROM DOWN TO UP UNTIL A CONDITION X
while (condition) {
Long numDocuments = (Long) getNodeService().getProperty(nodeRef, QName.createQName(Constantes.folder, Constantes.numDocuments)) + 1;
// THIS IS THE LINE THAT THROWS THE CONCURRENCY EXCEPTION WHEN SETS THE NODE THAT I CHANGE BEFORE WITH THE ALFRESCO EXPLORER
getNodeService().setProperty(nodeRef, QName.createQName(Constantes.folder, Constants.numDocumentsProperty), numDocuments);
nodeRef = getNodeService().getPrimaryParent(nodeRef).getParentRef();
} // while
trx.commit();
} catch(Throwable e) {
trx.rollback();
logger.error("transactionUpdateCustomProperties - ERROR: " + e);
throw new WebScriptException(Status.STATUS_PROPERTIES_ERROR, e.getMessage());
}
}
05-27-2014 03:33 AM
05-27-2014 05:04 AM
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException, WebScriptException
{
// AUTENTICATION
getAuthenticationService().authenticate(usuario, password);
// PATH WHERE BEGINS TO CREATE NODES
NodeRef nodeRef = serviceRegistry.getFileFolderService().resolveNamePath(repository.getCompanyHome(), pathInicial).getNodeRef();
// LIST OF PROPERTIES
Map properties = new HashMap();
properties.put(QName.createQName(Constantes.folder, Constants.numExpedienteProperty), numExpediente);
properties.put(QName.createQName(Constantes.folder, Constants.autorProperty), autor);
(…)
// CREATE THE FOLDERS OF THE PATH THAT NOT EXISTS
boolean newFolder = false;
StringTokenizer tokenizer = new StringTokenizer(path, "/");
while (tokenizer.hasMoreTokens()) {
if (!newFolder) {
List assocs = new ArrayList();
assocs = getNodeService().getChildAssocsByPropertyValue(nodeRef, QName.createQName(Constantes.folder, Constants.numExpedienteProperty), numExpediente);
if (existe) {
nodeRef = assocs.get(0).getChildRef();
} else {
newFolder = true;
}
}
if (newFolder) {
try {
nodeRef = getNodeService().createNode(nodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name), tipo, properties).getChildRef();
} catch(WebScriptException e) {
logger.error("ERROR: " + e);
throw new WebScriptException(Status.STATUS_PROPERTIES_ERROR, e.getMessage());
}
}
} // while
try {
// CREATE DOCUMENT NODE
nodeRef = getNodeService().createNode(nodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nameDoc), tipo, properties).getChildRef();
// DOCUMENT UPLOAD
InputStream myInputStream = getFileAsStream(pathDoc);
BufferedInputStream inputStream = new BufferedInputStream(myInputStream);
writer = getContentService().getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(inputStream);
} catch(WebScriptException e) {
logger.error("ERROR: " + e);
throw new WebScriptException(Status.STATUS_CREATE_ERROR, e.getMessage());
}
// POINTER AT THE PARENT NODE
NodeRef parent = getNodeService().getPrimaryParent(nodeRef).getParentRef();
try {
// UPDATE PROPERTIES FROM DOWN TO UP UNTIL A CONDITION X
while (condition) {
Long numDocuments = (Long) getNodeService().getProperty(nodeRef, QName.createQName(Constantes.folder, Constantes.numDocuments)) + 1;
// THIS IS THE LINE THAT THROWS THE CONCURRENCY EXCEPTION WHEN SETS THE NODE THAT I CHANGE BEFORE WITH THE ALFRESCO EXPLORER
getNodeService().setProperty(nodeRef, QName.createQName(Constantes.folder, Constants.numDocumentsProperty), numDocuments);
nodeRef = getNodeService().getPrimaryParent(nodeRef).getParentRef();
} // while
} catch(WebScriptException e) {
logger.error("transactionUpdateCustomProperties - ERROR: " + e);
throw new WebScriptException(Status.STATUS_PROPERTIES_ERROR, e.getMessage());
}
}
05-27-2014 05:43 AM
<webscript>
<shortname>Web script to create and upload</shortname>
<description>Return a JSON</description>
<url>/own/APD/createdocument</url>
<authentication>user</authentication>
<format default="json">argument</format>
<family>Alfresco Java-Backed WebScripts</family>
</webscript>
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.