Search in sources :

Example 6 with SUCCESS

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();
}
Also used : Program(org.hisp.dhis.program.Program) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 7 with 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();
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 8 with 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();
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary)

Example 9 with 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();
}
Also used : Program(org.hisp.dhis.program.Program) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ProgramInstance(org.hisp.dhis.program.ProgramInstance) IdScheme(org.hisp.dhis.common.IdScheme) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 10 with 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());
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)20 User (org.hisp.dhis.user.User)10 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)9 Test (org.junit.jupiter.api.Test)9 Event (org.hisp.dhis.dxf2.events.event.Event)6 Date (java.util.Date)4 Program (org.hisp.dhis.program.Program)4 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 DataValueService (org.hisp.dhis.datavalue.DataValueService)3 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)3 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)3 Events (org.hisp.dhis.dxf2.events.event.Events)3 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)3 IOException (java.io.IOException)2 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 IdScheme (org.hisp.dhis.common.IdScheme)2 IdSchemes (org.hisp.dhis.common.IdSchemes)2 ImportSummariesResponseExtractor (org.hisp.dhis.dxf2.common.ImportSummariesResponseExtractor)2 DataValueSetService (org.hisp.dhis.dxf2.datavalueset.DataValueSetService)2