Search in sources :

Example 56 with Pair

use of org.alfresco.util.Pair 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 57 with Pair

use of org.alfresco.util.Pair in project records-management by Alfresco.

the class FilePlanServiceImpl method getFilePlanRootContainer.

/**
 * Get the file root container for the given type.
 *
 * @param filePlan			file plan
 * @param containerName		container type
 * @return {@link NodeRef}	file plan container
 */
private NodeRef getFilePlanRootContainer(NodeRef filePlan, String containerName) {
    ParameterCheck.mandatory("filePlan", filePlan);
    if (!isFilePlan(filePlan)) {
        throw new AlfrescoRuntimeException("Unable to get the container " + containerName + ", because passed node is not a file plan.");
    }
    NodeRef result = null;
    Pair<NodeRef, String> key = new Pair<NodeRef, String>(filePlan, containerName);
    if (!rootContainerCache.contains(key)) {
        // try and get the unfiled record container
        List<ChildAssociationRef> assocs = nodeService.getChildAssocs(filePlan, ContentModel.ASSOC_CONTAINS, QName.createQName(RM_URI, containerName));
        if (assocs.size() > 1) {
            throw new AlfrescoRuntimeException("Unable to get unfiled conatiner " + containerName + ".");
        } else if (assocs.size() == 1) {
            result = assocs.get(0).getChildRef();
            rootContainerCache.put(key, result);
        }
    } else {
        result = rootContainerCache.get(key);
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Pair(org.alfresco.util.Pair)

Example 58 with Pair

use of org.alfresco.util.Pair in project records-management by Alfresco.

the class SearchTypesFactory method parseNodeTypeFilter.

/**
 * Helper method to parse the nodeType filter
 * default nodeType filtering is without subTypes (unless nodeType value is suffixed with ' INCLUDESUBTYPES')
 * @param nodeTypeStr
 * @return
 */
private Pair<QName, Boolean> parseNodeTypeFilter(String nodeTypeStr) {
    boolean filterIncludeSubTypes = false;
    int idx = nodeTypeStr.lastIndexOf(' ');
    if (idx > 0) {
        String suffix = nodeTypeStr.substring(idx);
        if (suffix.equalsIgnoreCase(" " + RMNode.PARAM_INCLUDE_SUBTYPES)) {
            filterIncludeSubTypes = true;
            nodeTypeStr = nodeTypeStr.substring(0, idx);
        }
    }
    QName filterNodeTypeQName = nodes.createQName(nodeTypeStr);
    if (dictionaryService.getType(filterNodeTypeQName) == null) {
        throw new InvalidParameterException("Filter nodeType: " + nodeTypeStr + " is invalid");
    }
    return new Pair<>(filterNodeTypeQName, filterIncludeSubTypes);
}
Also used : InvalidParameterException(java.security.InvalidParameterException) QName(org.alfresco.service.namespace.QName) Pair(org.alfresco.util.Pair)

Example 59 with Pair

use of org.alfresco.util.Pair in project records-management by Alfresco.

the class RMSearchGet method executeImpl.

/*
     * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
     */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>(1);
    try {
        // Get the site id and confirm it is valid
        Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
        String siteId = templateVars.get("site");
        if (siteId == null || siteId.length() == 0) {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Site id not provided.");
        }
        if (siteService.getSite(siteId) == null) {
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "Site not found.");
        }
        // Get the query parameter
        String query = req.getParameter(PARAM_QUERY);
        // TODO check that this is there
        String sortby = req.getParameter(PARAM_SORTBY);
        // TODO this is optional
        String filters = req.getParameter(PARAM_FILTERS);
        // TODO this is optional
        // Convert into a rm search parameter object
        RecordsManagementSearchParameters searchParameters = SavedSearchDetailsCompatibility.createSearchParameters(filters, new String[] { ",", "/" }, sortby, namespaceService);
        // Set the max results
        String maxItems = req.getParameter(PARAM_MAX_ITEMS);
        if (maxItems != null && maxItems.length() != 0) {
            searchParameters.setMaxItems(Integer.parseInt(maxItems));
        }
        // Execute search
        List<Pair<NodeRef, NodeRef>> results = recordsManagementSearchService.search(siteId, query, searchParameters);
        // Reset person data cache
        personDataCache = new HashMap<String, String>(57);
        // Process the result items
        List<Item> items = new ArrayList<Item>(results.size());
        for (Pair<NodeRef, NodeRef> pair : results) {
            // TC 3-3  Create User Groups
            try {
                Item item = new Item(pair.getFirst(), pair.getSecond());
                items.add(item);
            } catch (Exception e) {
                LOGGER.debug("Ignoring failed attempt to add item to search results.", e);
            }
        }
        // Return model
        model.put("items", items);
    } catch (Exception ex) {
        model.put("errorMessage", ex.toString());
    }
    return model;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) RecordsManagementSearchParameters(org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchParameters) Pair(org.alfresco.util.Pair)

