use of org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget in project alfresco-remote-api by Alfresco.
the class TestFavourites method testGetFavouritesWithPath.
/**
* Tests get favourites with 'include' parameter.
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/people/<userName>/favorites?include=path}
*/
@Test
public void testGetFavouritesWithPath() throws Exception {
// As person12 user
setRequestContext(network1.getId(), person12Id, "password");
// person1's folder (Test Folder1)
final NodeRef folderNodeRef = person1PublicFolders.get(0);
// a file (Test Doc2) in the folder (Test Folder1)
final NodeRef nodeRef = person1PublicDocs.get(1);
// person1's public site
final TestSite publicSite = person1PublicSites.get(0);
// Favourite the doc (Test Doc2)
Favourite fileFavourite = makeFileFavourite(nodeRef.getId());
favouritesProxy.createFavourite(person12Id, fileFavourite);
// Favourite the folder (Test Folder1)
Favourite folderFavourite = makeFolderFavourite(folderNodeRef.getId());
favouritesProxy.createFavourite(person12Id, folderFavourite);
// Favourite the public site
final Favourite siteFavourite = makeSiteFavourite(publicSite);
favouritesProxy.createFavourite(person12Id, siteFavourite);
Paging paging = getPaging(0, 100);
Map<String, String> otherParams = Collections.singletonMap("include", "path");
ListResponse<Favourite> resp = favouritesProxy.getFavourites(person12Id, createParams(paging, otherParams));
List<Favourite> actualFavouritesList = resp.getList();
assertEquals("Incorrect number of entries returned", 3, actualFavouritesList.size());
actualFavouritesList.forEach(fav -> {
FavouriteNode node;
switch(fav.getType()) {
case FILE:
{
node = ((FileFavouriteTarget) fav.getTarget()).getDocument();
assertNotNull("node is null.", node);
assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary/Test Folder1", true);
break;
}
case FOLDER:
{
node = ((FolderFavouriteTarget) fav.getTarget()).getFolder();
assertNotNull("node is null.", node);
assertPathInfo(node.getPath(), "/Company Home/Sites/" + publicSite.getSiteId() + "/documentLibrary", true);
break;
}
case SITE:
{
JSONObject siteJsonObject = fav.getTarget().toJSON();
assertNotNull("There should be a site JSON object.", siteJsonObject);
assertNull("Path info should not be returned for sites.", siteJsonObject.get("path"));
break;
}
}
});
// Get favourites without 'include' option
resp = favouritesProxy.getFavourites(person12Id, createParams(paging, null));
actualFavouritesList = resp.getList();
assertEquals("Incorrect number of entries returned", 3, actualFavouritesList.size());
actualFavouritesList.forEach(fav -> {
FavouriteNode node;
switch(fav.getType()) {
case FILE:
{
node = ((FileFavouriteTarget) fav.getTarget()).getDocument();
assertNotNull("node is null.", node);
assertNull("Path info should not be returned by default", node.getPath());
break;
}
case FOLDER:
{
node = ((FolderFavouriteTarget) fav.getTarget()).getFolder();
assertNotNull("node is null.", node);
assertNull("Path info should not be returned by default", node.getPath());
break;
}
case SITE:
{
JSONObject siteJsonObject = fav.getTarget().toJSON();
assertNotNull("There should be a site JSON object.", siteJsonObject);
assertNull("Path info should not be returned for sites.", siteJsonObject.get("path"));
break;
}
}
});
}
use of org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget in project alfresco-remote-api by Alfresco.
the class TestFavourites method makeFolderFavourite.
private Favourite makeFolderFavourite(String targetGuid) throws ParseException {
FavouriteFolder folder = new FavouriteFolder(targetGuid);
FolderFavouriteTarget target = new FolderFavouriteTarget(folder);
Date creationData = new Date();
Favourite favourite = new Favourite(creationData, null, target, null);
return favourite;
}
use of org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget in project alfresco-remote-api by Alfresco.
the class TestFavourites method filter.
/**
* Returns a new list.
*
* @param favourites List<Favourite>
* @param types Set<Type>
* @return ArrayList<Favourite>
*/
private ArrayList<Favourite> filter(List<Favourite> favourites, final Set<Type> types) {
Predicate<Favourite> predicate = new Predicate<Favourite>() {
@Override
public boolean apply(Favourite other) {
Type type = null;
if (other.getTarget() instanceof FileFavouriteTarget) {
type = Type.FILE;
} else if (other.getTarget() instanceof FolderFavouriteTarget) {
type = Type.FOLDER;
} else if (other.getTarget() instanceof SiteFavouriteTarget) {
type = Type.SITE;
}
boolean ret = (type != null && types.contains(type));
return ret;
}
};
ArrayList<Favourite> ret = Lists.newArrayList(Collections2.filter(favourites, predicate));
return ret;
}
Aggregations