Search in sources :

Example 66 with RetryingTransactionCallback

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

the class UnfiledContainerEntityResource method update.

@Override
@WebApiDescription(title = "Update unfiled record container", description = "Updates an unfiled record container with id 'unfiledContainerId'")
public UnfiledContainer update(String unfiledContainerId, UnfiledContainer unfiledContainerInfo, Parameters parameters) {
    checkNotBlank("unfiledContainerId", unfiledContainerId);
    mandatory("unfiledContainerInfo", unfiledContainerInfo);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            apiUtils.updateNode(nodeRef, unfiledContainerInfo, 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, unfiledContainerInfo.getParentId(), ActivityType.FILE_UPDATED);
    return nodesModelFactory.createUnfiledContainer(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 67 with RetryingTransactionCallback

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

the class UnfiledRecordFolderChildrenRelation method create.

@Override
@WebApiDescription(title = "Upload file content and meta-data into the repository.")
@WebApiParam(name = "formData", title = "A single form data", description = "A single form data which holds FormFields.")
public UnfiledRecordFolderChild create(String unfiledRecordFolderId, FormData formData, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("unfiledRecordFolderId", unfiledRecordFolderId);
    mandatory("formData", formData);
    mandatory("parameters", parameters);
    // Retrieve the input data and resolve the parent node
    final UploadInfo uploadInfo = new UploadInfo(formData);
    // Create the record  - returns pair(newNode,parentNode)
    RetryingTransactionCallback<Pair<NodeRef, NodeRef>> callback = new RetryingTransactionCallback<Pair<NodeRef, NodeRef>>() {

        public Pair<NodeRef, NodeRef> execute() {
            final NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER, uploadInfo.getRelativePath());
            NodeRef newNode = apiUtils.uploadRecord(parentNodeRef, uploadInfo, parameters);
            return new Pair<NodeRef, NodeRef>(newNode, parentNodeRef);
        }
    };
    Pair<NodeRef, NodeRef> nodeAndParentInfo = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    NodeRef newNode = nodeAndParentInfo.getFirst();
    NodeRef parent = nodeAndParentInfo.getSecond();
    // Get file info for response
    FileInfo info = fileFolderService.getFileInfo(newNode);
    apiUtils.postActivity(info, parent, ActivityType.FILE_ADDED);
    return nodesModelFactory.createUnfiledRecordFolderChild(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) Pair(org.alfresco.util.Pair) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Example 68 with RetryingTransactionCallback

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

the class RecordFolderChildrenRelation method create.

@Override
@WebApiDescription(title = "Create one (or more) records as children of a record folder identified by 'recordFolderId'")
public List<Record> create(String recordFolderId, List<Record> nodeInfos, Parameters parameters) {
    checkNotBlank("recordFolderId", recordFolderId);
    mandatory("nodeInfos", nodeInfos);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER);
    RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>() {

        public List<NodeRef> execute() {
            List<NodeRef> createdNodes = new LinkedList<>();
            for (Record nodeInfo : nodeInfos) {
                NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo, parameters);
                createdNodes.add(newNodeRef);
            }
            return createdNodes;
        }
    };
    List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // Get the nodes info
    List<Record> result = new LinkedList<>();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    for (NodeRef newNodeRef : createdNodes) {
        FileInfo info = fileFolderService.getFileInfo(newNodeRef);
        apiUtils.postActivity(info, parentNodeRef, ActivityType.FILE_ADDED);
        result.add(nodesModelFactory.createRecord(info, parameters, mapUserInfo, false));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) UserInfo(org.alfresco.rest.api.model.UserInfo) LinkedList(java.util.LinkedList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) AbstractList(java.util.AbstractList) LinkedList(java.util.LinkedList) List(java.util.List) Record(org.alfresco.rm.rest.api.model.Record) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 69 with RetryingTransactionCallback

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

the class DispositionLifecycleJobExecuter method executeAction.

/**
 * Helper method that executes a disposition action
 *
 * @param actionNode - the disposition action to execute
 */
private void executeAction(final NodeRef actionNode) {
    RetryingTransactionCallback<Boolean> processTranCB = new RetryingTransactionCallback<Boolean>() {

        public Boolean execute() {
            final String dispAction = (String) nodeService.getProperty(actionNode, RecordsManagementModel.PROP_DISPOSITION_ACTION);
            // Run disposition action
            if (dispAction != null && dispositionActions.contains(dispAction)) {
                ChildAssociationRef parent = nodeService.getPrimaryParent(actionNode);
                if (parent.getTypeQName().equals(RecordsManagementModel.ASSOC_NEXT_DISPOSITION_ACTION)) {
                    Map<String, Serializable> props = new HashMap<String, Serializable>(1);
                    props.put(RMDispositionActionExecuterAbstractBase.PARAM_NO_ERROR_CHECK, Boolean.FALSE);
                    try {
                        // execute disposition action
                        recordsManagementActionService.executeRecordsManagementAction(parent.getParentRef(), dispAction, props);
                        if (logger.isDebugEnabled()) {
                            logger.debug("Processed action: " + dispAction + "on" + parent);
                        }
                    } catch (AlfrescoRuntimeException exception) {
                        if (logger.isDebugEnabled()) {
                            logger.debug(exception);
                        }
                    }
                }
            }
            return Boolean.TRUE;
        }
    };
    // if exists
    if (nodeService.exists(actionNode)) {
        retryingTransactionHelper.doInTransaction(processTranCB);
    }
}
Also used : Serializable(java.io.Serializable) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) HashMap(java.util.HashMap) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 70 with RetryingTransactionCallback

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

the class PublishUpdatesJobExecuter method getUpdatedNodes.

/**
 * Get a list of the nodes with updates pending publish
 * @return  List<NodeRef>   list of node refences with updates pending publication
 */
private List<NodeRef> getUpdatedNodes() {
    RetryingTransactionCallback<List<NodeRef>> execution = new RetryingTransactionHelper.RetryingTransactionCallback<List<NodeRef>>() {

        @Override
        public List<NodeRef> execute() {
            // Build the query string
            StringBuilder sb = new StringBuilder();
            sb.append("ASPECT:\"rma:").append(ASPECT_UNPUBLISHED_UPDATE.getLocalName()).append("\"");
            String query = sb.toString();
            if (logger.isDebugEnabled()) {
                logger.debug("Executing query " + query);
            }
            // Execute query to find updates awaiting publishing
            List<NodeRef> resultNodes = null;
            SearchParameters searchParameters = new SearchParameters();
            searchParameters.setQuery(query);
            searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
            searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
            try {
                ResultSet results = searchService.query(searchParameters);
                try {
                    resultNodes = results.getNodeRefs();
                } finally {
                    results.close();
                }
            } catch (AlfrescoRuntimeException exception) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Error executing query, " + exception.getMessage());
                }
                throw exception;
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Found " + resultNodes.size() + " disposition action definitions updates awaiting publishing.");
            }
            return resultNodes;
        }
    };
    return retryingTransactionHelper.doInTransaction(execution, true);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) ResultSet(org.alfresco.service.cmr.search.ResultSet) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) List(java.util.List)

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