Search in sources :

Example 66 with Work

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

the class WorksController method getWorkInfo.

/**
     * Returns a blank work
     */
@RequestMapping(value = "/getWorkInfo.json", method = RequestMethod.GET)
@ResponseBody
public WorkForm getWorkInfo(@RequestParam(value = "workId") Long workId) {
    Map<String, String> countries = retrieveIsoCountries();
    Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
    if (workId == null)
        return null;
    long lastModifiedTime = profileEntityManager.getLastModified(getEffectiveUserOrcid());
    Work work = workManager.getWork(this.getEffectiveUserOrcid(), workId, lastModifiedTime);
    if (work != null) {
        WorkForm workForm = WorkForm.valueOf(work);
        if (workForm.getPublicationDate() == null) {
            initializePublicationDate(workForm);
        } else {
            if (workForm.getPublicationDate().getDay() == null) {
                workForm.getPublicationDate().setDay(new String());
            }
            if (workForm.getPublicationDate().getMonth() == null) {
                workForm.getPublicationDate().setMonth(new String());
            }
            if (workForm.getPublicationDate().getYear() == null) {
                workForm.getPublicationDate().setYear(new String());
            }
        }
        // Set country name
        if (!PojoUtil.isEmpty(workForm.getCountryCode())) {
            Text countryName = Text.valueOf(countries.get(workForm.getCountryCode().getValue()));
            workForm.setCountryName(countryName);
        }
        // Set language name
        if (!PojoUtil.isEmpty(workForm.getLanguageCode())) {
            Text languageName = Text.valueOf(languages.get(workForm.getLanguageCode().getValue()));
            workForm.setLanguageName(languageName);
        }
        // Set translated title language name
        if (!(workForm.getTranslatedTitle() == null) && !StringUtils.isEmpty(workForm.getTranslatedTitle().getLanguageCode())) {
            String languageName = languages.get(workForm.getTranslatedTitle().getLanguageCode());
            workForm.getTranslatedTitle().setLanguageName(languageName);
        }
        if (workForm.getContributors() != null) {
            for (Contributor contributor : workForm.getContributors()) {
                if (!PojoUtil.isEmpty(contributor.getOrcid())) {
                    String contributorOrcid = contributor.getOrcid().getValue();
                    if (profileEntityManager.orcidExists(contributorOrcid)) {
                        // contributor is an ORCID user - visibility of user's name in record must be taken into account 
                        ProfileEntity profileEntity = profileEntityCacheManager.retrieve(contributorOrcid);
                        String publicContributorCreditName = cacheManager.getPublicCreditName(profileEntity);
                        contributor.setCreditName(Text.valueOf(publicContributorCreditName));
                    }
                }
            }
        }
        return workForm;
    }
    return null;
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) Work(org.orcid.jaxb.model.record_v2.Work) Contributor(org.orcid.pojo.ajaxForm.Contributor) Text(org.orcid.pojo.ajaxForm.Text) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 67 with Work

use of org.orcid.jaxb.model.record_rc1.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.record_v2.Work)

Example 68 with Work

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

the class WorksController method createWorksIdList.

/**
     * created a work id list and sorts a map associated with the list in in the
     * session
     * 
     */
private List<String> createWorksIdList(HttpServletRequest request) {
    String orcid = getEffectiveUserOrcid();
    List<Work> works = workManager.findWorks(orcid, profileEntityManager.getLastModified(orcid));
    HashMap<Long, WorkForm> worksMap = new HashMap<Long, WorkForm>();
    List<String> workIds = new ArrayList<String>();
    if (works != null) {
        for (Work work : works) {
            try {
                worksMap.put(work.getPutCode(), WorkForm.valueOf(work));
                workIds.add(String.valueOf(work.getPutCode()));
            } catch (Exception e) {
                LOGGER.error("ProfileWork failed to parse as Work. Put code" + work.getPutCode());
            }
        }
        request.getSession().setAttribute(WORKS_MAP, worksMap);
    }
    return workIds;
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) HashMap(java.util.HashMap) Work(org.orcid.jaxb.model.record_v2.Work) ArrayList(java.util.ArrayList)

Example 69 with Work

use of org.orcid.jaxb.model.record_rc1.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.record_v2.Work)

Example 70 with Work

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

the class WorkFormTest method testSerializeWork.

@Test
public void testSerializeWork() throws Exception {
    Work work = getWork();
    WorkForm workForm = WorkForm.valueOf(work);
    MemoryEfficientByteArrayOutputStream.serialize(workForm);
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) 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)55 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 WorkExternalIdentifier (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier)12 WorkExternalIdentifierId (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId)12 Work (org.orcid.jaxb.model.record_rc3.Work)11 Work (org.orcid.jaxb.model.record_rc4.Work)11