use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class AbstractEnrollmentService method checkAttributes.
private void checkAttributes(org.hisp.dhis.trackedentity.TrackedEntityInstance trackedEntityInstance, Enrollment enrollment, ImportOptions importOptions, ImportConflicts importConflicts) {
Map<TrackedEntityAttribute, Boolean> mandatoryMap = Maps.newHashMap();
Map<String, String> attributeValueMap = Maps.newHashMap();
Program program = getProgram(importOptions.getIdSchemes(), enrollment.getProgram());
for (ProgramTrackedEntityAttribute programTrackedEntityAttribute : program.getProgramAttributes()) {
mandatoryMap.put(programTrackedEntityAttribute.getAttribute(), programTrackedEntityAttribute.isMandatory());
}
// ignore attributes which do not belong to this program
trackedEntityInstance.getTrackedEntityAttributeValues().stream().filter(value -> mandatoryMap.containsKey(value.getAttribute())).forEach(value -> attributeValueMap.put(value.getAttribute().getUid(), value.getValue()));
for (Attribute attribute : enrollment.getAttributes()) {
attributeValueMap.put(attribute.getAttribute(), attribute.getValue());
validateAttributeType(attribute, importOptions, importConflicts);
}
List<String> errors = trackerAccessManager.canRead(importOptions.getUser(), trackedEntityInstance);
if (!errors.isEmpty()) {
throw new IllegalQueryException(errors.toString());
}
checkAttributeForMandatoryMaxLengthAndUniqueness(trackedEntityInstance, importOptions, importConflicts, mandatoryMap, attributeValueMap);
if (!attributeValueMap.isEmpty()) {
importConflicts.addConflict(ATTRIBUTE_ATTRIBUTE, "Only program attributes is allowed for enrollment " + attributeValueMap);
}
if (!program.getSelectEnrollmentDatesInFuture()) {
if (Objects.nonNull(enrollment.getEnrollmentDate()) && enrollment.getEnrollmentDate().after(new Date())) {
importConflicts.addConflict("Enrollment.date", "Enrollment Date can't be future date :" + enrollment.getEnrollmentDate());
}
}
if (!program.getSelectIncidentDatesInFuture()) {
if (Objects.nonNull(enrollment.getIncidentDate()) && enrollment.getIncidentDate().after(new Date())) {
importConflicts.addConflict("Enrollment.incidentDate", "Incident Date can't be future date :" + enrollment.getIncidentDate());
}
}
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class AttributeOptionComboLoader method getAttributeOptionCombo.
private 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 = getCategoryOption(idScheme, uid);
if (categoryOption == null) {
throw new IllegalQueryException("Illegal category option identifier: " + uid);
}
categoryOptions.add(categoryOption);
}
final String id = resolveCategoryComboId(categoryCombo, idScheme);
attrOptCombo = getAttributeOptionCombo(idScheme, id, 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 = getCategoryOptionCombo(idScheme, attributeOptionCombo);
}
if (attrOptCombo == null) {
attrOptCombo = getDefault();
}
if (attrOptCombo == null) {
throw new IllegalQueryException("Default attribute option combo does not exist");
}
return attrOptCombo;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DefaultEventQueryValidator method validate.
// -------------------------------------------------------------------------
// EventQueryValidator implementation
// -------------------------------------------------------------------------
@Override
public void validate(EventQueryParams params) throws IllegalQueryException, MaintenanceModeException {
queryValidator.validateMaintenanceMode();
ErrorMessage error = validateForErrorMessage(params);
if (error != null) {
log.warn(String.format("Event analytics validation failed, code: '%s', message: '%s'", error.getErrorCode(), error.getMessage()));
throw new IllegalQueryException(error);
}
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DefaultEventDataQueryService method getValueDimension.
private DimensionalItemObject getValueDimension(String value) {
if (value == null) {
return null;
}
DataElement de = dataElementService.getDataElement(value);
if (de != null && de.isNumericType()) {
return de;
}
TrackedEntityAttribute at = attributeService.getTrackedEntityAttribute(value);
if (at != null && at.isNumericType()) {
return at;
}
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E7223, value));
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DefaultProgramInstanceService method validate.
@Override
public void validate(ProgramInstanceQueryParams params) throws IllegalQueryException {
String violation = null;
if (params == null) {
throw new IllegalQueryException("Params cannot be null");
}
User user = params.getUser();
if (!params.hasOrganisationUnits() && !(params.isOrganisationUnitMode(ALL) || params.isOrganisationUnitMode(ACCESSIBLE))) {
violation = "At least one organisation unit must be specified";
}
if (params.isOrganisationUnitMode(ACCESSIBLE) && (user == null || !user.hasDataViewOrganisationUnitWithFallback())) {
violation = "Current user must be associated with at least one organisation unit when selection mode is ACCESSIBLE";
}
if (params.hasProgram() && params.hasTrackedEntityType()) {
violation = "Program and tracked entity cannot be specified simultaneously";
}
if (params.hasProgramStatus() && !params.hasProgram()) {
violation = "Program must be defined when program status is defined";
}
if (params.hasFollowUp() && !params.hasProgram()) {
violation = "Program must be defined when follow up status is defined";
}
if (params.hasProgramStartDate() && !params.hasProgram()) {
violation = "Program must be defined when program start date is specified";
}
if (params.hasProgramEndDate() && !params.hasProgram()) {
violation = "Program must be defined when program end date is specified";
}
if (params.hasLastUpdated() && params.hasLastUpdatedDuration()) {
violation = "Last updated and last updated duration cannot be specified simultaneously";
}
if (params.hasLastUpdatedDuration() && DateUtils.getDuration(params.getLastUpdatedDuration()) == null) {
violation = "Duration is not valid: " + params.getLastUpdatedDuration();
}
if (violation != null) {
log.warn("Validation failed: " + violation);
throw new IllegalQueryException(violation);
}
}
Aggregations