Search in sources :

Example 36 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class EventImportTest method testVerifyEventCanBeUpdatedUsingProgramOnly2.

// 
// UPDATE EVENT TESTS
// 
@Test
void testVerifyEventCanBeUpdatedUsingProgramOnly2() throws IOException {
    // CREATE A NEW EVENT
    InputStream is = createEventJsonInputStream(programB.getUid(), programStageB.getUid(), organisationUnitB.getUid(), null, dataElementB, "10");
    ImportSummaries importSummaries = eventService.addEventsJson(is, null);
    String uid = importSummaries.getImportSummaries().get(0).getReference();
    assertEquals(ImportStatus.SUCCESS, importSummaries.getStatus());
    // FETCH NEWLY CREATED EVENT
    programStageInstanceService.getProgramStageInstance(uid);
    // UPDATE EVENT - Program is not specified
    Event event = new Event();
    event.setEvent(uid);
    event.setStatus(EventStatus.COMPLETED);
    final ImportSummary summary = eventService.updateEvent(event, false, ImportOptions.getDefaultImportOptions(), false);
    assertThat(summary.getStatus(), is(ImportStatus.ERROR));
    assertThat(summary.getDescription(), is("Event.program does not point to a valid program: null"));
    assertThat(summary.getReference(), is(uid));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) ImportSummaries(org.hisp.dhis.dxf2.importsummary.ImportSummaries) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 37 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class ProgramStageValidationStrategyTest method setUpTest.

