Search in sources :

Example 16 with RetryingTransactionHelper

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;
}
Also used : Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) HashMap(java.util.HashMap) Node(org.alfresco.web.bean.repository.Node) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ContentData(org.alfresco.service.cmr.repository.ContentData) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Example 17 with RetryingTransactionHelper

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;
}
Also used : Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) QName(org.alfresco.service.namespace.QName)

Example 18 with RetryingTransactionHelper

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);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) ReportedException(org.alfresco.web.ui.common.ReportedException)

Example 19 with RetryingTransactionHelper

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;
}
Also used : RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) NodeService(org.alfresco.service.cmr.repository.NodeService)

Example 20 with RetryingTransactionHelper

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());
}
Also used : TransactionService(org.alfresco.service.transaction.TransactionService) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) NodeService(org.alfresco.service.cmr.repository.NodeService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NamespaceService(org.alfresco.service.namespace.NamespaceService) SearchService(org.alfresco.service.cmr.search.SearchService) List(java.util.List) ServiceRegistry(org.alfresco.service.ServiceRegistry) ConfigurableService(org.alfresco.repo.configuration.ConfigurableService)

Aggregations

RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)25 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)20 FacesContext (javax.faces.context.FacesContext)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)5 QName (org.alfresco.service.namespace.QName)5 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)3 NodeService (org.alfresco.service.cmr.repository.NodeService)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FacesMessage (javax.faces.application.FacesMessage)2 UserTransaction (javax.transaction.UserTransaction)2 ServiceRegistry (org.alfresco.service.ServiceRegistry)2 ContentData (org.alfresco.service.cmr.repository.ContentData)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 TransactionService (org.alfresco.service.transaction.TransactionService)2 Node (org.alfresco.web.bean.repository.Node)2