Search in sources :

Example 86 with SourceEntity

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

the class ProfileKeywordManagerImpl method updateKeyword.

@Override
@Transactional
public Keyword updateKeyword(String orcid, Long putCode, Keyword keyword, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ProfileKeywordEntity updatedEntity = profileKeywordDao.getProfileKeyword(orcid, putCode);
    Visibility originalVisibility = Visibility.fromValue(updatedEntity.getVisibility().value());
    //Save the original source
    String existingSourceId = updatedEntity.getSourceId();
    String existingClientSourceId = updatedEntity.getClientSourceId();
    // Validate the keyword
    PersonValidator.validateKeyword(keyword, sourceEntity, false, isApiRequest, originalVisibility);
    // Validate it is not duplicated
    List<ProfileKeywordEntity> existingKeywords = profileKeywordDao.getProfileKeywors(orcid, getLastModified(orcid));
    for (ProfileKeywordEntity existing : existingKeywords) {
        if (isDuplicated(existing, keyword, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "keyword");
            params.put("value", keyword.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    orcidSecurityManager.checkSource(updatedEntity);
    adapter.toProfileKeywordEntity(keyword, updatedEntity);
    updatedEntity.setLastModified(new Date());
    //Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    profileKeywordDao.merge(updatedEntity);
    return adapter.toKeyword(updatedEntity);
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Date(java.util.Date) Transactional(javax.transaction.Transactional)

Example 87 with SourceEntity

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

the class ProfileKeywordManagerImpl method createKeyword.

@Override
public Keyword createKeyword(String orcid, Keyword keyword, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Validate the keyword
    PersonValidator.validateKeyword(keyword, sourceEntity, true, isApiRequest, null);
    // Validate it is not duplicated
    List<ProfileKeywordEntity> existingKeywords = profileKeywordDao.getProfileKeywors(orcid, getLastModified(orcid));
    for (ProfileKeywordEntity existing : existingKeywords) {
        if (isDuplicated(existing, keyword, sourceEntity)) {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", "keyword");
            params.put("value", keyword.getContent());
            throw new OrcidDuplicatedElementException(params);
        }
    }
    ProfileKeywordEntity newEntity = adapter.toProfileKeywordEntity(keyword);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    newEntity.setProfile(profile);
    newEntity.setDateCreated(new Date());
    //Set the source
    if (sourceEntity.getSourceProfile() != null) {
        newEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        newEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    setIncomingPrivacy(newEntity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(newEntity, isApiRequest);
    profileKeywordDao.persist(newEntity);
    return adapter.toKeyword(newEntity);
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) HashMap(java.util.HashMap) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidDuplicatedElementException(org.orcid.core.exception.OrcidDuplicatedElementException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 88 with SourceEntity

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

the class OrgManagerImpl method createUpdate.

@Override
public OrgEntity createUpdate(OrgEntity org, Long orgDisambiguatedId) {
    OrgEntity existingOrg = orgDao.findByNameCityRegionAndCountry(org.getName(), org.getCity(), org.getRegion(), org.getCountry());
    if (existingOrg != null) {
        org = existingOrg;
    }
    if (org.getOrgDisambiguated() == null) {
        OrgDisambiguatedEntity disambiguatedOrg = orgDisambiguatedDao.find(orgDisambiguatedId);
        if (disambiguatedOrg == null) {
            throw new IllegalArgumentException("No such disambiguated org with id=" + orgDisambiguatedId);
        }
        org.setOrgDisambiguated(disambiguatedOrg);
    }
    if (org.getSource() == null) {
        org.setSource(new SourceEntity(sourceManager.retrieveSourceOrcid()));
    }
    return orgDao.merge(org);
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) AmbiguousOrgEntity(org.orcid.persistence.jpa.entities.AmbiguousOrgEntity)

Example 89 with SourceEntity

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

the class SourceInActivitiesTest method sourceDoesntChange_Work_Test.

@Test
public void sourceDoesntChange_Work_Test() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    Work work1 = getWork(userOrcid);
    assertNotNull(work1);
    assertNotNull(work1.getWorkTitle());
    assertNotNull(work1.getWorkTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(work1.getWorkTitle().getTitle().getContent()));
    assertNotNull(work1.getSource());
    assertNotNull(work1.getSource().retrieveSourcePath());
    assertEquals(userOrcid, work1.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Work work2 = getWork(userOrcid);
    assertNotNull(work2);
    assertNotNull(work2.getWorkTitle());
    assertNotNull(work2.getWorkTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(work2.getWorkTitle().getTitle().getContent()));
    assertNotNull(work2.getSource());
    assertNotNull(work2.getSource().retrieveSourcePath());
    assertEquals(CLIENT_1_ID, work2.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_2_ID)));
    Work work3 = getWork(userOrcid);
    assertNotNull(work3);
    assertNotNull(work3.getWorkTitle());
    assertNotNull(work3.getWorkTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(work3.getWorkTitle().getTitle().getContent()));
    assertNotNull(work3.getSource());
    assertNotNull(work3.getSource().retrieveSourcePath());
    assertEquals(CLIENT_2_ID, work3.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    Work work4 = getWork(userOrcid);
    assertNotNull(work4);
    assertNotNull(work4.getWorkTitle());
    assertNotNull(work4.getWorkTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(work4.getWorkTitle().getTitle().getContent()));
    assertNotNull(work4.getSource());
    assertNotNull(work4.getSource().retrieveSourcePath());
    assertEquals(userOrcid, work4.getSource().retrieveSourcePath());
    Work fromDb1 = workManager.getWork(userOrcid, work1.getPutCode(), 0L);
    assertNotNull(fromDb1);
    assertEquals(userOrcid, fromDb1.getSource().retrieveSourcePath());
    Work fromDb2 = workManager.getWork(userOrcid, work2.getPutCode(), 0L);
    assertNotNull(fromDb2);
    assertEquals(CLIENT_1_ID, fromDb2.getSource().retrieveSourcePath());
    Work fromDb3 = workManager.getWork(userOrcid, work3.getPutCode(), 0L);
    assertNotNull(fromDb3);
    assertEquals(CLIENT_2_ID, fromDb3.getSource().retrieveSourcePath());
    Work fromDb4 = workManager.getWork(userOrcid, work4.getPutCode(), 0L);
    assertNotNull(fromDb4);
    assertEquals(userOrcid, fromDb4.getSource().retrieveSourcePath());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Work(org.orcid.jaxb.model.record_v2.Work) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test)

Example 90 with SourceEntity

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

the class GroupIdRecordManagerTest method before.

@Before
public void before() {
    TargetProxyHelper.injectIntoProxy(groupIdRecordManager, "sourceManager", sourceManager);
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_ID)));
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Before(org.junit.Before)

Aggregations

SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)111 Test (org.junit.Test)58 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)57 BaseTest (org.orcid.core.BaseTest)44 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)28 Date (java.util.Date)19 HashMap (java.util.HashMap)15 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)14 Work (org.orcid.jaxb.model.record_v2.Work)14 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)13 Visibility (org.orcid.jaxb.model.common_v2.Visibility)12 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Funding (org.orcid.jaxb.model.record_v2.Funding)10 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)6 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)6 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)6 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)6 WorkEntity (org.orcid.persistence.jpa.entities.WorkEntity)6 GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)5