Search in sources :

Example 1 with Site

use of org.alfresco.rest.api.model.Site in project alfresco-remote-api by Alfresco.

the class NodeApiTest method testAllowableOps.

/**
 * Tests optional lookup of Allowable Operations (eg. when getting node info, listing node children, ...)
 *
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/children?include=allowableOperations}
 * {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>?include=allowableOperations}
 */
@Test
public void testAllowableOps() throws Exception {
    // as user1 ...
    setRequestContext(user1);
    String rootNodeId = getRootNodeId();
    String sharedNodeId = getSharedNodeId();
    Map params = new HashMap<>();
    params.put(Nodes.PARAM_RELATIVE_PATH, "/Sites");
    HttpResponse response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
    Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    String sitesNodeId = nodeResp.getId();
    params = new HashMap<>();
    params.put(Nodes.PARAM_RELATIVE_PATH, "/Data Dictionary");
    response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    String ddNodeId = nodeResp.getId();
    params = new HashMap<>();
    params.put("include", "allowableOperations");
    response = getSingle(NodesEntityResource.class, rootNodeId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNull(nodeResp.getAllowableOperations());
    response = getSingle(NodesEntityResource.class, sharedNodeId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(1, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    // -ve
    deleteNode(sharedNodeId, 403);
    response = getSingle(NodesEntityResource.class, getMyNodeId(), params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(4, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // create folder
    nodeResp = createFolder(sharedNodeId, "folder 1 - " + RUNID);
    String folderId = nodeResp.getId();
    assertNull(nodeResp.getAllowableOperations());
    response = getSingle(NodesEntityResource.class, folderId, null, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNull(nodeResp.getAllowableOperations());
    response = getSingle(NodesEntityResource.class, folderId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(4, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // create file
    nodeResp = createTextFile(folderId, "my file - " + RUNID + ".txt", "The quick brown fox jumps over the lazy dog");
    String fileId = nodeResp.getId();
    assertNull(nodeResp.getAllowableOperations());
    response = getSingle(NodesEntityResource.class, fileId, null, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNull(nodeResp.getAllowableOperations());
    // a file - no create
    response = getSingle(NodesEntityResource.class, fileId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // as user2 ...
    setRequestContext(user2);
    response = getSingle(NodesEntityResource.class, folderId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(1, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    // -ve
    deleteNode(folderId, 403);
    response = getSingle(NodesEntityResource.class, fileId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNull(nodeResp.getAllowableOperations());
    // -ve
    deleteNode(fileId, 403);
    // as admin ...
    setRequestContext(networkAdmin);
    response = publicApiClient.get(NodesEntityResource.class, folderId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(4, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // a file - no create
    response = publicApiClient.get(NodesEntityResource.class, fileId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    response = publicApiClient.get(NodesEntityResource.class, sharedNodeId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(4, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_DELETE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // Company Home - no delete
    response = publicApiClient.get(NodesEntityResource.class, rootNodeId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // -ve
    deleteNode(rootNodeId, 403);
    // Sites - no delete
    response = publicApiClient.get(NodesEntityResource.class, sitesNodeId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // -ve
    deleteNode(sitesNodeId, 403);
    // Data Dictionary - no delete
    response = publicApiClient.get(NodesEntityResource.class, ddNodeId, null, params);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // -ve
    deleteNode(ddNodeId, 403);
    publicApiClient.setRequestContext(null);
    // as user1 ...
    String userId = user1;
    setRequestContext(userId);
    response = getSingle("sites", tSiteId, null, null, 200);
    Site siteResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Site.class);
    String siteNodeId = siteResp.getGuid();
    response = getSingle(NodesEntityResource.class, siteNodeId, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertEquals(userId, nodeResp.getCreatedByUser().getId());
    assertNotNull(nodeResp.getAllowableOperations());
    assertEquals(3, nodeResp.getAllowableOperations().size());
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_CREATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE));
    assertTrue(nodeResp.getAllowableOperations().contains(Nodes.OP_UPDATE_PERMISSIONS));
    // -ve
    deleteNode(siteNodeId, 403);
    setRequestContext(user1);
    // fix for REPO-514 (NPE for a node that was neither a file/document nor a folder)
    Node n = new Node();
    n.setName("o1");
    n.setNodeType(TYPE_CM_OBJECT);
    response = post(getNodeChildrenUrl(folderId), toJsonAsStringNonNull(n), 201);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    String o1Id = nodeResp.getId();
    params = new HashMap<>();
    params.put("include", "allowableOperations");
    response = getSingle(NodesEntityResource.class, o1Id, params, 200);
    nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
    assertNotNull(nodeResp.getAllowableOperations());
    // some cleanup
    deleteNode(folderId, true, 204);
}
Also used : Site(org.alfresco.rest.api.model.Site) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Node(org.alfresco.rest.api.tests.client.data.Node) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) NodesEntityResource(org.alfresco.rest.api.nodes.NodesEntityResource) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 2 with Site

use of org.alfresco.rest.api.model.Site in project alfresco-remote-api by Alfresco.

the class NodeApiTest method testCopySite.

@Test
public void testCopySite() throws Exception {
    setRequestContext(user1);
    // create folder
    Folder folderResp = createFolder(Nodes.PATH_MY, "siteCopytarget");
    String targetId = folderResp.getId();
    Map<String, String> body = new HashMap<>();
    body.put("targetParentId", targetId);
    // test that you can't copy a site
    HttpResponse response = getSingle("sites", tSiteId, null, null, 200);
    Site siteResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Site.class);
    String siteNodeId = siteResp.getGuid();
    post("nodes/" + siteNodeId + "/copy", toJsonAsStringNonNull(body), null, 422);
    // test that you can't copy a site doclib
    post("nodes/" + tDocLibNodeId + "/copy", toJsonAsStringNonNull(body), null, 422);
}
Also used : Site(org.alfresco.rest.api.model.Site) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Folder(org.alfresco.rest.api.tests.client.data.Folder) Test(org.junit.Test) AbstractSingleNetworkSiteTest(org.alfresco.rest.AbstractSingleNetworkSiteTest)

Example 3 with Site

use of org.alfresco.rest.api.model.Site in project alfresco-remote-api by Alfresco.

the class QueriesSitesApiTest method checkApiCall.

// Note expectedIds defaults to ids
private void checkApiCall(String term, String orderBy, Paging paging, int expectedStatus, String[] expectedIds, String... ids) throws Exception {
    Map<String, String> params = new HashMap<>(1);
    params.put(Queries.PARAM_TERM, "\"" + term + "\"");
    if (orderBy != null) {
        params.put(Queries.PARAM_ORDERBY, orderBy);
    }
    dummySearchServiceQueryNodeRefs.clear();
    for (String id : ids) {
        NodeRef nodeRef = getNodeRef(id);
        dummySearchServiceQueryNodeRefs.add(nodeRef);
    }
    expectedIds = expectedIds != null ? expectedIds : ids;
    HttpResponse response = getAll(URL_QUERIES_LSS, paging, params, 200);
    if (expectedStatus == 200) {
        String termWithEscapedAsterisks = term.replaceAll("\\*", "\\\\*");
        String expectedQuery = "TYPE:\"{http://www.alfresco.org/model/site/1.0}site\" AND (\"*" + termWithEscapedAsterisks + "*\")";
        ArgumentCaptor<SearchParameters> searchParametersCaptor = ArgumentCaptor.forClass(SearchParameters.class);
        verify(mockSearchService, times(++callCountToMockSearchService)).query(searchParametersCaptor.capture());
        SearchParameters parameters = searchParametersCaptor.getValue();
        assertEquals("Query", expectedQuery, parameters.getQuery());
        List<Site> sites = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Site.class);
        assertEquals(expectedIds.length, sites.size());
        if (orderBy != null) {
            for (int i = 0; i < expectedIds.length; i++) {
                String id = expectedIds[i];
                String actualId = sites.get(i).getId();
                assertEquals("Order " + i + ":", id, actualId);
            }
        }
    }
}
Also used : Site(org.alfresco.rest.api.model.Site) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) HashMap(java.util.HashMap) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse)

Example 4 with Site

use of org.alfresco.rest.api.model.Site in project alfresco-remote-api by Alfresco.

the class SharedLinkApiTest method testGetSharedLinksIncludePath.

/**
 * Tests for get /shared-links?include=path
 *
 * <p>GET:</p>
 * {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/shared-links?include=path}
 */
@Test
@Category({ LuceneTests.class, RedundantTests.class })
public void testGetSharedLinksIncludePath() throws Exception {
    String contentText = "includePathTest" + RUNID;
    Paging paging = getPaging(0, 100);
    Map<String, String> queryParams = new HashMap<>();
    queryParams.put("include", "path");
    // As user 1: Test the backward compatibility by checking response with and without path is consistent when no shared-links
    setRequestContext(user1);
    // Get all shared links visible to user 1
    HttpResponse response = getAll(URL_SHARED_LINKS, paging, 200);
    List<QuickShareLink> sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    // Check that the same no of items is returned with include=path
    response = getAll(URL_SHARED_LINKS, paging, queryParams, 200);
    List<QuickShareLink> sharedLinksWithPath = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    assertEquals("get /shared-links/ API returns same no of shared-links with or without include=path, when there are no shared-links", sharedLinks, sharedLinksWithPath);
    // Create Files in various locations: My Files, SharedFiles, Sites with different visibility
    // Create doc in "My Files"
    Document myFile = createTextFile(getMyNodeId(), "MyFile" + RUNID + ".txt", contentText);
    // Create doc in "Shared" folder
    Document sharedFile = createTextFile(getSharedNodeId(), "SharedFile" + RUNID + ".txt", contentText);
    // Create Sites
    Site publicSite = createSite("TestSite-Public-" + RUNID, SiteVisibility.PUBLIC);
    Site modSite = createSite("TestSite-Moderate-" + RUNID, SiteVisibility.MODERATED);
    Site privateSite = createSite("TestSite-Private-" + RUNID, SiteVisibility.PRIVATE);
    // Create file in Site Public > DocumentLibrary
    String docLibPub = getSiteContainerNodeId(publicSite.getId(), "documentLibrary");
    Document filePublic = createTextFile(docLibPub, "filePublic.txt", contentText);
    // Create files in Site Moderated > DocumentLibrary > Folder 1 and Folder 2
    String docLibMod = getSiteContainerNodeId(modSite.getId(), "documentLibrary");
    Folder folder1 = createFolder(docLibMod, "1");
    Folder folder2 = createFolder(docLibMod, "2");
    Document fileMod = createTextFile(folder1.getId(), "fileMod.txt", contentText);
    Document fileMod2 = createTextFile(folder2.getId(), "fileMod2.txt", contentText);
    // Create file in Site Private > DocumentLibrary
    String docLibPvt = getSiteContainerNodeId(privateSite.getId(), "documentLibrary");
    Document filePrivate = createTextFile(docLibPvt, "filePrivate.txt", contentText);
    // Share the files above in: My Files, SharedFiles, Sites with different visibility
    String myFileLinkId = postSharedLink(myFile);
    String sharedLinkId = postSharedLink(sharedFile);
    String filePublicLinkId = postSharedLink(filePublic);
    String fileModLinkId = postSharedLink(fileMod);
    String fileMod2LinkId = postSharedLink(fileMod2);
    String filePrivateLinkId = postSharedLink(filePrivate);
    // Grant user2: Consumer Permission for Moderated Site > File1
    List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
    locallySetPermissions.add(new NodePermissions.NodePermission(user2, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
    NodePermissions nodePermissions = new NodePermissions();
    nodePermissions.setIsInheritanceEnabled(false);
    nodePermissions.setLocallySet(locallySetPermissions);
    Document docPermissions = new Document();
    docPermissions.setPermissions(nodePermissions);
    put(URL_NODES, fileMod.getId(), toJsonAsStringNonNull(docPermissions), null, 200);
    // Grant user2: Consumer Permission for Moderated Site > Folder 2, File2
    put(URL_NODES, fileMod2.getId(), toJsonAsStringNonNull(docPermissions), null, 200);
    Folder folderPermissions = new Folder();
    folderPermissions.setPermissions(nodePermissions);
    put(URL_NODES, folder2.getId(), toJsonAsStringNonNull(folderPermissions), null, 200);
    // Get links For User1
    setRequestContext(user1);
    response = getSingle(QuickShareLinkEntityResource.class, myFileLinkId, null, 200);
    QuickShareLink link = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
    assertNull("get /shared-links/<id> API does not return Path info by default", link.getPath());
    // Path info is not included for get shared-links/<id>
    response = getSingle(QuickShareLinkEntityResource.class, myFileLinkId, queryParams, 200);
    link = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class);
    assertNull("get /shared-links/<id> API ignores Path info when requested as it is a noAuth API.", link.getPath());
    response = getAll(URL_SHARED_LINKS, paging, 200);
    sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    assertEquals("API returns correct shared-links as expected: without path info", 6, sharedLinks.size());
    sharedLinks.forEach(sharedLink -> assertNull("API does not return Path info for any shared-links by default", sharedLink.getPath()));
    // Path info is included for get shared-links when requested
    response = getAll(URL_SHARED_LINKS, paging, queryParams, 200);
    sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    // Complete path info is retrieved for the user with access to the complete path
    assertEquals("API returns correct shared-links as expected: with path info", 6, sharedLinks.size());
    sharedLinks.forEach(sharedLink -> assertTrue("API returns Complete Path info for each link when requested by content owner", sharedLink.getPath().getIsComplete()));
    // Get links For User2
    setRequestContext(user2);
    response = getAll(URL_SHARED_LINKS, paging, 200);
    sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    // Path info is not included when not requested
    assertEquals("API returns correct shared-links as expected for user2: without path info", 4, sharedLinks.size());
    sharedLinks.forEach(sharedLink -> assertNull("get /shared-links/ API does not return Path info for any shared-links by default", sharedLink.getPath()));
    response = getAll(URL_SHARED_LINKS, paging, queryParams, 200);
    sharedLinks = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), QuickShareLink.class);
    // Path info is retrieved for the user with access to the complete path: Sorted as LIFO
    assertEquals("API returns correct shared-links as expected for user2: with path info", 4, sharedLinks.size());
    sharedLinks.forEach(sharedLink -> assertNotNull("API returns Path info for each link when requested by user2", sharedLink.getPath()));
    // Moderated Site > fileMod2: Path only includes elements where user2 has access
    QuickShareLink sharedLink = sharedLinks.get(0);
    assertEquals("Incorrect sort order or SharedLink ID for fileMod2: " + sharedLink, fileMod2LinkId, sharedLink.getId());
    PathInfo path = sharedLink.getPath();
    assertEquals("Complete Path is returned even when user2 does not have appropriate permissions. SharedLink Path: " + path, false, path.getIsComplete());
    assertEquals("Path omits immediate Parent folder Name when user has access to it. SharedLink Path: " + path, "/" + folder2.getName(), path.getName());
    assertEquals("Path omits immediate Parent folder ID when user has access to it. SharedLink Path: " + path, folder2.getId(), path.getElements().get(0).getId());
    // Moderated Site > fileMod: Path empty when user2 does not have access to the immediate parent
    sharedLink = sharedLinks.get(1);
    assertEquals("Incorrect sort order or SharedLink ID for fileMod: " + sharedLink, fileModLinkId, sharedLink.getId());
    path = sharedLink.getPath();
    assertNotNull("Path info is not included in the response when user does not have right permissions. SharedLink Path: " + path, path);
    assertNull("Path Name is returned when user does not have right permissions. SharedLink Path: " + path, path.getName());
    assertNull("Path info is returned when user does not have right permissions. SharedLink Path: " + path, path.getIsComplete());
    assertNull("Path Elements are returned when user does not have right permissions. SharedLink Path: " + path, path.getElements());
    // Public Site > filePublic: Path includes all the elements when user2 has appropriate access
    sharedLink = sharedLinks.get(2);
    assertEquals("Incorrect sort order or SharedLink ID for filePublic: " + sharedLink, filePublicLinkId, sharedLink.getId());
    path = sharedLink.getPath();
    assertEquals("Complete Path is not returned for user2 for public files. SharedLink Path: " + path, true, path.getIsComplete());
    assertEquals("Incorrect Path Name for Public Site Files. SharedLink Path: " + path, "/Company Home/Sites/" + publicSite.getId() + "/documentLibrary", path.getName());
    assertEquals("Incorrect Path Elements for Public Site Files. SharedLink Path: " + path, 4, path.getElements().size());
    assertEquals("Incorrect ID in the Path for Company Home. SharedLink Path: " + path, getRootNodeId(), path.getElements().get(0).getId());
    assertEquals("Incorrect ID in the Path for Public Site. SharedLink Path: " + path, publicSite.getGuid(), path.getElements().get(2).getId());
    assertEquals("Incorrect ID in the Path for Public Site DocLib. SharedLink Path: " + path, docLibPub, path.getElements().get(3).getId());
    // Shared Files > shared: Path includes all the elements when user2 has appropriate access
    sharedLink = sharedLinks.get(3);
    assertEquals("Incorrect sort order or SharedLink ID for sharedFiles: " + sharedLink, sharedLinkId, sharedLink.getId());
    path = sharedLink.getPath();
    assertEquals("Complete Path is not returned for user2 for shared files. SharedLink Path: " + path, true, path.getIsComplete());
    assertEquals("Incorrect Path Name for Shared Files. SharedLink Path: " + path, "/Company Home/Shared", path.getName());
    assertEquals("Incorrect Path Elements for Shared Files. SharedLink Path: " + path, 2, path.getElements().size());
    assertEquals("Incorrect ID in the Path for Company Home. SharedLink Path: " + path, getRootNodeId(), path.getElements().get(0).getId());
    assertEquals("Incorrect ID in the path for Shared Files. SharedLink Path: " + path, getSharedNodeId(), path.getElements().get(1).getId());
    // Unauthorized request returns 401
    setRequestContext(null, "UserNotKnown", DEFAULT_ADMIN_PWD);
    queryParams = new HashMap<>();
    getAll(URL_SHARED_LINKS, paging, queryParams, 401);
    // Unauthenticated request returns 401
    setRequestContext(user2, null, null);
    getAll(URL_SHARED_LINKS, paging, queryParams, 401);
    // Delete the shared links
    setRequestContext(user1);
    deleteSharedLink(myFileLinkId);
    deleteSharedLink(sharedLinkId);
    deleteSharedLink(filePublicLinkId);
    deleteSharedLink(fileModLinkId);
    deleteSharedLink(fileMod2LinkId);
    deleteSharedLink(filePrivateLinkId);
}
Also used : Site(org.alfresco.rest.api.model.Site) NodePermissions(org.alfresco.rest.api.model.NodePermissions) HashMap(java.util.HashMap) Paging(org.alfresco.rest.api.tests.client.PublicApiClient.Paging) ArrayList(java.util.ArrayList) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) Document(org.alfresco.rest.api.tests.client.data.Document) Folder(org.alfresco.rest.api.tests.client.data.Folder) QuickShareLinkEntityResource(org.alfresco.rest.api.quicksharelinks.QuickShareLinkEntityResource) PathInfo(org.alfresco.rest.api.model.PathInfo) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 5 with Site

use of org.alfresco.rest.api.model.Site 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)

Aggregations

Site (org.alfresco.rest.api.model.Site)10 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)5 HashMap (java.util.HashMap)4 RMSite (org.alfresco.rm.rest.api.model.RMSite)3 RMSiteCompliance (org.alfresco.rm.rest.api.model.RMSiteCompliance)3 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)3 Test (org.junit.Test)3 LinkedHashMap (java.util.LinkedHashMap)2 AbstractSingleNetworkSiteTest (org.alfresco.rest.AbstractSingleNetworkSiteTest)2 Document (org.alfresco.rest.api.model.Document)2 DocumentTarget (org.alfresco.rest.api.model.DocumentTarget)2 Folder (org.alfresco.rest.api.model.Folder)2 FolderTarget (org.alfresco.rest.api.model.FolderTarget)2 SiteTarget (org.alfresco.rest.api.model.SiteTarget)2 Target (org.alfresco.rest.api.model.Target)2 Folder (org.alfresco.rest.api.tests.client.data.Folder)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 BeanProperty (com.fasterxml.jackson.databind.BeanProperty)1 JavaType (com.fasterxml.jackson.databind.JavaType)1