Search in sources :

Example 6 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class LinksRestApiTest method setUp.

// General methods
@Override
protected void setUp() throws Exception {
    super.setUp();
    this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean("authenticationComponent");
    this.policyBehaviourFilter = (BehaviourFilter) getServer().getApplicationContext().getBean("policyBehaviourFilter");
    this.transactionService = (TransactionService) getServer().getApplicationContext().getBean("transactionService");
    this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
    this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
    this.siteService = (SiteService) getServer().getApplicationContext().getBean("SiteService");
    this.internalNodeService = (NodeService) getServer().getApplicationContext().getBean("nodeService");
    this.nodeArchiveService = (NodeArchiveService) getServer().getApplicationContext().getBean("nodeArchiveService");
    this.activityService = (ActivityService) getServer().getApplicationContext().getBean("activityService");
    ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory) getServer().getApplicationContext().getBean("ActivitiesFeed");
    ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
    this.feedGenerator = (FeedGenerator) activitiesFeedCtx.getBean("feedGenerator");
    this.postLookup = (PostLookup) activitiesFeedCtx.getBean("postLookup");
    // Authenticate as user
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    // Create test site
    // - only create the site if it doesn't already exist
    SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_LINKS);
    if (siteInfo == null) {
        this.siteService.createSite("CalendarSitePreset", SITE_SHORT_NAME_LINKS, "LinksSiteTitle", "TestDescription", SiteVisibility.PUBLIC);
    }
    // Ensure the links container is there
    if (!siteService.hasContainer(SITE_SHORT_NAME_LINKS, "links")) {
        siteService.createContainer(SITE_SHORT_NAME_LINKS, "links", null, null);
    }
    // Create users
    createUser(USER_ONE, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_LINKS);
    createUser(USER_TWO, SiteModel.SITE_COLLABORATOR, SITE_SHORT_NAME_LINKS);
    // Do tests as inviter user
    this.authenticationComponent.setCurrentUser(USER_ONE);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ApplicationContext(org.springframework.context.ApplicationContext) ChildApplicationContextFactory(org.alfresco.repo.management.subsystems.ChildApplicationContextFactory)

Example 7 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class NodeWebScripTest method testLinkCreation.

