use of org.orcid.persistence.jpa.entities.OtherNameEntity in project ORCID-Source by ORCID.
the class Jpa2JaxbAdapterImpl method getOtherNames.
private OtherNames getOtherNames(ProfileEntity profile) {
OtherNames otherNames = new OtherNames();
Visibility mostRestrictive = Visibility.PUBLIC;
Set<OtherNameEntity> otherNamesEntitiy = profile.getOtherNames();
if (otherNamesEntitiy != null && otherNamesEntitiy.size() > 0) {
for (OtherNameEntity otherNameEntity : otherNamesEntitiy) {
//will only be null if there's an issue with the data or you're using this layer directly
Visibility vis = (otherNameEntity.getVisibility() != null) ? Visibility.fromValue(otherNameEntity.getVisibility().value()) : Visibility.PRIVATE;
if (vis.isMoreRestrictiveThan(mostRestrictive))
mostRestrictive = vis;
OtherName otherName = new OtherName(otherNameEntity.getDisplayName(), vis);
if (!PojoUtil.isEmpty(otherNameEntity.getElementSourceId())) {
Source source = getSource(otherNameEntity);
otherName.setSource(source);
}
otherNames.getOtherName().add(otherName);
}
}
otherNames.setVisibility(mostRestrictive);
return otherNames;
}
use of org.orcid.persistence.jpa.entities.OtherNameEntity 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.OtherNameEntity 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.OtherNameEntity in project ORCID-Source by ORCID.
the class OtherNameManagerImpl method updateOtherName.
@Override
@Transactional
public OtherName updateOtherName(String orcid, Long putCode, OtherName otherName, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
OtherNameEntity updatedOtherNameEntity = otherNameDao.getOtherName(orcid, putCode);
Visibility originalVisibility = Visibility.fromValue(updatedOtherNameEntity.getVisibility().value());
//Save the original source
String existingSourceId = updatedOtherNameEntity.getSourceId();
String existingClientSourceId = updatedOtherNameEntity.getClientSourceId();
// Validate the other name
PersonValidator.validateOtherName(otherName, sourceEntity, false, isApiRequest, originalVisibility);
// Validate it is not duplicated
List<OtherNameEntity> existingOtherNames = otherNameDao.getOtherNames(orcid, getLastModified(orcid));
for (OtherNameEntity existing : existingOtherNames) {
if (isDuplicated(existing, otherName, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "otherName");
params.put("value", otherName.getContent());
throw new OrcidDuplicatedElementException(params);
}
}
orcidSecurityManager.checkSource(updatedOtherNameEntity);
jpaJaxbOtherNameAdapter.toOtherNameEntity(otherName, updatedOtherNameEntity);
updatedOtherNameEntity.setLastModified(new Date());
//Be sure it doesn't overwrite the source
updatedOtherNameEntity.setSourceId(existingSourceId);
updatedOtherNameEntity.setClientSourceId(existingClientSourceId);
otherNameDao.merge(updatedOtherNameEntity);
return jpaJaxbOtherNameAdapter.toOtherName(updatedOtherNameEntity);
}
use of org.orcid.persistence.jpa.entities.OtherNameEntity in project ORCID-Source by ORCID.
the class JpaJaxbOtherNameAdapterTest method fromOtherNameEntityToOtherNameTest.
@Test
public void fromOtherNameEntityToOtherNameTest() {
OtherNameEntity entity = getOtherNameEntity();
OtherName otherName = adapter.toOtherName(entity);
assertNotNull(otherName);
assertEquals("display-name", otherName.getContent());
assertNotNull(otherName.getCreatedDate());
assertNotNull(otherName.getLastModifiedDate());
assertEquals(Long.valueOf(1), otherName.getPutCode());
assertNotNull(otherName.getSource());
assertEquals("APP-000000001", otherName.getSource().retrieveSourcePath());
assertEquals(Visibility.PUBLIC, otherName.getVisibility());
}
Aggregations