use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class SourceManagerImpl method retrieveSourceEntity.
@Override
public SourceEntity retrieveSourceEntity() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
return null;
}
// API
if (OAuth2Authentication.class.isAssignableFrom(authentication.getClass())) {
OAuth2Request authorizationRequest = ((OAuth2Authentication) authentication).getOAuth2Request();
String clientId = authorizationRequest.getClientId();
ClientDetailsEntity clientDetails = clientDetailsManager.findByClientId(clientId);
SourceEntity sourceEntity = new SourceEntity();
sourceEntity.setSourceClient(new ClientDetailsEntity(clientId, clientDetails.getClientName()));
sourceEntity.getSourceName();
return sourceEntity;
}
String userOrcid = retrieveEffectiveOrcid(authentication);
if (userOrcid == null) {
// Must be system role
return null;
}
// Normal web user
SourceEntity sourceEntity = new SourceEntity();
sourceEntity.setSourceProfile(new ProfileEntity(userOrcid));
return sourceEntity;
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class NotificationManagerTest method testAmendEmail.
@Test
public void testAmendEmail() throws JAXBException, IOException, URISyntaxException {
SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
String testOrcid = "0000-0000-0000-0003";
for (Locale locale : Locale.values()) {
NotificationEntity previousNotification = notificationDao.findLatestByOrcid(testOrcid);
long minNotificationId = previousNotification != null ? previousNotification.getId() : -1;
OrcidProfile orcidProfile = getProfile(locale);
notificationManager.sendAmendEmail(orcidProfile, AmendedSection.UNKNOWN);
// New notification entity should have been created
NotificationEntity latestNotification = notificationDao.findLatestByOrcid(testOrcid);
assertNotNull(latestNotification);
assertTrue(latestNotification.getId() > minNotificationId);
assertEquals(NotificationType.AMENDED, latestNotification.getNotificationType());
}
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class IdentifierTypeManagerTest method before.
@Before
public void before() throws Exception {
TargetProxyHelper.injectIntoProxy(idTypeMan, "sourceManager", sourceManager);
TargetProxyHelper.injectIntoProxy(idTypeMan, "securityManager", securityManager);
doNothing().when(securityManager).checkSource(Matchers.any(IdentifierTypeEntity.class));
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
}
use of org.orcid.persistence.jpa.entities.SourceEntity 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(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");
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);
DelegationDetails firstNewDelegate = new DelegationDetails();
DelegateSummary firstNewDelegateSummary = new DelegateSummary();
firstNewDelegateSummary.setCreditName(new CreditName("Jimmy Dove"));
firstNewDelegate.setDelegateSummary(firstNewDelegateSummary);
firstNewDelegateSummary.setOrcidIdentifier(new OrcidIdentifier(delegateOrcid));
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", firstNewDelegate);
}
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendWelcomeEmail.
@Override
public void sendWelcomeEmail(String userOrcid, String email) {
ProfileEntity profileEntity = profileEntityCacheManager.retrieve(userOrcid);
Locale userLocale = getUserLocaleFromProfileEntity(profileEntity);
Map<String, Object> templateParams = new HashMap<String, Object>();
String subject = getSubject("email.subject.register.thanks", userLocale);
String emailName = deriveEmailFriendlyName(profileEntity);
String verificationUrl = createVerificationUrl(email, orcidUrlManager.getBaseUrl());
String orcidId = userOrcid;
String baseUri = orcidUrlManager.getBaseUrl();
String baseUriHttp = orcidUrlManager.getBaseUriHttp();
templateParams.put("subject", subject);
templateParams.put("emailName", emailName);
templateParams.put("verificationUrl", verificationUrl);
templateParams.put("orcidId", orcidId);
templateParams.put("baseUri", baseUri);
templateParams.put("baseUriHttp", baseUriHttp);
SourceEntity source = sourceManager.retrieveSourceEntity();
if (source != null) {
String sourceId = source.getSourceId();
String sourceName = source.getSourceName();
// If the source is not the user itself
if (sourceId != null && !sourceId.equals(orcidId)) {
if (!PojoUtil.isEmpty(sourceName)) {
String paramValue = " " + localeManager.resolveMessage("common.through") + " " + sourceName + ".";
templateParams.put("source_name_if_exists", paramValue);
} else {
templateParams.put("source_name_if_exists", ".");
}
} else {
templateParams.put("source_name_if_exists", ".");
}
} else {
templateParams.put("source_name_if_exists", ".");
}
addMessageParams(templateParams, userLocale);
// Generate body from template
String body = templateManager.processTemplate("welcome_email.ftl", templateParams);
// Generate html from template
String html = templateManager.processTemplate("welcome_email_html.ftl", templateParams);
mailGunManager.sendEmail(SUPPORT_VERIFY_ORCID_ORG, email, subject, body, html);
}
Aggregations