@SuppressWarnings("unchecked")
public void testLinkCreation() throws Exception {
    // Create a folder within the DocLib
    NodeRef siteDocLib = siteService.getContainer(TEST_SITE.getShortName(), SiteService.DOCUMENT_LIBRARY);
    String testFolder1Name = "testingLinkCreationFolder1";
    Map<QName, Serializable> testFolderProps = new HashMap<QName, Serializable>();
    testFolderProps.put(ContentModel.PROP_NAME, testFolder1Name);
    NodeRef testFolder1 = nodeService.createNode(siteDocLib, ContentModel.ASSOC_CONTAINS, QName.createQName("testingLinkCreationFolder1"), ContentModel.TYPE_FOLDER, testFolderProps).getChildRef();
    JSONObject jsonReq = null;
    JSONObject json = null;
    JSONArray jsonArray = new JSONArray();
    JSONArray jsonLinkNodes = null;
    JSONObject jsonLinkNode = null;
    // Create files in the testFolder1
    NodeRef testFile1 = createNode(testFolder1, "testingLinkCreationFile1", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
    NodeRef testFile2 = createNode(testFolder1, "testingLinkCreationFile2", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
    NodeRef testFile3 = createNode(testFolder1, "testingLinkCreationFile3", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
    // Create testFolder2 in the testFolder1
    String testFolder2Name = "testingLinkCreationFolder2";
    testFolderProps = new HashMap<QName, Serializable>();
    testFolderProps.put(ContentModel.PROP_NAME, testFolder2Name);
    NodeRef testFolder2 = nodeService.createNode(siteDocLib, ContentModel.ASSOC_CONTAINS, QName.createQName("testingLinkCreationFolder2"), ContentModel.TYPE_FOLDER, testFolderProps).getChildRef();
    // Create link to file1 in same folder - testFolder1
    Request req = new Request("POST", CREATE_LINK_API + testFile1.getStoreRef().getProtocol() + "/" + testFile1.getStoreRef().getIdentifier() + "/" + testFile1.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
    jsonArray.add(testFile1.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_OK));
    jsonLinkNodes = (JSONArray) json.get("linkNodes");
    assertNotNull(jsonLinkNodes);
    assertEquals(1, jsonLinkNodes.size());
    assertEquals("true", json.get("overallSuccess"));
    assertEquals("1", json.get("successCount"));
    assertEquals("0", json.get("failureCount"));
    jsonLinkNode = (JSONObject) jsonLinkNodes.get(0);
    String nodeRef = (String) jsonLinkNode.get("nodeRef");
    NodeRef file1Link = new NodeRef(nodeRef);
    // Check that app:linked aspect is added on sourceNode
    assertEquals(true, nodeService.hasAspect(testFile1, ApplicationModel.ASPECT_LINKED));
    assertEquals(true, nodeService.exists(file1Link));
    nodeService.deleteNode(file1Link);
    assertEquals(false, nodeService.hasAspect(testFile1, ApplicationModel.ASPECT_LINKED));
    // Create link to testFolder2 in same folder (testFolder1)
    req = new Request("POST", CREATE_LINK_API + testFolder2.getStoreRef().getProtocol() + "/" + testFolder2.getStoreRef().getIdentifier() + "/" + testFolder2.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
    jsonArray = new JSONArray();
    jsonArray.add(testFolder2.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_OK));
    jsonLinkNodes = (JSONArray) json.get("linkNodes");
    assertNotNull(jsonLinkNodes);
    assertEquals(1, jsonLinkNodes.size());
    assertEquals("true", json.get("overallSuccess"));
    assertEquals("1", json.get("successCount"));
    assertEquals("0", json.get("failureCount"));
    jsonLinkNode = (JSONObject) jsonLinkNodes.get(0);
    nodeRef = (String) jsonLinkNode.get("nodeRef");
    NodeRef folder2Link = new NodeRef(nodeRef);
    assertEquals(true, nodeService.hasAspect(testFolder2, ApplicationModel.ASPECT_LINKED));
    assertEquals(true, nodeService.exists(folder2Link));
    // create another link of testFolder2 in siteDocLib
    req = new Request("POST", CREATE_LINK_API + testFolder2.getStoreRef().getProtocol() + "/" + testFolder2.getStoreRef().getIdentifier() + "/" + testFolder2.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, siteDocLib.toString());
    jsonArray = new JSONArray();
    jsonArray.add(testFolder2.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_OK));
    jsonLinkNodes = (JSONArray) json.get("linkNodes");
    assertNotNull(jsonLinkNodes);
    assertEquals(1, jsonLinkNodes.size());
    assertEquals("true", json.get("overallSuccess"));
    assertEquals("1", json.get("successCount"));
    assertEquals("0", json.get("failureCount"));
    jsonLinkNode = (JSONObject) jsonLinkNodes.get(0);
    nodeRef = (String) jsonLinkNode.get("nodeRef");
    NodeRef folder2Link2 = new NodeRef(nodeRef);
    // delete folder2Link and check that aspect exists since we have another
    // link for testFolder2
    nodeService.deleteNode(folder2Link);
    assertEquals(true, nodeService.hasAspect(testFolder2, ApplicationModel.ASPECT_LINKED));
    nodeService.deleteNode(folder2Link2);
    assertEquals(false, nodeService.hasAspect(testFolder2, ApplicationModel.ASPECT_LINKED));
    // Create link to testFile1, testFile2 and testFile3 in same testFolder1
    req = new Request("POST", CREATE_LINK_API + testFolder1.getStoreRef().getProtocol() + "/" + testFolder1.getStoreRef().getIdentifier() + "/" + testFolder1.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
    jsonArray = new JSONArray();
    jsonArray.add(testFile1.toString());
    jsonArray.add(testFile2.toString());
    jsonArray.add(testFile3.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_OK));
    jsonLinkNodes = (JSONArray) json.get("linkNodes");
    assertNotNull(jsonLinkNodes);
    assertEquals(3, jsonLinkNodes.size());
    assertEquals("true", json.get("overallSuccess"));
    assertEquals("3", json.get("successCount"));
    assertEquals("0", json.get("failureCount"));
    NodeRef fileLink = null;
    List<NodeRef> fileLinks = new ArrayList<NodeRef>();
    for (int i = 0; i < jsonLinkNodes.size(); i++) {
        jsonLinkNode = (JSONObject) jsonLinkNodes.get(i);
        nodeRef = (String) jsonLinkNode.get("nodeRef");
        fileLink = new NodeRef(nodeRef);
        fileLinks.add(fileLink);
        assertEquals(true, nodeService.exists(fileLink));
    }
    // try to create another link in the same location - an exception should be thrown
    req = new Request("POST", CREATE_LINK_API + testFolder1.getStoreRef().getProtocol() + "/" + testFolder1.getStoreRef().getIdentifier() + "/" + testFolder1.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
    jsonArray = new JSONArray();
    jsonArray.add(testFile1.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_BAD_REQUEST));
    // delete all 3 files and check that the links are deleted too
    nodeService.deleteNode(testFile1);
    nodeService.deleteNode(testFile2);
    nodeService.deleteNode(testFile3);
    for (NodeRef linkNodeRef : fileLinks) {
        assertEquals(false, nodeService.exists(linkNodeRef));
    }
    // try create a link to a site - shouldn't be possible
    SiteInfo site2 = createSite("Site2TestingNodeCreateLink");
    NodeRef siteNodeRef = site2.getNodeRef();
    req = new Request("POST", CREATE_LINK_API + testFolder1.getStoreRef().getProtocol() + "/" + testFolder1.getStoreRef().getIdentifier() + "/" + testFolder1.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
    jsonArray = new JSONArray();
    jsonArray.add(siteNodeRef.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_BAD_REQUEST));
    // create a file and a link to that file inside the documentLibrary
    NodeRef site2DocLib = siteService.getContainer(TEST_SITE.getShortName(), SiteService.DOCUMENT_LIBRARY);
    NodeRef testFileSite2 = createNode(site2DocLib, "testingLinkCreationFileInSite2", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
    req = new Request("POST", CREATE_LINK_API + testFolder1.getStoreRef().getProtocol() + "/" + testFolder1.getStoreRef().getIdentifier() + "/" + testFolder1.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, site2DocLib.toString());
    jsonArray = new JSONArray();
    jsonArray.add(testFileSite2.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_OK));
    // links are created with success, try to delete site2 - should succeed
    siteService.deleteSite(site2.getShortName());
    nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(siteNodeRef));
    // Links can be created in Shared Files, My Files and Repository
    NodeRef testFile4 = createNode(testFolder1, "testingLinkCreationFile4", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
    req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://company/shared");
    jsonArray = new JSONArray();
    jsonArray.add(testFile4.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_OK));
    req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://user/home");
    jsonArray = new JSONArray();
    jsonArray.add(testFile4.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_OK));
    // create link in Repository as Admin
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    req = new Request("POST", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://company/home");
    jsonArray = new JSONArray();
    jsonArray.add(testFile4.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_OK));
    // all 3 links are created with success, delete all links
    req = new Request("DELETE", CREATE_LINK_API + testFile4.getStoreRef().getProtocol() + "/" + testFile4.getStoreRef().getIdentifier() + "/" + testFile4.getId() + "/delete");
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_OK));
    // all links are removed with success marker aspect should be removed too
    assertEquals(false, nodeService.hasAspect(testFile4, ApplicationModel.ASPECT_LINKED));
    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
    // you should not be able to create links for locked nodes but you can delete links
    final NodeRef testFile5 = createNode(testFolder1, "testingLinkCreationFileWithLock", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
    req = new Request("POST", CREATE_LINK_API + testFile5.getStoreRef().getProtocol() + "/" + testFile5.getStoreRef().getIdentifier() + "/" + testFile5.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
    jsonArray = new JSONArray();
    jsonArray.add(testFile5.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_OK));
    jsonLinkNodes = (JSONArray) json.get("linkNodes");
    assertNotNull(jsonLinkNodes);
    assertEquals(1, jsonLinkNodes.size());
    assertEquals("true", json.get("overallSuccess"));
    assertEquals("1", json.get("successCount"));
    assertEquals("0", json.get("failureCount"));
    jsonLinkNode = (JSONObject) jsonLinkNodes.get(0);
    nodeRef = (String) jsonLinkNode.get("nodeRef");
    NodeRef file5Link = new NodeRef(nodeRef);
    assertEquals(true, nodeService.hasAspect(testFile5, ApplicationModel.ASPECT_LINKED));
    assertEquals(true, nodeService.exists(file5Link));
    // checkout the node testFile5
    final NodeRef workingCopy = retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Exception {
            return checkOutCheckInService.checkout(testFile5);
        }
    });
    assertNotNull(workingCopy);
    // try to create link for working copy
    req = new Request("POST", CREATE_LINK_API + workingCopy.getStoreRef().getProtocol() + "/" + workingCopy.getStoreRef().getIdentifier() + "/" + workingCopy.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString());
    jsonArray = new JSONArray();
    jsonArray.add(workingCopy.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    // should fail since source node is working copy
    json = asJSON(sendRequest(req, Status.STATUS_BAD_REQUEST));
    // delete the link when source node is locked
    nodeService.deleteNode(file5Link);
    assertEquals(false, nodeService.hasAspect(testFile5, ApplicationModel.ASPECT_LINKED));
    // release the lock
    retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>() {

        public Object execute() throws Exception {
            checkOutCheckInService.checkin(workingCopy, new HashMap<String, Serializable>());
            return null;
        }
    });
    assertEquals(false, nodeService.hasAspect(testFile5, ContentModel.ASPECT_LOCKABLE));
    // test that Consumers can create and delete links if they have only read permission
    NodeRef testFile6 = createNode(testFolder1, "testingLinkCreationFile6", ContentModel.TYPE_CONTENT, AuthenticationUtil.getAdminUserName());
    AuthenticationUtil.setFullyAuthenticatedUser(USER_TWO);
    assertTrue(permissionService.hasPermission(testFile6, PermissionService.READ) == AccessStatus.ALLOWED);
    assertTrue(permissionService.hasPermission(testFile6, PermissionService.WRITE) == AccessStatus.DENIED);
    // create another link of testFile1 in MyFiles
    req = new Request("POST", CREATE_LINK_API + testFile6.getStoreRef().getProtocol() + "/" + testFile6.getStoreRef().getIdentifier() + "/" + testFile6.getId());
    jsonReq = new JSONObject();
    jsonReq.put(DESTINATION_NODE_REF_PARAM, "alfresco://user/home");
    jsonArray = new JSONArray();
    jsonArray.add(testFile6.toString());
    jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray);
    req.setBody(jsonReq.toString().getBytes());
    req.setType(MimetypeMap.MIMETYPE_JSON);
    json = asJSON(sendRequest(req, Status.STATUS_OK));
    jsonLinkNodes = (JSONArray) json.get("linkNodes");
    assertNotNull(jsonLinkNodes);
    assertEquals(1, jsonLinkNodes.size());
    assertEquals("true", json.get("overallSuccess"));
    assertEquals("1", json.get("successCount"));
    assertEquals("0", json.get("failureCount"));
    jsonLinkNode = (JSONObject) jsonLinkNodes.get(0);
    nodeRef = (String) jsonLinkNode.get("nodeRef");
    NodeRef testFileSite3Link = new NodeRef(nodeRef);
    nodeService.exists(testFileSite3Link);
    assertEquals(true, nodeService.hasAspect(testFile6, ApplicationModel.ASPECT_LINKED));
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) JSONArray(org.json.simple.JSONArray) Request(org.springframework.extensions.webscripts.TestWebScriptServer.Request) ArrayList(java.util.ArrayList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject)

