use of org.orcid.persistence.jpa.entities.ProfileKeywordEntity in project ORCID-Source by ORCID.
the class SetUpClientsAndUsers method clearRegistry.
private boolean clearRegistry(OrcidProfile existingProfile, Map<String, String> params) {
if (existingProfile != null) {
String orcid = params.get(ORCID);
String email = params.get(EMAIL);
// exception
if (existingProfile.getOrcidBio() == null || existingProfile.getOrcidBio().getContactDetails() == null || existingProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail() == null || !email.equals(existingProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue())) {
throw new ApplicationException("User with email " + params.get(EMAIL) + " must have orcid id '" + orcid + "' but it is '" + existingProfile.getOrcidId() + "'");
}
// Check if the profile have the same password, if not, update the
// password
String encryptedPassword = encryptionManager.hashForInternalUse(params.get(PASSWORD));
if (!encryptedPassword.equals(existingProfile.getPassword())) {
existingProfile.setPassword(params.get(PASSWORD));
orcidProfileManager.updatePasswordInformation(existingProfile);
}
// Set default names
Name name = new Name();
name.setCreditName(new CreditName(params.get(CREDIT_NAME)));
name.setGivenNames(new GivenNames(params.get(GIVEN_NAMES)));
name.setFamilyName(new FamilyName(params.get(FAMILY_NAMES)));
name.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility().value()));
if (recordNameManager.exists(orcid)) {
recordNameManager.updateRecordName(orcid, name);
} else {
recordNameManager.createRecordName(orcid, name);
}
profileDao.updatePreferences(orcid, true, true, true, true, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC, true, 1f);
// Set default bio
org.orcid.jaxb.model.record_v2.Biography bio = biographyManager.getBiography(orcid, 0L);
if (bio == null || bio.getContent() == null) {
bio = new org.orcid.jaxb.model.record_v2.Biography(params.get(BIO));
bio.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.BIOGRAPHY_DEFAULT.getVisibility().value()));
biographyManager.createBiography(orcid, bio);
} else {
bio.setContent(params.get(BIO));
bio.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(OrcidVisibilityDefaults.BIOGRAPHY_DEFAULT.getVisibility().value()));
biographyManager.updateBiography(orcid, bio);
}
// Remove other names
List<OtherNameEntity> otherNames = otherNameDao.getOtherNames(orcid, 0L);
if (otherNames != null && !otherNames.isEmpty()) {
for (OtherNameEntity otherName : otherNames) {
otherNameDao.deleteOtherName(otherName);
}
}
// Remove keywords
List<ProfileKeywordEntity> keywords = profileKeywordDao.getProfileKeywors(orcid, 0L);
if (keywords != null && !keywords.isEmpty()) {
for (ProfileKeywordEntity keyword : keywords) {
profileKeywordDao.deleteProfileKeyword(keyword);
}
}
//Remove researcher urls
List<ResearcherUrlEntity> rUrls = researcherUrlDao.getResearcherUrls(orcid, 0L);
if (rUrls != null && !rUrls.isEmpty()) {
for (ResearcherUrlEntity rUrl : rUrls) {
researcherUrlDao.deleteResearcherUrl(orcid, rUrl.getId());
}
}
// Remove external ids
List<ExternalIdentifierEntity> extIds = externalIdentifierDao.getExternalIdentifiers(orcid, System.currentTimeMillis());
if (extIds != null && !extIds.isEmpty()) {
for (ExternalIdentifierEntity extId : extIds) {
externalIdentifierDao.removeExternalIdentifier(orcid, extId.getId());
}
}
// Remove addresses
List<AddressEntity> addresses = addressDao.getAddresses(orcid, 0L);
if (addresses != null && !addresses.isEmpty()) {
for (AddressEntity address : addresses) {
addressDao.deleteAddress(orcid, address.getId());
}
}
// Remove emails
List<EmailEntity> emails = emailDao.findByOrcid(orcid);
if (emails != null && !emails.isEmpty()) {
for (EmailEntity rc2Email : emails) {
if (!params.get(EMAIL).equals(rc2Email.getId())) {
emailDao.removeEmail(orcid, rc2Email.getId());
}
}
}
// Remove notifications
List<NotificationEntity> notifications = notificationDao.findByOrcid(orcid, true, 0, 10000);
if (notifications != null && !notifications.isEmpty()) {
for (NotificationEntity notification : notifications) {
notificationDao.deleteNotificationItemByNotificationId(notification.getId());
notificationDao.deleteNotificationWorkByNotificationId(notification.getId());
notificationDao.deleteNotificationById(notification.getId());
}
}
// Remove works
List<MinimizedWorkEntity> works = workDao.findWorks(orcid, 0L);
if (works != null && !works.isEmpty()) {
for (MinimizedWorkEntity work : works) {
workDao.removeWork(orcid, work.getId());
}
}
// Remove affiliations
List<OrgAffiliationRelationEntity> affiliations = orgAffiliationRelationDao.getByUser(orcid);
if (affiliations != null && !affiliations.isEmpty()) {
for (OrgAffiliationRelationEntity affiliation : affiliations) {
orgAffiliationRelationDao.remove(affiliation.getId());
}
}
// Remove fundings
List<ProfileFundingEntity> fundings = profileFundingDao.getByUser(orcid);
if (fundings != null && !fundings.isEmpty()) {
for (ProfileFundingEntity funding : fundings) {
profileFundingDao.removeProfileFunding(orcid, funding.getId());
}
}
// Remove peer reviews
List<PeerReviewEntity> peerReviews = peerReviewDao.getByUser(orcid);
if (peerReviews != null && !peerReviews.isEmpty()) {
for (PeerReviewEntity peerReview : peerReviews) {
peerReviewDao.removePeerReview(orcid, peerReview.getId());
}
}
// Remove 3d party links
List<OrcidOauth2TokenDetail> tokenDetails = orcidOauth2TokenDetailDao.findByUserName(orcid);
if (tokenDetails != null && !tokenDetails.isEmpty()) {
for (OrcidOauth2TokenDetail token : tokenDetails) {
orcidOauth2TokenDetailDao.remove(token.getId());
}
}
//Unlock just in case it is locked
profileDao.unlockProfile(orcid);
return true;
}
return false;
}
use of org.orcid.persistence.jpa.entities.ProfileKeywordEntity in project ORCID-Source by ORCID.
the class ProfileDaoTest method testInsertWithSubjectsAndKeywords.
@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testInsertWithSubjectsAndKeywords() {
String newOrcid = "4444-1111-6666-4444";
ProfileEntity profile = new ProfileEntity();
profile.setId(newOrcid);
Set<SubjectEntity> subjects = new HashSet<SubjectEntity>(2);
// profile.setSubjects(subjects);
subjects.add(new SubjectEntity("Rhymin"));
subjects.add(new SubjectEntity("Stealin"));
SortedSet<ProfileKeywordEntity> keywords = new TreeSet<ProfileKeywordEntity>();
profile.setKeywords(keywords);
ProfileKeywordEntity entity = new ProfileKeywordEntity();
entity.setProfile(profile);
entity.setKeywordName("Bilocation");
keywords.add(entity);
entity = new ProfileKeywordEntity();
entity.setProfile(profile);
entity.setKeywordName("Humour");
keywords.add(entity);
entity = new ProfileKeywordEntity();
entity.setProfile(profile);
entity.setKeywordName("Ceramics");
keywords.add(entity);
profileDao.persist(profile);
profileDao.flush();
profile = profileDao.find(newOrcid);
assertNotNull(profile);
assertEquals(newOrcid, profile.getId());
// assertEquals(2, profile.getSubjects().size());
assertEquals(3, profile.getKeywords().size());
}
use of org.orcid.persistence.jpa.entities.ProfileKeywordEntity in project ORCID-Source by ORCID.
the class ProfileKeywordManagerImpl method updateKeywords.
@Override
@Transactional
public Keywords updateKeywords(String orcid, Keywords keywords) {
List<ProfileKeywordEntity> existingKeywordsList = profileKeywordDao.getProfileKeywors(orcid, getLastModified(orcid));
// Delete the deleted ones
for (ProfileKeywordEntity existing : existingKeywordsList) {
boolean deleteMe = true;
if (keywords.getKeywords() != null) {
for (Keyword updatedOrNew : keywords.getKeywords()) {
if (existing.getId().equals(updatedOrNew.getPutCode())) {
deleteMe = false;
break;
}
}
}
if (deleteMe) {
try {
profileKeywordDao.deleteProfileKeyword(existing);
} catch (Exception e) {
throw new ApplicationException("Unable to delete keyword " + existing.getId(), e);
}
}
}
if (keywords != null && keywords.getKeywords() != null) {
for (Keyword updatedOrNew : keywords.getKeywords()) {
if (updatedOrNew.getPutCode() != null) {
// Update the existing ones
for (ProfileKeywordEntity existingKeyword : existingKeywordsList) {
if (existingKeyword.getId().equals(updatedOrNew.getPutCode())) {
existingKeyword.setLastModified(new Date());
existingKeyword.setVisibility(updatedOrNew.getVisibility());
existingKeyword.setKeywordName(updatedOrNew.getContent());
existingKeyword.setDisplayIndex(updatedOrNew.getDisplayIndex());
profileKeywordDao.merge(existingKeyword);
}
}
} else {
// Add the new ones
ProfileKeywordEntity newKeyword = adapter.toProfileKeywordEntity(updatedOrNew);
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileEntity profile = new ProfileEntity(orcid);
newKeyword.setProfile(profile);
newKeyword.setDateCreated(new Date());
//Set the source
if (sourceEntity.getSourceProfile() != null) {
newKeyword.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
newKeyword.setClientSourceId(sourceEntity.getSourceClient().getId());
}
newKeyword.setVisibility(updatedOrNew.getVisibility());
newKeyword.setDisplayIndex(updatedOrNew.getDisplayIndex());
profileKeywordDao.persist(newKeyword);
}
}
}
return keywords;
}
use of org.orcid.persistence.jpa.entities.ProfileKeywordEntity in project ORCID-Source by ORCID.
the class ProfileKeywordManagerImpl method updateKeyword.
@Override
@Transactional
public Keyword updateKeyword(String orcid, Long putCode, Keyword keyword, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
ProfileKeywordEntity updatedEntity = profileKeywordDao.getProfileKeyword(orcid, putCode);
Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
//Save the original source
String existingSourceId = updatedEntity.getSourceId();
String existingClientSourceId = updatedEntity.getClientSourceId();
// Validate the keyword
PersonValidator.validateKeyword(keyword, sourceEntity, false, isApiRequest, originalVisibility);
// Validate it is not duplicated
List<ProfileKeywordEntity> existingKeywords = profileKeywordDao.getProfileKeywors(orcid, getLastModified(orcid));
for (ProfileKeywordEntity existing : existingKeywords) {
if (isDuplicated(existing, keyword, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "keyword");
params.put("value", keyword.getContent());
throw new OrcidDuplicatedElementException(params);
}
}
orcidSecurityManager.checkSource(updatedEntity);
adapter.toProfileKeywordEntity(keyword, updatedEntity);
updatedEntity.setLastModified(new Date());
//Be sure it doesn't overwrite the source
updatedEntity.setSourceId(existingSourceId);
updatedEntity.setClientSourceId(existingClientSourceId);
profileKeywordDao.merge(updatedEntity);
return adapter.toKeyword(updatedEntity);
}
use of org.orcid.persistence.jpa.entities.ProfileKeywordEntity in project ORCID-Source by ORCID.
the class ProfileKeywordManagerImpl method createKeyword.
@Override
public Keyword createKeyword(String orcid, Keyword keyword, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// Validate the keyword
PersonValidator.validateKeyword(keyword, sourceEntity, true, isApiRequest, null);
// Validate it is not duplicated
List<ProfileKeywordEntity> existingKeywords = profileKeywordDao.getProfileKeywors(orcid, getLastModified(orcid));
for (ProfileKeywordEntity existing : existingKeywords) {
if (isDuplicated(existing, keyword, sourceEntity)) {
Map<String, String> params = new HashMap<String, String>();
params.put("type", "keyword");
params.put("value", keyword.getContent());
throw new OrcidDuplicatedElementException(params);
}
}
ProfileKeywordEntity newEntity = adapter.toProfileKeywordEntity(keyword);
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
newEntity.setProfile(profile);
newEntity.setDateCreated(new Date());
//Set the source
if (sourceEntity.getSourceProfile() != null) {
newEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
newEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
setIncomingPrivacy(newEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest);
profileKeywordDao.persist(newEntity);
return adapter.toKeyword(newEntity);
}
Aggregations