Search in sources :

Example 1 with OrcidHistory

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

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

the class OrcidProfileManagerImplTest method testAddOrcidWorks.

@Test
@Transactional
@Rollback(true)
public void testAddOrcidWorks() {
    OrcidProfile profile1 = createBasicProfile();
    OrcidHistory history = new OrcidHistory();
    history.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
    profile1.setOrcidHistory(history);
    history.setClaimed(new Claimed(true));
    profile1 = orcidProfileManager.createOrcidProfile(profile1, false, false);
    String originalPutCode = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getPutCode();
    OrcidProfile profile2 = new OrcidProfile();
    profile2.setOrcidIdentifier(TEST_ORCID);
    OrcidWorks orcidWorks = new OrcidWorks();
    profile2.setOrcidWorks(orcidWorks);
    WorkTitle workTitle1 = new WorkTitle();
    workTitle1.setTitle(new Title("Another Title"));
    workTitle1.setSubtitle(new Subtitle("Journal of Cloud Spotting"));
    OrcidWork work1 = createWork1(workTitle1);
    Source source = new Source(TEST_ORCID);
    work1.setSource(source);
    orcidWorks.getOrcidWork().add(work1);
    WorkTitle workTitle2 = new WorkTitle();
    workTitle2.setTitle(new Title("New Title"));
    workTitle2.setSubtitle(new Subtitle("Another New subtitle"));
    OrcidWork work2 = createWork2(workTitle2);
    orcidWorks.getOrcidWork().add(work2);
    // Try to add a duplicate
    WorkTitle workTitle3 = new WorkTitle();
    workTitle3.setTitle(new Title("New Title"));
    workTitle3.setSubtitle(new Subtitle("Another New subtitle"));
    OrcidWork work3 = createWork2(workTitle3);
    work3.setVisibility(Visibility.LIMITED);
    orcidWorks.getOrcidWork().add(work3);
    orcidProfileManager.addOrcidWorks(profile2);
    OrcidProfile resultProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertEquals("Will", resultProfile.getOrcidBio().getPersonalDetails().getGivenNames().getContent());
    List<OrcidWork> works = resultProfile.retrieveOrcidWorks().getOrcidWork();
    assertEquals(3, works.size());
    assertEquals("Another Title", works.get(0).getWorkTitle().getTitle().getContent());
    assertEquals("Journal of Cloud Spotting", works.get(0).getWorkTitle().getSubtitle().getContent());
    for (OrcidWork work : works) {
        assertEquals(Visibility.PRIVATE, work.getVisibility());
    }
    assertEquals("Put code of original work should not have changed", originalPutCode, works.get(2).getPutCode());
}
Also used : OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Title(org.orcid.jaxb.model.message.Title) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) FundingTitle(org.orcid.jaxb.model.message.FundingTitle) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) ApprovalDate(org.orcid.jaxb.model.message.ApprovalDate) Claimed(org.orcid.jaxb.model.message.Claimed) Source(org.orcid.jaxb.model.message.Source) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Subtitle(org.orcid.jaxb.model.message.Subtitle) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with OrcidHistory

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

the class RDFMessageBodyWriter method describeAccount.

