use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class EditSearchDialog method saveEditSearchOK.
public String saveEditSearchOK(FacesContext newContext, String newOutcome) {
String outcome = newOutcome;
final SearchContext search = this.navigator.getSearchContext();
if (search != null) {
try {
final FacesContext context = newContext;
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// handle Edit e.g. Overwrite of existing search
// detect if was previously selected saved search (e.g.
// NodeRef not null)
NodeRef searchRef = new NodeRef(Repository.getStoreRef(), properties.getSavedSearch());
if (getNodeService().exists(searchRef)) {
Map<QName, Serializable> props = getNodeService().getProperties(searchRef);
props.put(ContentModel.PROP_NAME, properties.getSearchName());
props.put(ContentModel.PROP_DESCRIPTION, properties.getSearchDescription());
getNodeService().setProperties(searchRef, props);
ContentService contentService = Repository.getServiceRegistry(context).getContentService();
ContentWriter writer = contentService.getWriter(searchRef, ContentModel.PROP_CONTENT, true);
// get a writer to our new node ready for XML
// content
writer.setMimetype(MimetypeMap.MIMETYPE_XML);
writer.setEncoding("UTF-8");
// output an XML serialized version of the
// SearchContext object
writer.putContent(search.toXML());
}
return null;
}
};
callback.execute();
properties.getCachedSavedSearches().clear();
properties.setSavedSearch(null);
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(newContext, MSG_ERROR_SAVE_SEARCH), e.getMessage()), e);
outcome = null;
this.isFinished = false;
ReportedException.throwIfNecessary(e);
}
}
return outcome;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class DocumentDetailsDialog method unlock.
/**
* Action Handler to unlock a locked document
*/
public void unlock(final ActionEvent event) {
final FacesContext fc = FacesContext.getCurrentInstance();
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
getLockService().unlock(getNode().getNodeRef());
String msg = Application.getMessage(fc, MSG_SUCCESS_UNLOCK);
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg);
String formId = Utils.getParentForm(fc, event.getComponent()).getClientId(fc);
fc.addMessage(formId + ':' + getPropertiesPanelId(), facesMsg);
getNode().reset();
return null;
}
};
txnHelper.doInTransaction(callback);
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(fc, Repository.ERROR_GENERIC), e.getMessage()), e);
ReportedException.throwIfNecessary(e);
}
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class DocumentDetailsDialog method applyInlineEditable.
/**
* Applies the inlineeditable aspect to the current document
*/
public String applyInlineEditable() {
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// add the inlineeditable aspect to the node
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1, 1.0f);
String contentType = null;
ContentData contentData = (ContentData) getDocument().getProperties().get(ContentModel.PROP_CONTENT);
if (contentData != null) {
contentType = contentData.getMimetype();
}
if (contentType != null) {
// set the property to true by default if the filetype is a known content type
if (MimetypeMap.MIMETYPE_HTML.equals(contentType) || MimetypeMap.MIMETYPE_TEXT_PLAIN.equals(contentType) || MimetypeMap.MIMETYPE_XML.equals(contentType) || MimetypeMap.MIMETYPE_TEXT_CSS.equals(contentType) || MimetypeMap.MIMETYPE_JAVASCRIPT.equals(contentType)) {
props.put(ApplicationModel.PROP_EDITINLINE, true);
}
}
getNodeService().addAspect(getDocument().getNodeRef(), ApplicationModel.ASPECT_INLINEEDITABLE, props);
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_INLINEEDITABLE), e.getMessage()), e);
ReportedException.throwIfNecessary(e);
}
// force recreation of the details view - this means the properties sheet component will reinit
return OUTCOME_RETURN;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback 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.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class CreateDiscussionDialog method deleteTopic.
/**
* Deletes the setup performed during the initialisation of the dialog.
*/
protected void deleteTopic() {
RetryingTransactionCallback<Object> deleteTopicCallback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// remove this node from the breadcrumb if required
Node forumNode = navigator.getCurrentNode();
browseBean.removeSpaceFromBreadcrumb(forumNode);
// remove the discussable aspect from the node we were going to discuss!
// AWC-1519: removing the aspect that defines the child association now does the
// cascade delete so we no longer have to delete the child explicitly
getNodeService().removeAspect(discussingNodeRef, ForumModel.ASPECT_DISCUSSABLE);
// Done
return null;
}
};
FacesContext context = FacesContext.getCurrentInstance();
try {
getTransactionService().getRetryingTransactionHelper().doInTransaction(deleteTopicCallback, false);
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, Repository.ERROR_GENERIC), e.getMessage()), e);
ReportedException.throwIfNecessary(e);
}
}
Aggregations