Search in sources :

Example 1 with UserInfo

use of org.alfresco.rest.api.model.UserInfo in project records-management by Alfresco.

the class UnfiledRecordFolderChildrenRelation method create.

@Override
@WebApiDescription(title = "Create one (or more) nodes as children of a unfiled record folder identified by 'unfiledRecordFolderId'")
public List<UnfiledRecordFolderChild> create(String unfiledRecordFolderId, final List<UnfiledRecordFolderChild> nodeInfos, Parameters parameters) {
    checkNotBlank("unfiledRecordFolderId", unfiledRecordFolderId);
    mandatory("nodeInfos", nodeInfos);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER);
    // Create the children
    RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>() {

        public List<NodeRef> execute() {
            List<NodeRef> createdNodes = new LinkedList<>();
            for (UnfiledRecordFolderChild nodeInfo : nodeInfos) {
                NodeRef nodeParent;
                if (StringUtils.isNoneBlank(nodeInfo.getRelativePath())) {
                    nodeParent = apiUtils.lookupAndValidateRelativePath(parentNodeRef, nodeInfo.getRelativePath(), RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER);
                } else {
                    nodeParent = parentNodeRef;
                }
                NodeRef newNodeRef = apiUtils.createRMNode(nodeParent, nodeInfo, parameters);
                createdNodes.add(newNodeRef);
            }
            return createdNodes;
        }
    };
    List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // Get the nodes info
    List<UnfiledRecordFolderChild> 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.createUnfiledRecordFolderChild(info, parameters, mapUserInfo, false));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) UserInfo(org.alfresco.rest.api.model.UserInfo) LinkedList(java.util.LinkedList) UnfiledRecordFolderChild(org.alfresco.rm.rest.api.model.UnfiledRecordFolderChild) 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) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 2 with UserInfo

use of org.alfresco.rest.api.model.UserInfo in project records-management by Alfresco.

the class RecordCategoryChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of record category children for the container identified by 'recordCategoryId'")
public CollectionWithPagingInfo<RecordCategoryChild> readAll(String recordCategoryId, Parameters parameters) {
    checkNotBlank("recordCategoryId", recordCategoryId);
    mandatory("parameters", parameters);
    String relativePath = parameters.getParameter(Nodes.PARAM_RELATIVE_PATH);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordCategoryId, RecordsManagementModel.TYPE_RECORD_CATEGORY, relativePath, true);
    // list record categories and record folders
    Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesCategoriesEndpoint(parameters, LIST_RECORD_CATEGORY_CHILDREN_EQUALS_QUERY_PROPERTIES);
    Set<QName> assocTypeQNames = Collections.singleton(ContentModel.ASSOC_CONTAINS);
    List<FilterProp> filterProps = apiUtils.getListChildrenFilterProps(parameters, LIST_RECORD_CATEGORY_CHILDREN_EQUALS_QUERY_PROPERTIES);
    final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, assocTypeQNames, searchTypeQNames, null, apiUtils.getSortProperties(parameters), filterProps, Util.getPagingRequest(parameters.getPaging()));
    final List<FileInfo> page = pagingResults.getPage();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    List<RecordCategoryChild> nodes = new AbstractList<RecordCategoryChild>() {

        @Override
        public RecordCategoryChild get(int index) {
            FileInfo info = page.get(index);
            return nodesModelFactory.createRecordCategoryChild(info, parameters, mapUserInfo, true);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    RecordCategory sourceEntity = null;
    if (parameters.includeSource()) {
        FileInfo info = fileFolderService.getFileInfo(parentNodeRef);
        sourceEntity = nodesModelFactory.createRecordCategory(info, parameters, mapUserInfo, true);
    }
    return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity);
}
Also used : AbstractList(java.util.AbstractList) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) RecordCategoryChild(org.alfresco.rm.rest.api.model.RecordCategoryChild) UserInfo(org.alfresco.rest.api.model.UserInfo) RecordCategory(org.alfresco.rm.rest.api.model.RecordCategory) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 3 with UserInfo

