Search in sources :

Example 11 with Favourite

use of org.alfresco.rest.api.tests.client.data.Favourite in project alfresco-remote-api by Alfresco.

the class TestFavourites method testVerifyFavorite.

@Test
public void testVerifyFavorite() throws Exception {
    setRequestContext(network1.getId(), person12Id, "password");
    // person1's folder (Test Folder1)
    final NodeRef folderNodeRef = person1PublicFolders.get(0);
    // a file in the site's document library (Test Doc1)
    final NodeRef nodeRef1 = person1PublicDocs.get(0);
    // a file (Test Doc2) in the folder (Test Folder1)
    final NodeRef nodeRef2 = person1PublicDocs.get(1);
    // Favourite the doc (Test Doc1)
    Favourite file1Favourite = makeFileFavourite(nodeRef1.getId());
    favouritesProxy.createFavourite(person12Id, file1Favourite);
    // Favourite the doc (Test Doc2)
    Favourite file2Favourite = makeFileFavourite(nodeRef2.getId());
    favouritesProxy.createFavourite(person12Id, file2Favourite);
    Map<String, String> params = new HashMap<>();
    params.put("include", "isFavorite");
    HttpResponse response = getAll(getNodeChildrenUrl(folderNodeRef.getId()), null, params, 200);
    List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
    assertTrue(nodes.size() == 1);
    assertTrue(nodes.get(0).getIsFavorite());
    response = getAll(getNode(nodeRef1.getId()), null, params, 200);
    Node node1 = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertTrue(node1.getIsFavorite());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) Node(org.alfresco.rest.api.tests.client.data.Node) FavouriteNode(org.alfresco.rest.api.tests.client.data.FavouriteNode) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Favourite(org.alfresco.rest.api.tests.client.data.Favourite) Test(org.junit.Test)

Example 12 with Favourite

use of org.alfresco.rest.api.tests.client.data.Favourite 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;
}
Also used : Type(org.alfresco.service.cmr.favourites.FavouritesService.Type) FolderFavouriteTarget(org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget) SiteFavouriteTarget(org.alfresco.rest.api.tests.client.data.SiteFavouriteTarget) FileFavouriteTarget(org.alfresco.rest.api.tests.client.data.FileFavouriteTarget) Favourite(org.alfresco.rest.api.tests.client.data.Favourite) Predicate(com.google.common.base.Predicate)

Example 13 with Favourite

use of org.alfresco.rest.api.tests.client.data.Favourite 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);
    return favourite;
}
Also used : FavouriteFolder(org.alfresco.rest.api.tests.client.data.FavouriteFolder) FolderFavouriteTarget(org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget) Date(java.util.Date) Favourite(org.alfresco.rest.api.tests.client.data.Favourite)

Aggregations

Favourite (org.alfresco.rest.api.tests.client.data.Favourite)13 NodeRef (org.alfresco.service.cmr.repository.NodeRef)7 Test (org.junit.Test)7 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)6 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)5 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)5 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)5 FileFavouriteTarget (org.alfresco.rest.api.tests.client.data.FileFavouriteTarget)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)3 FavouriteDocument (org.alfresco.rest.api.tests.client.data.FavouriteDocument)3 FavouriteFolder (org.alfresco.rest.api.tests.client.data.FavouriteFolder)3 FavouriteNode (org.alfresco.rest.api.tests.client.data.FavouriteNode)3 FolderFavouriteTarget (org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget)3 JSONObject (org.json.simple.JSONObject)3 ParseException (java.text.ParseException)2 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)2 SiteFavouriteTarget (org.alfresco.rest.api.tests.client.data.SiteFavouriteTarget)2 SiteMembershipRequest (org.alfresco.rest.api.tests.client.data.SiteMembershipRequest)2