Search in sources :

Example 6 with UserInfo

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

the class ApiNodesModelFactory method mapTransferInfo.

/**
 * Helper method that sets the information for transfer type.
 *
 * @param transfer
 * @param info
 * @param propertyFilter
 */
private void mapTransferInfo(Transfer transfer, FileInfo info, Map<String, UserInfo> mapUserInfo, BeanPropertiesFilter propertyFilter, List<String> includeParam, boolean isMinimalInfo) {
    if (propertyFilter.isAllowed(RMNode.PARAM_ID)) {
        transfer.setNodeRef(info.getNodeRef());
    }
    if (propertyFilter.isAllowed(RMNode.PARAM_PARENT_ID)) {
        transfer.setParentId(nodeService.getPrimaryParent(info.getNodeRef()).getParentRef());
    }
    if (propertyFilter.isAllowed(RMNode.PARAM_NAME)) {
        transfer.setName(info.getName());
    }
    if (propertyFilter.isAllowed(RMNode.PARAM_NODE_TYPE)) {
        transfer.setNodeType(info.getType().toPrefixString(namespaceService));
    }
    if (propertyFilter.isAllowed(RMNode.PARAM_CREATED_AT)) {
        transfer.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);
        transfer.setCreatedByUser(creator);
    }
    if (!isMinimalInfo && propertyFilter.isAllowed(RMNode.PARAM_ASPECT_NAMES)) {
        transfer.setAspectNames(mapFromNodeAspects(nodeService.getAspects(info.getNodeRef())));
    }
    if (!isMinimalInfo && propertyFilter.isAllowed(RMNode.PARAM_PROPERTIES)) {
        transfer.setProperties(mapFromNodeProperties(info.getProperties()));
    }
    // optional parameters
    if (isMinimalInfo && includeParam == null || includeParam.isEmpty()) {
        return;
    }
    if (includeParam.contains(RMNode.PARAM_ALLOWABLE_OPERATIONS)) {
        transfer.setAllowableOperations(apiUtils.getAllowableOperations(info.getNodeRef(), info.getType()));
    }
    if (isMinimalInfo && includeParam.contains(RMNode.PARAM_ASPECT_NAMES)) {
        transfer.setAspectNames(mapFromNodeAspects(nodeService.getAspects(info.getNodeRef())));
    }
    if (isMinimalInfo && includeParam.contains(RMNode.PARAM_PROPERTIES)) {
        transfer.setProperties(mapFromNodeProperties(info.getProperties()));
    }
    if ((!isMinimalInfo && propertyFilter.isAllowed(Transfer.PARAM_TRANSFER_ACCESSION_INDICATOR)) || (isMinimalInfo && includeParam.contains(Transfer.PARAM_TRANSFER_ACCESSION_INDICATOR))) {
        transfer.setTransferAccessionIndicator((Boolean) nodeService.getProperty(info.getNodeRef(), RecordsManagementModel.PROP_TRANSFER_ACCESSION_INDICATOR));
    }
    if ((!isMinimalInfo && propertyFilter.isAllowed(Transfer.PARAM_TRANSFER_LOCATION)) || (isMinimalInfo && includeParam.contains(Transfer.PARAM_TRANSFER_LOCATION))) {
        transfer.setTransferLocation((String) nodeService.getProperty(info.getNodeRef(), RecordsManagementModel.PROP_TRANSFER_LOCATION));
    }
    if ((!isMinimalInfo && propertyFilter.isAllowed(Transfer.PARAM_TRANSFER_PDF_INDICATOR)) || (isMinimalInfo && includeParam.contains(Transfer.PARAM_TRANSFER_PDF_INDICATOR))) {
        transfer.setTransferPDFIndicator((Boolean) nodeService.getProperty(info.getNodeRef(), RecordsManagementModel.PROP_TRANSFER_PDF_INDICATOR));
    }
}
Also used : UserInfo(org.alfresco.rest.api.model.UserInfo)

Example 7 with UserInfo

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

