use of org.orcid.jaxb.model.record_rc2.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;
}
use of org.orcid.jaxb.model.record_rc2.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));
}
use of org.orcid.jaxb.model.record_rc2.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;
}
use of org.orcid.jaxb.model.record_rc2.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);
}
use of org.orcid.jaxb.model.record_rc2.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);
}
Aggregations