Search in sources :

Example 1 with PutAccountsProjectRequest

use of org.geosdi.geoplatform.request.PutAccountsProjectRequest in project geo-platform by geosdi.

the class LayerService method shareProjectToUsers.

@Override
public boolean shareProjectToUsers(long idSharedProject, List<Long> accountIDsProject, HttpServletRequest httpServletRequest) throws GeoPlatformException {
    boolean result;
    try {
        GPAccount account = this.sessionUtility.getLoggedAccount(httpServletRequest);
        result = this.geoPlatformServiceClient.updateAccountsProjectSharing(new PutAccountsProjectRequest(idSharedProject, accountIDsProject));
        if (result) {
            MessageDTO message = new MessageDTO();
            message.setCommands(Lists.newArrayList(GPMessageCommandType.OPEN_PROJECT));
            message.setCommandsProperties("" + idSharedProject);
            message.setCreationDate(new Date());
            message.setSenderID(account.getId());
            message.setSubject("Project Shared");
            String sharerName;
            if (account instanceof GPUser) {
                GPUser user = (GPUser) account;
                sharerName = user.getName();
            } else {
                sharerName = account.getNaturalID();
            }
            GPProject project = this.geoPlatformServiceClient.getProjectDetail(idSharedProject);
            message.setText(sharerName + " shared with you the " + project.getName() + " project. Do you want to open it?");
            message.setRecipientIDs(accountIDsProject);
            this.geoPlatformServiceClient.insertMultiMessage(message);
        }
    } catch (GPSessionTimeout timeout) {
        throw new GeoPlatformException(timeout);
    } catch (ResourceNotFoundFault | IllegalParameterFault rnf) {
        logger.error("Failed to save Shared project to Accounts for Shared Project with id: " + idSharedProject + "on SecurityService: " + rnf);
        throw new GeoPlatformException(rnf);
    }
    return result;
}
Also used : GPAccount(org.geosdi.geoplatform.core.model.GPAccount) IllegalParameterFault(org.geosdi.geoplatform.exception.IllegalParameterFault) GPUser(org.geosdi.geoplatform.core.model.GPUser) PutAccountsProjectRequest(org.geosdi.geoplatform.request.PutAccountsProjectRequest) ResourceNotFoundFault(org.geosdi.geoplatform.exception.ResourceNotFoundFault) GPSessionTimeout(org.geosdi.geoplatform.gui.utility.GPSessionTimeout) Date(java.util.Date) GPProject(org.geosdi.geoplatform.core.model.GPProject) GeoPlatformException(org.geosdi.geoplatform.gui.global.GeoPlatformException)

Example 2 with PutAccountsProjectRequest

use of org.geosdi.geoplatform.request.PutAccountsProjectRequest in project geo-platform by geosdi.

the class RSProjectTest method testUpdateAccountsProjectSharingRemoveAllRest.

@Test
public void testUpdateAccountsProjectSharingRemoveAllRest() throws Exception {
    // Insert a User to which the Project is shared as viewer
    Long newUserID = this.createAndInsertUser("user_to_share_project_rs", organizationTest, GPRole.USER);
    GPUser newUser = gpWSClient.getUserDetail(newUserID);
    this.createAndInsertAccountProject(newUser, projectTest, BasePermission.READ);
    // Set the Project as share
    projectTest.setShared(true);
    gpWSClient.updateProject(projectTest);
    // Initial test
    GPProject project = gpWSClient.getProjectDetail(idProjectTest);
    assertTrue(project.isShared());
    List<ShortAccountDTO> accountsToShare = gpWSClient.getAccountsByProjectID(idProjectTest).getAccounts();
    Assert.assertNotNull(accountsToShare);
    assertEquals(2, accountsToShare.size());
    assertEquals(2, accountsToShare.size());
    boolean check = false;
    for (ShortAccountDTO accountDTO : accountsToShare) {
        if (newUserID.equals(accountDTO.getId())) {
            check = true;
            break;
        }
    }
    assertTrue(check);
    // Test delete user for sharing
    boolean result = gpWSClient.updateAccountsProjectSharing(new PutAccountsProjectRequest(idProjectTest, Arrays.asList(idUserTest)));
    assertTrue(result);
    project = gpWSClient.getProjectDetail(idProjectTest);
    Assert.assertFalse(project.isShared());
    accountsToShare = gpWSClient.getAccountsByProjectID(idProjectTest).getAccounts();
    Assert.assertNotNull(accountsToShare);
    assertEquals(1, accountsToShare.size());
    assertEquals(idUserTest, accountsToShare.get(0).getId().longValue());
}
Also used : PutAccountsProjectRequest(org.geosdi.geoplatform.request.PutAccountsProjectRequest) Test(org.junit.Test)

