use of org.orcid.jaxb.model.record_rc3.Biography in project ORCID-Source by ORCID.
the class ManageProfileController method setBiographyFormJson.
@RequestMapping(value = "/biographyForm.json", method = RequestMethod.POST)
@ResponseBody
public BiographyForm setBiographyFormJson(@RequestBody BiographyForm bf) {
bf.setErrors(new ArrayList<String>());
if (bf.getBiography() != null) {
validateBiography(bf.getBiography());
copyErrors(bf.getBiography(), bf);
if (bf.getErrors().size() > 0)
return bf;
Biography bio = new Biography();
if (bf.getBiography() != null) {
bio.setContent(bf.getBiography().getValue());
}
if (bf.getVisiblity() != null && bf.getVisiblity().getVisibility() != null) {
org.orcid.jaxb.model.common_v2.Visibility v = org.orcid.jaxb.model.common_v2.Visibility.fromValue(bf.getVisiblity().getVisibility().value());
bio.setVisibility(v);
}
String orcid = getCurrentUserOrcid();
if (biographyManager.exists(orcid)) {
biographyManager.updateBiography(orcid, bio);
} else {
biographyManager.createBiography(orcid, bio);
}
}
return bf;
}
use of org.orcid.jaxb.model.record_rc3.Biography in project ORCID-Source by ORCID.
the class PublicV2ApiServiceDelegatorImpl method viewBiography.
@Override
public Response viewBiography(String orcid) {
Biography bio = biographyManagerReadOnly.getBiography(orcid, getLastModifiedTime(orcid));
publicAPISecurityManagerV2.checkIsPublic(bio);
ElementUtils.setPathToBiography(bio, orcid);
return Response.ok(bio).build();
}
use of org.orcid.jaxb.model.record_rc3.Biography in project ORCID-Source by ORCID.
the class PublicProfileControllerTest method testViewValidUser.
@SuppressWarnings("unchecked")
@Test
public void testViewValidUser() {
ModelAndView mav = publicProfileController.publicPreview(request, 1, 0, 15, userOrcid);
assertEquals("public_profile_v3", mav.getViewName());
Map<String, Object> model = mav.getModel();
assertNotNull(model);
assertTrue(model.containsKey("isPublicProfile"));
assertTrue(model.containsKey("effectiveUserOrcid"));
assertEquals(userOrcid, model.get("effectiveUserOrcid"));
assertTrue(model.containsKey("biography"));
Biography biography = (Biography) model.get("biography");
assertEquals("Biography for 0000-0000-0000-0003", biography.getContent());
assertTrue(model.containsKey("displayName"));
String displayName = (String) model.get("displayName");
assertEquals("Credit Name", displayName);
assertTrue(model.containsKey("title"));
assertEquals(localeManager.resolveMessage("layout.public-layout.title", displayName, userOrcid), model.get("title"));
assertTrue(model.containsKey("publicGroupedOtherNames"));
Map<String, List<OtherName>> groupedOtherNames = (Map<String, List<OtherName>>) model.get("publicGroupedOtherNames");
assertNotNull(groupedOtherNames);
assertEquals(1, groupedOtherNames.keySet().size());
assertTrue(groupedOtherNames.containsKey("Other Name PUBLIC"));
List<OtherName> publicOtherNames = groupedOtherNames.get("Other Name PUBLIC");
assertEquals(1, publicOtherNames.size());
assertEquals(Long.valueOf(13), publicOtherNames.get(0).getPutCode());
assertEquals("Other Name PUBLIC", publicOtherNames.get(0).getContent());
assertEquals(Visibility.PUBLIC, publicOtherNames.get(0).getVisibility());
assertTrue(model.containsKey("publicGroupedAddresses"));
Map<String, List<Address>> groupedAddresses = (Map<String, List<Address>>) model.get("publicGroupedAddresses");
assertNotNull(groupedAddresses);
assertEquals(1, groupedAddresses.keySet().size());
assertTrue(groupedAddresses.containsKey("US"));
List<Address> publicAddresses = groupedAddresses.get("US");
assertEquals(1, publicAddresses.size());
assertEquals(Long.valueOf(9), publicAddresses.get(0).getPutCode());
assertEquals(Iso3166Country.US, publicAddresses.get(0).getCountry().getValue());
assertEquals(Visibility.PUBLIC, publicAddresses.get(0).getVisibility());
assertTrue(model.containsKey("countryNames"));
Map<String, String> countryNames = (Map<String, String>) model.get("countryNames");
Map<String, String> testCountry = new HashMap<String, String>();
testCountry.put("US", localeManager.resolveMessage("org.orcid.persistence.jpa.entities.CountryIsoEntity.US"));
assertEquals(testCountry, countryNames);
assertTrue(model.containsKey("publicGroupedKeywords"));
Map<String, List<Keyword>> groupedKeywords = (Map<String, List<Keyword>>) model.get("publicGroupedKeywords");
assertNotNull(groupedKeywords);
assertEquals(1, groupedKeywords.keySet().size());
assertTrue(groupedKeywords.containsKey("PUBLIC"));
List<Keyword> publicKeywords = groupedKeywords.get("PUBLIC");
assertEquals(1, publicKeywords.size());
assertEquals(Long.valueOf(9), publicKeywords.get(0).getPutCode());
assertEquals("PUBLIC", publicKeywords.get(0).getContent());
assertEquals(Visibility.PUBLIC, publicKeywords.get(0).getVisibility());
assertTrue(model.containsKey("publicGroupedResearcherUrls"));
Map<String, List<ResearcherUrl>> rUrls = (Map<String, List<ResearcherUrl>>) model.get("publicGroupedResearcherUrls");
assertNotNull(rUrls);
assertEquals(1, rUrls.keySet().size());
assertTrue(rUrls.containsKey("http://www.researcherurl.com?id=13"));
List<ResearcherUrl> publicResearchUrls = rUrls.get("http://www.researcherurl.com?id=13");
assertEquals(Long.valueOf(13), publicResearchUrls.get(0).getPutCode());
assertEquals("public_rurl", publicResearchUrls.get(0).getUrlName());
assertEquals(Visibility.PUBLIC, publicResearchUrls.get(0).getVisibility());
assertTrue(model.containsKey("publicGroupedEmails"));
Map<String, List<Email>> emails = (Map<String, List<Email>>) model.get("publicGroupedEmails");
assertNotNull(emails);
assertEquals(1, emails.keySet().size());
assertTrue(emails.containsKey("public_0000-0000-0000-0003@test.orcid.org"));
List<Email> publicEmails = emails.get("public_0000-0000-0000-0003@test.orcid.org");
assertEquals("public_0000-0000-0000-0003@test.orcid.org", publicEmails.get(0).getEmail());
assertEquals(Visibility.PUBLIC, publicEmails.get(0).getVisibility());
assertTrue(model.containsKey("publicGroupedPersonExternalIdentifiers"));
Map<String, List<PersonExternalIdentifier>> extIds = (Map<String, List<PersonExternalIdentifier>>) model.get("publicGroupedPersonExternalIdentifiers");
assertNotNull(extIds);
assertEquals(1, extIds.keySet().size());
assertTrue(extIds.containsKey("public_type:public_ref"));
List<PersonExternalIdentifier> publicExternalIdentifiers = extIds.get("public_type:public_ref");
assertEquals(Long.valueOf(13), publicExternalIdentifiers.get(0).getPutCode());
assertEquals("http://ext-id/public_ref", publicExternalIdentifiers.get(0).getUrl().getValue());
assertEquals(Visibility.PUBLIC, publicExternalIdentifiers.get(0).getVisibility());
assertTrue(model.containsKey("workIdsJson"));
assertEquals("[11]", model.get("workIdsJson"));
assertTrue(model.containsKey("affiliationIdsJson"));
assertEquals("[17,20]", model.get("affiliationIdsJson"));
assertTrue(model.containsKey("fundingIdsJson"));
assertEquals("[10]", model.get("fundingIdsJson"));
assertTrue(model.containsKey("peerReviewIdsJson"));
assertEquals("[9]", model.get("peerReviewIdsJson"));
assertTrue(model.containsKey("isProfileEmpty"));
Boolean isProfileEmpty = (Boolean) model.get("isProfileEmpty");
assertFalse(isProfileEmpty);
assertFalse(model.containsKey("noIndex"));
}
use of org.orcid.jaxb.model.record_rc3.Biography in project ORCID-Source by ORCID.
the class ManageProfileControllerTest method testValidateBiography.
@Test
public void testValidateBiography() {
BiographyManager mockBiographyManager = Mockito.mock(BiographyManager.class);
SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
TargetProxyHelper.injectIntoProxy(controller, "biographyManager", mockBiographyManager);
when(mockBiographyManager.exists(Mockito.anyString())).thenReturn(true);
BiographyForm bf = new BiographyForm();
// No NPE exception on empty bio
controller.setBiographyFormJson(bf);
assertNotNull(bf.getErrors());
assertTrue(bf.getErrors().isEmpty());
String bio = StringUtils.repeat('a', 5001);
bf.setBiography(Text.valueOf(bio));
controller.setBiographyFormJson(bf);
assertEquals(1, bf.getErrors().size());
assertEquals("Length.changePersonalInfoForm.biography", bf.getErrors().get(0));
bio = StringUtils.repeat('a', 5000);
bf.setBiography(Text.valueOf(bio));
controller.setBiographyFormJson(bf);
assertTrue(bf.getErrors().isEmpty());
Biography bioElement = new Biography();
bioElement.setContent(bio);
verify(mockBiographyManager, times(1)).updateBiography(Mockito.eq(USER_ORCID), Mockito.eq(bioElement));
}
use of org.orcid.jaxb.model.record_rc3.Biography in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_ReadPersonTest method testPerson.
private void testPerson(Person p, String orcid) {
// This is more an utility that will work only for 0000-0000-0000-0003
assertEquals("0000-0000-0000-0003", orcid);
assertNotNull(p);
assertEquals("/0000-0000-0000-0003/person", p.getPath());
Utils.verifyLastModified(p.getLastModifiedDate());
// Address
assertNotNull(p.getAddresses());
Addresses a = p.getAddresses();
assertNotNull(a);
Utils.verifyLastModified(a.getLastModifiedDate());
assertEquals(3, a.getAddress().size());
boolean found1 = false, found2 = false, found3 = false;
for (Address element : a.getAddress()) {
Utils.verifyLastModified(element.getLastModifiedDate());
if (element.getPutCode() == 9) {
found1 = true;
} else if (element.getPutCode() == 10) {
found2 = true;
} else if (element.getPutCode() == 11) {
found3 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
// Biography
assertNotNull(p.getBiography());
Biography b = p.getBiography();
assertNotNull(b);
Utils.verifyLastModified(b.getLastModifiedDate());
assertEquals("Biography for 0000-0000-0000-0003", b.getContent());
// Email
assertNotNull(p.getEmails());
Emails email = p.getEmails();
assertNotNull(email);
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(3, email.getEmails().size());
assertEquals("public_0000-0000-0000-0003@test.orcid.org", email.getEmails().get(0).getEmail());
found1 = false;
found2 = false;
found3 = false;
for (Email element : email.getEmails()) {
if (element.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) {
found1 = true;
} else if (element.getEmail().equals("limited_0000-0000-0000-0003@test.orcid.org")) {
found2 = true;
} else if (element.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) {
found3 = true;
} else {
fail("Invalid email " + element.getEmail());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
// External identifiers
assertNotNull(p.getExternalIdentifiers());
PersonExternalIdentifiers extIds = p.getExternalIdentifiers();
assertNotNull(extIds);
Utils.verifyLastModified(extIds.getLastModifiedDate());
assertEquals(3, extIds.getExternalIdentifiers().size());
found1 = false;
found2 = false;
found3 = false;
for (PersonExternalIdentifier element : extIds.getExternalIdentifiers()) {
Utils.verifyLastModified(element.getLastModifiedDate());
if (element.getPutCode() == 13) {
found1 = true;
} else if (element.getPutCode() == 14) {
found2 = true;
} else if (element.getPutCode() == 15) {
found3 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
// Keywords
assertNotNull(p.getKeywords());
Keywords k = p.getKeywords();
assertNotNull(k);
Utils.verifyLastModified(k.getLastModifiedDate());
assertEquals(3, k.getKeywords().size());
found1 = false;
found2 = false;
found3 = false;
for (Keyword element : k.getKeywords()) {
Utils.verifyLastModified(element.getLastModifiedDate());
if (element.getPutCode() == 9) {
found1 = true;
} else if (element.getPutCode() == 10) {
found2 = true;
} else if (element.getPutCode() == 11) {
found3 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
// Name
assertNotNull(p.getName());
assertEquals("Credit Name", p.getName().getCreditName().getContent());
assertEquals("Given Names", p.getName().getGivenNames().getContent());
assertEquals("Family Name", p.getName().getFamilyName().getContent());
// Other names
assertNotNull(p.getOtherNames());
OtherNames o = p.getOtherNames();
assertNotNull(o);
Utils.verifyLastModified(o.getLastModifiedDate());
assertEquals(3, o.getOtherNames().size());
found1 = false;
found2 = false;
found3 = false;
for (OtherName element : o.getOtherNames()) {
Utils.verifyLastModified(element.getLastModifiedDate());
if (element.getPutCode() == 13) {
found1 = true;
} else if (element.getPutCode() == 14) {
found2 = true;
} else if (element.getPutCode() == 15) {
found3 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
// Researcher urls
assertNotNull(p.getResearcherUrls());
ResearcherUrls ru = p.getResearcherUrls();
assertNotNull(ru);
Utils.verifyLastModified(ru.getLastModifiedDate());
assertEquals(3, ru.getResearcherUrls().size());
found1 = false;
found2 = false;
found3 = false;
for (ResearcherUrl element : ru.getResearcherUrls()) {
Utils.verifyLastModified(element.getLastModifiedDate());
if (element.getPutCode() == 13) {
found1 = true;
} else if (element.getPutCode() == 14) {
found2 = true;
} else if (element.getPutCode() == 15) {
found3 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertNotNull(p.getPath());
}
Aggregations