Search in sources :

Example 1 with SubjectEntity

use of org.orcid.persistence.jpa.entities.SubjectEntity 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());
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) SubjectEntity(org.orcid.persistence.jpa.entities.SubjectEntity) TreeSet(java.util.TreeSet) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) HashSet(java.util.HashSet) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SubjectEntity

use of org.orcid.persistence.jpa.entities.SubjectEntity in project ORCID-Source by ORCID.

the class SubjectManagerImpl method retrieveSubjectAsMap.

@Override
public Map<String, String> retrieveSubjectAsMap() {
    Map<String, String> map = new TreeMap<String, String>();
    for (SubjectEntity subject : subjectDao.getAll()) {
        String name = subject.getName();
        map.put(name, name);
    }
    return map;
}
Also used : SubjectEntity(org.orcid.persistence.jpa.entities.SubjectEntity) TreeMap(java.util.TreeMap)

Example 3 with SubjectEntity

use of org.orcid.persistence.jpa.entities.SubjectEntity in project ORCID-Source by ORCID.

the class OrcidProfileManagerImplTest method before.

@Before
@Transactional
@Rollback
public void before() throws Exception {
    OrcidProfileManagerImpl orcidProfileManagerImpl = getTargetObject(orcidProfileManager, OrcidProfileManagerImpl.class);
    orcidProfileManagerImpl.setNotificationManager(notificationManager);
    if (profileDao.find(TEST_ORCID) != null) {
        profileDao.remove(TEST_ORCID);
    }
    subjectDao.merge(new SubjectEntity("Computer Science"));
    subjectDao.merge(new SubjectEntity("Dance"));
    OrcidProfile delegateProfile = new OrcidProfile();
    delegateProfile.setOrcidIdentifier(DELEGATE_ORCID);
    OrcidBio delegateBio = new OrcidBio();
    delegateProfile.setOrcidBio(delegateBio);
    PersonalDetails delegatePersonalDetails = new PersonalDetails();
    delegateBio.setPersonalDetails(delegatePersonalDetails);
    CreditName delegateCreditName = new CreditName("H. Shearer");
    delegateCreditName.setVisibility(Visibility.PUBLIC);
    delegatePersonalDetails.setCreditName(delegateCreditName);
    orcidProfileManager.createOrcidProfile(delegateProfile, false, false);
    OrcidProfile applicationProfile = new OrcidProfile();
    applicationProfile.setOrcidIdentifier(APPLICATION_ORCID);
    OrcidBio applicationBio = new OrcidBio();
    applicationProfile.setOrcidBio(applicationBio);
    PersonalDetails applicationPersonalDetails = new PersonalDetails();
    applicationBio.setPersonalDetails(applicationPersonalDetails);
    applicationPersonalDetails.setCreditName(new CreditName("Brown University"));
    orcidProfileManager.createOrcidProfile(applicationProfile, false, false);
    ClientDetailsEntity clientDetails = new ClientDetailsEntity();
    clientDetails.setId(applicationProfile.getOrcidIdentifier().getPath());
    ProfileEntity applicationProfileEntity = profileDao.find(applicationProfile.getOrcidIdentifier().getPath());
    profileDao.refresh(applicationProfileEntity);
    clientDetails.setGroupProfileId(applicationProfileEntity.getId());
    clientDetailsManager.merge(clientDetails);
    ClientDetailsEntity clientDetails2 = new ClientDetailsEntity();
    clientDetails2.setId(APPLICATION_ORCID_2);
    clientDetails.setGroupProfileId(applicationProfileEntity.getId());
    clientDetailsManager.merge(clientDetails2);
    OrcidOauth2TokenDetail token = new OrcidOauth2TokenDetail();
    token.setTokenValue("1234");
    token.setClientDetailsId(clientDetails.getId());
    token.setProfile(profileDao.find(delegateProfile.getOrcidIdentifier().getPath()));
    token.setScope(StringUtils.join(new String[] { ScopePathType.ORCID_BIO_READ_LIMITED.value(), ScopePathType.ORCID_BIO_UPDATE.value() }, " "));
    SortedSet<OrcidOauth2TokenDetail> tokens = new TreeSet<>();
    tokens.add(token);
    ProfileEntity delegateProfileEntity = profileDao.find(delegateProfile.getOrcidIdentifier().getPath());
    delegateProfileEntity.setTokenDetails(tokens);
    profileDao.merge(delegateProfileEntity);
    SecurityQuestionEntity existingSecurityQuestionEntity = securityQuestionDao.find(3);
    if (existingSecurityQuestionEntity == null) {
        SecurityQuestionEntity securityQuestionEntity = new SecurityQuestionEntity();
        securityQuestionEntity.setId(3);
        securityQuestionEntity.setQuestion("What?");
        securityQuestionDao.persist(securityQuestionEntity);
    }
    orcidProfileManager.setCompareWorksUsingScopusWay(true);
    MockitoAnnotations.initMocks(this);
    TargetProxyHelper.injectIntoProxy(jaxb2JpaAdapter, "sourceManager", mockSourceManager);
    TargetProxyHelper.injectIntoProxy(orcidProfileManager, "sourceManager", mockSourceManager);
    SourceEntity sourceEntity = new SourceEntity();
    sourceEntity.setSourceClient(clientDetails);
    when(mockSourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
    SourceEntity sourceEntity2 = new SourceEntity();
    sourceEntity2.setSourceClient(clientDetails2);
    when(anotherMockSourceManager.retrieveSourceEntity()).thenReturn(sourceEntity2);
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) SubjectEntity(org.orcid.persistence.jpa.entities.SubjectEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) CreditName(org.orcid.jaxb.model.message.CreditName) PersonalDetails(org.orcid.jaxb.model.message.PersonalDetails) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) SecurityQuestionEntity(org.orcid.persistence.jpa.entities.SecurityQuestionEntity) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidProfileManagerImpl(org.orcid.core.manager.impl.OrcidProfileManagerImpl) TreeSet(java.util.TreeSet) OrcidOauth2TokenDetail(org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail) Before(org.junit.Before) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SubjectEntity (org.orcid.persistence.jpa.entities.SubjectEntity)3 TreeSet (java.util.TreeSet)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 Rollback (org.springframework.test.annotation.Rollback)2 Transactional (org.springframework.transaction.annotation.Transactional)2 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 Before (org.junit.Before)1 Test (org.junit.Test)1 OrcidProfileManagerImpl (org.orcid.core.manager.impl.OrcidProfileManagerImpl)1 CreditName (org.orcid.jaxb.model.message.CreditName)1 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)1 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)1 PersonalDetails (org.orcid.jaxb.model.message.PersonalDetails)1 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)1 OrcidOauth2TokenDetail (org.orcid.persistence.jpa.entities.OrcidOauth2TokenDetail)1 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)1 SecurityQuestionEntity (org.orcid.persistence.jpa.entities.SecurityQuestionEntity)1 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)1 DBUnitTest (org.orcid.test.DBUnitTest)1