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();
}
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());
}
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);
}
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);
}
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);
}
}
Aggregations