use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.
the class JpaJaxbNameAdapterTest method fromOtherNameEntityToOtherNameTest.
@Test
public void fromOtherNameEntityToOtherNameTest() {
RecordNameEntity entity = new RecordNameEntity();
entity.setCreditName("Credit Name");
entity.setFamilyName("Family Name");
entity.setGivenNames("Given Names");
entity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
entity.setProfile(new ProfileEntity("0000-0000-0000-0000"));
Name name = adapter.toName(entity);
assertNotNull(name);
assertEquals("Credit Name", name.getCreditName().getContent());
assertEquals("Family Name", name.getFamilyName().getContent());
assertEquals("Given Names", name.getGivenNames().getContent());
assertEquals("0000-0000-0000-0000", name.getPath());
assertEquals(Visibility.PUBLIC, name.getVisibility());
}
use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.
the class MembersManagerImpl method createMember.
@Override
public Member createMember(Member member) throws IllegalArgumentException {
if (emailManager.emailExists(member.getEmail().getValue())) {
throw new IllegalArgumentException("Email already exists");
}
Date now = new Date();
String orcid = orcidGenerationManager.createNewOrcid();
ProfileEntity newRecord = new ProfileEntity();
newRecord.setId(orcid);
newRecord.setOrcidType(org.orcid.jaxb.model.common_v2.OrcidType.GROUP);
try {
newRecord.setHashedOrcid(encryptionManager.sha256Hash(orcid));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
newRecord.setActivitiesVisibilityDefault(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
newRecord.setClaimed(true);
newRecord.setCreationMethod(CreationMethod.DIRECT.value());
newRecord.setDateCreated(now);
newRecord.setEnableDeveloperTools(false);
newRecord.setEnableNotifications(DefaultPreferences.NOTIFICATIONS_ENABLED);
newRecord.setEncryptedPassword(null);
newRecord.setGroupType(MemberType.fromValue(member.getType().getValue()));
newRecord.setLastModified(now);
newRecord.setLocale(org.orcid.jaxb.model.common_v2.Locale.EN);
newRecord.setRecordLocked(false);
newRecord.setReviewed(false);
newRecord.setSalesforeId(PojoUtil.isEmpty(member.getSalesforceId()) ? null : member.getSalesforceId().getValue());
newRecord.setSendChangeNotifications(false);
newRecord.setSendEmailFrequencyDays(Float.valueOf(DefaultPreferences.SEND_EMAIL_FREQUENCY_DAYS));
newRecord.setSendMemberUpdateRequests(DefaultPreferences.SEND_MEMBER_UPDATE_REQUESTS);
newRecord.setSendOrcidNews(false);
newRecord.setSubmissionDate(now);
newRecord.setUsedRecaptchaOnRegistration(false);
// Set primary email
EmailEntity emailEntity = new EmailEntity();
emailEntity.setId(member.getEmail().getValue());
emailEntity.setProfile(newRecord);
emailEntity.setPrimary(true);
emailEntity.setCurrent(true);
emailEntity.setVerified(true);
// Email is private by default
emailEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
String sourceId = sourceEntity.getSourceProfile().getId();
emailEntity.setSourceId(sourceId);
Set<EmailEntity> emails = new HashSet<>();
emails.add(emailEntity);
// Add all emails to record
newRecord.setEmails(emails);
// Set the name
RecordNameEntity recordNameEntity = new RecordNameEntity();
recordNameEntity.setDateCreated(now);
recordNameEntity.setLastModified(now);
recordNameEntity.setProfile(newRecord);
recordNameEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
recordNameEntity.setCreditName(member.getGroupName().getValue());
newRecord.setRecordNameEntity(recordNameEntity);
// Set authority
OrcidGrantedAuthority authority = new OrcidGrantedAuthority();
authority.setProfileEntity(newRecord);
authority.setAuthority(OrcidWebRole.ROLE_GROUP.getAuthority());
Set<OrcidGrantedAuthority> authorities = new HashSet<OrcidGrantedAuthority>(1);
authorities.add(authority);
newRecord.setAuthorities(authorities);
profileDao.persist(newRecord);
profileDao.flush();
member.setGroupOrcid(Text.valueOf(orcid));
return member;
}
use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.
the class ProfileEntityManagerImpl method getMemberDisplayName.
private String getMemberDisplayName(ProfileEntity member) {
RecordNameEntity recordName = member.getRecordNameEntity();
if (recordName == null) {
return StringUtils.EMPTY;
}
// If it is a member, return the credit name
if (OrcidType.GROUP.equals(member.getOrcidType())) {
return recordName.getCreditName();
}
Visibility namesVisibilty = Visibility.fromValue(recordName.getVisibility().value());
if (Visibility.PUBLIC.equals(namesVisibilty)) {
if (!PojoUtil.isEmpty(recordName.getCreditName())) {
return recordName.getCreditName();
} else {
String displayName = recordName.getGivenNames();
String familyName = recordName.getFamilyName();
if (StringUtils.isNotBlank(familyName)) {
displayName += " " + familyName;
}
return displayName;
}
}
return StringUtils.EMPTY;
}
use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.
the class ProfileEntityManagerImpl method retrivePublicDisplayName.
@Override
public String retrivePublicDisplayName(String orcid) {
String publicName = "";
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
if (profile != null) {
RecordNameEntity recordName = profile.getRecordNameEntity();
if (recordName != null) {
Visibility namesVisibility = (recordName.getVisibility() != null) ? Visibility.fromValue(recordName.getVisibility().value()) : Visibility.fromValue(OrcidVisibilityDefaults.NAMES_DEFAULT.getVisibility().value());
if (Visibility.PUBLIC.equals(namesVisibility)) {
if (!PojoUtil.isEmpty(recordName.getCreditName())) {
publicName = recordName.getCreditName();
} else {
publicName = PojoUtil.isEmpty(recordName.getGivenNames()) ? "" : recordName.getGivenNames();
publicName += PojoUtil.isEmpty(recordName.getFamilyName()) ? "" : " " + recordName.getFamilyName();
}
}
}
}
return publicName;
}
use of org.orcid.persistence.jpa.entities.RecordNameEntity 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;
}
Aggregations