Example 8 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class NodeWebScripTest method tearDown.

@Override
protected void tearDown() throws Exception {
    super.tearDown();
    // Admin user required to delete users and sites
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    SiteInfo siteInfo = siteService.getSite(TEST_SITE.getShortName());
    if (siteInfo != null) {
        // Zap the site, and their contents
        siteService.deleteSite(TEST_SITE.getShortName());
        nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(siteInfo.getNodeRef()));
    }
    // Delete users
    for (String user : new String[] { USER_ONE, USER_TWO, USER_THREE }) {
        // Delete the user, as admin
        AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
        if (personService.personExists(user)) {
            personService.deletePerson(user);
        }
        if (this.authenticationService.authenticationExists(user)) {
            this.authenticationService.deleteAuthentication(user);
        }
    }
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo)

Example 9 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class SiteServiceTest method testChangeSiteVisibilityAsSiteAdmin.

public void testChangeSiteVisibilityAsSiteAdmin() throws Exception {
    // Create a site
    String shortName = GUID.generate();
    // Create a new site
    JSONObject result = createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    assertEquals(SiteVisibility.PUBLIC.toString(), result.get("visibility"));
    // try to change the site visibility as user2
    this.authenticationComponent.setCurrentUser(USER_TWO);
    JSONObject changeVisibility = new JSONObject();
    changeVisibility.put("shortName", shortName);
    changeVisibility.put("visibility", "PRIVATE");
    // we should get AccessDeniedException
    sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 500);
    SiteInfo siteInfo = siteService.getSite(shortName);
    assertEquals("Site visibility should not have been changed.", SiteVisibility.PUBLIC, siteInfo.getVisibility());
    // set the current user as site-admin
    this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
    // Change the visibility to private
    Response response = sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 200);
    JSONObject jsonObj = new JSONObject(response.getContentAsString());
    assertEquals(SiteVisibility.PRIVATE.toString(), jsonObj.get("visibility"));
    // Change the visibility to moderated. We want to test if we can find
    // the private site before changing its visibility
    changeVisibility.put("visibility", "MODERATED");
    response = sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 200);
    jsonObj = new JSONObject(response.getContentAsString());
    assertEquals(SiteVisibility.MODERATED.toString(), jsonObj.get("visibility"));
    // Remove user4 from the site-admin group
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    authorityService.removeAuthority("GROUP_SITE_ADMINISTRATORS", USER_FOUR_AS_SITE_ADMIN);
    // set the current user as site-admin
    this.authenticationComponent.setCurrentUser(USER_FOUR_AS_SITE_ADMIN);
    // Now that we have removed user4 from the group, try to test if he can still modify the site
    changeVisibility.put("visibility", "PUBLIC");
    sendRequest(new PutRequest(URL_SITES + "/" + shortName, changeVisibility.toString(), "application/json"), 500);
    siteInfo = siteService.getSite(shortName);
    assertEquals("Site visibility should not have been changed.", SiteVisibility.MODERATED, siteInfo.getVisibility());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) JSONObject(org.json.JSONObject) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Example 10 with SiteInfo

