Search in sources :

Example 41 with Work

use of org.orcid.jaxb.model.v3.dev1.record.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.v3.dev1.record.WorkTitle workTitle = new org.orcid.jaxb.model.v3.dev1.record.WorkTitle();
    // Set title
    if (!PojoUtil.isEmpty(this.getTitle())) {
        workTitle.setTitle(new org.orcid.jaxb.model.v3.dev1.common.Title(this.getTitle().getValue()));
    }
    // Set translated title
    if (this.getTranslatedTitle() != null && !PojoUtil.isEmpty(this.getTranslatedTitle().getContent())) {
        org.orcid.jaxb.model.v3.dev1.common.TranslatedTitle translatedTitle = new org.orcid.jaxb.model.v3.dev1.common.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.v3.dev1.common.Subtitle subtitle = new org.orcid.jaxb.model.v3.dev1.common.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.v3.dev1.common.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 && this.getVisibility().getVisibility() != null) {
        work.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.fromValue(this.getVisibility().getVisibility().value()));
    }
    // Set country
    if (!PojoUtil.isEmpty(this.getCountryCode())) {
        work.setCountry(new org.orcid.jaxb.model.v3.dev1.common.Country(org.orcid.jaxb.model.v3.dev1.common.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.v3.dev1.common.Year year = null;
        org.orcid.jaxb.model.v3.dev1.common.Month month = null;
        org.orcid.jaxb.model.v3.dev1.common.Day day = null;
        if (yearInteger != null) {
            year = new org.orcid.jaxb.model.v3.dev1.common.Year(yearInteger);
        }
        if (monthInteger != null) {
            month = new org.orcid.jaxb.model.v3.dev1.common.Month(monthInteger);
        }
        if (dayInteger != null) {
            day = new org.orcid.jaxb.model.v3.dev1.common.Day(dayInteger);
        }
        work.setPublicationDate(new org.orcid.jaxb.model.v3.dev1.common.PublicationDate(year, month, day));
    }
    // Set citation
    if (this.getCitation() != null) {
        org.orcid.jaxb.model.v3.dev1.record.Citation citation = new org.orcid.jaxb.model.v3.dev1.record.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.v3.dev1.common.LastModifiedDate lastModified = new org.orcid.jaxb.model.v3.dev1.common.LastModifiedDate();
        lastModified.setValue(DateUtils.convertToXMLGregorianCalendar(this.getLastModified().toJavaDate()));
        work.setLastModifiedDate(lastModified);
    }
    if (!PojoUtil.isEmpty(this.getSource())) {
        org.orcid.jaxb.model.v3.dev1.common.Source source = new org.orcid.jaxb.model.v3.dev1.common.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.v3.dev1.common.SourceClientId) Url(org.orcid.jaxb.model.v3.dev1.common.Url) Work(org.orcid.jaxb.model.v3.dev1.record.Work) CreatedDate(org.orcid.jaxb.model.v3.dev1.common.CreatedDate) SourceOrcid(org.orcid.jaxb.model.v3.dev1.common.SourceOrcid)

Example 42 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class WorkForm method valueOf.

public static WorkForm valueOf(Work work) {
    if (work == null)
        return null;
    WorkForm w = new WorkForm();
    // Set work id
    if (work.getPutCode() != null) {
        w.setPutCode(Text.valueOf(work.getPutCode()));
    }
    // Set language
    if (!PojoUtil.isEmpty(work.getLanguageCode())) {
        w.setLanguageCode(Text.valueOf(work.getLanguageCode()));
    }
    // Set type
    if (work.getWorkType() != null) {
        w.setWorkType(Text.valueOf(work.getWorkType().value()));
        // Set category
        WorkCategory category = WorkCategory.fromWorkType(work.getWorkType());
        w.setWorkCategory(Text.valueOf(category.value()));
    }
    if (work.getWorkTitle() != null) {
        // Set title
        if (work.getWorkTitle().getTitle() != null) {
            w.setTitle(Text.valueOf(work.getWorkTitle().getTitle().getContent()));
        }
        // Set translated title
        if (work.getWorkTitle().getTranslatedTitle() != null) {
            TranslatedTitleForm tt = new TranslatedTitleForm();
            tt.setContent(work.getWorkTitle().getTranslatedTitle().getContent());
            tt.setLanguageCode(work.getWorkTitle().getTranslatedTitle().getLanguageCode());
            w.setTranslatedTitle(tt);
        }
        // Set subtitle
        if (work.getWorkTitle().getSubtitle() != null) {
            w.setSubtitle(Text.valueOf(work.getWorkTitle().getSubtitle().getContent()));
        }
    }
    // Set journal title
    if (work.getJournalTitle() != null) {
        w.setJournalTitle(Text.valueOf(work.getJournalTitle().getContent()));
    }
    // Set description
    if (work.getShortDescription() != null) {
        w.setShortDescription(Text.valueOf(work.getShortDescription()));
    }
    // Set url
    if (work.getUrl() != null) {
        w.setUrl(Text.valueOf(work.getUrl().getValue()));
    }
    // Set visibility
    if (work.getVisibility() != null) {
        w.setVisibility(Visibility.valueOf(work.getVisibility()));
    }
    // Set country
    if (work.getCountry() != null && work.getCountry().getValue() != null) {
        w.setCountryCode(Text.valueOf(work.getCountry().getValue().value()));
    }
    // Set publication date
    FuzzyDate fuzzyPublicationDate = null;
    if (work.getPublicationDate() != null) {
        org.orcid.jaxb.model.v3.dev1.common.PublicationDate publicationDate = work.getPublicationDate();
        Integer year = PojoUtil.isEmpty(publicationDate.getYear()) ? null : Integer.valueOf(publicationDate.getYear().getValue());
        Integer month = PojoUtil.isEmpty(publicationDate.getMonth()) ? null : Integer.valueOf(publicationDate.getMonth().getValue());
        Integer day = PojoUtil.isEmpty(publicationDate.getDay()) ? null : Integer.valueOf(publicationDate.getDay().getValue());
        if (year != null && year == 0) {
            year = null;
        }
        if (month != null && month == 0) {
            month = null;
        }
        if (day != null && day == 0) {
            day = null;
        }
        fuzzyPublicationDate = FuzzyDate.valueOf(year, month, day);
        w.setPublicationDate(Date.valueOf(fuzzyPublicationDate));
    }
    w.setDateSortString(PojoUtil.createDateSortString(null, fuzzyPublicationDate));
    // Set citation
    if (work.getWorkCitation() != null) {
        Citation citation = new Citation();
        if (!PojoUtil.isEmpty(work.getWorkCitation().getCitation())) {
            citation.setCitation(Text.valueOf(work.getWorkCitation().getCitation()));
        }
        if (work.getWorkCitation().getWorkCitationType() != null) {
            citation.setCitationType(Text.valueOf(work.getWorkCitation().getWorkCitationType().value()));
        }
        w.setCitation(citation);
    }
    // Set contributors
    populateContributors(work, w);
    // Set external identifiers
    populateExternalIdentifiers(work, w);
    // Set created date
    w.setCreatedDate(Date.valueOf(work.getCreatedDate()));
    // Set last modified
    w.setLastModified(Date.valueOf(work.getLastModifiedDate()));
    if (work.getSource() != null) {
        // Set source
        w.setSource(work.getSource().retrieveSourcePath());
        if (work.getSource().getSourceName() != null) {
            w.setSourceName(work.getSource().getSourceName().getContent());
        }
    }
    return w;
}
Also used : FuzzyDate(org.orcid.jaxb.model.v3.dev1.common.FuzzyDate) WorkCategory(org.orcid.jaxb.model.v3.dev1.record.WorkCategory)

Example 43 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class WorksController method addWork.

private void addWork(WorkForm workForm) {
    Work newWork = workForm.toWork();
    newWork.setPutCode(null);
    // Create work
    newWork = workManager.createWork(getEffectiveUserOrcid(), newWork, false);
    // Set the id in the work to be returned
    Long workId = newWork.getPutCode();
    workForm.setPutCode(Text.valueOf(workId));
}
Also used : Work(org.orcid.jaxb.model.v3.dev1.record.Work)

Example 44 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class WorksController method retriveWorkTypes.

/**
 * Return a list of work types based on the work category provided as a
 * parameter
 *
 * @param workCategoryName
 * @return a map containing the list of types associated with that type and
 *         his localized name
 */
@RequestMapping(value = "/loadWorkTypes.json", method = RequestMethod.GET)
@ResponseBody
public List<KeyValue> retriveWorkTypes(@RequestParam(value = "workCategory") String workCategoryName) {
    List<KeyValue> types = new ArrayList<KeyValue>();
    WorkCategory workCategory = null;
    if (!PojoUtil.isEmpty(workCategoryName))
        workCategory = WorkCategory.fromValue(workCategoryName);
    // Get work types based on category
    if (workCategory != null) {
        for (WorkType workType : workCategory.getSubTypes()) {
            // Dont put work type UNDEFINED
            if (!workType.equals(WorkType.UNDEFINED)) {
                types.add(new KeyValue(workType.value(), getMessage(new StringBuffer("org.orcid.jaxb.model.record.WorkType.").append(workType.value()).toString())));
            }
        }
    } else {
        // Get all work types
        for (WorkType workType : WorkType.values()) {
            // Dont put work type UNDEFINED
            if (!workType.equals(WorkType.UNDEFINED)) {
                types.add(new KeyValue(workType.value(), getMessage(new StringBuffer("org.orcid.jaxb.model.record.WorkType.").append(workType.value()).toString())));
            }
        }
    }
    return types;
}
Also used : KeyValue(org.orcid.pojo.KeyValue) WorkType(org.orcid.jaxb.model.v3.dev1.record.WorkType) ArrayList(java.util.ArrayList) WorkCategory(org.orcid.jaxb.model.v3.dev1.record.WorkCategory) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 45 with Work

use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.

the class WorksController method updateWork.

private void updateWork(WorkForm workForm) throws Exception {
    // Get current profile
    String userOrcid = getEffectiveUserOrcid();
    if (!userOrcid.equals(workForm.getSource())) {
        throw new Exception(getMessage("web.orcid.activity_incorrectsource.exception"));
    }
    Work updatedWork = workForm.toWork();
    // Edit work
    workManager.updateWork(userOrcid, updatedWork, false);
}
Also used : Work(org.orcid.jaxb.model.v3.dev1.record.Work)

Aggregations

Test (org.junit.Test)154 Work (org.orcid.jaxb.model.v3.dev1.record.Work)141 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)46 DBUnitTest (org.orcid.test.DBUnitTest)41 Response (javax.ws.rs.core.Response)39 Title (org.orcid.jaxb.model.v3.dev1.common.Title)29 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)29 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)29 Url (org.orcid.jaxb.model.v3.dev1.common.Url)28 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)24 WorkBulk (org.orcid.jaxb.model.v3.dev1.record.WorkBulk)22 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)21 BaseTest (org.orcid.core.BaseTest)20 NoResultException (javax.persistence.NoResultException)17 OrcidAccessControlException (org.orcid.core.exception.OrcidAccessControlException)17 OrcidUnauthorizedException (org.orcid.core.exception.OrcidUnauthorizedException)17 OrcidVisibilityException (org.orcid.core.exception.OrcidVisibilityException)17 VisibilityMismatchException (org.orcid.core.exception.VisibilityMismatchException)17 WrongSourceException (org.orcid.core.exception.WrongSourceException)17 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)15