Search in sources :

Example 1 with SiteDoesNotExistException

use of org.alfresco.repo.site.SiteDoesNotExistException 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)

Aggregations

PersonFavourite (org.alfresco.repo.favourites.PersonFavourite)1 SiteDoesNotExistException (org.alfresco.repo.site.SiteDoesNotExistException)1 DocumentTarget (org.alfresco.rest.api.model.DocumentTarget)1 Favourite (org.alfresco.rest.api.model.Favourite)1 FolderTarget (org.alfresco.rest.api.model.FolderTarget)1 SiteTarget (org.alfresco.rest.api.model.SiteTarget)1 Target (org.alfresco.rest.api.model.Target)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)1