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);
}
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);
}
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);
}
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());
}
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)));
}
Aggregations