Search in sources :

Example 21 with STATUS

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

the class EventSecurityTest method testAddEventSimpleUserFullAccess3.

/**
 * program = DATA READ/WRITE programStage = DATA READ orgUnit = Accessible
 * status = ERROR
 */
@Test
void testAddEventSimpleUserFullAccess3() {
    programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    programStageA.setPublicAccess(AccessStringHelper.DATA_READ);
    manager.update(programA);
    manager.update(programStageA);
    User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    injectSecurityContext(user);
    // make sure data is flushed, so event service can access it
    manager.flush();
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid());
    ImportSummary importSummary = eventService.addEvent(event, ImportOptions.getDefaultImportOptions(), false);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 22 with STATUS

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

the class EnrollmentSecurityTest method testGetEnrollmentUserWithDataRead.

/**
 * program = DATA READ orgUnit = Accessible status = SUCCESS
 */
@Test
void testGetEnrollmentUserWithDataRead() {
    ImportSummary importSummary = enrollmentService.addEnrollment(createEnrollment(programA.getUid(), maleA.getUid()), ImportOptions.getDefaultImportOptions());
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    programA.getSharing().setPublicAccess(AccessStringHelper.DATA_READ);
    manager.updateNoAcl(programA);
    User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    injectSecurityContext(user);
    Enrollment enrollment = enrollmentService.getEnrollment(importSummary.getReference());
    assertNotNull(enrollment);
    assertEquals(enrollment.getEnrollment(), importSummary.getReference());
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 23 with STATUS

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

the class ProgramStageInstanceSupplierTest method verifySupplier.

@Test
void verifySupplier() throws SQLException {
    // mock resultset data
    when(mockResultSet.getLong("programstageinstanceid")).thenReturn(100L);
    when(mockResultSet.getString("uid")).thenReturn("abcded");
    when(mockResultSet.getString("status")).thenReturn("ACTIVE");
    when(mockResultSet.getBoolean("deleted")).thenReturn(false);
    // create event to import
    Event event = new Event();
    event.setUid(CodeGenerator.generateUid());
    event.setEnrollment("abcded");
    // mock resultset extraction
    mockResultSetExtractor(mockResultSet);
    Map<String, ProgramStageInstance> map = subject.get(ImportOptions.getDefaultImportOptions(), Collections.singletonList(event));
    ProgramStageInstance programStageInstance = map.get("abcded");
    assertThat(programStageInstance, is(notNullValue()));
    assertThat(programStageInstance.getId(), is(100L));
    assertThat(programStageInstance.getUid(), is("abcded"));
    assertThat(programStageInstance.getStatus(), is(EventStatus.ACTIVE));
    assertThat(programStageInstance.isDeleted(), is(false));
}
Also used : Event(org.hisp.dhis.dxf2.events.event.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) Test(org.junit.jupiter.api.Test)

Example 24 with STATUS

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

the class SyncUtils method isRemoteServerAvailable.

/**
 * Checks the availability of remote server
 *
 * @param systemSettingManager Reference to SystemSettingManager
 * @param restTemplate Reference to RestTemplate
 * @return AvailabilityStatus that says whether the server is available or
 *         not
 */
public static AvailabilityStatus isRemoteServerAvailable(SystemSettingManager systemSettingManager, RestTemplate restTemplate) {
    if (!isRemoteServerConfigured(systemSettingManager)) {
        return new AvailabilityStatus(false, "Remote server is not configured", HttpStatus.BAD_GATEWAY);
    }
    String url = systemSettingManager.getStringSetting(SettingKey.REMOTE_INSTANCE_URL) + PING_PATH;
    String username = systemSettingManager.getStringSetting(SettingKey.REMOTE_INSTANCE_USERNAME);
    String password = systemSettingManager.getStringSetting(SettingKey.REMOTE_INSTANCE_PASSWORD);
    log.debug(String.format("Remote server ping URL: %s, username: %s", url, username));
    HttpEntity<String> request = getBasicAuthRequestEntity(username, password);
    ResponseEntity<String> response = null;
    HttpStatus sc = null;
    String st = null;
    AvailabilityStatus status = null;
    try {
        response = restTemplate.exchange(url, HttpMethod.GET, request, String.class);
        sc = response.getStatusCode();
    } catch (HttpClientErrorException | HttpServerErrorException ex) {
        sc = ex.getStatusCode();
        st = ex.getStatusText();
    } catch (ResourceAccessException ex) {
        return new AvailabilityStatus(false, "Network is unreachable", HttpStatus.BAD_GATEWAY);
    }
    log.debug("Response status code: " + sc);
    if (HttpStatus.OK.equals(sc)) {
        status = new AvailabilityStatus(true, "Authentication was successful", sc);
    } else if (HttpStatus.FOUND.equals(sc)) {
        status = new AvailabilityStatus(false, "No authentication was provided", sc);
    } else if (HttpStatus.UNAUTHORIZED.equals(sc)) {
        status = new AvailabilityStatus(false, "Authentication failed", sc);
    } else if (HttpStatus.INTERNAL_SERVER_ERROR.equals(sc)) {
        status = new AvailabilityStatus(false, "Remote server experienced an internal error", sc);
    } else {
        status = new AvailabilityStatus(false, "Server is not available: " + st, sc);
    }
    log.info("Status: " + status);
    return status;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) AvailabilityStatus(org.hisp.dhis.dxf2.synch.AvailabilityStatus) HttpStatus(org.springframework.http.HttpStatus) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) ResourceAccessException(org.springframework.web.client.ResourceAccessException)