use of org.alfresco.rest.api.model.UserInfo in project records-management by Alfresco.

the class RecordCategoryChildrenRelation method create.

@Override
@WebApiDescription(title = "Create one (or more) nodes as children of a record category identified by 'recordCategoryId'")
public List<RecordCategoryChild> create(String recordCategoryId, List<RecordCategoryChild> nodeInfos, Parameters parameters) {
    checkNotBlank("recordCategoryId", recordCategoryId);
    mandatory("nodeInfos", nodeInfos);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordCategoryId, RecordsManagementModel.TYPE_RECORD_CATEGORY);
    List<RecordCategoryChild> result = new ArrayList<>(nodeInfos.size());
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>() {

        public List<NodeRef> execute() {
            List<NodeRef> createdNodes = new LinkedList<>();
            for (RecordCategoryChild nodeInfo : nodeInfos) {
                // Resolve the parent node
                NodeRef nodeParent = parentNodeRef;
                if (StringUtils.isNoneBlank(nodeInfo.getRelativePath())) {
                    nodeParent = apiUtils.lookupAndValidateRelativePath(parentNodeRef, nodeInfo.getRelativePath(), RecordsManagementModel.TYPE_RECORD_CATEGORY);
                }
                // Create the node
                NodeRef newNode = apiUtils.createRMNode(nodeParent, nodeInfo, parameters);
                createdNodes.add(newNode);
            }
            return createdNodes;
        }
    };
    List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    for (NodeRef nodeInfo : createdNodes) {
        FileInfo info = fileFolderService.getFileInfo(nodeInfo);
        result.add(nodesModelFactory.createRecordCategoryChild(info, parameters, mapUserInfo, false));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) RecordCategoryChild(org.alfresco.rm.rest.api.model.RecordCategoryChild) ArrayList(java.util.ArrayList) 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) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 4 with UserInfo

use of org.alfresco.rest.api.model.UserInfo in project records-management by Alfresco.

the class TransferChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of record folders or records for the transfer identified by 'transferId'")
public CollectionWithPagingInfo<TransferChild> readAll(String transferId, Parameters parameters) {
    checkNotBlank("transferId", transferId);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(transferId, RecordsManagementModel.TYPE_TRANSFER);
    // list record folder, electronic record or non electronic record
    final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, null, null, null, apiUtils.getSortProperties(parameters), null, Util.getPagingRequest(parameters.getPaging()));
    final List<FileInfo> page = pagingResults.getPage();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    List<TransferChild> nodes = new AbstractList<TransferChild>() {

        @Override
        public TransferChild get(int index) {
            FileInfo info = page.get(index);
            return nodesModelFactory.createTransferChild(info, parameters, mapUserInfo, true);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    Transfer sourceEntity = null;
    if (parameters.includeSource()) {
        FileInfo info = fileFolderService.getFileInfo(parentNodeRef);
        sourceEntity = nodesModelFactory.createTransfer(info, parameters, mapUserInfo, true);
    }
    return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity);
}
Also used : AbstractList(java.util.AbstractList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) HashMap(java.util.HashMap) TransferChild(org.alfresco.rm.rest.api.model.TransferChild) Transfer(org.alfresco.rm.rest.api.model.Transfer) UserInfo(org.alfresco.rest.api.model.UserInfo) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 5 with UserInfo

use of org.alfresco.rest.api.model.UserInfo in project records-management by Alfresco.

the class ApiNodesModelFactory method mapTransferContainerInfo.

/**
 * Helper method that sets the information for transfer container type.
 *
 * @param transferContainer
 * @param info
 * @param propertyFilter
 */
