use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.
the class DocumentDetailsDialog method applyClassifiable.
/**
* Applies the classifiable aspect to the current document
*/
public void applyClassifiable() {
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// add the general classifiable aspect to the node
getNodeService().addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, null);
return null;
}
};
txnHelper.doInTransaction(callback);
// reset the state of the current document
getDocument().reset();
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_CLASSIFY), e.getMessage()), e);
ReportedException.throwIfNecessary(e);
}
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.
the class CheckinCheckoutDialog method updateFileOK.
/**
* Action called upon completion of the Update File page
*/
public String updateFileOK(final FacesContext context, String outcome) {
// NOTE: for update the document node _is_ the working document!
final Node node = property.getDocument();
if (node != null && this.getFileName() != null) {
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
if (logger.isDebugEnabled())
logger.debug("Trying to update content node Id: " + node.getId());
// get an updating writer that we can use to modify the content on the current node
ContentWriter writer = property.getContentService().getWriter(node.getNodeRef(), ContentModel.PROP_CONTENT, true);
// also update the mime type in case a different type of file is uploaded
String mimeType = Repository.getMimeTypeForFileName(context, property.getFileName());
writer.setMimetype(mimeType);
writer.putContent(property.getFile());
return null;
}
};
txnHelper.doInTransaction(callback);
// clear action context
property.setDocument(null);
resetState();
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
} catch (Throwable err) {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE) + err.getMessage(), err);
ReportedException.throwIfNecessary(err);
}
} else {
logger.warn("WARNING: updateFileOK called without a current Document!");
}
return outcome;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper 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 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;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.
the class BaseDetailsBean method approve.
/**
* Event handler called to handle the approve step of the simple workflow
*
* @param event The event that was triggered
*/
public void approve(ActionEvent event) {
UIActionLink link = (UIActionLink) event.getComponent();
Map<String, String> params = link.getParameterMap();
String id = params.get("id");
if (id == null || id.length() == 0) {
throw new AlfrescoRuntimeException("approve called without an id");
}
final NodeRef docNodeRef = new NodeRef(Repository.getStoreRef(), id);
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// call the service to perform the approve
WorkflowUtil.approve(docNodeRef, getNodeService(), getCopyService());
return null;
}
};
txnHelper.doInTransaction(callback);
// if this was called via the node details dialog we need to reset the node
if (getNode() != null) {
getNode().reset();
}
// also make sure the UI will get refreshed
UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_WORKFLOW_APPROVE), e.getMessage()), e);
ReportedException.throwIfNecessary(e);
}
}
Aggregations