Example 25 with STATUS

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

the class EventController method getEventsGrid.

// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
@RequestMapping(value = "/query", method = RequestMethod.GET, produces = { ContextUtils.CONTENT_TYPE_JSON, ContextUtils.CONTENT_TYPE_JAVASCRIPT })
@PreAuthorize("hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD') or hasRole('F_TRACKED_ENTITY_DATAVALUE_READ')")
@ResponseBody
public Grid getEventsGrid(@RequestParam(required = false) String program, @RequestParam(required = false) String programStage, @RequestParam(required = false) ProgramStatus programStatus, @RequestParam(required = false) Boolean followUp, @RequestParam(required = false) String trackedEntityInstance, @RequestParam(required = false) String orgUnit, @RequestParam(required = false) OrganisationUnitSelectionMode ouMode, @RequestParam(required = false) Date startDate, @RequestParam(required = false) Date endDate, @RequestParam(required = false) Date dueDateStart, @RequestParam(required = false) Date dueDateEnd, @RequestParam(required = false) Date lastUpdated, @RequestParam(required = false) Date lastUpdatedStartDate, @RequestParam(required = false) Date lastUpdatedEndDate, @RequestParam(required = false) EventStatus status, @RequestParam(required = false) String attributeCc, @RequestParam(required = false) String attributeCos, @RequestParam(required = false) boolean skipMeta, @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) boolean totalPages, @RequestParam(required = false) boolean skipPaging, @RequestParam(required = false) String order, @RequestParam(required = false) String attachment, @RequestParam(required = false, defaultValue = "false") boolean includeDeleted, @RequestParam(required = false) String event, @RequestParam(required = false) Set<String> filter, @RequestParam(required = false) Set<String> dataElement, @RequestParam Map<String, String> parameters, IdSchemes idSchemes, Model model, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    boolean allowNoAttrOptionCombo = trackedEntityInstance != null && entityInstanceService.getTrackedEntityInstance(trackedEntityInstance) != null;
    DataElementCategoryOptionCombo attributeOptionCombo = inputUtils.getAttributeOptionCombo(attributeCc, attributeCos, allowNoAttrOptionCombo);
    if (attributeOptionCombo == null && !allowNoAttrOptionCombo) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal attribute option combo identifier: " + attributeCc + " " + attributeCos));
    }
    Set<String> eventIds = TextUtils.splitToArray(event, TextUtils.SEMICOLON);
    lastUpdatedStartDate = lastUpdatedStartDate != null ? lastUpdatedStartDate : lastUpdated;
    EventSearchParams params = eventService.getFromUrl(program, programStage, programStatus, followUp, orgUnit, ouMode, trackedEntityInstance, startDate, endDate, dueDateStart, dueDateEnd, lastUpdatedStartDate, lastUpdatedEndDate, status, attributeOptionCombo, idSchemes, page, pageSize, totalPages, skipPaging, null, getGridOrderParams(order), false, eventIds, filter, dataElement, includeDeleted);
    contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE);
    return eventService.getEventsGrid(params);
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) EventSearchParams(org.hisp.dhis.dxf2.events.event.EventSearchParams) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Test (org.junit.jupiter.api.Test)28 User (org.hisp.dhis.user.User)20 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)18 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)16 Event (org.hisp.dhis.dxf2.events.event.Event)14 EventSearchParams (org.hisp.dhis.dxf2.events.event.EventSearchParams)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 GetMapping (org.springframework.web.bind.annotation.GetMapping)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)6 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)6 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)5 Period (org.hisp.dhis.period.Period)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5