Search in sources :

Example 36 with RecordNameEntity

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());
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 37 with RecordNameEntity

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();
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) OrcidGrantedAuthority(org.orcid.persistence.jpa.entities.OrcidGrantedAuthority) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Date(java.util.Date) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) HashSet(java.util.HashSet)

Example 38 with RecordNameEntity

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);
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 39 with RecordNameEntity

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());
    }
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity)

Example 40 with RecordNameEntity

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());
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) CreditName(org.orcid.jaxb.model.common_v2.CreditName) Name(org.orcid.jaxb.model.record_v2.Name) Test(org.junit.Test)

Aggregations

RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)42 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)20 Test (org.junit.Test)15 DBUnitTest (org.orcid.test.DBUnitTest)8 Date (java.util.Date)7 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)6 HashSet (java.util.HashSet)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 Visibility (org.orcid.jaxb.model.common_v2.Visibility)4 Email (org.orcid.jaxb.model.record_v2.Email)4 Before (org.junit.Before)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Name (org.orcid.jaxb.model.record_v2.Name)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 List (java.util.List)2 Query (javax.persistence.Query)2 TypedQuery (javax.persistence.TypedQuery)2 CreditName (org.orcid.jaxb.model.common_v2.CreditName)2 FamilyName (org.orcid.jaxb.model.record_v2.FamilyName)2 Transactional (org.springframework.transaction.annotation.Transactional)2