use of org.alfresco.rest.api.model.Favourite 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);
}
use of org.alfresco.rest.api.model.Favourite 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);
}
}
use of org.alfresco.rest.api.model.Favourite 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;
}
use of org.alfresco.rest.api.model.Favourite 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;
}
Aggregations