use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DefaultProgramInstanceService method prepareProgramInstance.
@Override
@Transactional
public ProgramInstance prepareProgramInstance(TrackedEntityInstance trackedEntityInstance, Program program, ProgramStatus programStatus, Date enrollmentDate, Date incidentDate, OrganisationUnit organisationUnit, String uid) {
if (program.getTrackedEntityType() != null && !program.getTrackedEntityType().equals(trackedEntityInstance.getTrackedEntityType())) {
throw new IllegalQueryException("Tracked entity instance must have same tracked entity as program: " + program.getUid());
}
ProgramInstance programInstance = new ProgramInstance();
programInstance.setUid(CodeGenerator.isValidUid(uid) ? uid : CodeGenerator.generateUid());
programInstance.setOrganisationUnit(organisationUnit);
programInstance.enrollTrackedEntityInstance(trackedEntityInstance, program);
if (enrollmentDate != null) {
programInstance.setEnrollmentDate(enrollmentDate);
} else {
programInstance.setEnrollmentDate(new Date());
}
if (incidentDate != null) {
programInstance.setIncidentDate(incidentDate);
} else {
programInstance.setIncidentDate(new Date());
}
programInstance.setStatus(programStatus);
return programInstance;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class FilteringHelper method extractValueTypeFromEqualFilter.
/**
* This method will return the respective ValueType from the filter
* provided.
*
* @param filter should have the format of "valueType:eq:NUMBER", where
* NUMBER represents the ValueType. It could be any value represented
* by {@link ValueType}
* @return the respective value type associated with the given filter
* @throws IllegalQueryException if the filter points to a non supported
* value type
*/
private static String extractValueTypeFromEqualFilter(final String filter) {
final byte VALUE_TYPE = 2;
String valueType = null;
if (filterHasPrefix(filter, VALUE_TYPE_EQUAL.getCombination())) {
final String[] array = filter.split(":");
final boolean hasValueType = array.length == 3;
if (hasValueType) {
valueType = getValueTypeOrThrow(array[VALUE_TYPE]);
} else {
throw new IllegalQueryException(new ErrorMessage(E2014, filter));
}
}
return valueType;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DataValidator method getAndValidateOrganisationUnit.
/**
* Retrieves and verifies an organisation unit.
*
* @param uid the organisation unit identifier.
* @return the {@link OrganisationUnit}.
* @throws IllegalQueryException if the validation fails.
*/
public OrganisationUnit getAndValidateOrganisationUnit(final String uid) {
final OrganisationUnit organisationUnit = idObjectManager.get(OrganisationUnit.class, uid);
if (organisationUnit == null) {
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E1102, uid));
}
final boolean isInHierarchy = organisationUnitService.isInUserHierarchyCached(organisationUnit);
if (!isInHierarchy) {
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E2020, uid));
}
return organisationUnit;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DataValidator method getAndValidateDataValue.
/**
* Validates and retrieves a data value.
*
* @param dataValueRequest the {@link DataValueFollowUpRequest}.
* @return a data value.
* @throws IllegalQueryException if the validation fails.
*/
public DataValue getAndValidateDataValue(DataValueFollowUpRequest dataValueRequest) {
DataElement dataElement = getAndValidateDataElement(dataValueRequest.getDataElement());
Period period = PeriodType.getPeriodFromIsoString(dataValueRequest.getPeriod());
OrganisationUnit orgUnit = getAndValidateOrganisationUnit(dataValueRequest.getOrgUnit());
CategoryOptionCombo categoryOptionCombo = getAndValidateCategoryOptionCombo(dataValueRequest.getCategoryOptionCombo(), false);
CategoryOptionCombo attributeOptionCombo = getAndValidateCategoryOptionCombo(dataValueRequest.getAttributeOptionCombo(), false);
DataValue dataValue = dataValueService.getDataValue(dataElement, period, orgUnit, categoryOptionCombo, attributeOptionCombo);
if (dataValue == null) {
throw new IllegalQueryException(ErrorCode.E2032);
}
return dataValue;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DataValidator method validateAndSetAssigned.
/**
* Validates if the given file resource uid has a valid FileResource
* associated with.
*
* @param fileResourceUid the uid of the FileResource.
* @param valueType
* @param valueTypeOptions
* @return a valid FileResource.
* @throws WebMessageException if any validation fails.
*/
public FileResource validateAndSetAssigned(final String fileResourceUid, ValueType valueType, ValueTypeOptions valueTypeOptions) throws WebMessageException {
Preconditions.checkNotNull(fileResourceUid);
final FileResource fileResource = fileResourceService.getFileResource(fileResourceUid);
if (fileResource == null || fileResource.getDomain() != DATA_VALUE) {
throw new WebMessageException(notFound(FileResource.class, fileResourceUid));
}
if (fileResource.isAssigned()) {
throw new IllegalQueryException(ErrorCode.E2026);
}
if (valueType != null && valueTypeOptions != null) {
String validationResult = dataValueIsValid(fileResource, valueType, valueTypeOptions);
if (validationResult != null) {
fileResourceService.deleteFileResource(fileResource);
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E2027, validationResult));
}
}
fileResource.setAssigned(true);
return fileResource;
}
Aggregations