Search in sources :

Example 1 with ExternalIdentifier

use of org.orcid.jaxb.model.message.ExternalIdentifier in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorImpl method addExternalIdentifiers.

/**
     * Add new external identifiers to the profile. As with all calls, if the
     * message contains any other elements, a 400 Bad Request will be returned.
     * 
     * @param orcidMessage
     *            the message congtaining the external ids
     * @return If successful, returns a 200 OK with the updated content.
     */
@Override
@AccessControl(requiredScope = ScopePathType.ORCID_BIO_EXTERNAL_IDENTIFIERS_CREATE)
public Response addExternalIdentifiers(UriInfo uriInfo, String orcid, OrcidMessage orcidMessage) {
    OrcidProfile orcidProfile = orcidMessage.getOrcidProfile();
    try {
        ExternalIdentifiers updatedExternalIdentifiers = orcidProfile.getOrcidBio().getExternalIdentifiers();
        // Get the client profile information
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String clientId = null;
        if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
            OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
            clientId = authorizationRequest.getClientId();
        }
        for (ExternalIdentifier ei : updatedExternalIdentifiers.getExternalIdentifier()) {
            // Set the client profile to each external identifier
            if (ei.getSource() == null) {
                Source source = new Source();
                source.setSourceClientId(new SourceClientId(clientId));
                ei.setSource(source);
            } else {
                // Check if the provided external orcid exists
                Source source = ei.getSource();
                String sourceOrcid = source.retrieveSourcePath();
                if (sourceOrcid != null) {
                    if (StringUtils.isBlank(sourceOrcid) || (!profileEntityManager.orcidExists(sourceOrcid) && !clientDetailsManager.exists(sourceOrcid))) {
                        Map<String, String> params = new HashMap<String, String>();
                        params.put("orcid", sourceOrcid);
                        throw new OrcidNotFoundException(params);
                    }
                }
            }
        }
        orcidProfile = orcidProfileManager.addExternalIdentifiers(orcidProfile);
        return getOrcidMessageResponse(orcidProfile, orcid);
    } catch (DataAccessException e) {
        throw new OrcidBadRequestException(localeManager.resolveMessage("apiError.badrequest_createorcid.exception"));
    }
}
Also used : ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) HashMap(java.util.HashMap) SourceClientId(org.orcid.jaxb.model.message.SourceClientId) Source(org.orcid.jaxb.model.message.Source) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OrcidBadRequestException(org.orcid.core.exception.OrcidBadRequestException) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) OrcidNotFoundException(org.orcid.core.exception.OrcidNotFoundException) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) DataAccessException(org.springframework.dao.DataAccessException) AccessControl(org.orcid.core.security.visibility.aop.AccessControl)

Example 2 with ExternalIdentifier

use of org.orcid.jaxb.model.message.ExternalIdentifier in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorTest method testAddDuplicatedExtIdsWhenThereIsNonPublicCountry.

@Test
public void testAddDuplicatedExtIdsWhenThereIsNonPublicCountry() {
    String userOrcid = "0000-0000-0000-0003";
    OrcidMessage message = new OrcidMessage();
    message.setMessageVersion("1.2_rc6");
    message.setOrcidProfile(new OrcidProfile());
    message.getOrcidProfile().setOrcidBio(new OrcidBio());
    ExternalIdentifiers extIds = new ExternalIdentifiers();
    ExternalIdentifier extId1 = new ExternalIdentifier();
    String commonName = "common-name-1-" + System.currentTimeMillis();
    extId1.setExternalIdCommonName(new ExternalIdCommonName(commonName));
    extId1.setExternalIdReference(new ExternalIdReference("ext-id-reference-1"));
    extId1.setExternalIdUrl(new ExternalIdUrl("http://test.orcid.org/" + System.currentTimeMillis()));
    extIds.getExternalIdentifier().add(extId1);
    message.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
    //Add for client 1
    SecurityContextTestUtils.setUpSecurityContext(userOrcid, "APP-5555555555555555", ScopePathType.PERSON_UPDATE, ScopePathType.PERSON_READ_LIMITED);
    Response r = t2OrcidApiServiceDelegator.addExternalIdentifiers(null, userOrcid, message);
    assertNotNull(r);
    OrcidMessage newMessage1 = (OrcidMessage) r.getEntity();
    assertNotNull(newMessage1);
    assertNotNull(newMessage1.getOrcidProfile());
    assertNotNull(newMessage1.getOrcidProfile().getOrcidBio());
    assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
    assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
    assertEquals(4, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    assertEquals(commonName, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(3).getExternalIdCommonName().getContent());
    assertEquals("APP-5555555555555555", newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(3).getSource().retrieveSourcePath());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Response(javax.ws.rs.core.Response) ExternalIdCommonName(org.orcid.jaxb.model.message.ExternalIdCommonName) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) FundingExternalIdentifier(org.orcid.jaxb.model.message.FundingExternalIdentifier) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) FundingExternalIdentifiers(org.orcid.jaxb.model.message.FundingExternalIdentifiers) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) ExternalIdUrl(org.orcid.jaxb.model.message.ExternalIdUrl) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 3 with ExternalIdentifier

