use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.
the class AttributeOptionComboCheck method check.
@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
Program program = ctx.getProgramsMap().get(event.getProgram());
CategoryOptionCombo coc = ctx.getCategoryOptionComboMap().get(event.getUid());
if (coc != null && coc.isDefault() && program.getCategoryCombo() != null && !program.getCategoryCombo().isDefault()) {
ImportSummary importSummary = new ImportSummary(event.getEvent());
importSummary.addConflict("attributeOptionCombo", "Valid attribute option combo must be specified since program does not have the default category combo");
importSummary.setStatus(ImportStatus.ERROR);
return importSummary.incrementIgnored();
}
return success();
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.
the class ProgramStageInstanceBasicCheck method check.
@Override
public ImportSummary check(final ImmutableEvent event, final WorkContext ctx) {
final ProgramStageInstance programStageInstance = ctx.getProgramStageInstanceMap().get(event.getEvent());
if (programStageInstance == null) {
final ImportSummary error = error("Event ID " + event.getEvent() + " doesn't point to valid event", event.getEvent());
error.addConflict("Invalid Event ID", event.getEvent());
return error;
} else if (programStageInstance.isDeleted() || ctx.getImportOptions().getImportStrategy().isCreate()) {
return error("Event ID " + event.getEvent() + " was already used and/or deleted. This event can not be modified.").setReference(event.getEvent());
}
return success();
}
use of org.hisp.dhis.dxf2.importsummary.ImportStatus.SUCCESS 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.importsummary.ImportStatus.SUCCESS 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.importsummary.ImportStatus.SUCCESS in project dhis2-core by dhis2.
the class EventSecurityTest method testAddEventSimpleUserFullAccess5.
/**
* program = DATA READ programStage = DATA READ orgUnit = Accessible status
* = SUCCESS
*/
@Test
void testAddEventSimpleUserFullAccess5() {
programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
programStageA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
manager.update(programA);
manager.update(programStageA);
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid());
ImportSummary importSummary = eventService.addEvent(event, ImportOptions.getDefaultImportOptions(), false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertEquals(event.getEvent(), importSummary.getReference());
programA.setPublicAccess(AccessStringHelper.DATA_READ);
programStageA.setPublicAccess(AccessStringHelper.DATA_READ);
manager.update(programA);
manager.update(programStageA);
User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
injectSecurityContext(user);
assertTrue(programStageInstanceService.programStageInstanceExists(event.getEvent()));
ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(event.getUid());
assertNotNull(programStageInstance);
Event eventFromPsi = eventService.getEvent(programStageInstance);
assertNotNull(eventFromPsi);
assertEquals(event.getUid(), eventFromPsi.getEvent());
}
Aggregations