use of org.orcid.jaxb.model.record_rc2.Keywords in project ORCID-Source by ORCID.
the class ValidateV2RC3SamplesTest method testUnmarshallKeyword.
@Test
public void testUnmarshallKeyword() throws SAXException, URISyntaxException {
Keywords keywords = (Keywords) unmarshallFromPath("/record_2.0_rc3/samples/keywords-2.0_rc3.xml", Keywords.class, "/record_2.0_rc3/keyword-2.0_rc3.xsd");
assertNotNull(keywords);
assertNotNull(keywords.getKeywords());
assertEquals(2, keywords.getKeywords().size());
for (Keyword keyword : keywords.getKeywords()) {
assertThat(keyword.getContent(), anyOf(is("keyword1"), is("keyword2")));
assertThat(keyword.getPutCode(), anyOf(is(Long.valueOf(1)), is(Long.valueOf(2))));
assertEquals(Visibility.PUBLIC.value(), keyword.getVisibility().value());
assertNotNull(keyword.getCreatedDate());
assertNotNull(keyword.getLastModifiedDate());
assertNotNull(keyword.getSource());
assertEquals("8888-8888-8888-8880", keyword.getSource().retrieveSourcePath());
}
Keyword keyword = (Keyword) unmarshallFromPath("/record_2.0_rc3/samples/keyword-2.0_rc3.xml", Keyword.class);
assertNotNull(keyword);
assertEquals("keyword1", keyword.getContent());
assertEquals(Long.valueOf(1), keyword.getPutCode());
assertEquals(Visibility.PUBLIC.value(), keyword.getVisibility().value());
assertNotNull(keyword.getCreatedDate());
assertNotNull(keyword.getLastModifiedDate());
assertNotNull(keyword.getSource());
assertEquals("8888-8888-8888-8880", keyword.getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.record_rc2.Keywords in project ORCID-Source by ORCID.
the class ValidateV2RC4SamplesTest method testMarshallKeyword.
@Test
public void testMarshallKeyword() throws JAXBException, SAXException, URISyntaxException {
Keywords object = (Keywords) unmarshallFromPath("/record_2.0_rc4/samples/keywords-2.0_rc4.xml", Keywords.class);
marshall(object, "/record_2.0_rc4/keyword-2.0_rc4.xsd");
}
use of org.orcid.jaxb.model.record_rc2.Keywords in project ORCID-Source by ORCID.
the class ValidateV2RC3SamplesTest method testMarshallKeyword.
@Test
public void testMarshallKeyword() throws JAXBException, SAXException, URISyntaxException {
Keywords object = (Keywords) unmarshallFromPath("/record_2.0_rc3/samples/keywords-2.0_rc3.xml", Keywords.class);
marshall(object, "/record_2.0_rc3/keyword-2.0_rc3.xsd");
}
use of org.orcid.jaxb.model.record_rc2.Keywords in project ORCID-Source by ORCID.
the class WorkspaceController method getKeywordsFormJson.
@RequestMapping(value = "/my-orcid/keywordsForms.json", method = RequestMethod.GET)
@ResponseBody
public KeywordsForm getKeywordsFormJson(HttpServletRequest request) throws NoSuchRequestHandlingMethodException {
long lastModifiedTime = getLastModifiedTime(getCurrentUserOrcid());
Keywords keywords = profileKeywordManager.getKeywords(getCurrentUserOrcid(), lastModifiedTime);
KeywordsForm form = KeywordsForm.valueOf(keywords);
//Set the default visibility
ProfileEntity profile = profileEntityCacheManager.retrieve(getCurrentUserOrcid());
if (profile != null && profile.getActivitiesVisibilityDefault() != null) {
form.setVisibility(Visibility.valueOf(profile.getActivitiesVisibilityDefault()));
}
return form;
}
use of org.orcid.jaxb.model.record_rc2.Keywords in project ORCID-Source by ORCID.
the class WorkspaceController method setKeywordsFormJson.
@RequestMapping(value = "/my-orcid/keywordsForms.json", method = RequestMethod.POST)
@ResponseBody
public KeywordsForm setKeywordsFormJson(HttpServletRequest request, @RequestBody KeywordsForm kf) throws NoSuchRequestHandlingMethodException {
kf.setErrors(new ArrayList<String>());
ProfileEntity profile = profileEntityCacheManager.retrieve(getEffectiveUserOrcid());
Visibility defaultVisibility = Visibility.valueOf(profile.getActivitiesVisibilityDefault());
if (kf != null) {
Iterator<KeywordForm> it = kf.getKeywords().iterator();
while (it.hasNext()) {
KeywordForm k = it.next();
if (!PojoUtil.isEmpty(k.getContent())) {
if (k.getContent().length() > SiteConstants.KEYWORD_MAX_LENGTH) {
k.setContent(k.getContent().substring(0, SiteConstants.KEYWORD_MAX_LENGTH));
}
} else {
it.remove();
}
//Set default visibility in case it is null
if (k.getVisibility() == null || k.getVisibility().getVisibility() == null) {
k.setVisibility(defaultVisibility);
}
copyErrors(k, kf);
}
if (kf.getErrors().size() > 0) {
return kf;
}
Keywords updatedKeywords = kf.toKeywords();
profileKeywordManager.updateKeywords(getCurrentUserOrcid(), updatedKeywords);
}
return kf;
}
Aggregations