use of org.alfresco.service.cmr.site.SiteInfo in project alfresco-remote-api by Alfresco.

the class BlogServiceTest method tearDown.

@Override
protected void tearDown() throws Exception {
    super.tearDown();
    // admin user required to delete things
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_BLOG);
    if (siteInfo != null) {
        // delete invite site
        siteService.deleteSite(SITE_SHORT_NAME_BLOG);
        nodeArchiveService.purgeArchivedNode(nodeArchiveService.getArchivedNode(siteInfo.getNodeRef()));
    }
    // delete the users
    personService.deletePerson(USER_ONE);
    if (this.authenticationService.authenticationExists(USER_ONE)) {
        this.authenticationService.deleteAuthentication(USER_ONE);
    }
    personService.deletePerson(USER_TWO);
    if (this.authenticationService.authenticationExists(USER_TWO)) {
        this.authenticationService.deleteAuthentication(USER_TWO);
    }
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo)

Aggregations

SiteInfo (org.alfresco.service.cmr.site.SiteInfo)103 NodeRef (org.alfresco.service.cmr.repository.NodeRef)42 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)18 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)15 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)15 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)15 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)15 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)13 QName (org.alfresco.service.namespace.QName)13 HashMap (java.util.HashMap)12 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)12 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)12 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)12 IOException (java.io.IOException)8 Serializable (java.io.Serializable)8 JSONObject (org.json.simple.JSONObject)8 RMSite (org.alfresco.rm.rest.api.model.RMSite)7 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)5 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)5