Search in sources :

Example 1 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegatorImpl method updateWork.

@Override
public Response updateWork(String orcid, Long putCode, Work work) {
    orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.ORCID_WORKS_UPDATE);
    if (!putCode.equals(work.getPutCode())) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("urlPutCode", String.valueOf(putCode));
        params.put("bodyPutCode", String.valueOf(work.getPutCode()));
        throw new MismatchedPutCodeException(params);
    }
    clearSource(work);
    Work w = workManager.updateWork(orcid, work, true);
    sourceUtils.setSourceName(w);
    return Response.ok(w).build();
}
Also used : HashMap(java.util.HashMap) Work(org.orcid.jaxb.model.record_v2.Work) MismatchedPutCodeException(org.orcid.core.exception.MismatchedPutCodeException)

Example 2 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class Utils method getWork.

public static Work getWork(String title) {
    Work work = new Work();
    WorkTitle workTitle = new WorkTitle();
    workTitle.setTitle(new Title(title));
    work.setWorkTitle(workTitle);
    work.setWorkType(WorkType.BOOK);
    work.setVisibility(Visibility.PUBLIC);
    ExternalIDs extIds = new ExternalIDs();
    ExternalID extId = new ExternalID();
    extId.setRelationship(Relationship.PART_OF);
    extId.setType(WorkExternalIdentifierType.AGR.value());
    extId.setValue("ext-id-" + System.currentTimeMillis());
    extId.setUrl(new Url("http://thisIsANewUrl.com"));
    extIds.getExternalIdentifier().add(extId);
    work.setWorkExternalIdentifiers(extIds);
    return work;
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) Title(org.orcid.jaxb.model.common_v2.Title) Url(org.orcid.jaxb.model.common_v2.Url) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl)

Example 3 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class WorkForm method toWork.

public Work toWork() {
    Work work = new Work();
    // Set work id
    if (!PojoUtil.isEmpty(this.getPutCode())) {
        work.setPutCode(Long.valueOf(this.getPutCode().getValue()));
    }
    // Set language
    if (!PojoUtil.isEmpty(this.getLanguageCode())) {
        work.setLanguageCode(this.getLanguageCode().getValue());
    }
    // Set type
    if (!PojoUtil.isEmpty(this.getWorkType())) {
        work.setWorkType(WorkType.fromValue(this.getWorkType().getValue()));
    }
    org.orcid.jaxb.model.record_v2.WorkTitle workTitle = new org.orcid.jaxb.model.record_v2.WorkTitle();
    // Set title
    if (!PojoUtil.isEmpty(this.getTitle())) {
        workTitle.setTitle(new org.orcid.jaxb.model.common_v2.Title(this.getTitle().getValue()));
    }
    // Set translated title        
    if (this.getTranslatedTitle() != null && !PojoUtil.isEmpty(this.getTranslatedTitle().getContent())) {
        org.orcid.jaxb.model.common_v2.TranslatedTitle translatedTitle = new org.orcid.jaxb.model.common_v2.TranslatedTitle();
        translatedTitle.setContent(this.getTranslatedTitle().getContent());
        translatedTitle.setLanguageCode(this.getTranslatedTitle().getLanguageCode());
        workTitle.setTranslatedTitle(translatedTitle);
    }
    // Set subtitle
    if (!PojoUtil.isEmpty(this.getSubtitle())) {
        org.orcid.jaxb.model.common_v2.Subtitle subtitle = new org.orcid.jaxb.model.common_v2.Subtitle();
        subtitle.setContent(this.getSubtitle().getValue());
        workTitle.setSubtitle(subtitle);
    }
    work.setWorkTitle(workTitle);
    // Set journal title
    if (!PojoUtil.isEmpty(this.getJournalTitle())) {
        work.setJournalTitle(new org.orcid.jaxb.model.common_v2.Title(this.getJournalTitle().getValue()));
    }
    // Set description
    if (!PojoUtil.isEmpty(this.getShortDescription())) {
        work.setShortDescription(this.getShortDescription().getValue());
    }
    // Set url
    if (!PojoUtil.isEmpty(this.getUrl())) {
        work.setUrl(new Url(this.getUrl().getValue()));
    } else {
        work.setUrl(new Url());
    }
    // Set visibility
    if (this.getVisibility() != null) {
        work.setVisibility(this.getVisibility());
    }
    // Set country
    if (!PojoUtil.isEmpty(this.getCountryCode())) {
        work.setCountry(new org.orcid.jaxb.model.common_v2.Country(org.orcid.jaxb.model.common_v2.Iso3166Country.fromValue(this.getCountryCode().getValue())));
    }
    // Set publication date        
    if (this.getPublicationDate() != null) {
        Integer yearInteger = PojoUtil.isEmpty(this.getPublicationDate().getYear()) ? null : Integer.valueOf(this.getPublicationDate().getYear());
        Integer monthInteger = PojoUtil.isEmpty(this.getPublicationDate().getMonth()) ? null : Integer.valueOf(this.getPublicationDate().getMonth());
        Integer dayInteger = PojoUtil.isEmpty(this.getPublicationDate().getDay()) ? null : Integer.valueOf(this.getPublicationDate().getDay());
        org.orcid.jaxb.model.common_v2.Year year = null;
        org.orcid.jaxb.model.common_v2.Month month = null;
        org.orcid.jaxb.model.common_v2.Day day = null;
        if (yearInteger != null) {
            year = new org.orcid.jaxb.model.common_v2.Year(yearInteger);
        }
        if (monthInteger != null) {
            month = new org.orcid.jaxb.model.common_v2.Month(monthInteger);
        }
        if (dayInteger != null) {
            day = new org.orcid.jaxb.model.common_v2.Day(dayInteger);
        }
        work.setPublicationDate(new org.orcid.jaxb.model.common_v2.PublicationDate(year, month, day));
    }
    // Set citation
    if (this.getCitation() != null) {
        org.orcid.jaxb.model.record_v2.Citation citation = new org.orcid.jaxb.model.record_v2.Citation();
        if (!PojoUtil.isEmpty(this.getCitation().getCitation())) {
            citation.setCitation(this.getCitation().getCitation().getValue());
        }
        if (!PojoUtil.isEmpty(this.getCitation().getCitationType())) {
            citation.setWorkCitationType(CitationType.fromValue(this.getCitation().getCitationType().getValue()));
        }
        work.setWorkCitation(citation);
    }
    // Set contributors
    populateContributors(this, work);
    // Set external identifiers
    populateExternalIdentifiers(this, work);
    // Set created date
    if (!PojoUtil.isEmpty(this.getCreatedDate())) {
        CreatedDate createdDate = new CreatedDate();
        createdDate.setValue(DateUtils.convertToXMLGregorianCalendar(this.getCreatedDate().toJavaDate()));
        work.setCreatedDate(createdDate);
    }
    // Set last modified
    if (!PojoUtil.isEmpty(this.getLastModified())) {
        org.orcid.jaxb.model.common_v2.LastModifiedDate lastModified = new org.orcid.jaxb.model.common_v2.LastModifiedDate();
        lastModified.setValue(DateUtils.convertToXMLGregorianCalendar(this.getLastModified().toJavaDate()));
        work.setLastModifiedDate(lastModified);
    }
    if (!PojoUtil.isEmpty(this.getSource())) {
        org.orcid.jaxb.model.common_v2.Source source = new org.orcid.jaxb.model.common_v2.Source();
        if (OrcidStringUtils.isClientId(this.getSource())) {
            source.setSourceClientId(new SourceClientId(this.getSource()));
        } else {
            source.setSourceOrcid(new SourceOrcid(this.getSource()));
        }
        work.setSource(source);
    }
    return work;
}
Also used : SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) Url(org.orcid.jaxb.model.common_v2.Url) Work(org.orcid.jaxb.model.record_v2.Work) CreatedDate(org.orcid.jaxb.model.common_v2.CreatedDate) SourceOrcid(org.orcid.jaxb.model.common_v2.SourceOrcid)