the class TransferContainerChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of transfers for the transfer container identified by 'transferContainerId'")
public CollectionWithPagingInfo<Transfer> readAll(String transferContainerId, Parameters parameters) {
    checkNotBlank("transferContainerId", transferContainerId);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(transferContainerId, RecordsManagementModel.TYPE_TRANSFER_CONTAINER);
    // list transfers
    Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesForTransferContainersEndpoint();
    final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, null, searchTypeQNames, null, apiUtils.getSortProperties(parameters), null, Util.getPagingRequest(parameters.getPaging()));
    final List<FileInfo> page = pagingResults.getPage();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    List<Transfer> nodes = new AbstractList<Transfer>() {

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

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

Example 8 with UserInfo

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

the class UnfiledContainerChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of unfiled container children for the container identified by 'unfiledContainerId'")
public CollectionWithPagingInfo<UnfiledContainerChild> readAll(String unfiledContainerId, Parameters parameters) {
    // validate parameters
    checkNotBlank("unfiledContainerId", unfiledContainerId);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
    // list unfiled record folders and records
    Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesForUnfiledEndpoint(parameters, LIST_UNFILED_CONTAINER_CHILDREN_EQUALS_QUERY_PROPERTIES);
    List<FilterProp> filterProps = apiUtils.getListChildrenFilterProps(parameters, LIST_UNFILED_CONTAINER_CHILDREN_EQUALS_QUERY_PROPERTIES);
    final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, null, searchTypeQNames, null, apiUtils.getSortProperties(parameters), filterProps, Util.getPagingRequest(parameters.getPaging()));
    final List<FileInfo> page = pagingResults.getPage();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    List<UnfiledContainerChild> nodes = new AbstractList<UnfiledContainerChild>() {

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

        @Override
        public int size() {
            return page.size();
        }
    };
    UnfiledContainer sourceEntity = null;
    if (parameters.includeSource()) {
        FileInfo info = fileFolderService.getFileInfo(parentNodeRef);
        sourceEntity = nodesModelFactory.createUnfiledContainer(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) UnfiledContainerChild(org.alfresco.rm.rest.api.model.UnfiledContainerChild) QName(org.alfresco.service.namespace.QName) UserInfo(org.alfresco.rest.api.model.UserInfo) UnfiledContainer(org.alfresco.rm.rest.api.model.UnfiledContainer) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 9 with UserInfo

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

the class NodesImpl method listChildren.

@Override
public CollectionWithPagingInfo<Node> listChildren(String parentFolderNodeId, Parameters parameters) {
    String path = parameters.getParameter(PARAM_RELATIVE_PATH);
    final NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, path);
    final List<String> includeParam = parameters.getInclude();
    QName assocTypeQNameParam = null;
    Query q = parameters.getQuery();
    if (q != null) {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = createListChildrenQueryWalker();
        QueryHelper.walk(q, propertyWalker);
        String assocTypeQNameStr = propertyWalker.getProperty(PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
        if (assocTypeQNameStr != null) {
            assocTypeQNameParam = getAssocType(assocTypeQNameStr);
        }
    }
    List<Pair<QName, Boolean>> sortProps = getListChildrenSortProps(parameters);
    List<FilterProp> filterProps = getListChildrenFilterProps(parameters);
    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    final PagingResults<FileInfo> pagingResults;
    Pair<Set<QName>, Set<QName>> pair = buildSearchTypesAndIgnoreAspects(parameters);
    Set<QName> searchTypeQNames = pair.getFirst();
    Set<QName> ignoreAspectQNames = pair.getSecond();
    Set<QName> assocTypeQNames = buildAssocTypes(assocTypeQNameParam);
    // call GetChildrenCannedQuery (via FileFolderService)
    if (((filterProps == null) || (filterProps.size() == 0)) && ((assocTypeQNames == null) || (assocTypeQNames.size() == 0)) && (smartStore.isVirtual(parentNodeRef) || (smartStore.canVirtualize(parentNodeRef)))) {
        pagingResults = fileFolderService.list(parentNodeRef, searchTypeQNames, ignoreAspectQNames, sortProps, pagingRequest);
    } else {
        // TODO smart folders (see REPO-1173)
        pagingResults = fileFolderService.list(parentNodeRef, assocTypeQNames, searchTypeQNames, ignoreAspectQNames, sortProps, filterProps, pagingRequest);
    }
    final Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
    final List<FileInfo> page = pagingResults.getPage();
    List<Node> nodes = new AbstractList<Node>() {

        @Override
        public Node get(int index) {
            FileInfo fInfo = page.get(index);
            // minimal info by default (unless "include"d otherwise)
            // (pass in null as parentNodeRef to force loading of primary
            // parent node as parentId)
            Node node = getFolderOrDocument(fInfo.getNodeRef(), null, fInfo.getType(), includeParam, mapUserInfo);
            if (node.getPath() != null) {
                calculateRelativePath(parentFolderNodeId, node);
            }
            return node;
        }

        private void calculateRelativePath(String parentFolderNodeId, Node node) {
            NodeRef rootNodeRef = validateOrLookupNode(parentFolderNodeId, null);
            try {
                // get the path elements
                List<String> pathInfos = fileFolderService.getNameOnlyPath(rootNodeRef, node.getNodeRef());
                int sizePathInfos = pathInfos.size();
                if (sizePathInfos > 1) {
                    // remove the current child
                    pathInfos.remove(sizePathInfos - 1);
                    // build the path string
                    StringBuilder sb = new StringBuilder(pathInfos.size() * 20);
                    for (String fileInfo : pathInfos) {
                        sb.append("/");
                        sb.append(fileInfo);
                    }
                    node.getPath().setRelativePath(sb.toString());
                }
            } catch (FileNotFoundException e) {
            // NOTE: return null as relativePath
            }
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    Node sourceEntity = null;
    if (parameters.includeSource()) {
        sourceEntity = getFolderOrDocumentFullInfo(parentNodeRef, null, null, null, mapUserInfo);
    }
    return CollectionWithPagingInfo.asPaged(paging, nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity);
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) Query(org.alfresco.rest.framework.resource.parameters.where.Query) GetChildrenCannedQuery(org.alfresco.repo.node.getchildren.GetChildrenCannedQuery) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) UserInfo(org.alfresco.rest.api.model.UserInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) Pair(org.alfresco.util.Pair) AbstractList(java.util.AbstractList) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) QName(org.alfresco.service.namespace.QName) Paging(org.alfresco.rest.framework.resource.parameters.Paging) PagingRequest(org.alfresco.query.PagingRequest)

Example 10 with UserInfo

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

the class PersonPropertyLookup method lookup.

@Override
public String lookup(String propertyValue) {
    Map<String, UserInfo> mapUserInfo = TransactionalResourceHelper.getMap("PERSON_PROPERTY_LOOKUP_USER_INFO_CACHE");
    UserInfo user = Node.lookupUserInfo(propertyValue, mapUserInfo, serviceRegistry.getPersonService());
    if (user != null)
        return user.getDisplayName();
    return null;
}
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