Search in sources :

Example 21 with RetryingTransactionCallback

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;
}
Also used : FacesContext(javax.faces.context.FacesContext) Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ContentService(org.alfresco.service.cmr.repository.ContentService) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)

Example 22 with RetryingTransactionCallback

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);
    }
}
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 23 with RetryingTransactionCallback

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

Example 24 with RetryingTransactionCallback

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

Example 25 with RetryingTransactionCallback

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

Aggregations

RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)78 NodeRef (org.alfresco.service.cmr.repository.NodeRef)44 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)20 FileInfo (org.alfresco.service.cmr.model.FileInfo)20 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)16 HashMap (java.util.HashMap)15 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)15 FacesContext (javax.faces.context.FacesContext)12 QName (org.alfresco.service.namespace.QName)11 Serializable (java.io.Serializable)10 List (java.util.List)9 ArrayList (java.util.ArrayList)8 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)8 IOException (java.io.IOException)7 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)7 Test (org.junit.Test)7 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)7 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 AbstractList (java.util.AbstractList)5