use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class RecordFolderEntityResource method update.
@Override
@WebApiDescription(title = "Update record folder", description = "Updates a record folder with id 'recordFolderId'")
public RecordFolder update(String recordFolderId, RecordFolder recordFolderInfo, Parameters parameters) {
checkNotBlank("recordFolderId", recordFolderId);
mandatory("recordFolderInfo", recordFolderInfo);
mandatory("parameters", parameters);
NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER);
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {
public Void execute() {
apiUtils.updateNode(nodeRef, recordFolderInfo, 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.createRecordFolder(info, parameters, null, false);
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class UnfiledContainerChildrenRelation method create.
@Override
@WebApiDescription(title = "Upload file content and meta-data into a unfiled record container identified by 'unfiledContainerId'.")
@WebApiParam(name = "formData", title = "A single form data", description = "A single form data which holds FormFields.")
public UnfiledContainerChild create(String unfiledContainerId, FormData formData, Parameters parameters, WithResponse withResponse) {
checkNotBlank("unfiledContainerId", unfiledContainerId);
mandatory("formData", formData);
mandatory("parameters", parameters);
UploadInfo uploadInfo = new UploadInfo(formData);
NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
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.createUnfiledContainerChild(info, parameters, null, false);
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.
the class UnfiledRecordFolderEntityResource method update.
@Override
@WebApiDescription(title = "Update unfiled record folder", description = "Updates an unfiled record folder with id 'unfiledRecordFolderId'")
public UnfiledRecordFolder update(String unfiledRecordFolderId, UnfiledRecordFolder unfiledRecordFolderInfo, Parameters parameters) {
checkNotBlank("unfiledRecordFolderId", unfiledRecordFolderId);
mandatory("unfiledRecordFolderInfo", unfiledRecordFolderInfo);
mandatory("parameters", parameters);
NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(unfiledRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER);
RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {
public Void execute() {
apiUtils.updateNode(nodeRef, unfiledRecordFolderInfo, 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, unfiledRecordFolderInfo.getParentId(), ActivityType.FILE_UPDATED);
return nodesModelFactory.createUnfiledRecordFolder(info, parameters, null, false);
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class DocumentDetailsDialog method applyVersionable.
/**
* Applies the versionable aspect to the current document
*/
public void applyVersionable() {
try {
FacesContext context = FacesContext.getCurrentInstance();
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// add the versionable aspect to the node
getNodeService().addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_VERSIONABLE, null);
return null;
}
};
txnHelper.doInTransaction(callback);
// reset the state of the current document
getDocument().reset();
// get hold of the main property sheet on the page and remove the children to force a refresh
UIComponent comp = context.getViewRoot().findComponent("dialog:dialog-body:document-props");
if (comp != null) {
comp.getChildren().clear();
}
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_VERSIONING), e.getMessage()), e);
ReportedException.throwIfNecessary(e);
}
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class DeleteCategoryDialog method finishDelete.
public String finishDelete() {
String outcome = DEFAULT_OUTCOME;
if (getActionCategory() != null) {
try {
FacesContext context = FacesContext.getCurrentInstance();
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
RetryingTransactionCallback<NodeRef> callback = new RetryingTransactionCallback<NodeRef>() {
@SuppressWarnings("unchecked")
public NodeRef execute() throws Throwable {
// delete the category node using the nodeservice
NodeRef categoryNodeRef = getActionCategory().getNodeRef();
getCategoryService().deleteCategory(categoryNodeRef);
// all the associations to the category should be removed too
if (getMembers() != null && getMembers().size() > 0) {
for (ChildAssociationRef childRef : getMembers()) {
List<NodeRef> list = new ArrayList<NodeRef>(getMembers().size());
NodeRef member = childRef.getChildRef();
Collection<NodeRef> categories = (Collection<NodeRef>) getNodeService().getProperty(member, ContentModel.PROP_CATEGORIES);
for (NodeRef category : categories) {
if (category.equals(categoryNodeRef) == false) {
list.add(category);
}
}
// persist the list back to the repository
getNodeService().setProperty(member, ContentModel.PROP_CATEGORIES, (Serializable) list);
}
}
return categoryNodeRef;
}
};
NodeRef categoryNodeRef = txnHelper.doInTransaction(callback);
// Figure out if the deletion is made by an icon or by a list of actions
CategoriesDialog categoriesDialog = (CategoriesDialog) UIContextService.getInstance(FacesContext.getCurrentInstance()).getRegisteredBean(CategoriesDialog.CATEGORIES_DIALOG_CLASS_NAME);
setLocation(categoriesDialog.getLocation());
List<IBreadcrumbHandler> location = getLocation();
CategoryBreadcrumbHandler handler = (CategoryBreadcrumbHandler) location.get(location.size() - 1);
setCategoryFlag(!handler.toString().equals(getCategory().getName()));
// clear action context
setActionCategory(null);
} catch (Throwable err) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
outcome = null;
ReportedException.throwIfNecessary(err);
}
}
return outcome;
}
Aggregations