private void mapTransferContainerInfo(TransferContainer transferContainer, FileInfo info, Map<String, UserInfo> mapUserInfo, BeanPropertiesFilter propertyFilter, List<String> includeParam, boolean isMinimalInfo) {
    if (propertyFilter.isAllowed(RMNode.PARAM_ID)) {
        transferContainer.setNodeRef(info.getNodeRef());
    }
    if (propertyFilter.isAllowed(RMNode.PARAM_PARENT_ID)) {
        transferContainer.setParentId(nodeService.getPrimaryParent(info.getNodeRef()).getParentRef());
    }
    if (propertyFilter.isAllowed(RMNode.PARAM_NAME)) {
        transferContainer.setName(info.getName());
    }
    if (propertyFilter.isAllowed(RMNode.PARAM_NODE_TYPE)) {
        transferContainer.setNodeType(info.getType().toPrefixString(namespaceService));
    }
    if (propertyFilter.isAllowed(RMNode.PARAM_MODIFIED_AT)) {
        transferContainer.setModifiedAt(info.getModifiedDate());
    }
    if (propertyFilter.isAllowed(RMNode.PARAM_MODIFIED_BY_USER)) {
        if (mapUserInfo == null) {
            mapUserInfo = new HashMap<>(2);
        }
        UserInfo modifer = Node.lookupUserInfo((String) info.getProperties().get(ContentModel.PROP_MODIFIER), mapUserInfo, personService);
        transferContainer.setModifiedByUser(modifer);
    }
    if (propertyFilter.isAllowed(RMNode.PARAM_CREATED_AT)) {
        transferContainer.setCreatedAt(info.getCreatedDate());
    }
    if (propertyFilter.isAllowed(RMNode.PARAM_CREATED_BY_USER)) {
        if (mapUserInfo == null) {
            mapUserInfo = new HashMap<>(2);
        }
        UserInfo creator = Node.lookupUserInfo((String) info.getProperties().get(ContentModel.PROP_CREATOR), mapUserInfo, personService);
        transferContainer.setCreatedByUser(creator);
    }
    if (!isMinimalInfo && propertyFilter.isAllowed(RMNode.PARAM_ASPECT_NAMES)) {
        transferContainer.setAspectNames(mapFromNodeAspects(nodeService.getAspects(info.getNodeRef())));
    }
    if (!isMinimalInfo && propertyFilter.isAllowed(RMNode.PARAM_PROPERTIES)) {
        transferContainer.setProperties(mapFromNodeProperties(info.getProperties()));
    }
    // optional parameters
    if (includeParam == null || includeParam.isEmpty()) {
        return;
    }
    if (includeParam.contains(RMNode.PARAM_ALLOWABLE_OPERATIONS)) {
        transferContainer.setAllowableOperations(apiUtils.getAllowableOperations(info.getNodeRef(), info.getType()));
    }
    if (isMinimalInfo && includeParam.contains(RMNode.PARAM_ASPECT_NAMES)) {
        transferContainer.setAspectNames(mapFromNodeAspects(nodeService.getAspects(info.getNodeRef())));
    }
    if (isMinimalInfo && includeParam.contains(RMNode.PARAM_PROPERTIES)) {
        transferContainer.setProperties(mapFromNodeProperties(info.getProperties()));
    }
}
Also used : UserInfo(org.alfresco.rest.api.model.UserInfo)

Aggregations

UserInfo (org.alfresco.rest.api.model.UserInfo)26 HashMap (java.util.HashMap)22 NodeRef (org.alfresco.service.cmr.repository.NodeRef)18 AbstractList (java.util.AbstractList)13 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)13 FileInfo (org.alfresco.service.cmr.model.FileInfo)13 QName (org.alfresco.service.namespace.QName)12 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Node (org.alfresco.rest.api.model.Node)7 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)6 LinkedList (java.util.LinkedList)5 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)5 Map (java.util.Map)4 FilterProp (org.alfresco.repo.node.getchildren.FilterProp)4 Date (java.util.Date)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 AuditEntry (org.alfresco.rest.api.model.AuditEntry)3 AuditQueryParameters (org.alfresco.service.cmr.audit.AuditQueryParameters)3 AuditQueryCallback (org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback)3