Search in sources :

Example 21 with UserInfo

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

the class FilePlanChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of file plan children (record categories) for the container identified by 'filePlanId'")
public CollectionWithPagingInfo<RecordCategory> readAll(String filePlanId, Parameters parameters) {
    // validate parameters
    checkNotBlank("filePlanId", filePlanId);
    mandatory("parameters", parameters);
    QName filePlanType = apiUtils.getFilePlanType();
    if (// rm site not created
    filePlanType == null) {
        throw new EntityNotFoundException(filePlanId);
    }
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(filePlanId, filePlanType);
    // list record categories
    Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesForFilePlanEndpoint();
    // FIXME this param null
    List<FilterProp> filterProps = apiUtils.getListChildrenFilterProps(parameters, null);
    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<RecordCategory> nodes = new AbstractList<RecordCategory>() {

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

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

Example 22 with UserInfo

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

the class UnfiledContainerChildrenRelation method create.

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

        public List<NodeRef> execute() {
            List<NodeRef> createdNodes = new LinkedList<>();
            for (UnfiledContainerChild 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<UnfiledContainerChild> 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.createUnfiledContainerChild(info, parameters, mapUserInfo, false));
    }
    return result;
}
Also used : UnfiledContainerChild(org.alfresco.rm.rest.api.model.UnfiledContainerChild) 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) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 23 with UserInfo

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

the class AuditImpl method getAuditEntry.

@Override
public AuditEntry getAuditEntry(String auditAppId, long auditEntryId, Parameters parameters) {
    checkEnabled();
    AuditService.AuditApplication auditApplication = findAuditAppByIdOr404(auditAppId);
    // Execute the query
    AuditQueryParameters params = new AuditQueryParameters();
    params.setApplicationName(auditApplication.getName());
    params.setFromId(auditEntryId);
    params.setToId(auditEntryId + 1);
    List<String> includeParam = new ArrayList<>();
    if (parameters != null) {
        includeParam.addAll(parameters.getInclude());
    }
    // Add values for single get
    includeParam.add(PARAM_INCLUDE_VALUES);
    final List<AuditEntry> results = new ArrayList<>();
    // create the callback for auditQuery method
    final AuditQueryCallback callback = new AuditQueryCallback() {

        public boolean valuesRequired() {
            return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
        }

        public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) {
            throw new AlfrescoRuntimeException("Failed to retrieve audit data.", error);
        }

        public boolean handleAuditEntry(Long entryId, String applicationName, String userName, long time, Map<String, Serializable> values) {
            UserInfo userInfo = Node.lookupUserInfo(userName, new HashMap<>(0), personService);
            AuditEntry auditEntry = new AuditEntry(entryId, auditAppId, userInfo, new Date(time), values);
            results.add(auditEntry);
            return true;
        }
    };
    auditService.auditQuery(callback, params, 1);
    if (results.size() != 1) {
        throw new EntityNotFoundException("" + auditEntryId);
    }
    return results.get(0);
}
Also used : AuditQueryParameters(org.alfresco.service.cmr.audit.AuditQueryParameters) ArrayList(java.util.ArrayList) UserInfo(org.alfresco.rest.api.model.UserInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) Date(java.util.Date) AuditApplication(org.alfresco.service.cmr.audit.AuditService.AuditApplication) AuditEntry(org.alfresco.rest.api.model.AuditEntry) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AuditQueryCallback(org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback) AuditService(org.alfresco.service.cmr.audit.AuditService) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with UserInfo

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

the class QuickShareLinksImpl method getQuickShareInfo.

