use of org.alfresco.repo.transaction.RetryingTransactionHelper 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 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 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);
}
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.
the class Repository method getNamePathEx.
/**
* Resolve a Path by converting each element into its display NAME attribute.
* Note: This method resolves path regardless access permissions.
* Fixes the UI part of the ETWOONE-214 and ETWOONE-238 issues
*
* @param path Path to convert
* @param separator Separator to user between path elements
* @param prefix To prepend to the path
*
* @return Path converted using NAME attribute on each element
*/
public static String getNamePathEx(FacesContext context, final Path path, final NodeRef rootNode, final String separator, final String prefix) {
String result = null;
RetryingTransactionHelper transactionHelper = getRetryingTransactionHelper(context);
transactionHelper.setMaxRetries(1);
final NodeService runtimeNodeService = (NodeService) FacesContextUtils.getRequiredWebApplicationContext(context).getBean("nodeService");
result = transactionHelper.doInTransaction(new RetryingTransactionCallback<String>() {
public String execute() throws Throwable {
return getNamePath(runtimeNodeService, path, rootNode, separator, prefix);
}
});
return result;
}
use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.
the class User method getUserPreferencesRef.
/**
* Get or create the node used to store user preferences.
* Utilises the 'configurable' aspect on the Person linked to this user.
*/
synchronized NodeRef getUserPreferencesRef(WebApplicationContext context) {
final ServiceRegistry registry = (ServiceRegistry) context.getBean("ServiceRegistry");
final NodeService nodeService = registry.getNodeService();
final SearchService searchService = registry.getSearchService();
final NamespaceService namespaceService = registry.getNamespaceService();
final TransactionService txService = registry.getTransactionService();
final ConfigurableService configurableService = (ConfigurableService) context.getBean("ConfigurableService");
RetryingTransactionHelper txnHelper = registry.getTransactionService().getRetryingTransactionHelper();
return txnHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>() {
public NodeRef execute() throws Throwable {
NodeRef prefRef = null;
NodeRef person = getPerson();
if (nodeService.hasAspect(person, ApplicationModel.ASPECT_CONFIGURABLE) == false) {
// if the repository is in read-only mode just return null
if (txService.isReadOnly()) {
return null;
} else {
// create the configuration folder for this Person node
configurableService.makeConfigurable(person);
}
}
// target of the assoc is the configurations folder ref
NodeRef configRef = configurableService.getConfigurationFolder(person);
if (configRef == null) {
throw new IllegalStateException("Unable to find associated 'configurations' folder for node: " + person);
}
String xpath = NamespaceService.APP_MODEL_PREFIX + ":" + "preferences";
List<NodeRef> nodes = searchService.selectNodes(configRef, xpath, null, namespaceService, false);
if (nodes.size() == 1) {
prefRef = nodes.get(0);
} else {
// create the preferences Node for this user (if repo is not read-only)
if (txService.isReadOnly() == false) {
ChildAssociationRef childRef = nodeService.createNode(configRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "preferences"), ContentModel.TYPE_CMOBJECT);
prefRef = childRef.getChildRef();
}
}
return prefRef;
}
}, txService.isReadOnly());
}
Aggregations