use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class UnfiledContainerEntityResource method update.
@Override
@WebApiDescription(title = "Update unfiled record container", description = "Updates an unfiled record container with id 'unfiledContainerId'")
public UnfiledContainer update(String unfiledContainerId, UnfiledContainer unfiledContainerInfo, Parameters parameters) {
checkNotBlank("unfiledContainerId", unfiledContainerId);
mandatory("unfiledContainerInfo", unfiledContainerInfo);
mandatory("parameters", parameters);
NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {
public Void execute() {
apiUtils.updateNode(nodeRef, unfiledContainerInfo, parameters);
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>() {
public FileInfo execute() {
return fileFolderService.getFileInfo(nodeRef);
}
};
FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
apiUtils.postActivity(info, unfiledContainerInfo.getParentId(), ActivityType.FILE_UPDATED);
return nodesModelFactory.createUnfiledContainer(info, parameters, null, false);
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class UnfiledRecordFolderChildrenRelation method create.
@Override
@WebApiDescription(title = "Upload file content and meta-data into the repository.")
@WebApiParam(name = "formData", title = "A single form data", description = "A single form data which holds FormFields.")
public UnfiledRecordFolderChild create(String unfiledRecordFolderId, FormData formData, Parameters parameters, WithResponse withResponse) {
checkNotBlank("unfiledRecordFolderId", unfiledRecordFolderId);
mandatory("formData", formData);
mandatory("parameters", parameters);
// Retrieve the input data and resolve the parent node
final UploadInfo uploadInfo = new UploadInfo(formData);
// Create the record - returns pair(newNode,parentNode)
RetryingTransactionCallback<Pair<NodeRef, NodeRef>> callback = new RetryingTransactionCallback<Pair<NodeRef, NodeRef>>() {
public Pair<NodeRef, NodeRef> execute() {
final NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER, uploadInfo.getRelativePath());
NodeRef newNode = apiUtils.uploadRecord(parentNodeRef, uploadInfo, parameters);
return new Pair<NodeRef, NodeRef>(newNode, parentNodeRef);
}
};
Pair<NodeRef, NodeRef> nodeAndParentInfo = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
NodeRef newNode = nodeAndParentInfo.getFirst();
NodeRef parent = nodeAndParentInfo.getSecond();
// Get file info for response
FileInfo info = fileFolderService.getFileInfo(newNode);
apiUtils.postActivity(info, parent, ActivityType.FILE_ADDED);
return nodesModelFactory.createUnfiledRecordFolderChild(info, parameters, null, false);
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class RecordFolderChildrenRelation method create.
@Override
@WebApiDescription(title = "Create one (or more) records as children of a record folder identified by 'recordFolderId'")
public List<Record> create(String recordFolderId, List<Record> nodeInfos, Parameters parameters) {
checkNotBlank("recordFolderId", recordFolderId);
mandatory("nodeInfos", nodeInfos);
mandatory("parameters", parameters);
NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER);
RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>() {
public List<NodeRef> execute() {
List<NodeRef> createdNodes = new LinkedList<>();
for (Record nodeInfo : nodeInfos) {
NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo, parameters);
createdNodes.add(newNodeRef);
}
return createdNodes;
}
};
List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
// Get the nodes info
List<Record> result = new LinkedList<>();
Map<String, UserInfo> mapUserInfo = new HashMap<>();
for (NodeRef newNodeRef : createdNodes) {
FileInfo info = fileFolderService.getFileInfo(newNodeRef);
apiUtils.postActivity(info, parentNodeRef, ActivityType.FILE_ADDED);
result.add(nodesModelFactory.createRecord(info, parameters, mapUserInfo, false));
}
return result;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class DispositionLifecycleJobExecuter method executeAction.
/**
* Helper method that executes a disposition action
*
* @param actionNode - the disposition action to execute
*/
private void executeAction(final NodeRef actionNode) {
RetryingTransactionCallback<Boolean> processTranCB = new RetryingTransactionCallback<Boolean>() {
public Boolean execute() {
final String dispAction = (String) nodeService.getProperty(actionNode, RecordsManagementModel.PROP_DISPOSITION_ACTION);
// Run disposition action
if (dispAction != null && dispositionActions.contains(dispAction)) {
ChildAssociationRef parent = nodeService.getPrimaryParent(actionNode);
if (parent.getTypeQName().equals(RecordsManagementModel.ASSOC_NEXT_DISPOSITION_ACTION)) {
Map<String, Serializable> props = new HashMap<String, Serializable>(1);
props.put(RMDispositionActionExecuterAbstractBase.PARAM_NO_ERROR_CHECK, Boolean.FALSE);
try {
// execute disposition action
recordsManagementActionService.executeRecordsManagementAction(parent.getParentRef(), dispAction, props);
if (logger.isDebugEnabled()) {
logger.debug("Processed action: " + dispAction + "on" + parent);
}
} catch (AlfrescoRuntimeException exception) {
if (logger.isDebugEnabled()) {
logger.debug(exception);
}
}
}
}
return Boolean.TRUE;
}
};
// if exists
if (nodeService.exists(actionNode)) {
retryingTransactionHelper.doInTransaction(processTranCB);
}
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class PublishUpdatesJobExecuter method getUpdatedNodes.
/**
* Get a list of the nodes with updates pending publish
* @return List<NodeRef> list of node refences with updates pending publication
*/
private List<NodeRef> getUpdatedNodes() {
RetryingTransactionCallback<List<NodeRef>> execution = new RetryingTransactionHelper.RetryingTransactionCallback<List<NodeRef>>() {
@Override
public List<NodeRef> execute() {
// Build the query string
StringBuilder sb = new StringBuilder();
sb.append("ASPECT:\"rma:").append(ASPECT_UNPUBLISHED_UPDATE.getLocalName()).append("\"");
String query = sb.toString();
if (logger.isDebugEnabled()) {
logger.debug("Executing query " + query);
}
// Execute query to find updates awaiting publishing
List<NodeRef> resultNodes = null;
SearchParameters searchParameters = new SearchParameters();
searchParameters.setQuery(query);
searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
try {
ResultSet results = searchService.query(searchParameters);
try {
resultNodes = results.getNodeRefs();
} finally {
results.close();
}
} catch (AlfrescoRuntimeException exception) {
if (logger.isDebugEnabled()) {
logger.debug("Error executing query, " + exception.getMessage());
}
throw exception;
}
if (logger.isDebugEnabled()) {
logger.debug("Found " + resultNodes.size() + " disposition action definitions updates awaiting publishing.");
}
return resultNodes;
}
};
return retryingTransactionHelper.doInTransaction(execution, true);
}
Aggregations