use of org.orcid.jaxb.model.message.ExternalIdentifier in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorTest method testAddExternalIdentifiersToDeprecatedAccount.

@Test(expected = OrcidDeprecatedException.class)
public void testAddExternalIdentifiersToDeprecatedAccount() {
    SecurityContextTestUtils.setUpSecurityContext();
    OrcidMessage orcidMessage = new OrcidMessage();
    orcidMessage.setMessageVersion("1.2_rc6");
    orcidMessage.setOrcidProfile(new OrcidProfile());
    orcidMessage.getOrcidProfile().setOrcidBio(new OrcidBio());
    ExternalIdentifiers extIds = new ExternalIdentifiers();
    ExternalIdentifier extId1 = new ExternalIdentifier();
    String commonName = "common-name-1-" + System.currentTimeMillis();
    extId1.setExternalIdCommonName(new ExternalIdCommonName(commonName));
    extId1.setExternalIdReference(new ExternalIdReference("ext-id-reference-1"));
    extId1.setExternalIdUrl(new ExternalIdUrl("http://test.orcid.org/" + System.currentTimeMillis()));
    extIds.getExternalIdentifier().add(extId1);
    orcidMessage.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
    t2OrcidApiServiceDelegator.addExternalIdentifiers(mockedUriInfo, "4444-4444-4444-444X", orcidMessage);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ExternalIdCommonName(org.orcid.jaxb.model.message.ExternalIdCommonName) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) FundingExternalIdentifier(org.orcid.jaxb.model.message.FundingExternalIdentifier) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) FundingExternalIdentifiers(org.orcid.jaxb.model.message.FundingExternalIdentifiers) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) ExternalIdUrl(org.orcid.jaxb.model.message.ExternalIdUrl) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 4 with ExternalIdentifier

use of org.orcid.jaxb.model.message.ExternalIdentifier in project ORCID-Source by ORCID.

the class T2OrcidApiServiceDelegatorTest method testAddDuplicatedExtIdsWithDifferentClientWorks.

