Search in sources :

Example 6 with OrcidClientGroupManagementException

use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.

the class MembersManagerImpl method updateClient.

@Override
public Client updateClient(Client client) {
    OrcidClient result = null;
    try {
        result = orcidClientGroupManager.updateClient(client.toOrcidClient());
        clearCache();
    } catch (OrcidClientGroupManagementException e) {
        LOGGER.error(e.getMessage());
        result = new OrcidClient();
        result.setErrors(new ErrorDesc(getMessage("manage.developer_tools.group.unable_to_update")));
    }
    return Client.valueOf(result);
}
Also used : OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) ErrorDesc(org.orcid.jaxb.model.message.ErrorDesc)

Example 7 with OrcidClientGroupManagementException

use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.

the class GroupAdministratorController method editClient.

@RequestMapping(value = "/edit-client.json", method = RequestMethod.POST)
@Produces(value = { MediaType.APPLICATION_JSON })
@ResponseBody
public Client editClient(@RequestBody Client client) {
    // Clean the error list
    client.setErrors(new ArrayList<String>());
    // Validate fields
    validateDisplayName(client);
    validateWebsite(client);
    validateShortDescription(client);
    validateRedirectUris(client);
    copyErrors(client.getDisplayName(), client);
    copyErrors(client.getWebsite(), client);
    copyErrors(client.getShortDescription(), client);
    for (RedirectUri redirectUri : client.getRedirectUris()) {
        copyErrors(redirectUri, client);
    }
    if (client.getErrors().size() == 0) {
        OrcidProfile profile = getEffectiveProfile();
        String groupOrcid = profile.getOrcidIdentifier().getPath();
        if (profile.getType() == null || !profile.getType().equals(OrcidType.GROUP)) {
            LOGGER.warn("Trying to edit client with non group user {}", profile.getOrcidIdentifier().getPath());
            throw new OrcidClientGroupManagementException(getMessage("web.orcid.privilege.exception"));
        }
        OrcidClient result = null;
        try {
            result = orcidClientGroupManager.updateClient(groupOrcid, client.toOrcidClient());
            clearCache();
        } catch (OrcidClientGroupManagementException e) {
            LOGGER.error(e.getMessage());
            result = new OrcidClient();
            result.setErrors(new ErrorDesc(getMessage("manage.developer_tools.group.unable_to_update")));
        }
        client = Client.valueOf(result);
    }
    return client;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ErrorDesc(org.orcid.jaxb.model.message.ErrorDesc) RedirectUri(org.orcid.pojo.ajaxForm.RedirectUri) Produces(javax.ws.rs.Produces) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with OrcidClientGroupManagementException

use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerTest method testAddCreatorToPremiumGroup.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddCreatorToPremiumGroup() {
    final OrcidClientGroup group = new OrcidClientGroup();
    group.setGroupName("Elsevier");
    group.setEmail("premium-member@elsevier.com" + System.currentTimeMillis());
    group.setType(MemberType.PREMIUM);
    OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {

        public OrcidClientGroup doInTransaction(TransactionStatus status) {
            return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
        }
    });
    RedirectUris redirectUris = new RedirectUris();
    RedirectUri redirectUri = new RedirectUri("http://uri.com");
    redirectUris.getRedirectUri().add(redirectUri);
    OrcidClient client1 = new OrcidClient();
    client1.setDisplayName("Name");
    client1.setRedirectUris(redirectUris);
    client1.setShortDescription("Description");
    client1.setType(ClientType.CREATOR);
    client1.setWebsite("http://site.com");
    // Add one creator client to a premium group should fail
    try {
        OrcidClient orcidClient = orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client1);
        assertEquals(orcidClient.getType(), ClientType.PREMIUM_UPDATER);
    } catch (OrcidClientGroupManagementException e) {
    }
}
Also used : OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) TransactionStatus(org.springframework.transaction.TransactionStatus) RedirectUris(org.orcid.jaxb.model.clientgroup.RedirectUris) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with OrcidClientGroupManagementException

