Search in sources :

Example 16 with OrcidClient

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

the class OrcidClientGroupManagerTest method testAddCreatorToBasicGroup.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddCreatorToBasicGroup() {
    final OrcidClientGroup group = new OrcidClientGroup();
    group.setGroupName("Elsevier");
    group.setEmail("basic-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 basic group should fail
    try {
        OrcidClient orcidClient = orcidClientGroupManager.createAndPersistClientProfile(createdGroup.getGroupOrcid(), client1);
        assertEquals(ClientType.UPDATER, orcidClient.getType());
    } 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 17 with OrcidClient

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

the class OrcidClientGroupManagerTest method testUpdateOrcidClientGroup.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testUpdateOrcidClientGroup() {
    OrcidClientGroup createdGroup = transactionTemplate.execute(new TransactionCallback<OrcidClientGroup>() {

        public OrcidClientGroup doInTransaction(TransactionStatus status) {
            return orcidClientGroupManager.createOrUpdateOrcidClientGroup(group);
        }
    });
    createdGroup.setEmail("admin@somethingelse.com");
    for (OrcidClient createdClient : createdGroup.getOrcidClient()) {
        if ("Ecological Complexity".equals(createdClient.getDisplayName())) {
            createdClient.setWebsite("wwww.ecologicalcomplexity.com");
        }
    }
    OrcidClientGroup updatedGroup = orcidClientGroupManager.createOrUpdateOrcidClientGroup(createdGroup);
    assertNotNull(updatedGroup);
    assertEquals("Elsevier", updatedGroup.getGroupName());
    assertEquals("admin@somethingelse.com", updatedGroup.getEmail());
    assertNotNull(updatedGroup.getGroupOrcid());
    List<OrcidClient> updatedClients = updatedGroup.getOrcidClient();
    assertNotNull(updatedClients);
    assertEquals(2, updatedClients.size());
    Map<String, OrcidClient> updatedClientsMappedByName = new HashMap<String, OrcidClient>();
    for (OrcidClient upatedClient : updatedClients) {
        assertNotNull(upatedClient.getClientId());
        assertNotNull(upatedClient.getClientSecret());
        updatedClientsMappedByName.put(upatedClient.getDisplayName(), upatedClient);
    }
    OrcidClient complexityClient = updatedClientsMappedByName.get("Ecological Complexity");
    assertNotNull(complexityClient);
    assertEquals("wwww.ecologicalcomplexity.com", complexityClient.getWebsite());
    assertEquals("An International Journal on Biocomplexity in the Environment and Theoretical Ecology", complexityClient.getShortDescription());
    List<RedirectUri> updatedRedirectUris = complexityClient.getRedirectUris().getRedirectUri();
    assertNotNull(updatedRedirectUris);
    assertEquals(1, updatedRedirectUris.size());
    Collections.sort(updatedRedirectUris, new Comparator<RedirectUri>() {

        public int compare(RedirectUri redirectUri1, RedirectUri redirectUri2) {
            return ((String) redirectUri1.getValue()).compareToIgnoreCase((String) redirectUri1.getValue());
        }
    });
    assertEquals("http://www.journals.elsevier.com/ecological-complexity/orcid-callback", updatedRedirectUris.get(0).getValue());
    List<ScopePathType> scopesForRedirect = updatedRedirectUris.get(0).getScope();
    assertTrue(scopesForRedirect.size() == 2);
    assertTrue(scopesForRedirect.contains(ScopePathType.ORCID_PROFILE_CREATE) && scopesForRedirect.contains(ScopePathType.ORCID_BIO_READ_LIMITED));
}
Also used : OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) HashMap(java.util.HashMap) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) TransactionStatus(org.springframework.transaction.TransactionStatus) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) ScopePathType(org.orcid.jaxb.model.message.ScopePathType) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with OrcidClient

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

the class OrcidClientGroupManagerTest method testAddUpdaterToPremiumInstitutionGroup.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddUpdaterToPremiumInstitutionGroup() {
    final OrcidClientGroup group = new OrcidClientGroup();
    group.setGroupName("Elsevier");
    group.setEmail("premium-institution-member@elsevier.com" + System.currentTimeMillis());
    group.setType(MemberType.PREMIUM_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.UPDATER);
    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_CREATOR);
    } 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 19 with OrcidClient

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

the class WorkspaceController method getSourceGrantReadWizard.

@RequestMapping(value = "/my-orcid/sourceGrantReadWizard.json", method = RequestMethod.GET)
@ResponseBody
public ThirdPartyRedirect getSourceGrantReadWizard() {
    ThirdPartyRedirect tpr = new ThirdPartyRedirect();
    ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
    if (profile.getSource() == null || profile.getSource().getSourceId() == null) {
        return tpr;
    }
    String sourcStr = profile.getSource().getSourceId();
    // Check that the cache is up to date
    evictThirdPartyLinkManagerCacheIfNeeded();
    // Get list of clients
    List<OrcidClient> orcidClients = thirdPartyLinkManager.findOrcidClientsWithPredefinedOauthScopeReadAccess();
    for (OrcidClient orcidClient : orcidClients) {
        if (sourcStr.equals(orcidClient.getClientId())) {
            RedirectUri ru = orcidClient.getRedirectUris().getRedirectUri().get(0);
            String redirect = getBaseUri() + "/oauth/authorize?client_id=" + orcidClient.getClientId() + "&response_type=code&scope=" + ru.getScopeAsSingleString() + "&redirect_uri=" + ru.getValue();
            tpr.setUrl(redirect);
            tpr.setDisplayName(orcidClient.getDisplayName());
            tpr.setShortDescription(orcidClient.getShortDescription());
            return tpr;
        }
    }
    return tpr;
}
Also used : OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ThirdPartyRedirect(org.orcid.pojo.ThirdPartyRedirect) RedirectUri(org.orcid.jaxb.model.clientgroup.RedirectUri) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 20 with OrcidClient

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

the class OrcidClientGroupManagerImpl method createOrUpdateOrcidClientGroup.

@Override
@Transactional
public OrcidClient createOrUpdateOrcidClientGroup(String groupOrcid, OrcidClient orcidClient) {
    OrcidClient result = null;
    // Use the profile DAO to link the clients to the group, so get the
    // group profile entity.
    ProfileEntity groupProfileEntity = profileDao.find(groupOrcid);
    SortedSet<ClientDetailsEntity> clientDetailsEntities = groupProfileEntity.getClients();
    if (clientDetailsEntities == null) {
        clientDetailsEntities = new TreeSet<>(new OrcidEntityIdComparator<String>());
        groupProfileEntity.setClients(clientDetailsEntities);
    }
    processClient(groupOrcid, clientDetailsEntities, orcidClient, getClientType(groupProfileEntity.getGroupType()));
    OrcidClientGroup group = retrieveOrcidClientGroup(groupOrcid);
    for (OrcidClient populatedClient : group.getOrcidClient()) {
        if (compareClients(orcidClient, populatedClient))
            result = populatedClient;
    }
    // Regenerate client group and return.
    return result;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidEntityIdComparator(org.orcid.persistence.jpa.entities.OrcidEntityIdComparator) 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)

Aggregations

OrcidClient (org.orcid.jaxb.model.clientgroup.OrcidClient)22 OrcidClientGroup (org.orcid.jaxb.model.clientgroup.OrcidClientGroup)13 RedirectUri (org.orcid.jaxb.model.clientgroup.RedirectUri)12 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 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)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 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)2