Search in sources :

Example 1 with Type

use of org.alfresco.service.cmr.favourites.FavouritesService.Type in project alfresco-remote-api by Alfresco.

the class TestFavourites method testValidRequests.

@Test
public void testValidRequests() throws Exception {
    List<Favourite> expectedFavourites = new ArrayList<Favourite>();
    {
        // add some favourites
        // 2467
        log("cloud-2467");
        Favourite siteFavourite1 = makeSiteFavourite(person1PublicSites.get(0));
        FavouriteDocument document = repoService.getDocument(network1.getId(), person1PublicDocs.get(0));
        Favourite fileFavourite1 = makeFileFavourite(document.getGuid());
        FavouriteFolder folder = repoService.getFolder(network1.getId(), person1PublicFolders.get(0));
        Favourite folderFavourite1 = makeFolderFavourite(folder.getGuid());
        Favourite siteFavourite2 = makeSiteFavourite(person1PublicSites.get(1));
        document = repoService.getDocument(network1.getId(), person1PublicDocs.get(1));
        Favourite fileFavourite2 = makeFileFavourite(document.getGuid());
        folder = repoService.getFolder(network1.getId(), person1PublicFolders.get(1));
        Favourite folderFavourite2 = makeFolderFavourite(folder.getGuid());
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite1);
            expectedFavourites.add(ret);
            siteFavourite1.expected(ret);
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite1);
            expectedFavourites.add(ret);
            fileFavourite1.expected(ret);
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite1);
            expectedFavourites.add(ret);
            folderFavourite1.expected(ret);
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite2);
            expectedFavourites.add(ret);
            siteFavourite2.expected(ret);
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite2);
            expectedFavourites.add(ret);
            fileFavourite2.expected(ret);
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite2);
            expectedFavourites.add(ret);
            folderFavourite2.expected(ret);
        }
        // already a favourite - 201
        {
            log("cloud-2472");
            {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
                Favourite ret = favouritesProxy.createFavourite(person10Id, siteFavourite1);
                siteFavourite1.expected(ret);
            }
            {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
                Favourite ret = favouritesProxy.createFavourite(person10Id, folderFavourite1);
                folderFavourite1.expected(ret);
            }
            {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
                Favourite ret = favouritesProxy.createFavourite(person10Id, fileFavourite1);
                fileFavourite1.expected(ret);
            }
        }
        {
            // cloud-2498
            // cloud-2499
            // create and list favourites across networks
            List<Favourite> person21ExpectedFavourites = new ArrayList<Favourite>();
            log("cloud-2498");
            log("cloud-2499");
            {
                // favourite a site in another network
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id));
                Favourite favourite = makeSiteFavourite(person1PrivateSites.get(0));
                try {
                    favouritesProxy.createFavourite("-me-", favourite);
                    fail();
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
                }
                int skipCount = 0;
                int maxItems = 10;
                Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size());
                try {
                    favouritesProxy.getFavourites("-me-", createParams(paging, null));
                    fail();
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
                }
            }
            // favourite a document in another network
            {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id));
                FavouriteDocument document1 = new FavouriteDocument(person1PrivateDocs.get(0).getId());
                Favourite favourite = makeFileFavourite(document1.getGuid());
                try {
                    favouritesProxy.createFavourite("-me-", favourite);
                    fail();
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
                }
                sort(person21ExpectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
                int skipCount = 0;
                int maxItems = 10;
                Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size());
                try {
                    favouritesProxy.getFavourites("-me-", createParams(paging, null));
                    fail();
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
                }
            }
            // favourite a folder in another network
            {
                publicApiClient.setRequestContext(new RequestContext(network1.getId(), person21Id));
                FavouriteFolder folder1 = new FavouriteFolder(person1PrivateFolders.get(0).getId());
                Favourite favourite = makeFolderFavourite(folder1.getGuid());
                try {
                    favouritesProxy.createFavourite("-me-", favourite);
                    fail();
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
                }
                sort(person21ExpectedFavourites, FavouritesService.DEFAULT_SORT_PROPS);
                int skipCount = 0;
                int maxItems = 10;
                Paging paging = getPaging(skipCount, maxItems, person21ExpectedFavourites.size(), person21ExpectedFavourites.size());
                try {
                    favouritesProxy.getFavourites("-me-", createParams(paging, null));
                    fail();
                } catch (PublicApiException e) {
                    assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode());
                }
            }
        }
    }
    // GET favourites
    // test paging and sorting
    {
        // cloud-2458
        // cloud-2462
        // cloud-2461
        {
            log("cloud-2458");
            log("cloud-2461");
            log("cloud-2462");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            List<Favourite> expected = new ArrayList<Favourite>(expectedFavourites);
            sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
            int skipCount = 0;
            int maxItems = 2;
            Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, null));
            checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            List<Favourite> expected = new ArrayList<Favourite>(expectedFavourites);
            sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
            int skipCount = 2;
            int maxItems = 4;
            Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, null));
            checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        // 2466
        // GET favourites for "-me-"
        {
            log("cloud-2466");
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            List<Favourite> expected = new ArrayList<Favourite>(expectedFavourites);
            sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expectedFavourites.size(), expectedFavourites.size());
            ListResponse<Favourite> resp = favouritesProxy.getFavourites("-me-", createParams(paging, null));
            checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
    }
    // 2459
    {
        log("cloud-2459");
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
        int skipCount = 0;
        int maxItems = Integer.MAX_VALUE;
        Paging paging = getPaging(skipCount, maxItems, 0, 0);
        ListResponse<Favourite> resp = favouritesProxy.getFavourites(person11Id, createParams(paging, null));
        List<Favourite> empty = Collections.emptyList();
        checkList(empty, paging.getExpectedPaging(), resp);
    }
    // cloud-2460: filtering by target type
    {
        log("cloud-2460");
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Set<Type> types = new HashSet<Type>(Arrays.asList(Type.FILE));
            List<Favourite> expected = filter(expectedFavourites, types);
            sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
            Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/file))");
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
            checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Set<Type> types = new HashSet<Type>(Arrays.asList(Type.FOLDER));
            List<Favourite> expected = filter(expectedFavourites, types);
            sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
            Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/folder))");
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
            checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        // target/file
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Set<Type> types = new HashSet<Type>(Arrays.asList(Type.FILE));
            List<Favourite> expected = filter(expectedFavourites, types);
            sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
            Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/file))");
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
            checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        // target/folder
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Set<Type> types = new HashSet<Type>(Arrays.asList(Type.FOLDER));
            List<Favourite> expected = filter(expectedFavourites, types);
            sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
            Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/folder))");
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
            checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        // target/site
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Set<Type> types = new HashSet<Type>(Arrays.asList(Type.SITE));
            List<Favourite> expected = filter(expectedFavourites, types);
            sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
            Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/site))");
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
            checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        // target/folder OR target/file.
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Set<Type> types = new HashSet<Type>(Arrays.asList(Type.FOLDER, Type.FILE));
            List<Favourite> expected = filter(expectedFavourites, types);
            sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
            Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/file) OR EXISTS(target/folder))");
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
            checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        // target/site OR target/file.
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Set<Type> types = new HashSet<Type>(Arrays.asList(Type.SITE, Type.FILE));
            List<Favourite> expected = filter(expectedFavourites, types);
            sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
            Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/file) OR EXISTS(target/site))");
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
            checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
        // target/site OR target/folder.
        {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            Set<Type> types = new HashSet<Type>(Arrays.asList(Type.SITE, Type.FOLDER));
            List<Favourite> expected = filter(expectedFavourites, types);
            sort(expected, FavouritesService.DEFAULT_SORT_PROPS);
            int skipCount = 0;
            int maxItems = Integer.MAX_VALUE;
            Paging paging = getPaging(skipCount, maxItems, expected.size(), expected.size());
            Map<String, String> params = Collections.singletonMap("where", "(EXISTS(target/site) OR EXISTS(target/folder))");
            ListResponse<Favourite> resp = favouritesProxy.getFavourites(person10Id, createParams(paging, params));
            checkList(expected.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
        }
    }
    // GET a favourite
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
        favouritesProxy.getFavourite(person10Id, GUID.generate());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
        Favourite favourite = expectedFavourites.get(0);
        favouritesProxy.getFavourite(GUID.generate(), favourite.getTargetGuid());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
        Favourite favourite = expectedFavourites.get(0);
        Favourite resp = favouritesProxy.getFavourite(person10Id, favourite.getTargetGuid());
        favourite.expected(resp);
    }
    // cloud-2479, PUT case
    {
        log("cloud-2479.1");
        updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.site);
        log("cloud-2479.2");
        updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.file);
        log("cloud-2479.3");
        updateFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.folder);
    }
    try {
        // cloud-2474
        // non-existent personId
        log("cloud-2474");
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
        favouritesProxy.removeFavourite(GUID.generate(), GUID.generate());
        fail();
    } catch (PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
    }
    // cloud-2475
    // try delete a non-existent favourite for a node that exists
    {
        log("cloud-2475");
        NodeRef doc = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() {

            @Override
            public NodeRef doWork() throws Exception {
                NodeRef containerNodeRef = person1PublicSites.get(0).getContainerNodeRef("documentLibrary");
                NodeRef doc = repoService.createDocument(containerNodeRef, GUID.generate(), "");
                return doc;
            }
        }, person11Id, network1.getId());
        String favouriteId = doc.getId();
        publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
        ListResponse<Favourite> before = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null);
        List<Favourite> beforeList = before.getList();
        assertTrue(beforeList.size() > 0);
        try {
            favouritesProxy.removeFavourite(person10Id, favouriteId);
            fail("Should be a 404");
        } catch (PublicApiException e) {
            // expected
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        // check no favourites have been removed
        ListResponse<Favourite> after = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null);
        assertEquals(beforeList.size(), after.getList().size());
    }
    // cloud-2473, DELETE case
    {
        log("cloud-2473.1");
        deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.site);
        log("cloud-2473.2");
        deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.file);
        log("cloud-2473.3");
        Favourite favourite = deleteFavourite(network1.getId(), person10Id, person10Id, TARGET_TYPE.folder);
        // try to delete non-existent favourite
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id));
            favouritesProxy.removeFavourite(person10Id, favourite.getTargetGuid());
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
    }
    // cloud-2476
    // try delete another user's favourite
    {
        log("cloud-2476");
        // make sure there are favourites to delete
        // publicApiClient.setRequestContext(new RequestContext(network1.getId(), personId));
        // SiteFavouriteTarget target = new SiteFavouriteTarget(person1Sites.get(0));
        // Favourite favourite = new Favourite(target);
        // favouritesProxy.createFavourite(personId, favourite);
        ListResponse<Favourite> before = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null);
        assertTrue(before.getList().size() > 0);
        Favourite favourite = before.getList().get(0);
        try {
            publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id));
            favouritesProxy.removeFavourite(person10Id, favourite.getTargetGuid());
            fail();
        } catch (PublicApiException e) {
            assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
        }
        ListResponse<Favourite> after = getFavourites(network1.getId(), person10Id, person10Id, 0, Integer.MAX_VALUE, null, null, null);
        assertEquals(before.getList().size(), after.getList().size());
    }
}
Also used : ListResponse(org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) ArrayList(java.util.ArrayList) FavouriteFolder(org.alfresco.rest.api.tests.client.data.FavouriteFolder) FavouriteDocument(org.alfresco.rest.api.tests.client.data.FavouriteDocument) PublicApiException(org.alfresco.rest.api.tests.client.PublicApiException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Type(org.alfresco.service.cmr.favourites.FavouritesService.Type) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) List(java.util.List) ArrayList(java.util.ArrayList) RequestContext(org.alfresco.rest.api.tests.client.RequestContext) Favourite(org.alfresco.rest.api.tests.client.data.Favourite) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Type

