use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.
the class RecordNameDaoTest method testfindByCreditName.
@Test
public void testfindByCreditName() {
RecordNameEntity recordName = recordNameDao.findByCreditName("P. Sellers III");
assertNotNull(recordName);
assertEquals("P. Sellers III", recordName.getCreditName());
assertEquals("Peter", recordName.getGivenNames());
assertEquals("Sellers", recordName.getFamilyName());
assertEquals(Visibility.LIMITED, recordName.getVisibility());
}
use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.
the class RegistrationManagerImpl method createMinimalProfile.
/**
* Creates a minimal record
*
* @param orcidProfile
* The record to create
* @return the new record
*/
private String createMinimalProfile(Registration registration, boolean usedCaptcha, Locale locale, String ip) {
Date now = new Date();
String orcid = orcidGenerationManager.createNewOrcid();
ProfileEntity newRecord = new ProfileEntity();
newRecord.setId(orcid);
try {
newRecord.setHashedOrcid(encryptionManager.sha256Hash(orcid));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
newRecord.setOrcidType(OrcidType.USER);
newRecord.setDateCreated(now);
newRecord.setLastModified(now);
newRecord.setSubmissionDate(now);
newRecord.setClaimed(true);
newRecord.setEnableDeveloperTools(false);
newRecord.setRecordLocked(false);
newRecord.setReviewed(false);
newRecord.setEnableNotifications(DefaultPreferences.NOTIFICATIONS_ENABLED);
newRecord.setUsedRecaptchaOnRegistration(usedCaptcha);
newRecord.setUserLastIp(ip);
if (PojoUtil.isEmpty(registration.getSendEmailFrequencyDays())) {
newRecord.setSendEmailFrequencyDays(Float.valueOf(DefaultPreferences.SEND_EMAIL_FREQUENCY_DAYS));
} else {
newRecord.setSendEmailFrequencyDays(Float.valueOf(registration.getSendEmailFrequencyDays().getValue()));
}
if (registration.getSendMemberUpdateRequests() == null) {
newRecord.setSendMemberUpdateRequests(DefaultPreferences.SEND_MEMBER_UPDATE_REQUESTS);
} else {
newRecord.setSendMemberUpdateRequests(registration.getSendMemberUpdateRequests().getValue());
}
newRecord.setCreationMethod(PojoUtil.isEmpty(registration.getCreationType()) ? CreationMethod.DIRECT.value() : registration.getCreationType().getValue());
newRecord.setSendChangeNotifications(registration.getSendChangeNotifications().getValue());
newRecord.setSendOrcidNews(registration.getSendOrcidNews().getValue());
newRecord.setLocale(locale == null ? org.orcid.jaxb.model.common_v2.Locale.EN : org.orcid.jaxb.model.common_v2.Locale.fromValue(locale.toString()));
// Visibility defaults
newRecord.setActivitiesVisibilityDefault(Visibility.fromValue(registration.getActivitiesVisibilityDefault().getVisibility().value()));
// Encrypt the password
newRecord.setEncryptedPassword(encryptionManager.hashForInternalUse(registration.getPassword().getValue()));
// Set the email
EmailEntity emailEntity = new EmailEntity();
emailEntity.setId(registration.getEmail().getValue().trim());
emailEntity.setProfile(newRecord);
emailEntity.setPrimary(true);
emailEntity.setCurrent(true);
emailEntity.setVerified(false);
// Email is private by default
emailEntity.setVisibility(Visibility.PRIVATE);
emailEntity.setSourceId(orcid);
Set<EmailEntity> emails = new HashSet<>();
emails.add(emailEntity);
newRecord.setEmails(emails);
// Set the name
RecordNameEntity recordNameEntity = new RecordNameEntity();
recordNameEntity.setDateCreated(now);
recordNameEntity.setLastModified(now);
recordNameEntity.setProfile(newRecord);
// Name is public by default
recordNameEntity.setVisibility(Visibility.PUBLIC);
if (!PojoUtil.isEmpty(registration.getFamilyNames())) {
recordNameEntity.setFamilyName(registration.getFamilyNames().getValue().trim());
}
if (!PojoUtil.isEmpty(registration.getGivenNames())) {
recordNameEntity.setGivenNames(registration.getGivenNames().getValue().trim());
}
newRecord.setRecordNameEntity(recordNameEntity);
// Set authority
OrcidGrantedAuthority authority = new OrcidGrantedAuthority();
authority.setProfileEntity(newRecord);
authority.setAuthority(OrcidWebRole.ROLE_USER.getAuthority());
Set<OrcidGrantedAuthority> authorities = new HashSet<OrcidGrantedAuthority>(1);
authorities.add(authority);
newRecord.setAuthorities(authorities);
profileDao.persist(newRecord);
profileDao.flush();
return newRecord.getId();
}
use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.
the class RecordNameManagerImpl method createRecordName.
@Override
public void createRecordName(String orcid, Name name) {
if (name == null) {
return;
}
if (recordNameDao.exists(orcid)) {
throw new IllegalArgumentException("The name for " + orcid + " already exists");
}
RecordNameEntity entity = jpaJaxbNameAdapter.toRecordNameEntity(name);
if (entity.getProfile() == null || PojoUtil.isEmpty(entity.getProfile().getId())) {
entity.setProfile(new ProfileEntity(orcid));
}
Date now = new Date();
entity.setDateCreated(now);
entity.setLastModified(now);
recordNameDao.createRecordName(entity);
}
use of org.orcid.persistence.jpa.entities.RecordNameEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setPersonalDetails.
private void setPersonalDetails(ProfileEntity profileEntity, PersonalDetails personalDetails) {
if (personalDetails != null) {
if (profileEntity.getRecordNameEntity() == null) {
profileEntity.setRecordNameEntity(new RecordNameEntity());
}
profileEntity.getRecordNameEntity().setProfile(profileEntity);
setCreditNameDetails(profileEntity, personalDetails.getCreditName());
setFamilyName(profileEntity, personalDetails.getFamilyName());
setGivenNames(profileEntity, personalDetails.getGivenNames());
setOtherNames(profileEntity, personalDetails.getOtherNames());
}
}
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(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());
}
Aggregations