Search in sources :

Example 1 with FolderFavouriteTarget

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;
                }
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.simple.JSONObject) TestSite(org.alfresco.rest.api.tests.RepoService.TestSite) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) FolderFavouriteTarget(org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget) FavouriteNode(org.alfresco.rest.api.tests.client.data.FavouriteNode) FileFavouriteTarget(org.alfresco.rest.api.tests.client.data.FileFavouriteTarget) Favourite(org.alfresco.rest.api.tests.client.data.Favourite) Test(org.junit.Test)

Example 2 with FolderFavouriteTarget

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;
}
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)

Example 3 with FolderFavouriteTarget

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;
}
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)

Aggregations

Favourite (org.alfresco.rest.api.tests.client.data.Favourite)3 FolderFavouriteTarget (org.alfresco.rest.api.tests.client.data.FolderFavouriteTarget)3 FileFavouriteTarget (org.alfresco.rest.api.tests.client.data.FileFavouriteTarget)2 Predicate (com.google.common.base.Predicate)1 Date (java.util.Date)1 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)1 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)1 FavouriteFolder (org.alfresco.rest.api.tests.client.data.FavouriteFolder)1 FavouriteNode (org.alfresco.rest.api.tests.client.data.FavouriteNode)1 SiteFavouriteTarget (org.alfresco.rest.api.tests.client.data.SiteFavouriteTarget)1 Type (org.alfresco.service.cmr.favourites.FavouritesService.Type)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 JSONObject (org.json.simple.JSONObject)1 Test (org.junit.Test)1