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());
}
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());
}
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));
}
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;
}
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);
}
Aggregations