use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class SelfServiceController method addContactByEmail.
@RequestMapping(value = "/add-contact-by-email.json")
@ResponseBody
public Contact addContactByEmail(@RequestBody Contact contact) {
checkFullAccess(contact.getAccountId());
EmailEntity emailEntity = emailManager.findCaseInsensitive(contact.getEmail());
contact.setOrcid(emailEntity.getProfile().getId());
RecordNameEntity recordNameEntity = emailEntity.getProfile().getRecordNameEntity();
if (Visibility.PUBLIC.equals(recordNameEntity.getVisibility())) {
contact.setFirstName(recordNameEntity.getGivenNames());
contact.setLastName(recordNameEntity.getFamilyName());
} else {
contact.setFirstName(NOT_PUBLIC);
contact.setLastName(NOT_PUBLIC);
}
salesForceManager.createContact(contact);
return contact;
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getEmailMapperFacade.
public MapperFacade getEmailMapperFacade() {
MapperFactory mapperFactory = getNewMapperFactory();
ClassMapBuilder<Email, EmailEntity> emailClassMap = mapperFactory.classMap(Email.class, EmailEntity.class);
emailClassMap.byDefault();
emailClassMap.field("email", "id");
emailClassMap.field("primary", "primary");
emailClassMap.field("verified", "verified");
addV2DateFields(emailClassMap);
registerSourceConverters(mapperFactory, emailClassMap);
emailClassMap.register();
return mapperFactory.getMapperFacade();
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class Jpa2JaxbAdapterImpl method setEmails.
private void setEmails(ProfileEntity profileEntity, ContactDetails contactDetails) {
// The new way of doing emails.
Set<EmailEntity> emailEntities = profileEntity.getEmails();
List<Email> emailList = contactDetails.getEmail();
if (emailEntities != null) {
for (EmailEntity emailEntity : emailEntities) {
Email email = new Email(emailEntity.getId());
email.setPrimary(emailEntity.getPrimary());
email.setCurrent(emailEntity.getCurrent());
email.setVerified(emailEntity.getVerified());
email.setVisibility(emailEntity.getVisibility() == null ? OrcidVisibilityDefaults.PRIMARY_EMAIL_DEFAULT.getVisibility() : org.orcid.jaxb.model.message.Visibility.fromValue(emailEntity.getVisibility().value()));
email.setSource(emailEntity.getSourceId());
if (!PojoUtil.isEmpty(emailEntity.getClientSourceId())) {
if (OrcidStringUtils.isValidOrcid(emailEntity.getClientSourceId())) {
email.setSource(emailEntity.getClientSourceId());
} else {
email.setSourceClientId(emailEntity.getClientSourceId());
}
}
emailList.add(email);
}
}
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getEmailMapperFacade.
public MapperFacade getEmailMapperFacade() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
ClassMapBuilder<Email, EmailEntity> emailClassMap = mapperFactory.classMap(Email.class, EmailEntity.class);
emailClassMap.byDefault();
emailClassMap.field("email", "id");
emailClassMap.field("primary", "primary");
emailClassMap.field("verified", "verified");
addV3DateFields(emailClassMap);
registerSourceConverters(mapperFactory, emailClassMap);
emailClassMap.register();
return mapperFactory.getMapperFacade();
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class NotificationManagerTest method testAddedDelegatesSentCorrectEmail.
@Test
public void testAddedDelegatesSentCorrectEmail() throws JAXBException, IOException, URISyntaxException {
TargetProxyHelper.injectIntoProxy(notificationManager, "profileEntityCacheManager", mockProfileEntityCacheManager);
TargetProxyHelper.injectIntoProxy(notificationManager, "emailManager", mockEmailManager);
TargetProxyHelper.injectIntoProxy(notificationManager, "profileDao", mockProfileDao);
TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
TargetProxyHelper.injectIntoProxy(notificationManager, "notificationAdapter", mockNotificationAdapter);
final String orcid = "0000-0000-0000-0003";
String delegateOrcid = "1234-5678-1234-5678";
ProfileEntity profile = new ProfileEntity();
RecordNameEntity recordName = new RecordNameEntity();
recordName.setCreditName("My credit name");
recordName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
profile.setRecordNameEntity(recordName);
profile.setSendAdministrativeChangeNotifications(true);
profile.setSendChangeNotifications(true);
profile.setSendMemberUpdateRequests(true);
profile.setSendOrcidNews(true);
EmailEntity emailEntity = new EmailEntity();
emailEntity.setId("test@email.com");
emailEntity.setPrimary(true);
emailEntity.setCurrent(true);
Set<EmailEntity> emails = new HashSet<EmailEntity>();
emails.add(emailEntity);
profile.setEmails(emails);
SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
when(mockNotificationAdapter.toNotificationEntity(Mockito.any(Notification.class))).thenReturn(new NotificationCustomEntity());
Email email = new Email();
email.setEmail("test@email.com");
Email delegateEmail = new Email();
delegateEmail.setEmail("delegate@email.com");
when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
profile.setId(invocation.getArgument(0));
return profile;
}
});
when(mockProfileDao.find(Mockito.anyString())).thenAnswer(new Answer<ProfileEntity>() {
@Override
public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
profile.setId(invocation.getArgument(0));
return profile;
}
});
when(mockEmailManager.findPrimaryEmail(orcid)).thenReturn(email);
when(mockEmailManager.findPrimaryEmail(delegateOrcid)).thenReturn(delegateEmail);
for (org.orcid.jaxb.model.common_v2.Locale locale : org.orcid.jaxb.model.common_v2.Locale.values()) {
profile.setLocale(locale);
notificationManager.sendNotificationToAddedDelegate("0000-0000-0000-0003", delegateOrcid);
}
}
Aggregations