use of org.alfresco.service.cmr.favourites.FavouritesService.Type 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 3 with Type

use of org.alfresco.service.cmr.favourites.FavouritesService.Type in project alfresco-remote-api by Alfresco.

the class FavouritesImpl method getTarget.

private Target getTarget(PersonFavourite personFavourite, Parameters parameters) {
    Target target = null;
    NodeRef nodeRef = personFavourite.getNodeRef();
    Type type = personFavourite.getType();
    if (type.equals(Type.FILE)) {
        Document document = nodes.getDocument(nodeRef);
        setPathInfo(document, parameters.getInclude());
        target = new DocumentTarget(document);
    } else if (type.equals(Type.FOLDER)) {
        Folder folder = nodes.getFolder(nodeRef);
        setPathInfo(folder, parameters.getInclude());
        target = new FolderTarget(folder);
    } else if (type.equals(Type.SITE)) {
        SiteInfo siteInfo = siteService.getSite(nodeRef);
        String role = sites.getSiteRole(siteInfo.getShortName());
        Site site = new Site(siteInfo, role);
        target = new SiteTarget(site);
    } else {
        throw new AlfrescoRuntimeException("Unexpected favourite target type: " + type);
    }
    return target;
}
Also used : Site(org.alfresco.rest.api.model.Site) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) 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) Type(org.alfresco.service.cmr.favourites.FavouritesService.Type) DocumentTarget(org.alfresco.rest.api.model.DocumentTarget) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) SiteTarget(org.alfresco.rest.api.model.SiteTarget) FolderTarget(org.alfresco.rest.api.model.FolderTarget) Document(org.alfresco.rest.api.model.Document) Folder(org.alfresco.rest.api.model.Folder)

