use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class TrackedEntityInstanceQueryTest method testTeiQueryParamsWithoutEitherProgramOrTrackedEntityType.
@Test
void testTeiQueryParamsWithoutEitherProgramOrTrackedEntityType() {
TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
params.setOrganisationUnitMode(OrganisationUnitSelectionMode.ALL);
IllegalQueryException exception = assertThrows(IllegalQueryException.class, () -> instanceService.validate(params));
assertEquals("Either Program or Tracked entity type should be specified", exception.getMessage());
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DefaultCompleteDataSetRegistrationExchangeService method validate.
public void validate(ExportParams params) throws IllegalQueryException {
ErrorMessage error = null;
if (params == null) {
throw new IllegalQueryException(ErrorCode.E2000);
}
if (params.getDataSets().isEmpty()) {
error = new ErrorMessage(ErrorCode.E2013);
}
if (!params.hasPeriods() && !params.hasStartEndDate() && !params.hasCreated() && !params.hasCreatedDuration()) {
error = new ErrorMessage(ErrorCode.E2002);
}
if (params.hasPeriods() && params.hasStartEndDate()) {
error = new ErrorMessage(ErrorCode.E2003);
}
if (params.hasStartEndDate() && params.getStartDate().after(params.getEndDate())) {
error = new ErrorMessage(ErrorCode.E2004);
}
if (params.hasCreatedDuration() && DateUtils.getDuration(params.getCreatedDuration()) == null) {
error = new ErrorMessage(ErrorCode.E2005);
}
if (!params.hasOrganisationUnits() && !params.hasOrganisationUnitGroups()) {
error = new ErrorMessage(ErrorCode.E2006);
}
if (params.isIncludeChildren() && params.hasOrganisationUnitGroups()) {
error = new ErrorMessage(ErrorCode.E2007);
}
if (params.isIncludeChildren() && !params.hasOrganisationUnits()) {
error = new ErrorMessage(ErrorCode.E2008);
}
if (params.hasLimit() && params.getLimit() < 0) {
error = new ErrorMessage(ErrorCode.E2009);
}
if (error != null) {
log.warn(String.format("Complete data set registration validation failed, code: '%s', message: '%s'", error.getErrorCode(), error.getMessage()));
throw new IllegalQueryException(error);
}
limitToValidIdSchemes(params);
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class AbstractEnrollmentService method getEnrollment.
@Override
public Enrollment getEnrollment(User user, ProgramInstance programInstance, TrackedEntityInstanceParams params, boolean skipOwnershipCheck) {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(programInstance.getUid());
List<String> errors = trackerAccessManager.canRead(user, programInstance, skipOwnershipCheck);
if (!errors.isEmpty()) {
throw new IllegalQueryException(errors.toString());
}
if (programInstance.getEntityInstance() != null) {
enrollment.setTrackedEntityType(programInstance.getEntityInstance().getTrackedEntityType().getUid());
enrollment.setTrackedEntityInstance(programInstance.getEntityInstance().getUid());
}
if (programInstance.getOrganisationUnit() != null) {
enrollment.setOrgUnit(programInstance.getOrganisationUnit().getUid());
enrollment.setOrgUnitName(programInstance.getOrganisationUnit().getName());
}
if (programInstance.getGeometry() != null) {
enrollment.setGeometry(programInstance.getGeometry());
}
enrollment.setCreated(DateUtils.getIso8601NoTz(programInstance.getCreated()));
enrollment.setCreatedAtClient(DateUtils.getIso8601NoTz(programInstance.getCreatedAtClient()));
enrollment.setLastUpdated(DateUtils.getIso8601NoTz(programInstance.getLastUpdated()));
enrollment.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(programInstance.getLastUpdatedAtClient()));
enrollment.setProgram(programInstance.getProgram().getUid());
enrollment.setStatus(EnrollmentStatus.fromProgramStatus(programInstance.getStatus()));
enrollment.setEnrollmentDate(programInstance.getEnrollmentDate());
enrollment.setIncidentDate(programInstance.getIncidentDate());
enrollment.setFollowup(programInstance.getFollowup());
enrollment.setCompletedDate(programInstance.getEndDate());
enrollment.setCompletedBy(programInstance.getCompletedBy());
enrollment.setStoredBy(programInstance.getStoredBy());
enrollment.setCreatedByUserInfo(programInstance.getCreatedByUserInfo());
enrollment.setLastUpdatedByUserInfo(programInstance.getLastUpdatedByUserInfo());
enrollment.setDeleted(programInstance.isDeleted());
enrollment.getNotes().addAll(NoteHelper.convertNotes(programInstance.getComments()));
if (params.isIncludeEvents()) {
for (ProgramStageInstance programStageInstance : programInstance.getProgramStageInstances()) {
if ((params.isIncludeDeleted() || !programStageInstance.isDeleted()) && trackerAccessManager.canRead(user, programStageInstance, true).isEmpty()) {
enrollment.getEvents().add(eventService.getEvent(programStageInstance, params.isDataSynchronizationQuery(), true));
}
}
}
if (params.isIncludeRelationships()) {
for (RelationshipItem relationshipItem : programInstance.getRelationshipItems()) {
enrollment.getRelationships().add(relationshipService.getRelationship(relationshipItem.getRelationship(), RelationshipParams.FALSE, user));
}
}
return enrollment;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class AbstractEventService method getEventsGrid.
@Transactional(readOnly = true)
@Override
public Grid getEventsGrid(EventSearchParams params) {
User user = currentUserService.getCurrentUser();
if (params.getProgramStage() == null || params.getProgramStage().getProgram() == null) {
throw new IllegalQueryException("Program stage can not be null");
}
if (params.getProgramStage().getProgramStageDataElements() == null) {
throw new IllegalQueryException("Program stage should have at least one data element");
}
List<OrganisationUnit> organisationUnits = getOrganisationUnits(params, user);
params.handleCurrentUserSelectionMode(user);
if (params.isIncludeAllDataElements()) {
for (ProgramStageDataElement pde : params.getProgramStage().getProgramStageDataElements()) {
QueryItem qi = new QueryItem(pde.getDataElement(), pde.getDataElement().getLegendSet(), pde.getDataElement().getValueType(), pde.getDataElement().getAggregationType(), pde.getDataElement().hasOptionSet() ? pde.getDataElement().getOptionSet() : null);
params.getDataElements().add(qi);
}
} else {
if (params.getDataElements().isEmpty()) {
for (ProgramStageDataElement pde : params.getProgramStage().getProgramStageDataElements()) {
if (pde.getDisplayInReports()) {
QueryItem qi = new QueryItem(pde.getDataElement(), pde.getDataElement().getLegendSet(), pde.getDataElement().getValueType(), pde.getDataElement().getAggregationType(), pde.getDataElement().hasOptionSet() ? pde.getDataElement().getOptionSet() : null);
params.getDataElements().add(qi);
}
}
}
}
// ---------------------------------------------------------------------
// Grid headers
// ---------------------------------------------------------------------
Grid grid = new ListGrid();
for (String col : STATIC_EVENT_COLUMNS) {
grid.addHeader(new GridHeader(col, col));
}
for (QueryItem item : params.getDataElements()) {
grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getName()));
}
List<Map<String, String>> events = eventStore.getEventsGrid(params, organisationUnits);
for (Map<String, String> event : events) {
grid.addRow();
for (String col : STATIC_EVENT_COLUMNS) {
grid.addValue(event.get(col));
}
for (QueryItem item : params.getDataElements()) {
grid.addValue(event.get(item.getItemId()));
}
}
Map<String, Object> metaData = new HashMap<>();
if (params.isPaging()) {
final Pager pager;
if (params.isTotalPages()) {
int count = eventStore.getEventCount(params, organisationUnits);
pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
} else {
pager = handleLastPageFlag(params, grid);
}
metaData.put(PAGER_META_KEY, pager);
}
grid.setMetaData(metaData);
return grid;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class InputUtils method getAttributeOptionCombo.
/**
* Validates and retrieves the attribute option combo. 409 conflict as
* status code along with a textual message will be set on the response in
* case of invalid input.
*
* @param categoryCombo the category combo.
* @param opts list of category option uid.
* @param attributeOptionCombo the explicit attribute option combo
* identifier.
* @return the attribute option combo identified from the given input, or
* null if the input was invalid.
*/
public CategoryOptionCombo getAttributeOptionCombo(CategoryCombo categoryCombo, Set<String> opts, String attributeOptionCombo, IdScheme idScheme) {
if (categoryCombo == null) {
throw new IllegalQueryException("Illegal category combo");
}
// ---------------------------------------------------------------------
// Attribute category options validation
// ---------------------------------------------------------------------
CategoryOptionCombo attrOptCombo = null;
if (opts != null) {
Set<CategoryOption> categoryOptions = new HashSet<>();
for (String uid : opts) {
CategoryOption categoryOption = idObjectManager.getObject(CategoryOption.class, idScheme, uid);
if (categoryOption == null) {
throw new IllegalQueryException("Illegal category option identifier: " + uid);
}
categoryOptions.add(categoryOption);
}
attrOptCombo = categoryService.getCategoryOptionCombo(categoryCombo, categoryOptions);
if (attrOptCombo == null) {
throw new IllegalQueryException("Attribute option combo does not exist for given category combo and category options");
}
} else if (attributeOptionCombo != null) {
attrOptCombo = categoryService.getCategoryOptionCombo(attributeOptionCombo);
}
if (attrOptCombo == null) {
attrOptCombo = categoryService.getDefaultCategoryOptionCombo();
}
if (attrOptCombo == null) {
throw new IllegalQueryException("Default attribute option combo does not exist");
}
return attrOptCombo;
}
Aggregations