Search in sources :

Example 1 with PersonFavourite

use of org.alfresco.repo.favourites.PersonFavourite in project alfresco-remote-api by Alfresco.

the class FavouritesImpl method wrap.

private CollectionWithPagingInfo<Favourite> wrap(Paging paging, PagingResults<PersonFavourite> personFavourites, Parameters parameters) {
    final List<PersonFavourite> page = personFavourites.getPage();
    final List<Favourite> list = new AbstractList<Favourite>() {

        @Override
        public Favourite get(int index) {
            PersonFavourite personFavourite = page.get(index);
            Favourite fav = getFavourite(personFavourite, parameters);
            return fav;
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    Pair<Integer, Integer> pair = personFavourites.getTotalResultCount();
    Integer total = null;
    if (pair.getFirst().equals(pair.getSecond())) {
        total = pair.getFirst();
    }
    return CollectionWithPagingInfo.asPaged(paging, list, personFavourites.hasMoreItems(), total);
}
Also used : AbstractList(java.util.AbstractList) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) Favourite(org.alfresco.rest.api.model.Favourite)

Example 2 with PersonFavourite

use of org.alfresco.repo.favourites.PersonFavourite in project alfresco-remote-api by Alfresco.

the class FavouritesImpl method getFavourite.

@Override
public Favourite getFavourite(String personId, String favouriteId, Parameters parameters) {
    NodeRef nodeRef = nodes.validateNode(favouriteId);
    personId = people.validatePerson(personId, true);
    PersonFavourite personFavourite = favouritesService.getFavourite(personId, nodeRef);
    if (personFavourite != null) {
        Favourite favourite = getFavourite(personFavourite, parameters);
        return favourite;
    } else {
        throw new RelationshipResourceNotFoundException(personId, favouriteId);
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) Favourite(org.alfresco.rest.api.model.Favourite)

Example 3 with PersonFavourite

use of org.alfresco.repo.favourites.PersonFavourite in project alfresco-remote-api by Alfresco.

the class FavouritesImpl method addFavourite.

@Override
public Favourite addFavourite(String personId, Favourite favourite, Parameters parameters) {
    Favourite ret = null;
    personId = people.validatePerson(personId, true);
    Target target = favourite.getTarget();
    if (target == null) {
        throw new InvalidArgumentException("target is missing");
    } else if (target instanceof SiteTarget) {
        SiteTarget siteTarget = (SiteTarget) target;
        String guid = siteTarget.getSite().getGuid();
        SiteInfo siteInfo = sites.validateSite(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, guid));
        NodeRef siteNodeRef = siteInfo.getNodeRef();
        String siteId = siteInfo.getShortName();
        try {
            PersonFavourite personFavourite = favouritesService.addFavourite(personId, siteNodeRef);
            ret = getFavourite(personFavourite, parameters);
        } catch (SiteDoesNotExistException e) {
            throw new RelationshipResourceNotFoundException(personId, siteId);
        }
    } else if (target instanceof DocumentTarget) {
        DocumentTarget documentTarget = (DocumentTarget) target;
        NodeRef nodeRef = documentTarget.getFile().getGuid();
        if (!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null)) {
            throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
        }
        PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
        ret = getFavourite(personFavourite, parameters);
    } else if (target instanceof FolderTarget) {
        FolderTarget folderTarget = (FolderTarget) target;
        NodeRef nodeRef = folderTarget.getFolder().getGuid();
        if (!nodes.nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_FOLDER), Collections.singleton(SiteModel.TYPE_SITE))) {
            throw new RelationshipResourceNotFoundException(personId, nodeRef.getId());
        }
        PersonFavourite personFavourite = favouritesService.addFavourite(personId, nodeRef);
        ret = getFavourite(personFavourite, parameters);
    }
    return ret;
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) 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) DocumentTarget(org.alfresco.rest.api.model.DocumentTarget) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) SiteDoesNotExistException(org.alfresco.repo.site.SiteDoesNotExistException) SiteTarget(org.alfresco.rest.api.model.SiteTarget) FolderTarget(org.alfresco.rest.api.model.FolderTarget) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) Favourite(org.alfresco.rest.api.model.Favourite)

Example 4 with PersonFavourite

use of org.alfresco.repo.favourites.PersonFavourite 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);
    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) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) Favourite(org.alfresco.rest.api.model.Favourite)

Example 5 with PersonFavourite

use of org.alfresco.repo.favourites.PersonFavourite in project alfresco-remote-api by Alfresco.

the class FavouritesImpl method getFavourites.

@Override
public CollectionWithPagingInfo<Favourite> getFavourites(String personId, final Parameters parameters) {
    personId = people.validatePerson(personId, true);
    Paging paging = parameters.getPaging();
    final Set<Type> filteredByClientQuery = new HashSet<Type>();
    // Default all
    Set<Type> filterTypes = FavouritesService.Type.ALL_FILTER_TYPES;
    // filterType is of the form 'target.<site|file|folder>'
    QueryHelper.walk(parameters.getQuery(), new WalkerCallbackAdapter() {

        @Override
        public void or() {
        // OR is supported but exists() will be called for each EXISTS so we don't
        // need to do anything here.  If we don't override it then it will be assumed
        // that OR in the grammar is not supported.
        }

        @Override
        public void exists(String filteredByClient, boolean negated) {
            if (filteredByClient != null) {
                int idx = filteredByClient.lastIndexOf("/");
                if (idx == -1 || idx == filteredByClient.length()) {
                    throw new InvalidArgumentException();
                } else {
                    String filtertype = filteredByClient.substring(idx + 1).toUpperCase();
                    filteredByClientQuery.add(Type.valueOf(filtertype));
                }
            }
        }
    });
    if (filteredByClientQuery.size() > 0) {
        filterTypes = filteredByClientQuery;
    }
    final PagingResults<PersonFavourite> favourites = favouritesService.getPagedFavourites(personId, filterTypes, FavouritesService.DEFAULT_SORT_PROPS, Util.getPagingRequest(paging));
    return wrap(paging, favourites, parameters);
}
Also used : Type(org.alfresco.service.cmr.favourites.FavouritesService.Type) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) Paging(org.alfresco.rest.framework.resource.parameters.Paging) WalkerCallbackAdapter(org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter) HashSet(java.util.HashSet)

Aggregations

PersonFavourite (org.alfresco.repo.favourites.PersonFavourite)5 Favourite (org.alfresco.rest.api.model.Favourite)4 DocumentTarget (org.alfresco.rest.api.model.DocumentTarget)2 FolderTarget (org.alfresco.rest.api.model.FolderTarget)2 SiteTarget (org.alfresco.rest.api.model.SiteTarget)2 Target (org.alfresco.rest.api.model.Target)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 AbstractList (java.util.AbstractList)1 HashSet (java.util.HashSet)1 SiteDoesNotExistException (org.alfresco.repo.site.SiteDoesNotExistException)1 Paging (org.alfresco.rest.framework.resource.parameters.Paging)1 WalkerCallbackAdapter (org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter)1 Type (org.alfresco.service.cmr.favourites.FavouritesService.Type)1 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)1