use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback 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);
}
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class CheckinCheckoutDialog method checkinFileOK.
/**
* Action called upon completion of the Check In file page
*/
public String checkinFileOK(final FacesContext context, String outcome) {
// NOTE: for checkin the document node _is_ the working document!
final Node node = property.getDocument();
if (node != null && (property.getCopyLocation().equals(CCProperties.COPYLOCATION_CURRENT) || (this.getFileName() != null && !this.getFileName().equals("")))) {
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 checkin content node Id: " + node.getId());
// we can either checkin the content from the current working copy node
// which would have been previously updated by the user
String contentUrl;
if (property.getCopyLocation().equals(CCProperties.COPYLOCATION_CURRENT)) {
ContentData contentData = (ContentData) node.getProperties().get(ContentModel.PROP_CONTENT);
contentUrl = (contentData == null ? null : contentData.getContentUrl());
} else // or specify a specific file as the content instead
{
// add the content to an anonymous but permanent writer location
// we can then retrieve the URL to the content to to be set on the node during checkin
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());
contentUrl = writer.getContentUrl();
}
if (contentUrl == null || contentUrl.length() == 0) {
throw new IllegalStateException("Content URL is empty for specified working copy content node!");
}
// add version history text to props
Map<String, Serializable> props = new HashMap<String, Serializable>(1, 1.0f);
props.put(Version.PROP_DESCRIPTION, property.getVersionNotes());
// set the flag for minor or major change
if (property.getMinorChange()) {
props.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
} else {
props.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
}
// perform the checkin
property.getVersionOperationsService().checkin(node.getNodeRef(), props, contentUrl, property.getKeepCheckedOut());
return null;
}
};
txnHelper.doInTransaction(callback);
outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
if (property.isWorkflowAction() == false) {
outcome = outcome + AlfrescoNavigationHandler.OUTCOME_SEPARATOR + "browse";
}
// clear action context
property.setDocument(null);
resetState();
} catch (Throwable err) {
Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_CHECKIN) + err.getMessage(), err);
ReportedException.throwIfNecessary(err);
}
} else {
logger.warn("WARNING: checkinFileOK called without a current Document!");
}
return outcome;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class SaveSearchDialog method saveNewSearchOK.
public String saveNewSearchOK(FacesContext newContext, String newOutcome) {
String outcome = newOutcome;
NodeRef searchesRef;
if (properties.isSearchSaveGlobal()) {
searchesRef = getGlobalSearchesRef();
} else {
searchesRef = getUserSearchesRef();
}
final SearchContext search = this.navigator.getSearchContext();
if (searchesRef != null && search != null) {
try {
// FacesContext.getCurrentInstance();
final FacesContext context = newContext;
final NodeRef searchesRefFinal = searchesRef;
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// create new content node as the saved search object
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
props.put(ContentModel.PROP_NAME, properties.getSearchName());
props.put(ContentModel.PROP_DESCRIPTION, properties.getSearchDescription());
ChildAssociationRef childRef = getNodeService().createNode(searchesRefFinal, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.ALFRESCO_URI, QName.createValidLocalName(properties.getSearchName())), ContentModel.TYPE_CONTENT, props);
ContentService contentService = Repository.getServiceRegistry(context).getContentService();
ContentWriter writer = contentService.getWriter(childRef.getChildRef(), 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 EditSimpleWorkflowDialog method saveWorkflow.
public String saveWorkflow() {
String outcome = "cancel";
try {
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(FacesContext.getCurrentInstance());
RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// firstly retrieve all the properties for the current node
Map<QName, Serializable> updateProps = getNodeService().getProperties(getNode().getNodeRef());
// update the simple workflow properties
// set the approve step name
updateProps.put(ApplicationModel.PROP_APPROVE_STEP, workflowProperties.get(SimpleWorkflowHandler.PROP_APPROVE_STEP_NAME));
// specify whether the approve step will copy or move the content
boolean approveMove = true;
String approveAction = (String) workflowProperties.get(SimpleWorkflowHandler.PROP_APPROVE_ACTION);
if (approveAction != null && approveAction.equals("copy")) {
approveMove = false;
}
updateProps.put(ApplicationModel.PROP_APPROVE_MOVE, Boolean.valueOf(approveMove));
// create node ref representation of the destination folder
updateProps.put(ApplicationModel.PROP_APPROVE_FOLDER, workflowProperties.get(SimpleWorkflowHandler.PROP_APPROVE_FOLDER));
// determine whether there should be a reject step
boolean requireReject = true;
String rejectStepPresent = (String) workflowProperties.get(SimpleWorkflowHandler.PROP_REJECT_STEP_PRESENT);
if (rejectStepPresent != null && rejectStepPresent.equals("no")) {
requireReject = false;
}
if (requireReject) {
// set the reject step name
updateProps.put(ApplicationModel.PROP_REJECT_STEP, workflowProperties.get(SimpleWorkflowHandler.PROP_REJECT_STEP_NAME));
// specify whether the reject step will copy or move the content
boolean rejectMove = true;
String rejectAction = (String) workflowProperties.get(SimpleWorkflowHandler.PROP_REJECT_ACTION);
if (rejectAction != null && rejectAction.equals("copy")) {
rejectMove = false;
}
updateProps.put(ApplicationModel.PROP_REJECT_MOVE, Boolean.valueOf(rejectMove));
// create node ref representation of the destination folder
updateProps.put(ApplicationModel.PROP_REJECT_FOLDER, workflowProperties.get(SimpleWorkflowHandler.PROP_REJECT_FOLDER));
} else {
// set all the reject properties to null to signify there should
// be no reject step
updateProps.put(ApplicationModel.PROP_REJECT_STEP, null);
updateProps.put(ApplicationModel.PROP_REJECT_MOVE, null);
updateProps.put(ApplicationModel.PROP_REJECT_FOLDER, null);
}
// set the properties on the node
getNodeService().setProperties(getNode().getNodeRef(), updateProps);
return null;
}
};
txnHelper.doInTransaction(callback);
// reset the state of the current node so it reflects the changes just made
getNode().reset();
outcome = "finish";
} catch (Throwable e) {
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_UPDATE_SIMPLEWORKFLOW), e.getMessage()), e);
ReportedException.throwIfNecessary(e);
}
return outcome;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project acs-community-packaging by Alfresco.
the class UsersBeanProperties method setPerson.
/**
* @param p The person context to set.
*/
public void setPerson(final Node p) {
// perform the set in a txn as certain bean calls require it
FacesContext context = FacesContext.getCurrentInstance();
RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
RetryingTransactionCallback callback = new RetryingTransactionCallback() {
public Object execute() throws Throwable {
person = p;
userName = (String) person.getProperties().get(ContentModel.PROP_USERNAME);
// rebuild the property immutability map helper object
immutabilty = new PropertyImmutabilityMap(getUserRegistrySynchronizer().getPersonMappedProperties(userName));
return null;
}
};
try {
txnHelper.doInTransaction(callback, false);
} catch (Throwable e) {
// reset the flag so we can re-attempt the operation
if (e instanceof ReportedException == false) {
Utils.addErrorMessage(e.getMessage(), e);
}
ReportedException.throwIfNecessary(e);
}
}
Aggregations