Search in sources :

Example 96 with Transactional

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;
}
Also used : NotificationPermissions(org.orcid.jaxb.model.notification.permission_v2.NotificationPermissions) ArrayList(java.util.ArrayList) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Notification(org.orcid.jaxb.model.notification_v2.Notification) Transactional(org.springframework.transaction.annotation.Transactional)

Example 97 with Transactional

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);
}
Also used : NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) ActionableNotificationEntity(org.orcid.persistence.jpa.entities.ActionableNotificationEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 98 with Transactional

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);
}
Also used : WrongSourceException(org.orcid.core.exception.WrongSourceException) OrcidNotificationAlreadyReadException(org.orcid.core.exception.OrcidNotificationAlreadyReadException) HashMap(java.util.HashMap) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) ActionableNotificationEntity(org.orcid.persistence.jpa.entities.ActionableNotificationEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 99 with Transactional

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);
    }
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) HashMap(java.util.HashMap) CustomEmailEntity(org.orcid.persistence.jpa.entities.CustomEmailEntity) Source(org.orcid.jaxb.model.message.Source) MessageSource(org.springframework.context.MessageSource) Transactional(org.springframework.transaction.annotation.Transactional)

Example 100 with Transactional

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);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidEntityIdComparator(org.orcid.persistence.jpa.entities.OrcidEntityIdComparator) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Transactional (org.springframework.transaction.annotation.Transactional)976 Test (org.junit.Test)323 Query (javax.persistence.Query)160 Date (java.util.Date)108 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)89 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)84 TypedQuery (javax.persistence.TypedQuery)81 Rollback (org.springframework.test.annotation.Rollback)81 OnmsNode (org.opennms.netmgt.model.OnmsNode)76 ArrayList (java.util.ArrayList)70 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)58 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)58 DBUnitTest (org.orcid.test.DBUnitTest)57 HashMap (java.util.HashMap)54 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)39 NoResultException (javax.persistence.NoResultException)36 SystemMessage (com.netsteadfast.greenstep.base.model.SystemMessage)34 DefaultResult (com.netsteadfast.greenstep.base.model.DefaultResult)32 HashSet (java.util.HashSet)32 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)30