Search in sources :

Example 1 with RetryingTransactionHelper

use of org.alfresco.repo.transaction.RetryingTransactionHelper in project alfresco-remote-api by Alfresco.

the class InviteServiceTest method testInviteeResourcesNotDeletedUponRejectWhenInvitesPending.

public void testInviteeResourcesNotDeletedUponRejectWhenInvitesPending() throws Exception {
    // Test only applies to legacy invite workflow
    this.invitationServiceImpl.setNominatedInvitationWorkflowId(WorkflowModelNominatedInvitation.WORKFLOW_DEFINITION_NAME_ACTIVITI_INVITE);
    // Create invitee person
    final String inviteeEmail = INVITEE_EMAIL_PREFIX + RandomStringUtils.randomAlphanumeric(6) + "@" + INVITEE_EMAIL_DOMAIN;
    AuthenticationUtil.runAs(new RunAsWork<Object>() {

        public Object doWork() throws Exception {
            createPerson(INVITEE_FIRSTNAME, INVITEE_LASTNAME, INVITEE_FIRSTNAME + "_" + INVITEE_LASTNAME, inviteeEmail);
            return null;
        }
    }, AuthenticationUtil.getSystemUserName());
    // inviter invites invitee to site 1
    JSONObject result = startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeEmail, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_1, Status.STATUS_CREATED);
    // get hold of properties of started invite
    JSONObject data = result.getJSONObject("data");
    String invite1Id = data.getString("inviteId");
    String invite1Ticket = data.getString("inviteTicket");
    final String inviteeUserName = data.getString("inviteeUserName");
    // inviter invites invitee to site 2
    startInvite(INVITEE_FIRSTNAME, INVITEE_LASTNAME, inviteeEmail, INVITEE_SITE_ROLE, SITE_SHORT_NAME_INVITE_2, Status.STATUS_CREATED);
    rejectInvite(invite1Id, invite1Ticket, Status.STATUS_OK);
    boolean inviteeUserExists = AuthenticationUtil.runAs(new RunAsWork<Boolean>() {

        public Boolean doWork() throws Exception {
            RetryingTransactionHelper tranHelper = transactionService.getRetryingTransactionHelper();
            Boolean result = tranHelper.doInTransaction(new RetryingTransactionCallback<Boolean>() {

                public Boolean execute() throws Throwable {
                    Boolean result = mutableAuthenticationDao.userExists(inviteeUserName);
                    return result;
                }
            });
            return result;
        }
    }, AuthenticationUtil.getSystemUserName());
    // test that the invitee's user account still exists (has not been deleted
    assertEquals(true, inviteeUserExists);
    boolean inviteePersonExists = AuthenticationUtil.runAs(new RunAsWork<Boolean>() {

        public Boolean doWork() throws Exception {
            Boolean result = personService.personExists(inviteeUserName);
            return result;
        }
    }, AuthenticationUtil.getSystemUserName());
    assertEquals(true, inviteePersonExists);
    // Reset back to default
    this.invitationServiceImpl.setNominatedInvitationWorkflowId(WorkflowModelNominatedInvitation.WORKFLOW_DEFINITION_NAME_ACTIVITI_ADD_DIRECT);
}
Also used : JSONObject(org.json.JSONObject) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) JSONObject(org.json.JSONObject)

Example 2 with RetryingTransactionHelper

use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.

the class BaseDetailsBean method saveWorkflow.

/**
 * Saves the details of the workflow stored in workflowProperties
 * to the current node
 *
 * @return The outcome string
 */
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 3 with RetryingTransactionHelper

use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.

the class BaseDetailsBean method takeOwnership.

/**
 * Action Handler to take Ownership of the current node
 */
public void takeOwnership(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 {
                getOwnableService().takeOwnership(getNode().getNodeRef());
                String msg = Application.getMessage(fc, MSG_SUCCESS_OWNERSHIP);
                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);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) FacesMessage(javax.faces.application.FacesMessage)

Example 4 with RetryingTransactionHelper

use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.

the class BaseDetailsBean method reject.

/**
 * Event handler called to handle the approve step of the simple workflow
 *
 * @param event The event that was triggered
 */
public void reject(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("reject 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 reject
                WorkflowUtil.reject(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) {
        // rollback the transaction
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_WORKFLOW_REJECT), e.getMessage()), e);
        ReportedException.throwIfNecessary(e);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) UIActionLink(org.alfresco.web.ui.common.component.UIActionLink) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 5 with RetryingTransactionHelper

use of org.alfresco.repo.transaction.RetryingTransactionHelper in project acs-community-packaging by Alfresco.

the class ImportDialog method performImport.

/**
 * Performs the import operation using the current state of the bean
 *
 * @return The outcome
 */
public String performImport(final FacesContext context, String outcome) {
    if (logger.isDebugEnabled())
        logger.debug("Called import for file: " + this.file);
    if (this.file != null && this.file.exists()) {
        // check the file actually has contents
        if (this.file.length() > 0) {
            try {
                RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
                RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

                    public Object execute() throws Throwable {
                        // first of all we need to add the uploaded ACP/ZIP file to the repository
                        NodeRef acpNodeRef = addFileToRepository(context);
                        // build the action params map based on the bean's current state
                        Map<String, Serializable> params = new HashMap<String, Serializable>(2, 1.0f);
                        params.put(ImporterActionExecuter.PARAM_DESTINATION_FOLDER, browseBean.getActionSpace().getNodeRef());
                        params.put(ImporterActionExecuter.PARAM_ENCODING, encoding);
                        // build the action to execute
                        Action action = getActionService().createAction(ImporterActionExecuter.NAME, params);
                        if (action instanceof ImporterActionExecuter) {
                            ((ImporterActionExecuter) action).setHighByteZip(highByteZip);
                        }
                        action.setExecuteAsynchronously(runInBackground);
                        // execute the action on the ACP file
                        getActionService().executeAction(action, acpNodeRef);
                        if (logger.isDebugEnabled()) {
                            logger.debug("Executed import action with action params of " + params);
                        }
                        return null;
                    }
                };
                txnHelper.doInTransaction(callback);
                // reset the bean
                reset();
            } catch (Throwable e) {
                if (e instanceof DuplicateChildNodeNameException) {
                    String name = ((DuplicateChildNodeNameException) e).getName();
                    String err_mess = MessageFormat.format(I18NUtil.getMessage(ERR_DUPLICATE_NAME), name);
                    Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR), err_mess), e);
                } else {
                    Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR), e.toString()), e);
                }
                outcome = null;
                ReportedException.throwIfNecessary(e);
            }
        } else {
            Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_EMPTY_FILE));
            outcome = null;
        }
    } else {
        Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_NO_FILE));
        outcome = null;
    }
    return outcome;
}
Also used : DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) Serializable(java.io.Serializable) Action(org.alfresco.service.cmr.action.Action) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) HashMap(java.util.HashMap) ImporterActionExecuter(org.alfresco.repo.action.executer.ImporterActionExecuter) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

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