@Override
protected void setUpTest() {
    final int testYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
    userService = _userService;
    createUserAndInjectSecurityContext(false, "F_TRACKED_ENTITY_DATAVALUE_ADD", "F_TRACKED_ENTITY_DATAVALUE_DELETE", "F_UNCOMPLETE_EVENT", "F_PROGRAMSTAGE_ADD", "F_PROGRAMSTAGE_DELETE", "F_PROGRAM_PUBLIC_ADD", "F_PROGRAM_PRIVATE_ADD", "F_PROGRAM_DELETE", "F_TRACKED_ENTITY_ADD", "F_TRACKED_ENTITY_UPDATE", "F_TRACKED_ENTITY_DELETE", "F_DATAELEMENT_PUBLIC_ADD", "F_DATAELEMENT_PRIVATE_ADD", "F_DATAELEMENT_DELETE", "F_CATEGORY_COMBO_PUBLIC_ADD", "F_CATEGORY_COMBO_PRIVATE_ADD", "F_CATEGORY_COMBO_DELETE");
    User currentUser = currentUserService.getCurrentUser();
    UserAccess userAccess1 = new UserAccess(currentUser, "rwrw----");
    UserAccess userAccess2 = new UserAccess(currentUser, "rwrw----");
    UserAccess userAccess3 = new UserAccess(currentUser, "rwrw----");
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitA.addUser(currentUser);
    organisationUnitA.getSharing().addUserAccess(userAccess1);
    currentUser.getTeiSearchOrganisationUnits().add(organisationUnitA);
    manager.save(organisationUnitA, false);
    userService.updateUser(currentUser);
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityType.getSharing().addUserAccess(userAccess1);
    manager.save(trackedEntityType, false);
    org.hisp.dhis.trackedentity.TrackedEntityInstance maleA = createTrackedEntityInstance(organisationUnitA);
    maleA.setTrackedEntityType(trackedEntityType);
    maleA.getSharing().addUserAccess(userAccess1);
    maleA.setCreatedBy(currentUser);
    manager.save(maleA, false);
    trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
    DataElement dataElementA = createDataElement('A');
    dataElementA.setValueType(ValueType.INTEGER);
    dataElementA.getSharing().addUserAccess(userAccess1);
    manager.save(dataElementA, false);
    DataElement dataElementB = createDataElement('B');
    dataElementB.setValueType(ValueType.TEXT);
    dataElementB.getSharing().addUserAccess(userAccess2);
    manager.save(dataElementB, false);
    DataElement dataElementC = createDataElement('C');
    dataElementC.setValueType(ValueType.INTEGER);
    dataElementC.getSharing().addUserAccess(userAccess3);
    manager.save(dataElementC, false);
    programStageA = createProgramStage('A', 0);
    programStageA.setValidationStrategy(ValidationStrategy.ON_COMPLETE);
    programStageA.getSharing().addUserAccess(userAccess1);
    manager.save(programStageA, false);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    programA.getSharing().addUserAccess(userAccess1);
    manager.save(programA, false);
    // Create a compulsory PSDE
    ProgramStageDataElement programStageDataElementA = new ProgramStageDataElement();
    programStageDataElementA.setDataElement(dataElementA);
    programStageDataElementA.setProgramStage(programStageA);
    programStageDataElementA.setCompulsory(true);
    programStageDataElementA.getSharing().addUserAccess(userAccess1);
    manager.save(programStageDataElementA, false);
    // Create a compulsory PSDE
    ProgramStageDataElement programStageDataElementB = new ProgramStageDataElement();
    programStageDataElementB.setDataElement(dataElementB);
    programStageDataElementB.setProgramStage(programStageA);
    programStageDataElementB.setCompulsory(true);
    programStageDataElementB.getSharing().addUserAccess(userAccess1);
    manager.save(programStageDataElementB, false);
    // Create a NON-compulsory PSDE
    ProgramStageDataElement programStageDataElementC = new ProgramStageDataElement();
    programStageDataElementC.setDataElement(dataElementC);
    programStageDataElementC.setProgramStage(programStageA);
    programStageDataElementC.setCompulsory(false);
    programStageDataElementC.getSharing().addUserAccess(userAccess1);
    manager.save(programStageDataElementC, false);
    // Assign all 3 created PSDEs to created ProgramStage programStageA and
    // to
    // created Program programA
    programStageA.getProgramStageDataElements().add(programStageDataElementA);
    programStageA.getProgramStageDataElements().add(programStageDataElementB);
    programStageA.getProgramStageDataElements().add(programStageDataElementC);
    programStageA.setProgram(programA);
    programA.getProgramStages().add(programStageA);
    manager.update(programStageA);
    manager.update(programA);
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setProgram(programA);
    programInstance.setIncidentDate(new Date());
    programInstance.setEnrollmentDate(new Date());
    programInstance.setEntityInstance(maleA);
    programInstance.getSharing().addUserAccess(userAccess1);
    maleA.getProgramInstances().add(programInstance);
    manager.save(programInstance, false);
    manager.update(maleA);
    Period periodA = createPeriod(testYear + "03");
    periodA.getSharing().addUserAccess(userAccess1);
    manager.save(periodA, false);
    CategoryCombo categoryComboA = createCategoryCombo('A');
    CategoryOptionCombo categoryOptionComboA = createCategoryOptionCombo('A');
    categoryOptionComboA.setCategoryCombo(categoryComboA);
    categoryComboA.getSharing().addUserAccess(userAccess1);
    categoryOptionComboA.getSharing().addUserAccess(userAccess1);
    manager.save(categoryComboA, false);
    manager.save(categoryOptionComboA, false);
    dataValueAMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementA.getUid(), "");
    dataValueBMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementB.getUid(), "");
    dataValueCMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementC.getUid(), "");
    dataValueA = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementA.getUid(), "42");
    dataValueB = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementB.getUid(), "Ford Prefect");
    dataValueC = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementC.getUid(), "84");
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Period(org.hisp.dhis.period.Period) Date(java.util.Date) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet)

Example 38 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class EventBaseCheckTest method verifyErrorOnInvalidCreatedAtClientDate.