Example 4 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class SourceInActivitiesTest method getWork.

private Work getWork(String userOrcid) {
    Work work = new Work();
    WorkTitle title = new WorkTitle();
    title.setTitle(new Title("Work " + System.currentTimeMillis()));
    work.setWorkTitle(title);
    work.setWorkType(org.orcid.jaxb.model.record_v2.WorkType.BOOK);
    ExternalID extId = new ExternalID();
    extId.setValue("111");
    extId.setType(WorkExternalIdentifierType.DOI.value());
    ExternalIDs extIdentifiers = new ExternalIDs();
    extIdentifiers.getExternalIdentifier().add(extId);
    work.setWorkExternalIdentifiers(extIdentifiers);
    work = workManager.createWork(userOrcid, work, false);
    return workManager.getWork(userOrcid, work.getPutCode(), 0L);
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) Title(org.orcid.jaxb.model.common_v2.Title)

Example 5 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class OrcidSecurityManager_WorkBulkTest method testMixedPublicAndLimitedWorkBulkReadLimitedToken.

@Test
public void testMixedPublicAndLimitedWorkBulkReadLimitedToken() {
    WorkBulk workBulk = new WorkBulk();
    workBulk.setBulk(Arrays.asList(createWork(Visibility.PUBLIC, CLIENT_2), createWork(Visibility.LIMITED, CLIENT_2)));
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_1, ScopePathType.READ_LIMITED);
    orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
    assertNotNull(workBulk);
    assertEquals(2, workBulk.getBulk().size());
    assertTrue(workBulk.getBulk().get(0) instanceof Work);
    assertTrue(workBulk.getBulk().get(1) instanceof Work);
}
Also used : WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Aggregations

Work (org.orcid.jaxb.model.record_v2.Work)150 Test (org.junit.Test)147 ClientResponse (com.sun.jersey.api.client.ClientResponse)52 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)33 DBUnitTest (org.orcid.test.DBUnitTest)24 Response (javax.ws.rs.core.Response)23 Title (org.orcid.jaxb.model.common_v2.Title)22 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)22 Url (org.orcid.jaxb.model.common_v2.Url)21 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)21 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)19 ArrayList (java.util.ArrayList)16 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)16 BaseTest (org.orcid.core.BaseTest)14 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)13 Work (org.orcid.jaxb.model.record_rc1.Work)12 Work (org.orcid.jaxb.model.record_rc3.Work)11 Work (org.orcid.jaxb.model.record_rc4.Work)11 Funding (org.orcid.jaxb.model.record_v2.Funding)11 BulkElement (org.orcid.jaxb.model.record_v2.BulkElement)9