Search in sources :

Example 11 with QuickShareLink

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

the class QuickShareLinksImpl method readById.

/**
 * Returns limited metadata regarding the shared (content) link.
 * <p>
 * Note: does *not* require authenticated access for (public) shared link.
 */
public QuickShareLink readById(final String sharedId, final Parameters parameters) {
    checkEnabled();
    try {
        Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
        String networkTenantDomain = pair.getFirst();
        return TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<QuickShareLink>() {

            public QuickShareLink doWork() throws Exception {
                // note: assume noAuth here (rather than rely on getRunAsUser which will be null in non-MT)
                return getQuickShareInfo(sharedId, true, parameters.getInclude());
            }
        }, networkTenantDomain);
    } catch (InvalidSharedIdException ex) {
        logger.warn("Unable to find: " + sharedId);
        throw new EntityNotFoundException(sharedId);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) TenantUtil(org.alfresco.repo.tenant.TenantUtil) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) QuickShareLinkExpiryActionException(org.alfresco.repo.quickshare.QuickShareLinkExpiryActionException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) InvalidSharedIdException(org.alfresco.service.cmr.quickshare.InvalidSharedIdException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)

Example 12 with QuickShareLink

use of org.alfresco.rest.api.model.QuickShareLink 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) {
            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));
                }
                Node doc = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, null);
                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));
            }
        }
        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 13 with QuickShareLink

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

the class QuickShareLinksImpl method findLinks.

public CollectionWithPagingInfo<QuickShareLink> findLinks(Parameters parameters) {
    checkEnabled();
    String queryString = "ASPECT:\"" + QuickShareModel.ASPECT_QSHARE.toString() + "\"";
    SearchParameters sp = new SearchParameters();
    // note: REST API query parameter (ie. where clause filter) - not to be confused with search query ;-)
    Query q = parameters.getQuery();
    if (q != null) {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(FIND_SHARED_LINKS_QUERY_PROPERTIES, null);
        QueryHelper.walk(q, propertyWalker);
        String sharedByUserId = propertyWalker.getProperty(PARAM_SHAREDBY, WhereClauseParser.EQUALS, String.class);
        if (sharedByUserId != null) {
            if (People.DEFAULT_USER.equalsIgnoreCase(sharedByUserId)) {
                sharedByUserId = AuthenticationUtil.getFullyAuthenticatedUser();
            }
            QueryParameterDefinition qpd = new QueryParameterDefImpl(QuickShareModel.PROP_QSHARE_SHAREDBY, dictionaryService.getDataType(DataTypeDefinition.TEXT), true, sharedByUserId);
            sp.addQueryParameterDefinition(qpd);
            String qsharedBy = QuickShareModel.PROP_QSHARE_SHAREDBY.toPrefixString(namespaceService);
            queryString += " +@" + SearchLanguageConversion.escapeLuceneQuery(qsharedBy) + ":\"${" + qsharedBy + "}\"";
        }
    }
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.setQuery(queryString);
    sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    sp.setSkipCount(pagingRequest.getSkipCount());
    sp.setMaxItems(pagingRequest.getMaxItems());
    sp.addSort("@" + ContentModel.PROP_MODIFIED, false);
    ResultSet results = searchService.query(sp);
    List<QuickShareLink> qsLinks = new ArrayList<>(results.length());
    List<String> includeParam = parameters.getInclude();
    for (ResultSetRow row : results) {
        NodeRef nodeRef = row.getNodeRef();
        qsLinks.add(getQuickShareInfo(nodeRef, false, includeParam));
    }
    results.close();
    return CollectionWithPagingInfo.asPaged(paging, qsLinks, results.hasMore(), Long.valueOf(results.getNumberFound()).intValue());
}
Also used : QueryParameterDefImpl(org.alfresco.repo.search.QueryParameterDefImpl) Query(org.alfresco.rest.framework.resource.parameters.where.Query) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) PagingRequest(org.alfresco.query.PagingRequest) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) ResultSet(org.alfresco.service.cmr.search.ResultSet) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink) QueryParameterDefinition(org.alfresco.service.cmr.search.QueryParameterDefinition)

Aggregations

QuickShareLink (org.alfresco.rest.api.model.QuickShareLink)13 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)8 Test (org.junit.Test)7 HashMap (java.util.HashMap)6 Document (org.alfresco.rest.api.tests.client.data.Document)5 ArrayList (java.util.ArrayList)4 QuickShareLinkEntityResource (org.alfresco.rest.api.quicksharelinks.QuickShareLinkEntityResource)4 QuickShareLinksImpl (org.alfresco.rest.api.impl.QuickShareLinksImpl)3 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)3 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)3 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 Category (org.junit.experimental.categories.Category)3 File (java.io.File)2 Date (java.util.Date)2 QuickShareLinkExpiryActionException (org.alfresco.repo.quickshare.QuickShareLinkExpiryActionException)2 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)2 PathInfo (org.alfresco.rest.api.model.PathInfo)2 Rendition (org.alfresco.rest.api.tests.client.data.Rendition)2 MultiPartBuilder (org.alfresco.rest.api.tests.util.MultiPartBuilder)2