use of org.springframework.transaction.annotation.Transactional in project ORCID-Source by ORCID.
the class NotificationManagerImpl method findPermissionsByOrcidAndClient.
@Override
@Transactional(readOnly = true)
public NotificationPermissions findPermissionsByOrcidAndClient(String orcid, String client, int firstResult, int maxResults) {
NotificationPermissions notifications = new NotificationPermissions();
List<Notification> notificationsForOrcidAndClient = notificationAdapter.toNotification(notificationDao.findPermissionsByOrcidAndClient(orcid, client, firstResult, maxResults));
List<NotificationPermission> notificationPermissions = new ArrayList<>();
notificationsForOrcidAndClient.forEach(n -> notificationPermissions.add((NotificationPermission) n));
notifications.setNotifications(notificationPermissions);
return notifications;
}
use of org.springframework.transaction.annotation.Transactional in project ORCID-Source by ORCID.
the class NotificationManagerImpl method setActionedAndReadDate.
@Override
@Transactional
public Notification setActionedAndReadDate(String orcid, Long id) {
NotificationEntity notificationEntity = notificationDao.findByOricdAndId(orcid, id);
if (notificationEntity == null) {
return null;
}
Date now = new Date();
if (notificationEntity.getActionedDate() == null) {
notificationEntity.setActionedDate(now);
notificationDao.merge(notificationEntity);
}
if (notificationEntity.getReadDate() == null) {
notificationEntity.setReadDate(now);
notificationDao.merge(notificationEntity);
}
return notificationAdapter.toNotification(notificationEntity);
}
use of org.springframework.transaction.annotation.Transactional in project ORCID-Source by ORCID.
the class NotificationManagerImpl method flagAsArchived.
@Override
@Transactional
public Notification flagAsArchived(String orcid, Long id, boolean validateForApi) throws OrcidNotificationAlreadyReadException {
NotificationEntity notificationEntity = notificationDao.findByOricdAndId(orcid, id);
if (notificationEntity == null) {
return null;
}
String sourceId = sourceManager.retrieveSourceOrcid();
if (validateForApi) {
if (sourceId != null && !sourceId.equals(notificationEntity.getElementSourceId())) {
Map<String, String> params = new HashMap<String, String>();
params.put("activity", "notification");
throw new WrongSourceException(params);
}
if (notificationEntity.getReadDate() != null) {
throw new OrcidNotificationAlreadyReadException();
}
}
if (notificationEntity.getArchivedDate() == null) {
notificationEntity.setArchivedDate(new Date());
notificationDao.merge(notificationEntity);
}
return notificationAdapter.toNotification(notificationEntity);
}
use of org.springframework.transaction.annotation.Transactional in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendApiRecordCreationEmail.
@Override
@Transactional
public void sendApiRecordCreationEmail(String toEmail, OrcidProfile createdProfile) {
Source source = null;
CustomEmailEntity customEmail = null;
if (createdProfile.getOrcidHistory() != null && createdProfile.getOrcidHistory().getSource() != null) {
if (!PojoUtil.isEmpty(createdProfile.getOrcidHistory().getSource().retrieveSourcePath())) {
source = createdProfile.getOrcidHistory().getSource();
customEmail = getCustomizedEmail(createdProfile.getOrcidHistory().getSource().retrieveSourcePath(), EmailType.CLAIM);
}
}
String email = createdProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue().trim();
String emailName = deriveEmailFriendlyName(createdProfile);
String orcid = createdProfile.getOrcidIdentifier().getPath();
String verificationUrl = createClaimVerificationUrl(email, orcidUrlManager.getBaseUrl());
String creatorName = "";
if (source != null) {
if (source.getSourceName() != null && source.getSourceName().getContent() != null) {
creatorName = source.getSourceName().getContent();
} else if (!PojoUtil.isEmpty(source.retrieveSourcePath())) {
creatorName = source.retrieveSourcePath();
}
}
String subject = null;
String body = null;
String htmlBody = null;
String sender = null;
if (customEmail != null) {
// Get the customized sender if available
sender = PojoUtil.isEmpty(customEmail.getSender()) ? CLAIM_NOTIFY_ORCID_ORG : customEmail.getSender();
// Get the customized subject is available
subject = PojoUtil.isEmpty(customEmail.getSubject()) ? getSubject("email.subject.api_record_creation", createdProfile) : customEmail.getSubject();
// Replace the wildcards
subject = subject.replace(WILDCARD_USER_NAME, emailName);
subject = subject.replace(WILDCARD_MEMBER_NAME, creatorName);
if (customEmail.isHtml()) {
htmlBody = customEmail.getContent();
htmlBody = htmlBody.replace(WILDCARD_USER_NAME, emailName);
htmlBody = htmlBody.replace(WILDCARD_MEMBER_NAME, creatorName);
htmlBody = htmlBody.replace(EmailConstants.WILDCARD_VERIFICATION_URL, verificationUrl);
if (htmlBody.contains(WILDCARD_WEBSITE) || htmlBody.contains(WILDCARD_DESCRIPTION)) {
ClientDetailsEntity clientDetails = customEmail.getClientDetailsEntity();
htmlBody = htmlBody.replace(WILDCARD_WEBSITE, clientDetails.getClientWebsite());
htmlBody = htmlBody.replace(WILDCARD_DESCRIPTION, clientDetails.getClientDescription());
}
} else {
body = customEmail.getContent();
body = body.replace(WILDCARD_USER_NAME, emailName);
body = body.replace(WILDCARD_MEMBER_NAME, creatorName);
body = body.replace(EmailConstants.WILDCARD_VERIFICATION_URL, verificationUrl);
if (body.contains(WILDCARD_WEBSITE) || body.contains(WILDCARD_DESCRIPTION)) {
ClientDetailsEntity clientDetails = customEmail.getClientDetailsEntity();
body = body.replace(WILDCARD_WEBSITE, clientDetails.getClientWebsite());
body = body.replace(WILDCARD_DESCRIPTION, clientDetails.getClientDescription());
}
}
} else {
subject = getSubject("email.subject.api_record_creation", createdProfile);
// Create map of template params
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("emailName", emailName);
templateParams.put("orcid", orcid);
templateParams.put("subject", subject);
templateParams.put("creatorName", creatorName);
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
templateParams.put("verificationUrl", verificationUrl);
addMessageParams(templateParams, createdProfile);
// Generate body from template
body = templateManager.processTemplate("api_record_creation_email.ftl", templateParams);
htmlBody = templateManager.processTemplate("api_record_creation_email_html.ftl", templateParams);
}
// Send message
if (apiRecordCreationEmailEnabled) {
boolean isCustomEmail = customEmail != null ? true : false;
// mailgun
if (isCustomEmail) {
mailGunManager.sendEmail(sender, email, subject, body, htmlBody, isCustomEmail);
} else {
mailGunManager.sendEmail(CLAIM_NOTIFY_ORCID_ORG, email, subject, body, htmlBody);
}
} else {
LOGGER.debug("Not sending API record creation email, because option is disabled. Message would have been: {}", body);
}
}
use of org.springframework.transaction.annotation.Transactional in project ORCID-Source by ORCID.
the class OrcidClientGroupManagerImpl method createOrUpdateOrcidClientGroup.
@Override
@Transactional
public OrcidClientGroup createOrUpdateOrcidClientGroup(OrcidClientGroup orcidClientGroup) {
// For each client in the client group, validate the client type
for (OrcidClient client : orcidClientGroup.getOrcidClient()) {
checkAndSetClientType(client, orcidClientGroup.getType());
}
String groupOrcid = orcidClientGroup.getGroupOrcid();
if (groupOrcid == null) {
orcidClientGroup = createGroup(orcidClientGroup);
groupOrcid = orcidClientGroup.getGroupOrcid();
} else {
updateGroup(orcidClientGroup);
}
// Use the profile DAO to link the clients to the group, so get the
// group profile entity.
ProfileEntity groupProfileEntity = profileDao.find(groupOrcid);
SortedSet<ClientDetailsEntity> clientProfileEntities = groupProfileEntity.getClients();
if (clientProfileEntities == null) {
clientProfileEntities = new TreeSet<>(new OrcidEntityIdComparator<String>());
groupProfileEntity.setClients(clientProfileEntities);
}
// For each client in the client group
for (OrcidClient client : orcidClientGroup.getOrcidClient()) {
processClient(groupOrcid, clientProfileEntities, client, getClientType(groupProfileEntity.getGroupType()));
}
// Regenerate client group and return.
return retrieveOrcidClientGroup(groupOrcid);
}
Aggregations