Example 3 with PutAccountsProjectRequest

use of org.geosdi.geoplatform.request.PutAccountsProjectRequest in project geo-platform by geosdi.

the class WSProjectTest method testUpdateAccountsProjectSharingCreate.

@Test
public void testUpdateAccountsProjectSharingCreate() throws Exception {
    // Initial test
    GPProject project = gpWSClient.getProjectDetail(idProjectTest);
    Assert.assertFalse(project.isShared());
    List<ShortAccountDTO> accountsToShare = gpWSClient.getAccountsByProjectID(idProjectTest).getAccounts();
    Assert.assertNotEquals(accountsToShare.isEmpty(), Boolean.TRUE);
    assertEquals(1, accountsToShare.size());
    assertEquals(idUserTest, accountsToShare.get(0).getId().longValue());
    // Insert User to which the Project will be share
    Long newUserID = this.createAndInsertUser("user_to_share_project", organizationTest, GPRole.USER);
    // Test add user for sharing
    boolean result = gpWSClient.updateAccountsProjectSharing(new PutAccountsProjectRequest(idProjectTest, Arrays.asList(idUserTest, newUserID)));
    assertTrue(result);
    project = gpWSClient.getProjectDetail(idProjectTest);
    assertTrue(project.isShared());
    accountsToShare = gpWSClient.getAccountsByProjectID(idProjectTest).getAccounts();
    assertNotNull(accountsToShare);
    assertEquals(2, accountsToShare.size());
    boolean check = false;
    for (ShortAccountDTO accountDTO : accountsToShare) {
        if (newUserID.equals(accountDTO.getId())) {
            check = true;
            break;
        }
    }
    assertTrue(check);
}
Also used : PutAccountsProjectRequest(org.geosdi.geoplatform.request.PutAccountsProjectRequest) Test(org.junit.Test)

Example 4 with PutAccountsProjectRequest

use of org.geosdi.geoplatform.request.PutAccountsProjectRequest in project geo-platform by geosdi.

the class WSProjectTest method testUpdateAccountsProjectSharingRemoveAll.

@Test
public void testUpdateAccountsProjectSharingRemoveAll() throws Exception {
    // Insert a User to which the Project is shared as viewer
    Long newUserID = this.createAndInsertUser("user_to_share_project", organizationTest, GPRole.USER);
    GPUser newUser = gpWSClient.getUserDetail(newUserID);
    this.createAndInsertAccountProject(newUser, projectTest, BasePermission.READ);
    // Set the Project as share
    projectTest.setShared(true);
    gpWSClient.updateProject(projectTest);
    // Initial test
    GPProject project = gpWSClient.getProjectDetail(idProjectTest);
    assertTrue(project.isShared());
    List<ShortAccountDTO> accountsToShare = gpWSClient.getAccountsByProjectID(idProjectTest).getAccounts();
    assertNotNull(accountsToShare);
    assertEquals(2, accountsToShare.size());
    assertEquals(2, accountsToShare.size());
    boolean check = false;
    for (ShortAccountDTO accountDTO : accountsToShare) {
        if (newUserID.equals(accountDTO.getId())) {
            check = true;
            break;
        }
    }
    assertTrue(check);
    // Test delete user for sharing
    boolean result = gpWSClient.updateAccountsProjectSharing(new PutAccountsProjectRequest(idProjectTest, Arrays.asList(idUserTest)));
    assertTrue(result);
    project = gpWSClient.getProjectDetail(idProjectTest);
    Assert.assertFalse(project.isShared());
    accountsToShare = gpWSClient.getAccountsByProjectID(idProjectTest).getAccounts();
    assertNotNull(accountsToShare);
    assertEquals(1, accountsToShare.size());
    assertEquals(idUserTest, accountsToShare.get(0).getId().longValue());
}
Also used : PutAccountsProjectRequest(org.geosdi.geoplatform.request.PutAccountsProjectRequest) Test(org.junit.Test)