@Test
public void testAddDuplicatedExtIdsWithDifferentClientWorks() {
    String orcid = "0000-0000-0000-0002";
    OrcidMessage message = new OrcidMessage();
    message.setMessageVersion("1.2_rc6");
    message.setOrcidProfile(new OrcidProfile());
    message.getOrcidProfile().setOrcidBio(new OrcidBio());
    ExternalIdentifiers extIds = new ExternalIdentifiers();
    ExternalIdentifier extId1 = new ExternalIdentifier();
    String commonName = "common-name-1-" + System.currentTimeMillis();
    extId1.setExternalIdCommonName(new ExternalIdCommonName(commonName));
    extId1.setExternalIdReference(new ExternalIdReference("ext-id-reference-1"));
    extId1.setExternalIdUrl(new ExternalIdUrl("http://test.orcid.org/" + System.currentTimeMillis()));
    extIds.getExternalIdentifier().add(extId1);
    message.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
    //Add for client 1
    SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0002", "APP-5555555555555555", ScopePathType.PERSON_UPDATE, ScopePathType.PERSON_READ_LIMITED);
    Response r = t2OrcidApiServiceDelegator.addExternalIdentifiers(null, orcid, message);
    assertNotNull(r);
    OrcidMessage newMessage1 = (OrcidMessage) r.getEntity();
    assertNotNull(newMessage1);
    assertNotNull(newMessage1.getOrcidProfile());
    assertNotNull(newMessage1.getOrcidProfile().getOrcidBio());
    assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
    assertNotNull(newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
    assertEquals(1, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    assertEquals(commonName, newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
    assertEquals("APP-5555555555555555", newMessage1.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getSource().retrieveSourcePath());
    //Reset message for source # 2
    message = new OrcidMessage();
    message.setMessageVersion("1.2_rc6");
    message.setOrcidProfile(new OrcidProfile());
    message.getOrcidProfile().setOrcidBio(new OrcidBio());
    extId1.setSource(null);
    message.getOrcidProfile().getOrcidBio().setExternalIdentifiers(extIds);
    SecurityContextTestUtils.setUpSecurityContext("0000-0000-0000-0002", "APP-5555555555555556", ScopePathType.PERSON_UPDATE, ScopePathType.PERSON_READ_LIMITED);
    r = t2OrcidApiServiceDelegator.addExternalIdentifiers(null, orcid, message);
    OrcidMessage newMessage2 = (OrcidMessage) r.getEntity();
    assertNotNull(newMessage2);
    assertNotNull(newMessage2.getOrcidProfile());
    assertNotNull(newMessage2.getOrcidProfile().getOrcidBio());
    assertNotNull(newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers());
    assertNotNull(newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
    assertEquals(2, newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
    assertEquals(commonName, newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
    assertEquals("APP-5555555555555555", newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getSource().retrieveSourcePath());
    assertEquals(commonName, newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(1).getExternalIdCommonName().getContent());
    assertEquals("APP-5555555555555556", newMessage2.getOrcidProfile().getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(1).getSource().retrieveSourcePath());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Response(javax.ws.rs.core.Response) ExternalIdCommonName(org.orcid.jaxb.model.message.ExternalIdCommonName) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) ExternalIdReference(org.orcid.jaxb.model.message.ExternalIdReference) WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) FundingExternalIdentifier(org.orcid.jaxb.model.message.FundingExternalIdentifier) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) WorkExternalIdentifiers(org.orcid.jaxb.model.message.WorkExternalIdentifiers) FundingExternalIdentifiers(org.orcid.jaxb.model.message.FundingExternalIdentifiers) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) ExternalIdUrl(org.orcid.jaxb.model.message.ExternalIdUrl) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 5 with ExternalIdentifier

use of org.orcid.jaxb.model.message.ExternalIdentifier in project ORCID-Source by ORCID.

the class OrcidMessageVersionConverterImplV1_2_rc5ToV1_2_rc6 method downgradeProfile.

private void downgradeProfile(OrcidProfile orcidProfile) {
    if (orcidProfile != null) {
        if (orcidProfile.getOrcidBio() != null)
            if (orcidProfile.getOrcidBio().getExternalIdentifiers() != null)
                for (ExternalIdentifier externalIdentifier : orcidProfile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier()) {
                    Source source = externalIdentifier.getSource();
                    if (source != null) {
                        SourceOrcid sourceOrcid = source.getSourceOrcid();
                        if (sourceOrcid != null) {
                            externalIdentifier.setSource(null);
                            externalIdentifier.setExternalIdSource(new ExternalIdSource(sourceOrcid));
                        }
                    }
                }
        if (orcidProfile.getOrcidActivities() != null) {
            if (orcidProfile.getOrcidActivities().getOrcidWorks() != null) {
                for (OrcidWork act : orcidProfile.getOrcidActivities().getOrcidWorks().getOrcidWork()) downGradeActivity(act);
            }
        }
        OrcidInternal orcidInternal = orcidProfile.getOrcidInternal();
        if (orcidInternal != null) {
            Preferences prefs = orcidInternal.getPreferences();
            if (prefs != null) {
                prefs.setSendEmailFrequencyDays(null);
                prefs.setSendMemberUpdateRequests(null);
            }
            ReferredBy referredBy = orcidInternal.getReferredBy();
            if (referredBy != null && !OrcidStringUtils.isValidOrcid(referredBy.getPath())) {
                orcidInternal.setReferredBy(null);
            }
        }
    }
}
Also used : WorkExternalIdentifier(org.orcid.jaxb.model.message.WorkExternalIdentifier) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) OrcidInternal(org.orcid.jaxb.model.message.OrcidInternal) ExternalIdSource(org.orcid.jaxb.model.message.ExternalIdSource) ReferredBy(org.orcid.jaxb.model.message.ReferredBy) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Preferences(org.orcid.jaxb.model.message.Preferences) ExternalIdSource(org.orcid.jaxb.model.message.ExternalIdSource) Source(org.orcid.jaxb.model.message.Source) WorkSource(org.orcid.jaxb.model.message.WorkSource)

Aggregations

ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)27 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)19 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)17 ExternalIdReference (org.orcid.jaxb.model.message.ExternalIdReference)15 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)15 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)15 ExternalIdCommonName (org.orcid.jaxb.model.message.ExternalIdCommonName)12 Test (org.junit.Test)11 FundingExternalIdentifier (org.orcid.jaxb.model.message.FundingExternalIdentifier)10 Keyword (org.orcid.jaxb.model.message.Keyword)10 WorkExternalIdentifiers (org.orcid.jaxb.model.message.WorkExternalIdentifiers)10 ExternalIdUrl (org.orcid.jaxb.model.message.ExternalIdUrl)9 FundingExternalIdentifiers (org.orcid.jaxb.model.message.FundingExternalIdentifiers)9 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)8 OtherNames (org.orcid.jaxb.model.message.OtherNames)8 ResearcherUrl (org.orcid.jaxb.model.message.ResearcherUrl)8 Keywords (org.orcid.jaxb.model.message.Keywords)7 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)7 OtherName (org.orcid.jaxb.model.message.OtherName)7 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)6