private QuickShareLink getQuickShareInfo(NodeRef nodeRef, Map<String, Object> map, boolean noAuth, List<String> includeParam) {
    String sharedId = (String) map.get("sharedId");
    try {
        Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
        ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT);
        String mimeType = cd.getMimetype();
        String mimeTypeName = mimeTypeService.getDisplaysByMimetype().get(mimeType);
        ContentInfo contentInfo = new ContentInfo(mimeType, mimeTypeName, cd.getSize(), cd.getEncoding());
        Map<String, UserInfo> mapUserInfo = new HashMap<>(2);
        // note: if noAuth mode then don't return userids (to limit disclosure and be consistent with v0 internal)
        boolean displayNameOnly = noAuth;
        UserInfo modifiedByUser = Node.lookupUserInfo((String) nodeProps.get(ContentModel.PROP_MODIFIER), mapUserInfo, personService, displayNameOnly);
        // TODO review - should we return sharedByUser for authenticated users only ?? (not exposed by V0 but needed for "find")
        String sharedByUserId = (String) nodeProps.get(QuickShareModel.PROP_QSHARE_SHAREDBY);
        UserInfo sharedByUser = Node.lookupUserInfo(sharedByUserId, mapUserInfo, personService, displayNameOnly);
        QuickShareLink qs = new QuickShareLink(sharedId, nodeRef.getId());
        qs.setName((String) map.get("name"));
        qs.setTitle((String) map.get("title"));
        qs.setDescription((String) map.get("description"));
        qs.setContent(contentInfo);
        qs.setModifiedAt((Date) map.get("modified"));
        qs.setModifiedByUser(modifiedByUser);
        qs.setSharedByUser(sharedByUser);
        qs.setExpiresAt((Date) map.get("expiryDate"));
        // note: if noAuth mode then do not return allowable operations (eg. but can be optionally returned when finding shared links)
        if (!noAuth) {
            // Cached document
            Node doc = null;
            if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS)) {
                if (quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId)) {
                    // the allowable operations for the shared link
                    qs.setAllowableOperations(Collections.singletonList(Nodes.OP_DELETE));
                }
                doc = getNode(nodeRef, includeParam, mapUserInfo);
                List<String> allowableOps = doc.getAllowableOperations();
                // the allowable operations for the actual file being shared
                qs.setAllowableOperationsOnTarget(allowableOps);
            }
            // in noAuth mode we don't return the path info
            if (includeParam.contains(PARAM_INCLUDE_PATH)) {
                qs.setPath(nodes.lookupPathInfo(nodeRef, null));
            }
            if (includeParam.contains(PARAM_INCLUDE_PROPERTIES)) {
                if (doc == null) {
                    doc = getNode(nodeRef, includeParam, mapUserInfo);
                }
                // Create a map from node properties excluding properties already in this QuickShareLink
                Map<String, Object> filteredNodeProperties = filterProps(doc.getProperties(), EXCLUDED_PROPS);
                qs.setProperties(filteredNodeProperties);
            }
            if (includeParam.contains(PARAM_INCLUDE_ISFAVORITE)) {
                if (doc == null) {
                    doc = getNode(nodeRef, includeParam, mapUserInfo);
                }
                qs.setIsFavorite(doc.getIsFavorite());
            }
            if (includeParam.contains(PARAM_INCLUDE_ASPECTNAMES)) {
                if (doc == null) {
                    doc = getNode(nodeRef, includeParam, mapUserInfo);
                }
                qs.setAspectNames(doc.getAspectNames());
            }
        }
        return qs;
    } catch (InvalidSharedIdException ex) {
        logger.warn("Unable to find: " + sharedId);
        throw new EntityNotFoundException(sharedId);
    } catch (InvalidNodeRefException inre) {
        logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]");
        throw new EntityNotFoundException(sharedId);
    }
}
Also used : Serializable(java.io.Serializable) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.rest.api.model.Node) UserInfo(org.alfresco.rest.api.model.UserInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ContentData(org.alfresco.service.cmr.repository.ContentData) ContentInfo(org.alfresco.rest.api.model.ContentInfo) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink)

Example 25 with UserInfo

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

the class NodeVersionsRelation method readAll.

/**
 * List version history
 *
 * @param nodeId String id of (live) node
 */
@Override
@WebApiDescription(title = "Return version history as a paged list of version node infos")
public CollectionWithPagingInfo<Node> readAll(String nodeId, Parameters parameters) {
    NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
    VersionHistory vh = versionService.getVersionHistory(nodeRef);
    Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
    List<String> includeParam = parameters.getInclude();
    List<Node> collection = null;
    if (vh != null) {
        collection = new ArrayList<>(vh.getAllVersions().size());
        for (Version v : vh.getAllVersions()) {
            Node node = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, includeParam, mapUserInfo);
            mapVersionInfo(v, node);
            collection.add(node);
        }
    }
    return listPage(collection, parameters.getPaging());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) Version(org.alfresco.service.cmr.version.Version) Node(org.alfresco.rest.api.model.Node) UserInfo(org.alfresco.rest.api.model.UserInfo) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

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