use of org.orcid.jaxb.model.v3.dev1.record.Emails in project ORCID-Source by ORCID.
the class Api3_0_Dev1LastModifiedDatesHelper method calculateLastModified.
public static void calculateLastModified(Emails emails) {
if (emails != null && emails.getEmails() != null && !emails.getEmails().isEmpty()) {
LastModifiedDate latest = null;
for (Email email : emails.getEmails()) {
if (email.getLastModifiedDate() != null && email.getLastModifiedDate().after(latest)) {
latest = email.getLastModifiedDate();
}
}
emails.setLastModifiedDate(latest);
}
}
use of org.orcid.jaxb.model.v3.dev1.record.Emails in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ReadPersonTest method testViewPerson.
@Test
public void testViewPerson() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.PERSON_READ_LIMITED);
Response response = serviceDelegator.viewPerson(ORCID);
assertNotNull(response);
assertEquals(Person.class.getName(), response.getEntity().getClass().getName());
Person p = (Person) response.getEntity();
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(4, a.getAddress().size());
boolean found1 = false, found2 = false, found3 = false, found4 = 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 if (element.getPutCode() == 12) {
found4 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
// 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(4, email.getEmails().size());
found1 = false;
found2 = false;
found3 = false;
found4 = 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 if (element.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) {
found4 = true;
} else {
fail("Invalid email " + element.getEmail());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
// External identifiers
assertNotNull(p.getExternalIdentifiers());
PersonExternalIdentifiers extIds = p.getExternalIdentifiers();
assertNotNull(extIds);
Utils.verifyLastModified(extIds.getLastModifiedDate());
assertEquals(4, extIds.getExternalIdentifiers().size());
found1 = false;
found2 = false;
found3 = false;
found4 = 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 if (element.getPutCode() == 16) {
found4 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
// Keywords
assertNotNull(p.getKeywords());
Keywords k = p.getKeywords();
assertNotNull(k);
Utils.verifyLastModified(k.getLastModifiedDate());
assertEquals(4, k.getKeywords().size());
found1 = false;
found2 = false;
found3 = false;
found4 = 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 if (element.getPutCode() == 12) {
found4 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
// 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(4, o.getOtherNames().size());
found1 = false;
found2 = false;
found3 = false;
found4 = 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 if (element.getPutCode() == 16) {
found4 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
// Researcher urls
assertNotNull(p.getResearcherUrls());
ResearcherUrls ru = p.getResearcherUrls();
assertNotNull(ru);
Utils.verifyLastModified(ru.getLastModifiedDate());
assertEquals(4, ru.getResearcherUrls().size());
found1 = false;
found2 = false;
found3 = false;
found4 = 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 if (element.getPutCode() == 16) {
found4 = true;
} else {
fail("Invalid put code " + element.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
assertNotNull(p.getPath());
}
use of org.orcid.jaxb.model.v3.dev1.record.Emails in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_ReadRecordTest method testReadPrivateEmails_OtherThingsJustPublic_Record.
@Test
public void testReadPrivateEmails_OtherThingsJustPublic_Record() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, "APP-5555555555555556", ScopePathType.EMAIL_READ_PRIVATE);
Response response = serviceDelegator.viewRecord(ORCID);
assertNotNull(response);
assertEquals(Record.class.getName(), response.getEntity().getClass().getName());
Record r = (Record) response.getEntity();
assertNotNull(r);
assertEquals("/0000-0000-0000-0003", r.getPath());
Utils.assertIsPublicOrSource(r.getActivitiesSummary(), "APP-5555555555555556");
Person p = r.getPerson();
// Check email
// Email
assertNotNull(p.getEmails());
Emails email = p.getEmails();
assertNotNull(email);
Utils.verifyLastModified(email.getLastModifiedDate());
assertEquals(5, email.getEmails().size());
boolean found1 = false, found2 = false, found3 = false, found4 = false, found5 = 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 if (element.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) {
found4 = true;
} else if (element.getEmail().equals("self_private_0000-0000-0000-0003@test.orcid.org")) {
found5 = true;
} else {
fail("Invalid email " + element.getEmail());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
assertTrue(found4);
assertTrue(found5);
this.assertAllPublicButEmails(p);
}
use of org.orcid.jaxb.model.v3.dev1.record.Emails in project ORCID-Source by ORCID.
the class EmailManagerImpl method updateEmails.
@Override
@Transactional
public void updateEmails(HttpServletRequest request, String orcid, Emails emails) {
Email currentPrimaryEmail = findPrimaryEmail(orcid);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
boolean primaryFound = false;
Email newPrimaryEmail = null;
if (emails != null && !emails.getEmails().isEmpty()) {
for (Email email : emails.getEmails()) {
emailDao.updateEmail(orcid, email.getEmail(), email.isCurrent(), org.orcid.jaxb.model.common_v2.Visibility.fromValue(email.getVisibility().value()));
if (email.isPrimary()) {
if (primaryFound) {
throw new IllegalArgumentException("More than one primary email specified");
} else {
primaryFound = true;
newPrimaryEmail = email;
}
emailDao.updatePrimary(orcid, email.getEmail());
}
}
}
if (!StringUtils.equals(currentPrimaryEmail.getEmail(), newPrimaryEmail.getEmail())) {
notificationManager.sendEmailAddressChangedNotification(orcid, newPrimaryEmail.getEmail(), currentPrimaryEmail.getEmail());
if (!newPrimaryEmail.isVerified()) {
notificationManager.sendVerificationEmail(orcid, newPrimaryEmail.getEmail());
request.getSession().setAttribute(EmailConstants.CHECK_EMAIL_VALIDATED, false);
}
}
}
});
}
use of org.orcid.jaxb.model.v3.dev1.record.Emails in project ORCID-Source by ORCID.
the class EmailManagerReadOnlyImpl method toEmails.
private Emails toEmails(List<EmailEntity> entities) {
List<org.orcid.jaxb.model.v3.dev1.record.Email> emailList = jpaJaxbEmailAdapter.toEmailList(entities);
Emails emails = new Emails();
emails.setEmails(emailList);
return emails;
}
Aggregations