use of org.orcid.persistence.jpa.entities.ProfileKeywordEntity 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;
}
use of org.orcid.persistence.jpa.entities.ProfileKeywordEntity 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.ProfileKeywordEntity in project ORCID-Source by ORCID.
the class ProfileKeywordDaoImpl method getProfileKeyword.
@Override
public ProfileKeywordEntity getProfileKeyword(String orcid, Long putCode) {
Query query = entityManager.createQuery("FROM ProfileKeywordEntity WHERE profile.id=:orcid and id=:id");
query.setParameter("orcid", orcid);
query.setParameter("id", putCode);
return (ProfileKeywordEntity) query.getSingleResult();
}
use of org.orcid.persistence.jpa.entities.ProfileKeywordEntity in project ORCID-Source by ORCID.
the class JpaJaxbKeywordAdapterTest method getProfileKeywordEntity.
private ProfileKeywordEntity getProfileKeywordEntity() {
ProfileKeywordEntity entity = new ProfileKeywordEntity();
entity.setDateCreated(new Date());
entity.setLastModified(new Date());
entity.setId(Long.valueOf(1));
entity.setKeywordName("keyword-1");
entity.setProfile(new ProfileEntity("0000-0000-0000-0000"));
entity.setClientSourceId("APP-000000000000");
entity.setVisibility(Visibility.LIMITED);
return entity;
}
use of org.orcid.persistence.jpa.entities.ProfileKeywordEntity in project ORCID-Source by ORCID.
the class JpaJaxbKeywordAdapterTest method fromProfileKeywordEntityToKeywordTest.
@Test
public void fromProfileKeywordEntityToKeywordTest() {
ProfileKeywordEntity entity = getProfileKeywordEntity();
Keyword keyword = adapter.toKeyword(entity);
assertNotNull(keyword);
assertEquals("keyword-1", keyword.getContent());
assertNotNull(keyword.getCreatedDate());
assertNotNull(keyword.getCreatedDate().getValue());
assertNotNull(keyword.getLastModifiedDate());
assertNotNull(keyword.getLastModifiedDate().getValue());
assertEquals(Long.valueOf(1), keyword.getPutCode());
assertNotNull(keyword.getSource());
assertEquals("APP-000000000000", keyword.getSource().retrieveSourcePath());
assertEquals(Visibility.LIMITED, keyword.getVisibility());
}
Aggregations