use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class ProfileEntityManagerImpl method claimProfileAndUpdatePreferences.
@Override
@Transactional
public boolean claimProfileAndUpdatePreferences(String orcid, String email, Locale locale, Claim claim) {
//Verify the email
boolean emailVerified = emailManager.verifySetCurrentAndPrimary(orcid, email);
if (!emailVerified) {
throw new InvalidParameterException("Unable to claim and verify email: " + email + " for user: " + orcid);
}
//Update the profile entity fields
ProfileEntity profile = profileDao.find(orcid);
profile.setLastModified(new Date());
profile.setIndexingStatus(IndexingStatus.REINDEX);
profile.setClaimed(true);
profile.setCompletedDate(new Date());
if (locale != null) {
profile.setLocale(org.orcid.jaxb.model.common_v2.Locale.fromValue(locale.value()));
}
if (claim != null) {
profile.setSendChangeNotifications(claim.getSendChangeNotifications().getValue());
profile.setSendOrcidNews(claim.getSendOrcidNews().getValue());
profile.setActivitiesVisibilityDefault(claim.getActivitiesVisibilityDefault().getVisibility());
}
//Update the visibility for every bio element to the visibility selected by the user
//Update the bio
org.orcid.jaxb.model.common_v2.Visibility defaultVisibility = org.orcid.jaxb.model.common_v2.Visibility.fromValue(claim.getActivitiesVisibilityDefault().getVisibility().value());
if (profile.getBiographyEntity() != null) {
profile.getBiographyEntity().setVisibility(defaultVisibility);
}
//Update address
if (profile.getAddresses() != null) {
for (AddressEntity a : profile.getAddresses()) {
a.setVisibility(defaultVisibility);
}
}
//Update the keywords
if (profile.getKeywords() != null) {
for (ProfileKeywordEntity k : profile.getKeywords()) {
k.setVisibility(defaultVisibility);
}
}
//Update the other names
if (profile.getOtherNames() != null) {
for (OtherNameEntity o : profile.getOtherNames()) {
o.setVisibility(defaultVisibility);
}
}
//Update the researcher urls
if (profile.getResearcherUrls() != null) {
for (ResearcherUrlEntity r : profile.getResearcherUrls()) {
r.setVisibility(defaultVisibility);
}
}
//Update the external identifiers
if (profile.getExternalIdentifiers() != null) {
for (ExternalIdentifierEntity e : profile.getExternalIdentifiers()) {
e.setVisibility(defaultVisibility);
}
}
profileDao.merge(profile);
profileDao.flush();
return true;
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class ProfileEntityManagerImpl method deactivateRecord.
@Override
@Transactional
public boolean deactivateRecord(String orcid) {
//Clear the record
ProfileEntity toClear = profileDao.find(orcid);
toClear.setLastModified(new Date());
toClear.setDeactivationDate(new Date());
toClear.setActivitiesVisibilityDefault(Visibility.PRIVATE);
toClear.setIndexingStatus(IndexingStatus.REINDEX);
// Remove works
workManager.removeAllWorks(orcid);
// Remove funding
if (toClear.getProfileFunding() != null) {
toClear.getProfileFunding().clear();
}
// Remove affiliations
if (toClear.getOrgAffiliationRelations() != null) {
toClear.getOrgAffiliationRelations().clear();
}
// Remove external identifiers
if (toClear.getExternalIdentifiers() != null) {
toClear.getExternalIdentifiers().clear();
}
// Remove researcher urls
if (toClear.getResearcherUrls() != null) {
toClear.getResearcherUrls().clear();
}
// Remove other names
if (toClear.getOtherNames() != null) {
toClear.getOtherNames().clear();
}
// Remove keywords
if (toClear.getKeywords() != null) {
toClear.getKeywords().clear();
}
// Remove address
if (toClear.getAddresses() != null) {
toClear.getAddresses().clear();
}
BiographyEntity bioEntity = toClear.getBiographyEntity();
if (bioEntity != null) {
bioEntity.setBiography("");
bioEntity.setVisibility(Visibility.PRIVATE);
}
//Set the deactivated names
RecordNameEntity recordName = toClear.getRecordNameEntity();
if (recordName != null) {
recordName.setCreditName(null);
recordName.setGivenNames("Given Names Deactivated");
recordName.setFamilyName("Family Name Deactivated");
recordName.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
}
Set<EmailEntity> emails = toClear.getEmails();
if (emails != null) {
// For each email in the deprecated profile
for (EmailEntity email : emails) {
email.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
}
}
profileDao.merge(toClear);
profileDao.flush();
//Delete all connections
userConnectionDao.deleteByOrcid(orcid);
notificationManager.sendAmendEmail(orcid, AmendedSection.UNKNOWN, null);
return true;
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class ProfileFundingManagerImpl method createFunding.
/**
* Add a new funding to the given user
* @param orcid
* The user to add the funding
* @param funding
* The funding to add
* @return the added funding
* */
@Override
@Transactional
public Funding createFunding(String orcid, Funding funding, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
activityValidator.validateFunding(funding, sourceEntity, true, isApiRequest, null);
//Check for duplicates
List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid);
List<Funding> fundings = jpaJaxbFundingAdapter.toFunding(existingFundings);
if (fundings != null && isApiRequest) {
for (Funding exstingFunding : fundings) {
activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), exstingFunding.getExternalIdentifiers(), exstingFunding.getSource(), sourceEntity);
}
}
ProfileFundingEntity profileFundingEntity = jpaJaxbFundingAdapter.toProfileFundingEntity(funding);
//Updates the give organization with the latest organization from database
OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
profileFundingEntity.setOrg(updatedOrganization);
//Set the source
if (sourceEntity.getSourceProfile() != null) {
profileFundingEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
profileFundingEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
profileFundingEntity.setProfile(profile);
setIncomingWorkPrivacy(profileFundingEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(profileFundingEntity, isApiRequest);
profileFundingDao.persist(profileFundingEntity);
profileFundingDao.flush();
if (isApiRequest) {
notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItem(profileFundingEntity));
}
return jpaJaxbFundingAdapter.toFunding(profileFundingEntity);
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class RecordNameManagerImpl method updateRecordName.
@Override
public boolean updateRecordName(String orcid, Name name) {
if (name == null) {
return false;
}
RecordNameEntity entity = jpaJaxbNameAdapter.toRecordNameEntity(name);
if (entity.getProfile() == null || PojoUtil.isEmpty(entity.getProfile().getId())) {
entity.setProfile(new ProfileEntity(orcid));
}
entity.setLastModified(new Date());
recordNameDao.updateRecordName(entity);
// Evict the name in the source name manager
sourceNameCacheManager.remove(orcid);
return true;
}
use of org.orcid.persistence.jpa.entities.ProfileEntity in project ORCID-Source by ORCID.
the class PeerReviewManagerImpl method createPeerReview.
@Override
public PeerReview createPeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// If request comes from the API, perform the validations
if (isApiRequest) {
// Validate it have at least one ext id
activityValidator.validatePeerReview(peerReview, sourceEntity, true, isApiRequest, null);
List<PeerReviewEntity> peerReviews = peerReviewDao.getByUser(orcid);
// duplicates
if (!sourceEntity.getSourceId().equals(orcid)) {
if (peerReviews != null) {
for (PeerReviewEntity entity : peerReviews) {
PeerReview existing = jpaJaxbPeerReviewAdapter.toPeerReview(entity);
activityValidator.checkExternalIdentifiersForDuplicates(peerReview.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
}
}
} else {
//check vocab of external identifiers
externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
}
validateGroupId(peerReview);
}
PeerReviewEntity entity = jpaJaxbPeerReviewAdapter.toPeerReviewEntity(peerReview);
// Updates the give organization with the latest organization from
// database
OrgEntity updatedOrganization = orgManager.getOrgEntity(peerReview);
entity.setOrg(updatedOrganization);
//Set the source
if (sourceEntity.getSourceProfile() != null) {
entity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
entity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
entity.setProfile(profile);
setIncomingPrivacy(entity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(entity, isApiRequest);
peerReviewDao.persist(entity);
peerReviewDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItem(entity));
return jpaJaxbPeerReviewAdapter.toPeerReview(entity);
}
Aggregations