Search in sources :

Example 1 with SourceOrcid

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

the class T2OrcidApiServiceDelegatorImpl method setSponsorFromAuthentication.

public void setSponsorFromAuthentication(OrcidProfile profile) {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (profile.getOrcidHistory() == null) {
        OrcidHistory orcidHistory = new OrcidHistory();
        orcidHistory.setCreationMethod(CreationMethod.API);
        profile.setOrcidHistory(orcidHistory);
    }
    profile.getOrcidHistory().setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
    if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
        OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
        Source sponsor = new Source();
        String sponsorId = authorizationRequest.getClientId();
        ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(sponsorId);
        if (clientDetails != null) {
            sponsor.setSourceName(new SourceName(clientDetails.getClientName()));
            if (OrcidStringUtils.isClientId(sponsorId)) {
                sponsor.setSourceClientId(new SourceClientId(sponsorId));
            } else {
                sponsor.setSourceOrcid(new SourceOrcid(sponsorId));
            }
        }
        profile.getOrcidHistory().setSource(sponsor);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) Authentication(org.springframework.security.core.Authentication) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) SourceClientId(org.orcid.jaxb.model.message.SourceClientId) SourceName(org.orcid.jaxb.model.message.SourceName) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Source(org.orcid.jaxb.model.message.Source)

Example 2 with SourceOrcid

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

the class OrcidJaxbCopyManagerImpl method createSource.

private Source createSource(String amenderOrcid) {
    Source source = new Source();
    if (OrcidStringUtils.isValidOrcid(amenderOrcid)) {
        source.setSourceOrcid(new SourceOrcid(amenderOrcid));
        source.setSourceClientId(null);
    } else {
        source.setSourceClientId(new SourceClientId(amenderOrcid));
        source.setSourceOrcid(null);
    }
    return source;
}
Also used : SourceClientId(org.orcid.jaxb.model.message.SourceClientId) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Source(org.orcid.jaxb.model.message.Source)

Example 3 with SourceOrcid

use of org.orcid.jaxb.model.message.SourceOrcid 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)

Example 4 with SourceOrcid

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

the class OrcidProfileManagerImplTest method testPreventDuplicatedWorks.

@Test
@Transactional
@Rollback(true)
public void testPreventDuplicatedWorks() {
    OrcidWork work1 = createWork1();
    OrcidWork work2 = createWork2();
    OrcidWork work3 = createWork3();
    OrcidProfile profile = createBasicProfile();
    profile = orcidProfileManager.createOrcidProfile(profile, false, false);
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(1, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    assertEquals(work1.getWorkTitle().getTitle().getContent(), profile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getWorkTitle().getTitle().getContent());
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    boolean found1 = false;
    boolean found2 = false;
    boolean found3 = false;
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(2, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    for (OrcidWork work : profile.getOrcidActivities().getOrcidWorks().getOrcidWork()) {
        String workTitle = work.getWorkTitle().getTitle().getContent();
        if (workTitle.equals(work1.getWorkTitle().getTitle().getContent())) {
            found1 = true;
        } else if (workTitle.equals(work2.getWorkTitle().getTitle().getContent())) {
            found2 = true;
        } else if (workTitle.equals(work3.getWorkTitle().getTitle().getContent())) {
            found3 = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertFalse(found3);
    // Add work # 3 and duplicate other works
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    // Work 3 was added and work 1 and 2 where not added twice
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(3, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    found1 = false;
    found2 = false;
    found3 = false;
    for (OrcidWork work : profile.getOrcidActivities().getOrcidWorks().getOrcidWork()) {
        String workTitle = work.getWorkTitle().getTitle().getContent();
        if (workTitle.equals(work1.getWorkTitle().getTitle().getContent())) {
            found1 = true;
        } else if (workTitle.equals(work2.getWorkTitle().getTitle().getContent())) {
            found2 = true;
        } else if (workTitle.equals(work3.getWorkTitle().getTitle().getContent())) {
            found3 = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    // Duplicate all works
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    // No new works are added and no duplicated was allowed
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(3, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    found1 = false;
    found2 = false;
    found3 = false;
    for (OrcidWork work : profile.getOrcidActivities().getOrcidWorks().getOrcidWork()) {
        String workTitle = work.getWorkTitle().getTitle().getContent();
        if (workTitle.equals(work1.getWorkTitle().getTitle().getContent())) {
            found1 = true;
        } else if (workTitle.equals(work2.getWorkTitle().getTitle().getContent())) {
            found2 = true;
        } else if (workTitle.equals(work3.getWorkTitle().getTitle().getContent())) {
            found3 = true;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    //Test using work source
    Source source = new Source();
    source.setSourceOrcid(new SourceOrcid(APPLICATION_ORCID));
    work1.setSource(source);
    // Add work1 again, since it have a different source, it should be added
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(4, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
    //Add work1 again, and it should not be added, since is duplicated
    profile.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work1);
    orcidProfileManager.addOrcidWorks(profile);
    profile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertNotNull(profile);
    assertNotNull(profile.getOrcidActivities());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks());
    assertNotNull(profile.getOrcidActivities().getOrcidWorks().getOrcidWork());
    assertEquals(4, profile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Source(org.orcid.jaxb.model.message.Source) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with SourceOrcid

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

the class OrcidProfileManagerImpl method createSource.

private Source createSource(String amenderOrcid) {
    Source source = new Source();
    if (OrcidStringUtils.isValidOrcid(amenderOrcid)) {
        source.setSourceOrcid(new SourceOrcid(amenderOrcid));
        source.setSourceClientId(null);
    } else {
        source.setSourceClientId(new SourceClientId(amenderOrcid));
        source.setSourceOrcid(null);
    }
    return source;
}
Also used : SourceClientId(org.orcid.jaxb.model.message.SourceClientId) SourceOrcid(org.orcid.jaxb.model.message.SourceOrcid) Source(org.orcid.jaxb.model.message.Source)

Aggregations

Source (org.orcid.jaxb.model.message.Source)8 SourceOrcid (org.orcid.jaxb.model.message.SourceOrcid)8 ExternalIdSource (org.orcid.jaxb.model.message.ExternalIdSource)3 SourceClientId (org.orcid.jaxb.model.message.SourceClientId)3 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)3 WorkSource (org.orcid.jaxb.model.message.WorkSource)3 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)2 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)2 Date (java.util.Date)1 Test (org.junit.Test)1 ExternalIdReference (org.orcid.jaxb.model.message.ExternalIdReference)1 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)1 OrcidInternal (org.orcid.jaxb.model.message.OrcidInternal)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1 Preferences (org.orcid.jaxb.model.message.Preferences)1 ReferredBy (org.orcid.jaxb.model.message.ReferredBy)1 SourceName (org.orcid.jaxb.model.message.SourceName)1 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)1 WorkExternalIdentifierType (org.orcid.jaxb.model.message.WorkExternalIdentifierType)1 WorkExternalIdentifiers (org.orcid.jaxb.model.message.WorkExternalIdentifiers)1