Search in sources :

Example 1 with OrcidClient

use of org.orcid.jaxb.model.clientgroup.OrcidClient in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerImpl method createOrUpdateOrcidClientGroup.

@Override
@Transactional
public OrcidClientGroup createOrUpdateOrcidClientGroup(OrcidClientGroup orcidClientGroup) {
    // For each client in the client group, validate the client type
    for (OrcidClient client : orcidClientGroup.getOrcidClient()) {
        checkAndSetClientType(client, orcidClientGroup.getType());
    }
    String groupOrcid = orcidClientGroup.getGroupOrcid();
    if (groupOrcid == null) {
        orcidClientGroup = createGroup(orcidClientGroup);
        groupOrcid = orcidClientGroup.getGroupOrcid();
    } else {
        updateGroup(orcidClientGroup);
    }
    // Use the profile DAO to link the clients to the group, so get the
    // group profile entity.
    ProfileEntity groupProfileEntity = profileDao.find(groupOrcid);
    SortedSet<ClientDetailsEntity> clientProfileEntities = groupProfileEntity.getClients();
    if (clientProfileEntities == null) {
        clientProfileEntities = new TreeSet<>(new OrcidEntityIdComparator<String>());
        groupProfileEntity.setClients(clientProfileEntities);
    }
    // For each client in the client group
    for (OrcidClient client : orcidClientGroup.getOrcidClient()) {
        processClient(groupOrcid, clientProfileEntities, client, getClientType(groupProfileEntity.getGroupType()));
    }
    // Regenerate client group and return.
    return retrieveOrcidClientGroup(groupOrcid);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidEntityIdComparator(org.orcid.persistence.jpa.entities.OrcidEntityIdComparator) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with OrcidClient

use of org.orcid.jaxb.model.clientgroup.OrcidClient in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerImpl method retrieveOrcidClientGroup.

@Override
@Transactional
public OrcidClientGroup retrieveOrcidClientGroup(String groupOrcid) {
    ProfileEntity profileEntity = profileDao.find(groupOrcid);
    if (profileEntity == null) {
        return null;
    }
    OrcidClientGroup group = adapter.toOrcidClientGroup(profileEntity);
    for (OrcidClient client : group.getOrcidClient()) {
        client.setClientSecret(encryptionManager.decryptForInternalUse(client.getClientSecret()));
    }
    return group;
}
Also used : OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OrcidClient

use of org.orcid.jaxb.model.clientgroup.OrcidClient 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 4 with OrcidClient

use of org.orcid.jaxb.model.clientgroup.OrcidClient in project ORCID-Source by ORCID.

the class Client method valueOf.

public static Client valueOf(OrcidClient orcidClient) {
    Client client = new Client();
    client.setClientId(Text.valueOf(orcidClient.getClientId()));
    client.setClientSecret(Text.valueOf(orcidClient.getClientSecret()));
    client.setDisplayName(Text.valueOf(orcidClient.getDisplayName()));
    client.setShortDescription(Text.valueOf(orcidClient.getShortDescription()));
    if (orcidClient.getType() != null)
        client.setType(Text.valueOf(orcidClient.getType().value()));
    client.setWebsite(Text.valueOf(orcidClient.getWebsite()));
    Checkbox persistentTokenEnabled = new Checkbox();
    persistentTokenEnabled.setValue(orcidClient.isPersistentTokenEnabled());
    client.setPersistentTokenEnabled(persistentTokenEnabled);
    List<RedirectUri> redirectUris = new ArrayList<RedirectUri>();
    RedirectUris orcidRedirectUris = orcidClient.getRedirectUris();
    if (orcidRedirectUris != null && orcidRedirectUris.getRedirectUri() != null) {
        for (org.orcid.jaxb.model.clientgroup.RedirectUri orcidRedirectUri : orcidRedirectUris.getRedirectUri()) {
            redirectUris.add(RedirectUri.toRedirectUri(orcidRedirectUri));
        }
    }
    if (orcidClient.getIdp() != null) {
        client.setAuthenticationProviderId(Text.valueOf(orcidClient.getIdp()));
    }
    client.setRedirectUris(redirectUris);
    client.setAllowAutoDeprecate(Checkbox.valueOf(orcidClient.getAllowAutoDeprecate()));
    return client;
}
Also used : ArrayList(java.util.ArrayList) RedirectUris(org.orcid.jaxb.model.clientgroup.RedirectUris) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient)

Example 5 with OrcidClient

use of org.orcid.jaxb.model.clientgroup.OrcidClient in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerTest method testCreateOrcidCreatorClientGroup.

@Test
public void testCreateOrcidCreatorClientGroup() {
    OrcidClientGroup createdGroup = orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
    assertNotNull(createdGroup);
    assertEquals(group.getGroupName(), createdGroup.getGroupName());
    assertEquals(group.getEmail(), createdGroup.getEmail());
    assertNotNull(createdGroup.getGroupOrcid());
    List<OrcidClient> createdClients = createdGroup.getOrcidClient();
    assertNotNull(createdClients);
    assertEquals(2, createdClients.size());
    Map<String, OrcidClient> createdClientsMappedByName = new HashMap<String, OrcidClient>();
    for (OrcidClient createdClient : createdClients) {
        assertNotNull(createdClient.getClientId());
        assertNotNull(createdClient.getClientSecret());
        assertNotNull(createdClient.getIdp());
        createdClientsMappedByName.put(createdClient.getDisplayName(), createdClient);
    }
    OrcidClient complexityClient = createdClientsMappedByName.get("Ecological Complexity");
    assertNotNull(complexityClient);
    assertEquals("http://www.journals.elsevier.com/ecological-complexity", complexityClient.getWebsite());
    assertEquals("An International Journal on Biocomplexity in the Environment and Theoretical Ecology", complexityClient.getShortDescription());
    List<RedirectUri> createdRedirectUris = complexityClient.getRedirectUris().getRedirectUri();
    assertNotNull(createdRedirectUris);
    assertEquals(1, createdRedirectUris.size());
    assertEquals("http://www.journals.elsevier.com/ecological-complexity/orcid-callback", createdRedirectUris.get(0).getValue());
    // Look up client details directly to check scopes
    ClientDetailsEntity complexityEntity = clientDetailsManager.findByClientId(complexityClient.getClientId());
    Set<String> clientScopeTypes = complexityEntity.getScope();
    assertNotNull(clientScopeTypes);
    assertTrue(clientScopeTypes.contains("/orcid-profile/read-limited"));
    assertTrue(clientScopeTypes.contains("/orcid-bio/read-limited"));
    assertTrue(clientScopeTypes.contains("/orcid-works/read-limited"));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) HashMap(java.util.HashMap) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)21 OrcidClientGroup (org.orcid.jaxb.model.clientgroup.OrcidClientGroup)13 RedirectUri (org.orcid.jaxb.model.clientgroup.RedirectUri)11 OrcidClientGroupManagementException (org.orcid.core.exception.OrcidClientGroupManagementException)10 RedirectUris (org.orcid.jaxb.model.clientgroup.RedirectUris)10 Transactional (org.springframework.transaction.annotation.Transactional)10 Test (org.junit.Test)9 BaseTest (org.orcid.core.BaseTest)9 TransactionStatus (org.springframework.transaction.TransactionStatus)7 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 Produces (javax.ws.rs.Produces)3 ErrorDesc (org.orcid.jaxb.model.message.ErrorDesc)3 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)3 ScopePathType (org.orcid.jaxb.model.message.ScopePathType)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)2