Search in sources :

Example 51 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(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());
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) CreditName(org.orcid.jaxb.model.v3.dev1.common.CreditName) FamilyName(org.orcid.jaxb.model.v3.dev1.record.FamilyName) Name(org.orcid.jaxb.model.v3.dev1.record.Name) Test(org.junit.Test)

Example 52 with RecordNameEntity

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

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;
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility)

Example 54 with RecordNameEntity

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;
}
Also used : RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 55 with RecordNameEntity

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

Aggregations

RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)66 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)35 Test (org.junit.Test)26 DBUnitTest (org.orcid.test.DBUnitTest)13 Date (java.util.Date)11 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)10 HashSet (java.util.HashSet)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Before (org.junit.Before)4 Name (org.orcid.jaxb.model.v3.dev1.record.Name)4 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 Query (javax.persistence.Query)3 TypedQuery (javax.persistence.TypedQuery)3 Locale (org.orcid.jaxb.model.common_v2.Locale)3 Visibility (org.orcid.jaxb.model.common_v2.Visibility)3 Email (org.orcid.jaxb.model.record_v2.Email)3 Name (org.orcid.jaxb.model.record_v2.Name)3 Email (org.orcid.jaxb.model.v3.dev1.record.Email)3