use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ActivityValidatorTest method validateDuplicatedExtIds_noDuplicatesTest.
/**
* VALIDATE DUPLICATED EXTERNAL IDENTIFIERS
* */
@SuppressWarnings("deprecation")
@Test
public void validateDuplicatedExtIds_noDuplicatesTest() {
SourceEntity source1 = mock(SourceEntity.class);
when(source1.getSourceName()).thenReturn("source name");
when(source1.getSourceId()).thenReturn("APP-00000000000000");
SourceOrcid sourceOrcid = new SourceOrcid();
sourceOrcid.setPath("0000-0000-0000-0000");
Source source2 = mock(Source.class);
when(source2.getSourceName()).thenReturn(new SourceName("other source name"));
when(source2.getSourceOrcid()).thenReturn(sourceOrcid);
ExternalIDs extIds1 = getExternalIDs();
ExternalIDs extIds2 = getExternalIDs();
activityValidator.checkExternalIdentifiersForDuplicates(extIds1, extIds2, source2, source1);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ActivityValidatorTest method validateGroupId_validTest.
/**
* VALIDATE GROUP ID RECORD
* */
@Test
public void validateGroupId_validTest() {
SourceEntity source = mock(SourceEntity.class);
when(source.getSourceName()).thenReturn("source name");
GroupIdRecord g = getGroupIdRecord();
activityValidator.validateGroupIdRecord(g, true, source);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class ActivityValidatorTest method validateDuplicatedExtIds_duplicatesFoundTest.
@SuppressWarnings("deprecation")
@Test(expected = OrcidDuplicatedActivityException.class)
public void validateDuplicatedExtIds_duplicatesFoundTest() {
SourceEntity source1 = mock(SourceEntity.class);
when(source1.getSourceName()).thenReturn("source name");
when(source1.getSourceId()).thenReturn("APP-00000000000000");
SourceClientId sourceClientId = new SourceClientId();
sourceClientId.setPath("APP-00000000000000");
Source source2 = mock(Source.class);
when(source2.getSourceName()).thenReturn(new SourceName("source name"));
when(source2.getSourceClientId()).thenReturn(sourceClientId);
ExternalIDs extIds1 = getExternalIDs();
ExternalIDs extIds2 = getExternalIDs();
activityValidator.checkExternalIdentifiersForDuplicates(extIds1, extIds2, source2, source1);
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method getSourceId.
private String getSourceId() {
SourceEntity source = sourceManager.retrieveSourceEntity();
String sourceId = null;
//source mananger should never return null, but for some unit tests it does, so, we return the user id
if (source != null) {
sourceId = source.getSourceId();
}
return sourceId;
}
use of org.orcid.persistence.jpa.entities.SourceEntity in project ORCID-Source by ORCID.
the class WorkManagerImpl method createWorks.
/**
* Add a list of works to the given profile
*
* @param works
* The list of works that want to be added
* @param orcid
* The id of the user we want to add the works to
*
* @return the work bulk with the put codes of the new works or the error
* that indicates why a work can't be added
*/
@Override
@Transactional
public WorkBulk createWorks(String orcid, WorkBulk workBulk) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
Set<ExternalID> existingExternalIdentifiers = buildExistingExternalIdsSet(orcid, sourceEntity.getSourceId());
if (workBulk.getBulk() != null && !workBulk.getBulk().isEmpty()) {
List<BulkElement> bulk = workBulk.getBulk();
//Check bulk size
if (bulk.size() > maxBulkSize) {
Locale locale = localeManager.getLocale();
throw new IllegalArgumentException(messageSource.getMessage("apiError.validation_too_many_elements_in_bulk.exception", new Object[] { maxBulkSize }, locale));
}
for (int i = 0; i < bulk.size(); i++) {
if (Work.class.isAssignableFrom(bulk.get(i).getClass())) {
Work work = (Work) bulk.get(i);
try {
//Validate the work
activityValidator.validateWork(work, sourceEntity, true, true, null);
//Validate it is not duplicated
if (work.getExternalIdentifiers() != null) {
for (ExternalID extId : work.getExternalIdentifiers().getExternalIdentifier()) {
if (existingExternalIdentifiers.contains(extId)) {
Map<String, String> params = new HashMap<String, String>();
params.put("clientName", sourceEntity.getSourceName());
throw new OrcidDuplicatedActivityException(params);
}
}
}
//Save the work
WorkEntity workEntity = jpaJaxbWorkAdapter.toWorkEntity(work);
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
workEntity.setProfile(profile);
workEntity.setAddedToProfileDate(new Date());
// Set source id
if (sourceEntity.getSourceProfile() != null) {
workEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
workEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
setIncomingWorkPrivacy(workEntity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(workEntity, true);
workDao.persist(workEntity);
//Update the element in the bulk
Work updatedWork = jpaJaxbWorkAdapter.toWork(workEntity);
bulk.set(i, updatedWork);
//Add the work extIds to the list of existing external identifiers
addExternalIdsToExistingSet(updatedWork, existingExternalIdentifiers);
} catch (Exception e) {
//Get the exception
OrcidError orcidError = orcidCoreExceptionMapper.getOrcidError(e);
bulk.set(i, orcidError);
}
}
}
workDao.flush();
}
return workBulk;
}
Aggregations