@Test
void verifyErrorOnInvalidCreatedAtClientDate() {
    event.setEvent(event.getUid());
    event.setCreatedAtClient("111-12-122");
    ImportSummary importSummary = rule.check(new ImmutableEvent(event), workContext);
    assertHasError(importSummary, event, null);
    assertHasConflict(importSummary, event, "Invalid event created at client date: " + event.getCreatedAtClient());
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ImmutableEvent(org.hisp.dhis.dxf2.events.importer.shared.ImmutableEvent) Test(org.junit.jupiter.api.Test) BaseValidationTest(org.hisp.dhis.dxf2.events.importer.validation.BaseValidationTest)

Example 39 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class MetadataImportServiceTest method testImportProgramWithProgramStageAndSharing.

/**
 * Payload includes Program and ProgramStage with sharing settings.
 * <p>
 * Expected: after created, both Program and ProgramStage are saved
 * correctly together with sharing settings.
 */
@Test
void testImportProgramWithProgramStageAndSharing() throws IOException {
    User user = createUser("A", "ALL");
    manager.save(user);
    injectSecurityContext(user);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_programStage_with_sharing.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
    params.setSkipSharing(false);
    params.setUser(user);
    ImportReport report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    ProgramStage programStage = programStageService.getProgramStage("oORy3Rg9hLE");
    assertEquals(1, programStage.getSharing().getUserGroups().size());
    Program program = manager.get("QIHW6CBdLsP");
    assertEquals(1, program.getSharing().getUserGroups().size());
}
Also used : User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ProgramStage(org.hisp.dhis.program.ProgramStage) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 40 with CREATED

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.CREATED in project dhis2-core by dhis2.

the class MetadataVersionDelegateTest method testShouldDownloadMetadataVersion.

@Test
void testShouldDownloadMetadataVersion() {
    when(metadataSystemSettingService.getDownloadVersionSnapshotURL("testVersion")).thenReturn(downloadUrl);
    when(synchronizationManager.isRemoteServerAvailable()).thenReturn(new AvailabilityStatus(true, "test_message", null));
    when(metadataSystemSettingService.getRemoteInstanceUserName()).thenReturn(username);
    when(metadataSystemSettingService.getRemoteInstancePassword()).thenReturn(password);
    try (MockedStatic<HttpUtils> mocked = mockStatic(HttpUtils.class)) {
        String response = "{\"name\":\"testVersion\",\"created\":\"2016-05-26T11:43:59.787+0000\",\"type\":\"BEST_EFFORT\",\"id\":\"ktwh8PHNwtB\",\"hashCode\":\"12wa32d4f2et3tyt5yu6i\"}";
        DhisHttpResponse dhisHttpResponse = new DhisHttpResponse(httpResponse, response, HttpStatus.OK.value());
        mocked.when(() -> HttpUtils.httpGET(downloadUrl, true, username, password, null, DOWNLOAD_TIMEOUT, true)).thenReturn(dhisHttpResponse);
        MetadataVersion metadataVersion = new MetadataVersion("testVersion", VersionType.BEST_EFFORT);
        metadataVersion.setHashCode("12wa32d4f2et3tyt5yu6i");
        String actualVersionSnapShot = target.downloadMetadataVersionSnapshot(metadataVersion);
        assertEquals(response, actualVersionSnapShot);
    }
}
Also used : MetadataVersion(org.hisp.dhis.metadata.version.MetadataVersion) DhisHttpResponse(org.hisp.dhis.system.util.DhisHttpResponse) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) HttpUtils(org.hisp.dhis.system.util.HttpUtils) Test(org.junit.jupiter.api.Test)

Aggregations

WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)12 Test (org.junit.jupiter.api.Test)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ArrayList (java.util.ArrayList)8 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)7 Date (java.util.Date)6 ImportSummaries (org.hisp.dhis.dxf2.importsummary.ImportSummaries)6 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)6 AvailabilityStatus (org.hisp.dhis.dxf2.synch.AvailabilityStatus)6 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)6 HttpUtils (org.hisp.dhis.system.util.HttpUtils)6 User (org.hisp.dhis.user.User)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 List (java.util.List)5 Map (java.util.Map)5 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)4 Event (org.hisp.dhis.dxf2.events.event.Event)4 HashMap (java.util.HashMap)3