private Individual describeAccount(OrcidProfile orcidProfile, OntModel m, Individual person) {
    String orcidURI = orcidProfile.getOrcidIdentifier().getUri();
    String orcidPublicationsUri = orcidURI + "#workspace-works";
    Individual publications = m.createIndividual(orcidPublicationsUri, FOAF.Document);
    // list of publications
    // (anchor in the HTML rendering - foaf:publications goes to a foaf:Document - not to an
    // RDF list of publications - although we should probably also have that)
    person.addProperty(FOAF.publications, publications);
    String orcidAccountUri = orcidURI + "#orcid-id";
    Individual account = m.createIndividual(orcidAccountUri, FOAF.OnlineAccount);
    person.addProperty(FOAF.account, account);
    Individual webSite = null;
    if (baseUri != null) {
        webSite = m.createIndividual(baseUri, null);
        account.addProperty(FOAF.accountServiceHomepage, webSite);
    }
    String orcId = orcidProfile.getOrcidIdentifier().getPath();
    account.addProperty(FOAF.accountName, orcId);
    account.addLabel(orcId, null);
    // The current page is the foaf:PersonalProfileDocument - this assumes
    // we have done a 303 See Other redirect to the RDF resource, so that it 
    // differs from the ORCID uri. 
    // for example:
    // 
    //     GET http://orcid.org/0000-0003-4654-1403
    //     Accept: text/turtle
    //  
    //     HTTP/1.1 303 See Other
    //     Location: https://pub.orcid.org/experimental_rdf_v1/0000-0001-9842-9718
    String profileUri;
    if (getUriInfo() != null) {
        profileUri = getUriInfo().getAbsolutePath().toASCIIString();
    } else {
        // Some kind of fallback, although the PersonalProfiledocument should be an 
        // information resource without #anchor
        profileUri = orcidURI + "#personalProfileDocument";
    }
    Individual profileDoc = m.createIndividual(profileUri, FOAF.PersonalProfileDocument);
    profileDoc.addProperty(FOAF.primaryTopic, person);
    OrcidHistory history = orcidProfile.getOrcidHistory();
    if (history != null) {
        if (history.isClaimed().booleanValue()) {
            // Set account as PersonalProfileDocument
            profileDoc.addProperty(FOAF.maker, person);
        }
        // Who made the profile?
        switch(history.getCreationMethod()) {
            case DIRECT:
            case MEMBER_REFERRED:
            case WEBSITE:
                profileDoc.addProperty(PAV.createdBy, person);
                profileDoc.addProperty(PROV.wasAttributedTo, person);
                if (webSite != null && (history.getCreationMethod() == CreationMethod.WEBSITE || history.getCreationMethod() == CreationMethod.DIRECT)) {
                    profileDoc.addProperty(PAV.createdWith, webSite);
                }
                break;
            case API:
                Individual api = m.createIndividual(MEMBER_API, PROV.SoftwareAgent);
                profileDoc.addProperty(PAV.importedBy, api);
                if (history.isClaimed().booleanValue()) {
                    profileDoc.addProperty(PAV.curatedBy, person);
                }
                break;
            default:
                // Some unknown agent!
                profileDoc.addProperty(PAV.createdWith, m.createIndividual(null, PROV.Agent));
        }
        if (history.getLastModifiedDate() != null) {
            Literal when = calendarAsLiteral(history.getLastModifiedDate().getValue(), m);
            profileDoc.addLiteral(PAV.lastUpdateOn, when);
            profileDoc.addLiteral(PROV.generatedAtTime, when);
        }
        if (history.getSubmissionDate() != null) {
            profileDoc.addLiteral(PAV.createdOn, calendarAsLiteral(history.getSubmissionDate().getValue(), m));
        }
        if (history.getCompletionDate() != null) {
            profileDoc.addLiteral(PAV.contributedOn, calendarAsLiteral(history.getCompletionDate().getValue(), m));
        }
        if (history.getDeactivationDate() != null) {
            profileDoc.addLiteral(PROV.invalidatedAtTime, calendarAsLiteral(history.getDeactivationDate().getValue(), m));
        }
    }
    return profileDoc;
}
Also used : Individual(org.apache.jena.ontology.Individual) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) Literal(org.apache.jena.rdf.model.Literal)

Example 4 with OrcidHistory

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

the class OrcidProfileManagerImpl method setWorkPrivacy.

private void setWorkPrivacy(OrcidProfile updatedOrcidProfile, Visibility defaultWorkVisibility) {
    OrcidHistory orcidHistory = updatedOrcidProfile.getOrcidHistory();
    boolean isClaimed = orcidHistory != null ? orcidHistory.getClaimed().isValue() : false;
    OrcidActivities incomingActivities = updatedOrcidProfile.getOrcidActivities();
    if (incomingActivities != null) {
        OrcidWorks incomingWorks = incomingActivities.getOrcidWorks();
        if (incomingWorks != null) {
            setWorkPrivacy(incomingWorks, defaultWorkVisibility, isClaimed);
        }
    }
}
Also used : OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks)

Example 5 with OrcidHistory

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

the class OrcidProfileManagerImpl method setFundingPrivacy.

private void setFundingPrivacy(OrcidProfile updatedOrcidProfile, Visibility defaultFundingVisibility) {
    OrcidHistory orcidHistory = updatedOrcidProfile.getOrcidHistory();
    boolean isClaimed = orcidHistory != null ? orcidHistory.getClaimed().isValue() : false;
    OrcidActivities incomingActivities = updatedOrcidProfile.getOrcidActivities();
    if (incomingActivities != null) {
        FundingList incomingFundingList = incomingActivities.getFundings();
        if (incomingFundingList != null) {
            setFundingPrivacy(incomingFundingList, defaultFundingVisibility, isClaimed);
        }
    }
}
Also used : FundingList(org.orcid.jaxb.model.message.FundingList) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities)

Aggregations

OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)27 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)20 Date (java.util.Date)17 SubmissionDate (org.orcid.jaxb.model.message.SubmissionDate)17 Claimed (org.orcid.jaxb.model.message.Claimed)15 Test (org.junit.Test)10 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)10 ActivitiesVisibilityDefault (org.orcid.jaxb.model.message.ActivitiesVisibilityDefault)9 Transactional (org.springframework.transaction.annotation.Transactional)9 ApprovalDate (org.orcid.jaxb.model.message.ApprovalDate)8 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)8 PersonalDetails (org.orcid.jaxb.model.message.PersonalDetails)8 Source (org.orcid.jaxb.model.message.Source)8 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)7 OrcidInternal (org.orcid.jaxb.model.message.OrcidInternal)7 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)7 Email (org.orcid.jaxb.model.message.Email)6 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)6 Rollback (org.springframework.test.annotation.Rollback)6 ArrayList (java.util.ArrayList)5