use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.
the class ValidateV2RC2SamplesTest method unmarshallFromPath.
private Object unmarshallFromPath(String path, Class<?> type, String schemaPath) throws SAXException, URISyntaxException {
try (Reader reader = new InputStreamReader(getClass().getResourceAsStream(path))) {
Object obj = unmarshall(reader, type, schemaPath);
Object result = null;
if (ResearcherUrls.class.equals(type)) {
result = (ResearcherUrls) obj;
} else if (ResearcherUrl.class.equals(type)) {
result = (ResearcherUrl) obj;
} else if (PersonalDetails.class.equals(type)) {
result = (PersonalDetails) obj;
} else if (PersonExternalIdentifier.class.equals(type)) {
result = (PersonExternalIdentifier) obj;
} else if (PersonExternalIdentifiers.class.equals(type)) {
result = (PersonExternalIdentifiers) obj;
} else if (Biography.class.equals(type)) {
result = (Biography) obj;
} else if (Name.class.equals(type)) {
result = (Name) obj;
} else if (CreditName.class.equals(type)) {
result = (CreditName) obj;
} else if (OtherName.class.equals(type)) {
result = (OtherName) obj;
} else if (OtherNames.class.equals(type)) {
result = (OtherNames) obj;
} else if (Keywords.class.equals(type)) {
result = (Keywords) obj;
} else if (Keyword.class.equals(type)) {
result = (Keyword) obj;
} else if (Addresses.class.equals(type)) {
result = (Addresses) obj;
} else if (Address.class.equals(type)) {
result = (Address) obj;
} else if (Emails.class.equals(type)) {
result = (Emails) obj;
} else if (Email.class.equals(type)) {
result = (Email) obj;
} else if (Person.class.equals(type)) {
result = (Person) obj;
} else if (Deprecated.class.equals(type)) {
result = (Deprecated) obj;
} else if (Preferences.class.equals(type)) {
result = (Preferences) obj;
} else if (History.class.equals(type)) {
result = (History) obj;
} else if (Record.class.equals(type)) {
result = (Record) obj;
} else if (ActivitiesSummary.class.equals(type)) {
result = (ActivitiesSummary) obj;
}
return result;
} catch (IOException e) {
throw new RuntimeException("Error reading notification from classpath", e);
}
}
use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.
the class ValidateV2RC2SamplesTest method testUnmarshallPerson.
@Test
public void testUnmarshallPerson() throws SAXException, URISyntaxException {
Person person = (Person) unmarshallFromPath("/record_2.0_rc2/samples/person-2.0_rc2.xml", Person.class, "/record_2.0_rc2/person-2.0_rc2.xsd");
assertNotNull(person);
assertNotNull(person.getName());
assertEquals("give-names", person.getName().getGivenNames().getContent());
assertEquals("family-name", person.getName().getFamilyName().getContent());
assertEquals("credit-name", person.getName().getCreditName().getContent());
assertEquals(Visibility.PUBLIC, person.getName().getVisibility());
assertNotNull(person.getOtherNames());
assertNotNull(person.getOtherNames().getOtherNames());
assertEquals(1, person.getOtherNames().getOtherNames().size());
OtherName otherName = person.getOtherNames().getOtherNames().get(0);
assertEquals("other-name-1", otherName.getContent());
assertNotNull(otherName.getCreatedDate());
assertNotNull(otherName.getCreatedDate().getValue());
assertEquals(2001, otherName.getCreatedDate().getValue().getYear());
assertEquals(12, otherName.getCreatedDate().getValue().getMonth());
assertEquals(31, otherName.getCreatedDate().getValue().getDay());
assertNotNull(otherName.getLastModifiedDate().getValue());
assertEquals(2001, otherName.getLastModifiedDate().getValue().getYear());
assertEquals(12, otherName.getLastModifiedDate().getValue().getMonth());
assertEquals(31, otherName.getLastModifiedDate().getValue().getDay());
assertNotNull(otherName.getSource());
assertEquals("8888-8888-8888-8880", otherName.getSource().retrieveSourcePath());
assertNotNull(person.getBiography());
assertEquals(Visibility.PUBLIC, person.getBiography().getVisibility());
assertEquals("biography", person.getBiography().getContent());
assertNotNull(person.getResearcherUrls());
assertNotNull(person.getResearcherUrls().getResearcherUrls());
assertEquals(1, person.getResearcherUrls().getResearcherUrls().size());
ResearcherUrl rUrl = person.getResearcherUrls().getResearcherUrls().get(0);
assertEquals(Visibility.PUBLIC, rUrl.getVisibility());
assertEquals(Long.valueOf(1248), rUrl.getPutCode());
assertEquals("url-name-1", rUrl.getUrlName());
assertNotNull(rUrl.getUrl());
assertEquals("http://url.com/", rUrl.getUrl().getValue());
assertNotNull(rUrl.getCreatedDate());
assertEquals(2001, rUrl.getCreatedDate().getValue().getYear());
assertEquals(12, rUrl.getCreatedDate().getValue().getMonth());
assertEquals(31, rUrl.getCreatedDate().getValue().getDay());
assertNotNull(rUrl.getLastModifiedDate());
assertEquals(2001, rUrl.getLastModifiedDate().getValue().getYear());
assertEquals(12, rUrl.getLastModifiedDate().getValue().getMonth());
assertEquals(31, rUrl.getLastModifiedDate().getValue().getDay());
assertNotNull(rUrl.getSource());
assertEquals("8888-8888-8888-8880", rUrl.getSource().retrieveSourcePath());
assertNotNull(person.getEmails());
assertNotNull(person.getEmails().getEmails());
assertEquals(1, person.getEmails().getEmails().size());
Email email = person.getEmails().getEmails().get(0);
assertEquals(Visibility.PUBLIC, email.getVisibility());
assertEquals("user1@email.com", email.getEmail());
assertNotNull(email.getCreatedDate());
assertNotNull(email.getCreatedDate().getValue());
assertEquals(2001, email.getCreatedDate().getValue().getYear());
assertEquals(12, email.getCreatedDate().getValue().getMonth());
assertEquals(31, email.getCreatedDate().getValue().getDay());
assertNotNull(email.getLastModifiedDate());
assertNotNull(email.getLastModifiedDate().getValue());
assertEquals(2001, email.getLastModifiedDate().getValue().getYear());
assertEquals(12, email.getLastModifiedDate().getValue().getMonth());
assertEquals(31, email.getLastModifiedDate().getValue().getDay());
assertNotNull(email.getSource());
assertEquals("8888-8888-8888-8880", email.retrieveSourcePath());
assertNotNull(person.getAddresses());
assertNotNull(person.getAddresses().getAddress());
assertEquals(1, person.getAddresses().getAddress().size());
Address address = person.getAddresses().getAddress().get(0);
assertEquals(Visibility.PUBLIC, address.getVisibility());
assertEquals(Long.valueOf(1), address.getPutCode());
assertNotNull(address.getCountry());
assertEquals(Iso3166Country.US, address.getCountry().getValue());
assertNotNull(address.getCreatedDate());
assertNotNull(address.getCreatedDate().getValue());
assertEquals(2001, address.getCreatedDate().getValue().getYear());
assertEquals(12, address.getCreatedDate().getValue().getMonth());
assertEquals(31, address.getCreatedDate().getValue().getDay());
assertNotNull(address.getLastModifiedDate());
assertNotNull(address.getLastModifiedDate().getValue());
assertEquals(2001, address.getLastModifiedDate().getValue().getYear());
assertEquals(12, address.getLastModifiedDate().getValue().getMonth());
assertEquals(31, address.getLastModifiedDate().getValue().getDay());
assertNotNull(address.getSource());
assertEquals("8888-8888-8888-8880", address.getSource().retrieveSourcePath());
assertNotNull(person.getKeywords());
assertNotNull(person.getKeywords().getKeywords());
assertEquals(1, person.getKeywords().getKeywords().size());
Keyword keyword = person.getKeywords().getKeywords().get(0);
assertEquals(Visibility.PUBLIC, keyword.getVisibility());
assertEquals(Long.valueOf(1), keyword.getPutCode());
assertEquals("keyword1", keyword.getContent());
assertNotNull(keyword.getCreatedDate());
assertNotNull(keyword.getCreatedDate().getValue());
assertEquals(2001, keyword.getCreatedDate().getValue().getYear());
assertEquals(12, keyword.getCreatedDate().getValue().getMonth());
assertEquals(31, keyword.getCreatedDate().getValue().getDay());
assertNotNull(keyword.getLastModifiedDate());
assertNotNull(keyword.getLastModifiedDate().getValue());
assertEquals(2001, keyword.getLastModifiedDate().getValue().getYear());
assertEquals(12, keyword.getLastModifiedDate().getValue().getMonth());
assertEquals(31, keyword.getLastModifiedDate().getValue().getDay());
assertNotNull(keyword.getSource());
assertEquals("8888-8888-8888-8880", keyword.getSource().retrieveSourcePath());
assertNotNull(person.getExternalIdentifiers());
assertNotNull(person.getExternalIdentifiers().getExternalIdentifiers());
assertEquals(1, person.getExternalIdentifiers().getExternalIdentifiers().size());
PersonExternalIdentifier extId = person.getExternalIdentifiers().getExternalIdentifiers().get(0);
assertEquals(Visibility.PUBLIC, extId.getVisibility());
assertEquals(Long.valueOf(1), extId.getPutCode());
assertEquals("type-1", extId.getType());
assertEquals("value-1", extId.getValue());
assertNotNull(extId.getUrl());
assertEquals("http://url.com/1", extId.getUrl().getValue());
assertNotNull(extId.getCreatedDate());
assertNotNull(extId.getCreatedDate().getValue());
assertEquals(2001, extId.getCreatedDate().getValue().getYear());
assertEquals(12, extId.getCreatedDate().getValue().getMonth());
assertEquals(31, extId.getCreatedDate().getValue().getDay());
assertNotNull(extId.getLastModifiedDate());
assertNotNull(extId.getLastModifiedDate().getValue());
assertEquals(2001, extId.getLastModifiedDate().getValue().getYear());
assertEquals(12, extId.getLastModifiedDate().getValue().getMonth());
assertEquals(31, extId.getLastModifiedDate().getValue().getDay());
assertNotNull(extId.getSource());
assertEquals("8888-8888-8888-8880", extId.getSource().retrieveSourcePath());
}
use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.
the class ValidateV2RC2SamplesTest method testUnmarshallEmails.
@Test
public void testUnmarshallEmails() throws SAXException, URISyntaxException {
Emails emails = (Emails) unmarshallFromPath("/record_2.0_rc2/samples/emails-2.0_rc2.xml", Emails.class, "/record_2.0_rc2/email-2.0_rc2.xsd");
assertNotNull(emails);
assertNotNull(emails.getEmails());
assertEquals(2, emails.getEmails().size());
for (Email email : emails.getEmails()) {
assertNotNull(email.getPutCode());
assertNotNull(email.getCreatedDate());
assertNotNull(email.getLastModifiedDate());
if (email.getPutCode().equals(Long.valueOf(1))) {
assertEquals(Visibility.PUBLIC, email.getVisibility());
assertEquals("user1@email.com", email.getEmail());
} else {
assertEquals(Visibility.PUBLIC, email.getVisibility());
assertEquals("user2@email.com", email.getEmail());
}
}
Email email = (Email) unmarshallFromPath("/record_2.0_rc2/samples/email-2.0_rc2.xml", Email.class);
assertNotNull(email);
assertNotNull(email.getPutCode());
assertNotNull(email.getCreatedDate());
assertNotNull(email.getLastModifiedDate());
assertEquals(Visibility.PUBLIC, email.getVisibility());
assertEquals("user1@email.com", email.getEmail());
}
use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.
the class ManageProfileControllerTest method initMocks.
@Before
public void initMocks() throws Exception {
controller = new ManageProfileController();
MockitoAnnotations.initMocks(this);
SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
TargetProxyHelper.injectIntoProxy(controller, "profileEntityCacheManager", mockProfileEntityCacheManager);
TargetProxyHelper.injectIntoProxy(controller, "encryptionManager", mockEncryptionManager);
TargetProxyHelper.injectIntoProxy(controller, "emailManager", mockEmailManager);
TargetProxyHelper.injectIntoProxy(controller, "localeManager", mockLocaleManager);
TargetProxyHelper.injectIntoProxy(controller, "profileEntityManager", mockProfileEntityManager);
TargetProxyHelper.injectIntoProxy(controller, "givenPermissionToManager", mockGivenPermissionToManager);
TargetProxyHelper.injectIntoProxy(controller, "orcidSecurityManager", mockOrcidSecurityManager);
when(mockOrcidSecurityManager.isPasswordConfirmationRequired()).thenReturn(true);
when(mockEncryptionManager.hashMatches(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
when(mockEncryptionManager.hashMatches(Mockito.eq("invalid password"), Mockito.anyString())).thenReturn(false);
when(mockProfileEntityManager.deprecateProfile(Mockito.anyString(), Mockito.anyString())).thenReturn(false);
when(mockProfileEntityManager.deprecateProfile(Mockito.eq(DEPRECATED_USER_ORCID), Mockito.eq(USER_ORCID))).thenReturn(true);
when(mockLocaleManager.resolveMessage(Mockito.anyString(), Mockito.any())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgument(0);
}
});
when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).then(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
ProfileEntity entity = new ProfileEntity();
entity.setId(invocation.getArgument(0));
Set<GivenPermissionToEntity> givenPermissionTo = new HashSet<GivenPermissionToEntity>();
IntStream.range(0, 2).forEachOrdered(i -> {
GivenPermissionToEntity e1 = new GivenPermissionToEntity();
e1.setId(Long.valueOf(i));
Date now = new Date();
e1.setApprovalDate(now);
e1.setDateCreated(now);
e1.setGiver(invocation.getArgument(0));
ProfileSummaryEntity ps = new ProfileSummaryEntity();
RecordNameEntity recordName = new RecordNameEntity();
recordName.setVisibility(Visibility.PUBLIC);
if (i == 0) {
ps.setId("0000-0000-0000-0004");
recordName.setCreditName("Credit Name");
} else {
ps.setId("0000-0000-0000-0005");
recordName.setFamilyName("Family Name");
recordName.setGivenNames("Given Names");
}
ps.setRecordNameEntity(recordName);
e1.setReceiver(ps);
givenPermissionTo.add(e1);
});
entity.setGivenPermissionTo(givenPermissionTo);
EmailEntity email1 = new EmailEntity();
email1.setId(invocation.getArgument(0) + "_1@test.orcid.org");
email1.setVerified(true);
email1.setCurrent(true);
email1.setDateCreated(new Date());
email1.setLastModified(new Date());
email1.setPrimary(true);
email1.setVisibility(Visibility.PUBLIC);
EmailEntity email2 = new EmailEntity();
email2.setId(invocation.getArgument(0) + "_2@test.orcid.org");
email2.setVerified(true);
email2.setCurrent(false);
email2.setDateCreated(new Date());
email2.setLastModified(new Date());
email2.setPrimary(false);
email2.setVisibility(Visibility.PUBLIC);
Set<EmailEntity> emails = new HashSet<EmailEntity>();
emails.add(email1);
emails.add(email2);
entity.setEmails(emails);
entity.setRecordNameEntity(getRecordName(invocation.getArgument(0)));
entity.setEncryptedPassword("password");
return entity;
}
});
when(mockEmailManager.getEmails(Mockito.anyString(), Mockito.anyLong())).thenAnswer(new Answer<Emails>() {
@Override
public Emails answer(InvocationOnMock invocation) throws Throwable {
Emails emails = new Emails();
Email email1 = new Email();
email1.setEmail(invocation.getArgument(0) + "_1@test.orcid.org");
email1.setVisibility(Visibility.PUBLIC);
emails.getEmails().add(email1);
Email email2 = new Email();
email2.setEmail(invocation.getArgument(0) + "_2@test.orcid.org");
email2.setVisibility(Visibility.PUBLIC);
emails.getEmails().add(email2);
return emails;
}
});
when(mockEmailManager.findCaseInsensitive(Mockito.anyString())).thenAnswer(new Answer<EmailEntity>() {
@Override
public EmailEntity answer(InvocationOnMock invocation) throws Throwable {
String emailString = invocation.getArgument(0);
String orcidString = emailString.substring(0, (emailString.indexOf("_")));
EmailEntity email = new EmailEntity();
email.setId(emailString);
email.setVisibility(Visibility.PUBLIC);
ProfileEntity entity = new ProfileEntity(orcidString);
entity.setEncryptedPassword("password");
entity.setRecordNameEntity(getRecordName(orcidString));
email.setProfile(entity);
return email;
}
});
}
use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.
the class OrcidSecurityManagerImpl method checkAndFilter.
private void checkAndFilter(String orcid, Collection<? extends VisibilityType> elements, ScopePathType requiredScope, boolean tokenAlreadyChecked) {
if (elements == null) {
return;
}
// Check the token
if (!tokenAlreadyChecked) {
isMyToken(orcid);
}
Iterator<? extends VisibilityType> it = elements.iterator();
while (it.hasNext()) {
VisibilityType element = it.next();
try {
if (element instanceof Email) {
Email email = (Email) element;
checkAndFilter(orcid, email, requiredScope, true);
} else {
checkAndFilter(orcid, element, requiredScope, true);
}
} catch (Exception e) {
it.remove();
}
}
}
Aggregations