Example 60 with Pair

use of org.alfresco.util.Pair in project records-management by Alfresco.

the class RMv22DODModelSeparationModulePatch method applyInternal.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch#applyInternal()
 */
@Override
public void applyInternal() {
    if (!convertToStandardFilePlan) {
        Long maxNodeId = nodeDAO.getMaxNodeId();
        long recordCount = patchDAO.getCountNodesWithAspects(Collections.singleton(ASPECT_RECORD));
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("   ... updating " + recordCount + " records in batches of " + BATCH_SIZE);
        }
        // apply the DOD record aspect to all exiting records
        int completed = 0;
        for (Long i = 0L; i < maxNodeId; i += BATCH_SIZE) {
            final Long finali = i;
            Integer batchCount = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Integer>() {

                int batchCount = 0;

                public Integer execute() throws Throwable {
                    nodeDAO.getNodesWithAspects(Collections.singleton(ASPECT_RECORD), finali, finali + BATCH_SIZE, new NodeDAO.NodeRefQueryCallback() {

                        public boolean handle(Pair<Long, NodeRef> nodePair) {
                            // get the records properties
                            Map<QName, Serializable> properties = nodeDAO.getNodeProperties(nodePair.getFirst());
                            boolean changed = false;
                            for (QName qname : qnames) {
                                // if the record has any of the moved properties
                                QName origional = QName.createQName(RecordsManagementModel.RM_URI, qname.getLocalName());
                                if (properties.containsKey(origional)) {
                                    // move the property value
                                    Serializable value = properties.get(origional);
                                    properties.put(qname, value);
                                    properties.remove(origional);
                                    changed = true;
                                }
                            }
                            // set properties and add aspect
                            if (changed) {
                                nodeDAO.setNodeProperties(nodePair.getFirst(), properties);
                            }
                            nodeDAO.addNodeAspects(nodePair.getFirst(), Collections.singleton(DOD5015Model.ASPECT_DOD_5015_RECORD));
                            batchCount++;
                            return true;
                        }
                    });
                    return batchCount;
                }
            }, false, true);
            if (batchCount != 0) {
                completed = completed + batchCount;
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("   ... completed " + completed + " of " + recordCount);
                }
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) Pair(org.alfresco.util.Pair)

Aggregations

Pair (org.alfresco.util.Pair)61 ArrayList (java.util.ArrayList)34 NodeRef (org.alfresco.service.cmr.repository.NodeRef)23 QName (org.alfresco.service.namespace.QName)22 HashMap (java.util.HashMap)16 PagingRequest (org.alfresco.query.PagingRequest)13 Paging (org.alfresco.rest.framework.resource.parameters.Paging)12 List (java.util.List)11 Serializable (java.io.Serializable)10 HashSet (java.util.HashSet)9 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)9 Set (java.util.Set)8 Map (java.util.Map)7 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)7 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)7 AbstractList (java.util.AbstractList)6 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 PagingResults (org.alfresco.query.PagingResults)6 Node (org.alfresco.rest.api.model.Node)6