Search in sources :

Example 16 with Node

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

the class FavouritesImpl method getFavourite.

private Favourite getFavourite(PersonFavourite personFavourite, Parameters parameters) {
    Favourite fav = new Favourite();
    fav.setTargetGuid(personFavourite.getNodeRef().getId());
    fav.setCreatedAt(personFavourite.getCreatedAt());
    Target target = getTarget(personFavourite, parameters);
    fav.setTarget(target);
    // REPO-1147 allow retrieving additional properties
    if (parameters.getInclude().contains(PARAM_INCLUDE_PROPERTIES)) {
        List<String> includeProperties = new LinkedList<>();
        includeProperties.add(PARAM_INCLUDE_PROPERTIES);
        // get node representation with only properties included
        Node node = nodes.getFolderOrDocument(personFavourite.getNodeRef(), null, null, includeProperties, null);
        // Create a map from node properties excluding properties already in this Favorite
        Map<String, Object> filteredNodeProperties = filterProps(node.getProperties(), EXCLUDED_PROPS);
        if (filteredNodeProperties.size() > 0) {
            fav.setProperties(filteredNodeProperties);
        }
    }
    return fav;
}
Also used : SiteTarget(org.alfresco.rest.api.model.SiteTarget) DocumentTarget(org.alfresco.rest.api.model.DocumentTarget) FolderTarget(org.alfresco.rest.api.model.FolderTarget) Target(org.alfresco.rest.api.model.Target) Node(org.alfresco.rest.api.model.Node) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) Favourite(org.alfresco.rest.api.model.Favourite) LinkedList(java.util.LinkedList)

Example 17 with Node

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

the class PeopleImpl method uploadAvatarContent.

@Override
public Person uploadAvatarContent(String personId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters) {
    if (!thumbnailService.getThumbnailsEnabled()) {
        throw new DisabledServiceException("Thumbnail generation has been disabled.");
    }
    personId = validatePerson(personId);
    checkCurrentUserOrAdmin(personId);
    NodeRef personNode = personService.getPerson(personId);
    NodeRef avatarOrigNodeRef = getAvatarOriginal(personNode);
    if (avatarOrigNodeRef != null) {
        deleteAvatar(avatarOrigNodeRef);
    }
    QName origAvatarQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "origAvatar");
    nodeService.addAspect(personNode, ContentModel.ASPECT_PREFERENCES, null);
    ChildAssociationRef assoc = nodeService.createNode(personNode, ContentModel.ASSOC_PREFERENCE_IMAGE, origAvatarQName, ContentModel.TYPE_CONTENT);
    NodeRef avatar = assoc.getChildRef();
    String avatarOriginalNodeId = avatar.getId();
    // TODO do we still need this ? - backward compatible with JSF web-client avatar
    nodeService.createAssociation(personNode, avatar, ContentModel.ASSOC_AVATAR);
    Node n = nodes.updateContent(avatarOriginalNodeId, contentInfo, stream, parameters);
    String mimeType = n.getContent().getMimeType();
    if (mimeType.indexOf("image/") != 0) {
        throw new InvalidArgumentException("Uploaded content must be an image (content type determined to be '" + mimeType + "')");
    }
    // create thumbnail synchronously
    Rendition avatarR = new Rendition();
    avatarR.setId("avatar");
    renditions.createRendition(avatar, avatarR, false, parameters);
    List<String> include = Arrays.asList(PARAM_INCLUDE_ASPECTNAMES, PARAM_INCLUDE_PROPERTIES);
    return getPersonWithProperties(personId, include);
}
Also used : DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) Rendition(org.alfresco.rest.api.model.Rendition) Node(org.alfresco.rest.api.model.Node) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 18 with Node

use of org.alfresco.rest.api.model.Node 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)

Example 19 with Node

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

the class SearchApiWebscript method execute.