use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerTest method testAddMoreThanOneClientToBasicInstitutionGroup.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddMoreThanOneClientToBasicInstitutionGroup() {
    final OrcidClientGroup group = new OrcidClientGroup();
    group.setGroupName("Elsevier");
    group.setEmail("basic-institution-member@elsevier.com" + System.currentTimeMillis());
    group.setType(MemberType.BASIC_INSTITUTION);
    OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {

        public OrcidClientGroup doInTransaction(TransactionStatus status) {
            return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
        }
    });
    RedirectUris redirectUris = new RedirectUris();
    RedirectUri redirectUri = new RedirectUri("http://uri.com");
    redirectUris.getRedirectUri().add(redirectUri);
    OrcidClient client1 = new OrcidClient();
    client1.setDisplayName("Name");
    client1.setRedirectUris(redirectUris);
    client1.setShortDescription("Description");
    client1.setType(ClientType.CREATOR);
    client1.setWebsite("http://site.com");
    // Add one client
    try {
        orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client1);
    } catch (OrcidClientGroupManagementException e) {
        fail();
    }
    OrcidClient client2 = new OrcidClient();
    client2.setDisplayName("Name");
    client2.setRedirectUris(redirectUris);
    client2.setShortDescription("Description");
    client2.setType(ClientType.CREATOR);
    client2.setWebsite("http://site.com");
    // Add other client should fail
    try {
        orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client2);
        fail();
    } catch (OrcidClientGroupManagementException e) {
    }
}
Also used : OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) TransactionStatus(org.springframework.transaction.TransactionStatus) RedirectUris(org.orcid.jaxb.model.clientgroup.RedirectUris) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with OrcidClientGroupManagementException

use of org.orcid.core.exception.OrcidClientGroupManagementException in project ORCID-Source by ORCID.

the class GroupAdministratorController method getClients.

@RequestMapping(value = "/get-clients.json", method = RequestMethod.GET)
@Produces(value = { MediaType.APPLICATION_JSON })
@ResponseBody
public List<Client> getClients() {
    OrcidProfile profile = getEffectiveProfile();
    String groupOrcid = profile.getOrcidIdentifier().getPath();
    if (profile.getType() == null || !profile.getType().equals(OrcidType.GROUP)) {
        LOGGER.warn("Trying to get clients of non group user {}", profile.getOrcidIdentifier().getPath());
        throw new OrcidClientGroupManagementException(getMessage("web.orcid.privilege.exception"));
    }
    OrcidClientGroup group = orcidClientGroupManager.retrieveOrcidClientGroup(groupOrcid);
    List<Client> clients = new ArrayList<Client>();
    for (OrcidClient orcidClient : group.getOrcidClient()) {
        clients.add(Client.valueOf(orcidClient));
    }
    return clients;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ArrayList(java.util.ArrayList) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) Client(org.orcid.pojo.ajaxForm.Client) Produces(javax.ws.rs.Produces) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)15 OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)10 OrcidClientGroup (org.orcid.jaxb.model.clientgroup.OrcidClientGroup)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Test (org.junit.Test)6 BaseTest (org.orcid.core.BaseTest)6 RedirectUri (org.orcid.jaxb.model.clientgroup.RedirectUri)6 RedirectUris (org.orcid.jaxb.model.clientgroup.RedirectUris)6 TransactionStatus (org.springframework.transaction.TransactionStatus)6 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)4 Produces (javax.ws.rs.Produces)3 ErrorDesc (org.orcid.jaxb.model.message.ErrorDesc)3 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 RedirectUri (org.orcid.pojo.ajaxForm.RedirectUri)2 ArrayList (java.util.ArrayList)1 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)1 OrcidEntityIdComparator (org.orcid.persistence.jpa.entities.OrcidEntityIdComparator)1