Search in sources :

Example 36 with RetryingTransactionCallback

use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.

the class RecordFolderEntityResource method update.

@Override
@WebApiDescription(title = "Update record folder", description = "Updates a record folder with id 'recordFolderId'")
public RecordFolder update(String recordFolderId, RecordFolder recordFolderInfo, Parameters parameters) {
    checkNotBlank("recordFolderId", recordFolderId);
    mandatory("recordFolderInfo", recordFolderInfo);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER);
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            apiUtils.updateNode(nodeRef, recordFolderInfo, parameters);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>() {

        public FileInfo execute() {
            return fileFolderService.getFileInfo(nodeRef);
        }
    };
    FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
    return nodesModelFactory.createRecordFolder(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 37 with RetryingTransactionCallback

use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.

the class UnfiledContainerChildrenRelation method create.

@Override
@WebApiDescription(title = "Upload file content and meta-data into a unfiled record container identified by 'unfiledContainerId'.")
@WebApiParam(name = "formData", title = "A single form data", description = "A single form data which holds FormFields.")
public UnfiledContainerChild create(String unfiledContainerId, FormData formData, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("unfiledContainerId", unfiledContainerId);
    mandatory("formData", formData);
    mandatory("parameters", parameters);
    UploadInfo uploadInfo = new UploadInfo(formData);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
    RetryingTransactionCallback<NodeRef> callback = new RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() {
            return apiUtils.uploadRecord(parentNodeRef, uploadInfo, parameters);
        }
    };
    NodeRef newNode = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // Get file info for response
    FileInfo info = fileFolderService.getFileInfo(newNode);
    apiUtils.postActivity(info, parentNodeRef, ActivityType.FILE_ADDED);
    return nodesModelFactory.createUnfiledContainerChild(info, parameters, null, false);
}
Also used : UploadInfo(org.alfresco.rm.rest.api.model.UploadInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Example 38 with RetryingTransactionCallback

use of org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback in project records-management by Alfresco.

the class UnfiledRecordFolderEntityResource method update.

@Override
@WebApiDescription(title = "Update unfiled record folder", description = "Updates an unfiled record folder with id 'unfiledRecordFolderId'")
public UnfiledRecordFolder update(String unfiledRecordFolderId, UnfiledRecordFolder unfiledRecordFolderInfo, Parameters parameters) {
    checkNotBlank("unfiledRecordFolderId", unfiledRecordFolderId);
    mandatory("unfiledRecordFolderInfo", unfiledRecordFolderInfo);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(unfiledRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER);
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            apiUtils.updateNode(nodeRef, unfiledRecordFolderInfo, parameters);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>() {

        public FileInfo execute() {
            return fileFolderService.getFileInfo(nodeRef);
        }
    };
    FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
    apiUtils.postActivity(info, unfiledRecordFolderInfo.getParentId(), ActivityType.FILE_UPDATED);
    return nodesModelFactory.createUnfiledRecordFolder(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 39 with RetryingTransactionCallback

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

the class DocumentDetailsDialog method applyVersionable.

/**
 * Applies the versionable aspect to the current document
 */
public void applyVersionable() {
    try {
        FacesContext context = FacesContext.getCurrentInstance();
        RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
        RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>() {

            public Object execute() throws Throwable {
                // add the versionable aspect to the node
                getNodeService().addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_VERSIONABLE, null);
                return null;
            }
        };
        txnHelper.doInTransaction(callback);
        // reset the state of the current document
        getDocument().reset();
        // get hold of the main property sheet on the page and remove the children to force a refresh
        UIComponent comp = context.getViewRoot().findComponent("dialog:dialog-body:document-props");
        if (comp != null) {
            comp.getChildren().clear();
        }
    } catch (Throwable e) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_ERROR_ASPECT_VERSIONING), 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) UIComponent(javax.faces.component.UIComponent)

Example 40 with RetryingTransactionCallback

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

the class DeleteCategoryDialog method finishDelete.

public String finishDelete() {
    String outcome = DEFAULT_OUTCOME;
    if (getActionCategory() != null) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
            RetryingTransactionCallback<NodeRef> callback = new RetryingTransactionCallback<NodeRef>() {

                @SuppressWarnings("unchecked")
                public NodeRef execute() throws Throwable {
                    // delete the category node using the nodeservice
                    NodeRef categoryNodeRef = getActionCategory().getNodeRef();
                    getCategoryService().deleteCategory(categoryNodeRef);
                    // all the associations to the category should be removed too
                    if (getMembers() != null && getMembers().size() > 0) {
                        for (ChildAssociationRef childRef : getMembers()) {
                            List<NodeRef> list = new ArrayList<NodeRef>(getMembers().size());
                            NodeRef member = childRef.getChildRef();
                            Collection<NodeRef> categories = (Collection<NodeRef>) getNodeService().getProperty(member, ContentModel.PROP_CATEGORIES);
                            for (NodeRef category : categories) {
                                if (category.equals(categoryNodeRef) == false) {
                                    list.add(category);
                                }
                            }
                            // persist the list back to the repository
                            getNodeService().setProperty(member, ContentModel.PROP_CATEGORIES, (Serializable) list);
                        }
                    }
                    return categoryNodeRef;
                }
            };
            NodeRef categoryNodeRef = txnHelper.doInTransaction(callback);
            // Figure out if the deletion is made by an icon or by a list of actions
            CategoriesDialog categoriesDialog = (CategoriesDialog) UIContextService.getInstance(FacesContext.getCurrentInstance()).getRegisteredBean(CategoriesDialog.CATEGORIES_DIALOG_CLASS_NAME);
            setLocation(categoriesDialog.getLocation());
            List<IBreadcrumbHandler> location = getLocation();
            CategoryBreadcrumbHandler handler = (CategoryBreadcrumbHandler) location.get(location.size() - 1);
            setCategoryFlag(!handler.toString().equals(getCategory().getName()));
            // clear action context
            setActionCategory(null);
        } catch (Throwable err) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
            outcome = null;
            ReportedException.throwIfNecessary(err);
        }
    }
    return outcome;
}
Also used : FacesContext(javax.faces.context.FacesContext) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) IBreadcrumbHandler(org.alfresco.web.ui.common.component.IBreadcrumbHandler) ArrayList(java.util.ArrayList) CategoryBreadcrumbHandler(org.alfresco.web.bean.categories.CategoriesDialog.CategoryBreadcrumbHandler) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) Collection(java.util.Collection)

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