use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class DataValueAclCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
final TrackerAccessManager trackerAccessManager = ctx.getServiceDelegator().getTrackerAccessManager();
final ProgramStageInstance programStageInstance = ctx.getProgramStageInstanceMap().get(event.getUid());
Map<String, Set<EventDataValue>> eventDataValueMap = ctx.getEventDataValueMap();
final User user = ctx.getImportOptions().getUser();
final ImportSummary importSummary = new ImportSummary();
// Note that here we are passing a ProgramStageInstance, which during a
// INSERT
// operation
// is going to be null, so the ACL method will not be able to check that
final Set<EventDataValue> dataValues = eventDataValueMap.get(event.getUid());
for (EventDataValue dataValue : dataValues) {
DataElement dataElement = ctx.getDataElementMap().get(dataValue.getDataElement());
List<String> errors = trackerAccessManager.canWrite(user, programStageInstance, dataElement, true);
if (!errors.isEmpty()) {
errors.forEach(error -> importSummary.addConflict(dataElement.getUid(), error));
}
}
return importSummary;
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class EventDateCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
if (EventStatus.ACTIVE == event.getStatus() && event.getEventDate() == null) {
return new ImportSummary(ImportStatus.ERROR, "Event date is required. ").setReference(event.getEvent()).incrementIgnored();
}
try {
DateUtils.parseDate(event.getDueDate());
DateUtils.parseDate(event.getEventDate());
DateUtils.parseDate(event.getCompletedDate());
} catch (Exception e) {
return new ImportSummary(ImportStatus.ERROR, "Event date or Execution date format is not correct. ").setReference(event.getEvent()).incrementIgnored();
}
return success();
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ProgramInstanceRepeatableStageCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
IdScheme scheme = ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme();
ProgramStage programStage = ctx.getProgramStage(scheme, event.getProgramStage());
ProgramInstance programInstance = ctx.getProgramInstanceMap().get(event.getUid());
Program program = ctx.getProgramsMap().get(event.getProgram());
TrackedEntityInstance tei = null;
if (program.isRegistration()) {
tei = ctx.getTrackedEntityInstanceMap().get(event.getUid()).getLeft();
}
// @formatter:off
if (programInstance != null && tei != null && program.isRegistration() && !programStage.getRepeatable() && hasProgramStageInstance(ctx.getServiceDelegator().getJdbcTemplate(), programInstance.getId(), programStage.getId(), tei.getId())) {
return new ImportSummary(ImportStatus.ERROR, "Program stage is not repeatable and an event already exists").setReference(event.getEvent()).incrementIgnored();
}
return success();
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class AttributeOptionComboAclCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
ImportSummary importSummary = new ImportSummary();
TrackerAccessManager trackerAccessManager = ctx.getServiceDelegator().getTrackerAccessManager();
ImportOptions importOptions = ctx.getImportOptions();
CategoryOptionCombo categoryOptionCombo = ctx.getCategoryOptionComboMap().get(event.getUid());
List<String> errors = trackerAccessManager.canWrite(importOptions.getUser(), categoryOptionCombo);
if (!errors.isEmpty()) {
importSummary.setStatus(ImportStatus.ERROR);
errors.forEach(error -> importSummary.addConflict("CategoryOptionCombo", error));
importSummary.incrementIgnored();
}
return importSummary;
}
use of org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent in project dhis2-core by dhis2.
the class ProgramInstanceRepeatableStageCheckTest method successOnNonRepeatableStageAndExistingEventsOnNewEnrollment.
@Test
void successOnNonRepeatableStageAndExistingEventsOnNewEnrollment() {
// Data preparation
Program program = createProgram('P');
TrackedEntityInstance tei = createTrackedEntityInstance('A', createOrganisationUnit('A'));
event.setProgramStage(CodeGenerator.generateUid());
event.setProgram(program.getUid());
event.setTrackedEntityInstance(tei.getUid());
ProgramStage programStage = createProgramStage('A', program);
programStage.setRepeatable(false);
when(workContext.getProgramStage(programStageIdScheme, event.getProgramStage())).thenReturn(programStage);
Map<String, Program> programMap = new HashMap<>();
programMap.put(program.getUid(), program);
Map<String, ProgramInstance> programInstanceMap = new HashMap<>();
ProgramInstance programInstance = new ProgramInstance();
programInstanceMap.put(event.getUid(), programInstance);
Pair<TrackedEntityInstance, Boolean> teiPair = Pair.of(tei, true);
Map<String, Pair<TrackedEntityInstance, Boolean>> teiMap = new HashMap<>();
teiMap.put(event.getUid(), teiPair);
when(workContext.getTrackedEntityInstanceMap()).thenReturn(teiMap);
when(workContext.getProgramsMap()).thenReturn(programMap);
when(workContext.getProgramInstanceMap()).thenReturn(programInstanceMap);
when(workContext.getServiceDelegator()).thenReturn(serviceDelegator);
when(serviceDelegator.getJdbcTemplate()).thenReturn(jdbcTemplate);
when(jdbcTemplate.queryForObject(anyString(), eq(Boolean.class), eq(programInstance.getId()), eq(programStage.getId()), eq(tei.getId()))).thenReturn(false);
// Method under test
ImportSummary summary = rule.check(new ImmutableEvent(event), workContext);
assertNoError(summary);
}
Aggregations