use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class RecordCategoryChildrenRelation method create.
@Override
@WebApiDescription(title = "Create one (or more) nodes as children of a record category identified by 'recordCategoryId'")
public List<RecordCategoryChild> create(String recordCategoryId, List<RecordCategoryChild> nodeInfos, Parameters parameters) {
checkNotBlank("recordCategoryId", recordCategoryId);
mandatory("nodeInfos", nodeInfos);
mandatory("parameters", parameters);
NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordCategoryId, RecordsManagementModel.TYPE_RECORD_CATEGORY);
List<RecordCategoryChild> result = new ArrayList<>(nodeInfos.size());
Map<String, UserInfo> mapUserInfo = new HashMap<>();
RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>() {
public List<NodeRef> execute() {
List<NodeRef> createdNodes = new LinkedList<>();
for (RecordCategoryChild nodeInfo : nodeInfos) {
// Resolve the parent node
NodeRef nodeParent = parentNodeRef;
if (StringUtils.isNoneBlank(nodeInfo.getRelativePath())) {
nodeParent = apiUtils.lookupAndValidateRelativePath(parentNodeRef, nodeInfo.getRelativePath(), RecordsManagementModel.TYPE_RECORD_CATEGORY);
}
// Create the node
NodeRef newNode = apiUtils.createRMNode(nodeParent, nodeInfo, parameters);
createdNodes.add(newNode);
}
return createdNodes;
}
};
List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
for (NodeRef nodeInfo : createdNodes) {
FileInfo info = fileFolderService.getFileInfo(nodeInfo);
result.add(nodesModelFactory.createRecordCategoryChild(info, parameters, mapUserInfo, false));
}
return result;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class RecordFolderChildrenRelation 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 Record create(String recordFolderId, FormData formData, Parameters parameters, WithResponse withResponse) {
checkNotBlank("recordFolderId", recordFolderId);
mandatory("formData", formData);
mandatory("parameters", parameters);
// Retrieve the input data and resolve the parent node
final UploadInfo uploadInfo = new UploadInfo(formData);
final NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER, uploadInfo.getRelativePath());
// Create the record
RetryingTransactionCallback<NodeRef> callback = new RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() {
return apiUtils.uploadRecord(parentNodeRef, uploadInfo, parameters);
}
};
NodeRef newNode = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
// Get file info for response
FileInfo info = fileFolderService.getFileInfo(newNode);
apiUtils.postActivity(info, parentNodeRef, ActivityType.FILE_ADDED);
return nodesModelFactory.createRecord(info, parameters, null, false);
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class TransferContainerEntityResource method update.
@Override
@WebApiDescription(title = "Update transfer container", description = "Updates a transfer container with id 'transferContainerId'")
public TransferContainer update(String transferContainerId, TransferContainer transferContainerInfo, Parameters parameters) {
checkNotBlank("transferContainerId", transferContainerId);
mandatory("transferContainerInfo", transferContainerInfo);
mandatory("parameters", parameters);
NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(transferContainerId, RecordsManagementModel.TYPE_TRANSFER_CONTAINER);
// update info
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {
public Void execute() {
apiUtils.updateTransferContainer(nodeRef, transferContainerInfo, 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);
return nodesModelFactory.createTransferContainer(info, parameters, null, false);
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class FilesEntityResource method declareAsRecord.
@Operation("declare")
@WebApiDescription(title = "Declare as record", description = "Declare a file as record.")
public Record declareAsRecord(String fileId, Void body, Parameters parameters, WithResponse withResponse) {
// Get fileplan
NodeRef filePlan = authenticationUtil.runAsSystem(new RunAsWork<NodeRef>() {
@Override
public NodeRef doWork() {
return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
}
});
// default false (if not provided)
boolean hideRecord = Boolean.valueOf(parameters.getParameter(Record.PARAM_HIDE_RECORD));
// Create the record
NodeRef file = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, fileId);
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {
public Void execute() {
recordService.createRecord(filePlan, file, !hideRecord);
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
// Return record state
FileInfo info = fileFolderService.getFileInfo(file);
return nodesModelFactory.createRecord(info, parameters, null, false);
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class DynamicAuthoritiesGetUnitTest method before.
/**
* Before test
*/
@SuppressWarnings("unchecked")
@Before
public void before() {
MockitoAnnotations.initMocks(this);
webScript.setNodeService(mockedNodeService);
webScript.setPermissionService(mockedPermissionService);
webScript.setExtendedSecurityService(mockedExtendedSecurityService);
webScript.setFileFolderService(mockedFileFolderService);
// setup retrying transaction helper
Answer<Object> doInTransactionAnswer = new Answer<Object>() {
@SuppressWarnings("rawtypes")
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
RetryingTransactionCallback callback = (RetryingTransactionCallback) invocation.getArguments()[0];
return callback.execute();
}
};
doAnswer(doInTransactionAnswer).when(mockedRetryingTransactionHelper).<Object>doInTransaction(any(RetryingTransactionCallback.class), anyBoolean(), anyBoolean());
when(mockedTransactionService.getRetryingTransactionHelper()).thenReturn(mockedRetryingTransactionHelper);
// max node id
when(mockedPatchDAO.getMaxAdmNodeID()).thenReturn(500000L);
// aspect
when(mockedQnameDAO.getQName(ASPECT_EXTENDED_SECURITY)).thenReturn(new Pair<Long, QName>(ASPECT_ID, ASPECT));
}
Aggregations