@Override
public void execute(WebScriptRequest webScriptRequest, WebScriptResponse webScriptResponse) throws IOException {
    try {
        // Turn JSON into a Java object respresentation
        SearchQuery searchQuery = extractJsonContent(webScriptRequest, assistant.getJsonHelper(), SearchQuery.class);
        // Parse the parameters
        Params params = getParams(webScriptRequest, searchQuery.getFields(), searchQuery.getInclude(), searchQuery.getPaging());
        // Make a copy of the request
        SearchRequestContext searchRequestContext = SearchRequestContext.from(searchQuery);
        // Turn the SearchQuery json into the Java SearchParameters object
        SearchParameters searchParams = searchMapper.toSearchParameters(params, searchQuery, searchRequestContext);
        // Call searchService
        ResultSet results = searchService.query(searchParams);
        // Turn solr results into JSON
        CollectionWithPagingInfo<Node> resultJson = resultMapper.toCollectionWithPagingInfo(params, searchRequestContext, searchQuery, results);
        // Post-process the request and pass in params, eg. params.getFilter()
        Object toRender = helper.processAdditionsToTheResponse(null, null, null, params, resultJson);
        // Write response
        setResponse(webScriptResponse, DEFAULT_SUCCESS);
        renderJsonResponse(webScriptResponse, toRender, assistant.getJsonHelper());
    } catch (Exception exception) {
        renderException(exception, webScriptResponse, assistant);
    }
}
Also used : SearchQuery(org.alfresco.rest.api.search.model.SearchQuery) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) Node(org.alfresco.rest.api.model.Node) ResultSet(org.alfresco.service.cmr.search.ResultSet) Params(org.alfresco.rest.framework.resource.parameters.Params) SearchRequestContext(org.alfresco.rest.api.search.context.SearchRequestContext) IOException(java.io.IOException)

Example 20 with Node

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

the class ResultMapper method toCollectionWithPagingInfo.

/**
 * Turns the results into a CollectionWithPagingInfo
 * @param params
 * @param searchQuery
 *@param results  @return CollectionWithPagingInfo<Node>
 */
public CollectionWithPagingInfo<Node> toCollectionWithPagingInfo(Params params, SearchRequestContext searchRequestContext, SearchQuery searchQuery, ResultSet results) {
    SearchContext context = null;
    Integer total = null;
    List<Node> noderesults = new ArrayList<Node>();
    Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
    Map<NodeRef, List<Pair<String, List<String>>>> hightLighting = results.getHighlighting();
    int notFound = 0;
    boolean isHistory = searchRequestContext.getStores().contains(StoreMapper.HISTORY);
    for (ResultSetRow row : results) {
        Node aNode = getNode(row, params, mapUserInfo, isHistory);
        if (aNode != null) {
            float f = row.getScore();
            List<HighlightEntry> highlightEntries = null;
            List<Pair<String, List<String>>> high = hightLighting.get(row.getNodeRef());
            if (high != null && !high.isEmpty()) {
                highlightEntries = new ArrayList<HighlightEntry>(high.size());
                for (Pair<String, List<String>> highlight : high) {
                    highlightEntries.add(new HighlightEntry(highlight.getFirst(), highlight.getSecond()));
                }
            }
            aNode.setSearch(new SearchEntry(f, highlightEntries));
            noderesults.add(aNode);
        } else {
            logger.debug("Unknown noderef returned from search results " + row.getNodeRef());
            notFound++;
        }
    }
    SolrJSONResultSet solrResultSet = findSolrResultSet(results);
    if (solrResultSet != null) {
        // We used Solr for this query
        context = toSearchContext(solrResultSet, searchRequestContext, searchQuery, notFound);
    }
    total = setTotal(results);
    return CollectionWithPagingInfo.asPaged(params.getPaging(), noderesults, results.hasMore(), total, null, context);
}
Also used : HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) ArrayList(java.util.ArrayList) SearchContext(org.alfresco.rest.api.search.context.SearchContext) UserInfo(org.alfresco.rest.api.model.UserInfo) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) NodeRef(org.alfresco.service.cmr.repository.NodeRef) List(java.util.List) TupleList(org.alfresco.rest.api.search.model.TupleList) ArrayList(java.util.ArrayList) SearchEntry(org.alfresco.rest.api.search.model.SearchEntry) HighlightEntry(org.alfresco.rest.api.search.model.HighlightEntry) Pair(org.alfresco.util.Pair)

Aggregations

Node (org.alfresco.rest.api.model.Node)21 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 HashMap (java.util.HashMap)12 QName (org.alfresco.service.namespace.QName)10 Serializable (java.io.Serializable)7 UserInfo (org.alfresco.rest.api.model.UserInfo)7 ArrayList (java.util.ArrayList)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 FilterPropBoolean (org.alfresco.repo.node.getchildren.FilterPropBoolean)3 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)3 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)3 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)3 Version (org.alfresco.service.cmr.version.Version)3 List (java.util.List)2 Map (java.util.Map)2 PagingRequest (org.alfresco.query.PagingRequest)2 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)2 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)2