Search in sources :

Example 6 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class MemberV2ApiServiceVersionedDelegatorTest method updateProfileSubmissionDate.

private void updateProfileSubmissionDate(String orcid, int increment) {
    // Update the submission date so it is long enough
    ProfileEntity profileEntity = profileDao.find(orcid);
    profileEntity.setSubmissionDate(DateUtils.addDays(new Date(), increment));
    profileDao.merge(profileEntity);
    profileDao.flush();
}
Also used : ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 7 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class MigrateEncryptedData method migrateProfiles.

private void migrateProfiles() {
    Date start = new Date();
    @SuppressWarnings("unchecked") List<ProfileEntity> profiles = Collections.EMPTY_LIST;
    do {
        profiles = profileDao.findLastModifiedBefore(start, CHUNK_SIZE);
        for (ProfileEntity profileEntity : profiles) {
            LOG.info("Migrating encrypted data for profile: {}", profileEntity.getId());
            fixSecurityAnswer(profileEntity);
            fixVerificationCode(profileEntity);
            profileEntity.setLastModified(new Date());
            profileDao.merge(profileEntity);
        }
    } while (!profiles.isEmpty());
}
Also used : Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 8 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class NotificationManagerImpl method createNotification.

@Override
public Notification createNotification(String orcid, Notification notification) {
    if (notification.getPutCode() != null) {
        throw new IllegalArgumentException("Put code must be null when creating a new notification");
    }
    NotificationEntity notificationEntity = notificationAdapter.toNotificationEntity(notification);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    if (profile == null) {
        throw OrcidNotFoundException.newInstance(orcid);
    }
    notificationEntity.setProfile(profile);
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    if (sourceEntity != null) {
        // Set source id
        if (sourceEntity.getSourceProfile() != null) {
            notificationEntity.setSourceId(sourceEntity.getSourceProfile().getId());
        }
        if (sourceEntity.getSourceClient() != null) {
            notificationEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
        }
    } else {
        // If we can't find source id, set the user as the source
        notificationEntity.setSourceId(orcid);
    }
    notificationDao.persist(notificationEntity);
    return notificationAdapter.toNotification(notificationEntity);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) ActionableNotificationEntity(org.orcid.persistence.jpa.entities.ActionableNotificationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 9 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity 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)

Example 10 with ProfileEntity

use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.

the class OrcidClientGroupManagerImpl method updateGroup.

/**
     * Updates an existing group profile. If the group doesnt exists it will
     * throw a OrcidClientGroupManagementException
     * 
     * @param orcidClientGroup
     *            The group to be updated
     */
@Transactional
public void updateGroup(OrcidClientGroup orcidClientGroup) {
    String groupOrcid = orcidClientGroup.getGroupOrcid();
    // If the incoming client group ORCID is not null, then lookup the
    // existing client group.
    ProfileEntity groupProfileEntity = profileDao.find(groupOrcid);
    if (groupProfileEntity == null) {
        // then raise an error.
        throw new OrcidClientGroupManagementException("Group ORCID was specified but does not yet exist: " + groupOrcid);
    } else {
        boolean updateClientScopes = false;
        // profile DAO
        if (!orcidClientGroup.getEmail().equals(groupProfileEntity.getPrimaryEmail().getId())) {
            EmailEntity primaryEmailEntity = new EmailEntity();
            primaryEmailEntity.setId(orcidClientGroup.getEmail().toLowerCase().trim());
            primaryEmailEntity.setCurrent(true);
            primaryEmailEntity.setVerified(true);
            primaryEmailEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
            groupProfileEntity.setPrimaryEmail(primaryEmailEntity);
        }
        if (groupProfileEntity.getRecordNameEntity() == null) {
            groupProfileEntity.setRecordNameEntity(new RecordNameEntity());
            groupProfileEntity.getRecordNameEntity().setProfile(groupProfileEntity);
        }
        // Set the record name entity table
        groupProfileEntity.getRecordNameEntity().setCreditName(orcidClientGroup.getGroupName());
        groupProfileEntity.getRecordNameEntity().setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
        groupProfileEntity.setSalesforeId(orcidClientGroup.getSalesforceId());
        // If group type changed
        if (!groupProfileEntity.getGroupType().equals(orcidClientGroup.getType())) {
            // Update the group type
            groupProfileEntity.setGroupType(orcidClientGroup.getType());
            // Set the flag to update the client scopes
            updateClientScopes = true;
        }
        // Merge changes
        profileDao.merge(groupProfileEntity);
        profileEntityManager.updateLastModifed(groupOrcid);
        // Update client types and scopes
        if (updateClientScopes)
            updateClientTypeDueGroupTypeUpdate(groupProfileEntity);
    }
}
Also used : OrcidClientGroupManagementException(org.orcid.core.exception.OrcidClientGroupManagementException) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)374 Date (java.util.Date)107 Test (org.junit.Test)107 HashMap (java.util.HashMap)74 Transactional (org.springframework.transaction.annotation.Transactional)74 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)71 DBUnitTest (org.orcid.test.DBUnitTest)65 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)48 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)44 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)37 HashSet (java.util.HashSet)35 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)35 Locale (java.util.Locale)34 Rollback (org.springframework.test.annotation.Rollback)27 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)26 ArrayList (java.util.ArrayList)25 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)21 Set (java.util.Set)17 Authentication (org.springframework.security.core.Authentication)17 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)16