Example 5 with PutAccountsProjectRequest

use of org.geosdi.geoplatform.request.PutAccountsProjectRequest in project geo-platform by geosdi.

the class RSProjectTest method testUpdateAccountsProjectSharingManageRest.

@Test
public void testUpdateAccountsProjectSharingManageRest() throws Exception {
    // Insert a User to which the Project is shared as viewer
    Long firstUserID = this.createAndInsertUser("first_to_share_project", organizationTest, GPRole.USER);
    Long latterUserID = this.createAndInsertUser("latter_to_share_project", organizationTest, GPRole.VIEWER);
    GPUser newUser = gpWSClient.getUserDetail(firstUserID);
    this.createAndInsertAccountProject(newUser, projectTest, BasePermission.READ);
    // Set the Project as share
    projectTest.setShared(true);
    gpWSClient.updateProject(projectTest);
    // Initial test
    GPProject project = gpWSClient.getProjectDetail(idProjectTest);
    assertTrue(project.isShared());
    List<ShortAccountDTO> accountsToShare = gpWSClient.getAccountsByProjectID(idProjectTest).getAccounts();
    Assert.assertNotNull(accountsToShare);
    assertEquals(2, accountsToShare.size());
    assertEquals(2, accountsToShare.size());
    boolean checkFirst = false;
    for (ShortAccountDTO accountDTO : accountsToShare) {
        if (firstUserID.equals(accountDTO.getId())) {
            checkFirst = true;
            break;
        }
    }
    assertTrue(checkFirst);
    // Test add latter user for sharing
    boolean result = gpWSClient.updateAccountsProjectSharing(new PutAccountsProjectRequest(idProjectTest, Arrays.asList(idUserTest, firstUserID, latterUserID)));
    assertTrue(result);
    project = gpWSClient.getProjectDetail(idProjectTest);
    assertTrue(project.isShared());
    accountsToShare = gpWSClient.getAccountsByProjectID(idProjectTest).getAccounts();
    Assert.assertNotNull(accountsToShare);
    assertEquals(3, accountsToShare.size());
    checkFirst = false;
    boolean checkLatter = false;
    for (ShortAccountDTO accountDTO : accountsToShare) {
        if (firstUserID.equals(accountDTO.getId())) {
            checkFirst = true;
        }
        if (latterUserID.equals(accountDTO.getId())) {
            checkLatter = true;
        }
    }
    assertTrue(checkFirst);
    assertTrue(checkLatter);
    // Test delete first user for sharing
    result = gpWSClient.updateAccountsProjectSharing(new PutAccountsProjectRequest(idProjectTest, Arrays.asList(idUserTest, latterUserID)));
    assertTrue(result);
    project = gpWSClient.getProjectDetail(idProjectTest);
    assertTrue(project.isShared());
    accountsToShare = gpWSClient.getAccountsByProjectID(idProjectTest).getAccounts();
    Assert.assertNotNull(accountsToShare);
    assertEquals(2, accountsToShare.size());
    checkLatter = false;
    for (ShortAccountDTO accountDTO : accountsToShare) {
        if (latterUserID.equals(accountDTO.getId())) {
            checkLatter = true;
            break;
        }
    }
    assertTrue(checkLatter);
}
Also used : PutAccountsProjectRequest(org.geosdi.geoplatform.request.PutAccountsProjectRequest) Test(org.junit.Test)

Aggregations

PutAccountsProjectRequest (org.geosdi.geoplatform.request.PutAccountsProjectRequest)9 Test (org.junit.Test)8 Date (java.util.Date)1 GPAccount (org.geosdi.geoplatform.core.model.GPAccount)1 GPProject (org.geosdi.geoplatform.core.model.GPProject)1 GPUser (org.geosdi.geoplatform.core.model.GPUser)1 IllegalParameterFault (org.geosdi.geoplatform.exception.IllegalParameterFault)1 ResourceNotFoundFault (org.geosdi.geoplatform.exception.ResourceNotFoundFault)1 GeoPlatformException (org.geosdi.geoplatform.gui.global.GeoPlatformException)1 GPSessionTimeout (org.geosdi.geoplatform.gui.utility.GPSessionTimeout)1