use of org.orcid.persistence.jpa.entities.EmailEntity 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);
}
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class EmailManagerReadOnlyImpl method getEmails.
private Emails getEmails(String orcid, Visibility visibility) {
List<EmailEntity> entities = new ArrayList<EmailEntity>();
if (visibility == null) {
entities = emailDao.findByOrcid(orcid);
} else {
entities = emailDao.findByOrcid(orcid, Visibility.PUBLIC);
}
List<org.orcid.jaxb.model.record_v2.Email> emailList = jpaJaxbEmailAdapter.toEmailList(entities);
Emails emails = new Emails();
emails.setEmails(emailList);
return emails;
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setEmails.
private void setEmails(ProfileEntity profileEntity, ContactDetails contactDetails) {
Set<EmailEntity> existingEmailEntities = profileEntity.getEmails();
Map<String, EmailEntity> existingEmailEntitiesMap = createEmailEntitiesMap(existingEmailEntities);
Set<EmailEntity> emailEntities = null;
if (existingEmailEntities == null) {
emailEntities = new HashSet<>();
} else {
// To allow for orphan deletion
existingEmailEntities.clear();
emailEntities = existingEmailEntities;
}
for (Email email : contactDetails.getEmail()) {
String emailId = email.getValue().trim();
EmailEntity emailEntity = null;
EmailEntity existingEmailEntity = existingEmailEntitiesMap.get(emailId);
if (existingEmailEntity == null) {
emailEntity = new EmailEntity();
emailEntity.setId(emailId);
emailEntity.setProfile(profileEntity);
emailEntity.setSourceId(email.getSource());
emailEntity.setClientSourceId(email.getSourceClientId());
} else {
existingEmailEntity.clean();
emailEntity = existingEmailEntity;
}
emailEntity.setPrimary(email.isPrimary());
emailEntity.setCurrent(email.isCurrent());
emailEntity.setVerified(email.isVerified());
if (email.getVisibility() == null) {
emailEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
} else {
emailEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(email.getVisibility().value()));
}
emailEntities.add(emailEntity);
}
profileEntity.setEmails(emailEntities);
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class Jpa2JaxbAdapterImpl method getOrcidHistory.
private OrcidHistory getOrcidHistory(ProfileEntity profileEntity) {
OrcidHistory history = new OrcidHistory();
if (profileEntity.getCompletedDate() != null) {
history.setCompletionDate(new CompletionDate(toXMLGregorianCalendar(profileEntity.getCompletedDate())));
}
Boolean confirmed = profileEntity.getClaimed() != null ? profileEntity.getClaimed() : Boolean.FALSE;
history.setClaimed(new Claimed(confirmed));
String creationMethod = profileEntity.getCreationMethod();
history.setCreationMethod(CreationMethod.isValid(creationMethod) ? CreationMethod.fromValue(creationMethod) : CreationMethod.WEBSITE);
history.setSource(getSponsor(profileEntity));
if (profileEntity.getSubmissionDate() != null) {
history.setSubmissionDate(new SubmissionDate(toXMLGregorianCalendar(profileEntity.getSubmissionDate())));
}
if (profileEntity.getDeactivationDate() != null) {
history.setDeactivationDate(new DeactivationDate(toXMLGregorianCalendar(profileEntity.getDeactivationDate())));
}
if (profileEntity.getLastModified() != null) {
history.setLastModifiedDate(new LastModifiedDate(toXMLGregorianCalendar(profileEntity.getLastModified())));
}
boolean verfiedEmail = false;
boolean verfiedPrimaryEmail = false;
if (profileEntity.getEmails() != null) {
for (EmailEntity emailEntity : profileEntity.getEmails()) {
if (emailEntity != null && emailEntity.getVerified()) {
verfiedEmail = true;
if (emailEntity.getPrimary()) {
verfiedPrimaryEmail = true;
break;
}
}
}
}
history.setVerifiedEmail(new VerifiedEmail(verfiedEmail));
history.setVerifiedPrimaryEmail(new VerifiedPrimaryEmail(verfiedPrimaryEmail));
return history;
}
use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.
the class ProfileEntityManagerImpl method deprecateProfile.
/**
* Deprecates a profile
*
* @param deprecatedProfile
* The profile that want to be deprecated
* @param primaryProfile
* The primary profile for the deprecated profile
* @return true if the account was successfully deprecated, false otherwise
*/
@Override
@Transactional
public boolean deprecateProfile(String deprecatedOrcid, String primaryOrcid) {
boolean wasDeprecated = profileDao.deprecateProfile(deprecatedOrcid, primaryOrcid);
// If it was successfully deprecated
if (wasDeprecated) {
LOGGER.info("Account {} was deprecated to primary account: {}", deprecatedOrcid, primaryOrcid);
ProfileEntity deprecated = profileDao.find(deprecatedOrcid);
// Remove works
workManager.removeAllWorks(deprecatedOrcid);
// Remove funding
if (deprecated.getProfileFunding() != null) {
for (ProfileFundingEntity funding : deprecated.getProfileFunding()) {
fundingManager.removeProfileFunding(funding.getProfile().getId(), funding.getId());
}
}
// Remove affiliations
if (deprecated.getOrgAffiliationRelations() != null) {
for (OrgAffiliationRelationEntity affiliation : deprecated.getOrgAffiliationRelations()) {
orgAffiliationRelationDao.removeOrgAffiliationRelation(affiliation.getProfile().getId(), affiliation.getId());
}
}
// Remove external identifiers
if (deprecated.getExternalIdentifiers() != null) {
for (ExternalIdentifierEntity externalIdentifier : deprecated.getExternalIdentifiers()) {
externalIdentifierManager.deleteExternalIdentifier(deprecated.getId(), externalIdentifier.getId(), false);
}
}
// Remove researcher urls
if (deprecated.getResearcherUrls() != null) {
for (ResearcherUrlEntity rUrl : deprecated.getResearcherUrls()) {
researcherUrlManager.deleteResearcherUrl(deprecatedOrcid, rUrl.getId(), false);
}
}
// Remove other names
if (deprecated.getOtherNames() != null) {
for (OtherNameEntity otherName : deprecated.getOtherNames()) {
otherNamesManager.deleteOtherName(deprecatedOrcid, otherName.getId(), false);
}
}
// Remove keywords
if (deprecated.getKeywords() != null) {
for (ProfileKeywordEntity keyword : deprecated.getKeywords()) {
profileKeywordManager.deleteKeyword(deprecatedOrcid, keyword.getId(), false);
}
}
//Remove biography
if (biographyManager.exists(deprecatedOrcid)) {
Biography deprecatedBio = new Biography();
deprecatedBio.setContent(null);
deprecatedBio.setVisibility(Visibility.PRIVATE);
biographyManager.updateBiography(deprecatedOrcid, deprecatedBio);
}
//Set the deactivated names
if (recordNameManager.exists(deprecatedOrcid)) {
Name name = new Name();
name.setCreditName(new CreditName());
name.setGivenNames(new GivenNames("Given Names Deactivated"));
name.setFamilyName(new FamilyName("Family Name Deactivated"));
name.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
name.setPath(deprecatedOrcid);
recordNameManager.updateRecordName(deprecatedOrcid, name);
}
userConnectionDao.deleteByOrcid(deprecatedOrcid);
// Move all emails to the primary email
Set<EmailEntity> deprecatedAccountEmails = deprecated.getEmails();
if (deprecatedAccountEmails != null) {
// For each email in the deprecated profile
for (EmailEntity email : deprecatedAccountEmails) {
// Delete each email from the deprecated
// profile
LOGGER.info("About to move email {} from profile {} to profile {}", new Object[] { email.getId(), deprecatedOrcid, primaryOrcid });
emailManager.moveEmailToOtherAccount(email.getId(), deprecatedOrcid, primaryOrcid);
}
}
return true;
}
return false;
}
Aggregations