Example 4 with Type

use of org.alfresco.service.cmr.favourites.FavouritesService.Type in project alfresco-remote-api by Alfresco.

the class FavouritesImpl method removeFavourite.

@Override
public void removeFavourite(String personId, String id) {
    personId = people.validatePerson(personId, true);
    NodeRef nodeRef = nodes.validateNode(id);
    boolean exists = false;
    Type type = favouritesService.getType(nodeRef);
    if (type.equals(Type.SITE)) {
        SiteInfo siteInfo = siteService.getSite(nodeRef);
        if (siteInfo == null) {
            // shouldn't happen because the type implies it's a site
            throw new AlfrescoRuntimeException("Unable to find site with nodeRef " + nodeRef);
        }
        exists = favouritesService.removeFavourite(personId, siteInfo.getNodeRef());
    } else if (type.equals(Type.FILE)) {
        exists = favouritesService.removeFavourite(personId, nodeRef);
    } else if (type.equals(Type.FOLDER)) {
        exists = favouritesService.removeFavourite(personId, nodeRef);
    }
    if (!exists) {
        throw new RelationshipResourceNotFoundException(personId, id);
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Type(org.alfresco.service.cmr.favourites.FavouritesService.Type) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 5 with Type

use of org.alfresco.service.cmr.favourites.FavouritesService.Type in project alfresco-remote-api by Alfresco.

the class FavouritesImpl method getFavourites.

@Override
public CollectionWithPagingInfo<Favourite> getFavourites(String personId, final Parameters parameters) {
    personId = people.validatePerson(personId, true);
    Paging paging = parameters.getPaging();
    List<Pair<FavouritesService.SortFields, Boolean>> sortProps = getSortProps(parameters);
    final Set<Type> filteredByClientQuery = new HashSet<Type>();
    // Default all
    Set<Type> filterTypes = FavouritesService.Type.ALL_FILTER_TYPES;
    // filterType is of the form 'target.<site|file|folder>'
    QueryHelper.walk(parameters.getQuery(), new WalkerCallbackAdapter() {

        @Override
        public void or() {
        // OR is supported but exists() will be called for each EXISTS so we don't
        // need to do anything here.  If we don't override it then it will be assumed
        // that OR in the grammar is not supported.
        }

        @Override
        public void exists(String filteredByClient, boolean negated) {
            if (filteredByClient != null) {
                int idx = filteredByClient.lastIndexOf("/");
                if (idx == -1 || idx == filteredByClient.length()) {
                    throw new InvalidArgumentException();
                } else {
                    String filtertype = filteredByClient.substring(idx + 1).toUpperCase();
                    filteredByClientQuery.add(Type.valueOf(filtertype));
                }
            }
        }
    });
    if (filteredByClientQuery.size() > 0) {
        filterTypes = filteredByClientQuery;
    }
    final PagingResults<PersonFavourite> favourites = favouritesService.getPagedFavourites(personId, filterTypes, sortProps, Util.getPagingRequest(paging));
    return wrap(paging, favourites, parameters);
}
Also used : Paging(org.alfresco.rest.framework.resource.parameters.Paging) FavouritesService(org.alfresco.service.cmr.favourites.FavouritesService) Type(org.alfresco.service.cmr.favourites.FavouritesService.Type) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) PersonFavourite(org.alfresco.repo.favourites.PersonFavourite) WalkerCallbackAdapter(org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter) Pair(org.alfresco.util.Pair) HashSet(java.util.HashSet)

Aggregations

Type (org.alfresco.service.cmr.favourites.FavouritesService.Type)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 HashSet (java.util.HashSet)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 Favourite (org.alfresco.rest.api.tests.client.data.Favourite)2 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)2 Predicate (com.google.common.base.Predicate)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PersonFavourite (org.alfresco.repo.favourites.PersonFavourite)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1 Document (org.alfresco.rest.api.model.Document)1 DocumentTarget (org.alfresco.rest.api.model.DocumentTarget)1 Folder (org.alfresco.rest.api.model.Folder)1 FolderTarget (org.alfresco.rest.api.model.FolderTarget)1 Site (org.alfresco.rest.api.model.Site)1 SiteTarget (org.alfresco.rest.api.model.SiteTarget)1 Target (org.alfresco.rest.api.model.Target)1 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)1 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)1