use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class DataValidator method validateOrganisationUnitPeriod.
/**
* Validates the OrganisationUnit dates against the given period.
*
* @param organisationUnit the {@link OrganisationUnit} and its dates.
* @param period the {@link Period} to be checked.
* @throws IllegalQueryException if the validation fails.
*/
public void validateOrganisationUnitPeriod(final OrganisationUnit organisationUnit, final Period period) {
final Date openingDate = organisationUnit.getOpeningDate();
final Date closedDate = organisationUnit.getClosedDate();
final Date startDate = period.getStartDate();
final Date endDate = period.getEndDate();
if ((closedDate != null && closedDate.before(startDate)) || openingDate.after(endDate)) {
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E2019, organisationUnit.getUid()));
}
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class DataValidator method validateAndNormalizeDataValue.
/**
* Validates if the given data value is valid for the given DataElement, and
* normalize it if the dataValue is a boolean type.
*
* @param dataValue the data value.
* @param dataElement the {@link DataElement}.
* @return the normalized boolean or the same dataValue provided.
* @throws IllegalQueryException if the validation fails.
*/
public String validateAndNormalizeDataValue(final String dataValue, final DataElement dataElement) {
final String normalizedBoolean = normalizeBoolean(dataValue, dataElement.getValueType());
final String valueValid = dataValueIsValid(normalizedBoolean, dataElement);
if (valueValid != null) {
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E2030, dataElement.getValueType()));
}
return normalizedBoolean;
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class FilteringHelper method extractEntityFromEqualFilter.
/**
* This method will return the respective BaseDimensionalItemObject class
* from the filter provided.
*
* @param filter should have the format of "dimensionItemType:eq:INDICATOR",
* where INDICATOR represents the BaseDimensionalItemObject. It could
* be any value represented by
* {@link org.hisp.dhis.common.DataDimensionItemType}
* @return the respective class associated with the given filter
* @throws IllegalQueryException if the filter points to a non supported
* class/entity
*/
public static Class<? extends BaseIdentifiableObject> extractEntityFromEqualFilter(final String filter) {
final byte DIMENSION_TYPE = 2;
Class<? extends BaseIdentifiableObject> entity = null;
if (filterHasPrefix(filter, DIMENSION_TYPE_EQUAL.getCombination())) {
final String[] dimensionFilterPair = filter.split(":");
final boolean hasDimensionType = dimensionFilterPair.length == 3;
if (hasDimensionType) {
entity = entityClassFromString(dimensionFilterPair[DIMENSION_TYPE]);
} else {
throw new IllegalQueryException(new ErrorMessage(E2014, filter));
}
}
return entity;
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class JobConfigurationController method executeJobConfiguration.
@PostMapping(value = "{uid}/execute", produces = { APPLICATION_JSON_VALUE, "application/javascript" })
public ObjectReport executeJobConfiguration(@PathVariable("uid") String uid) throws WebMessageException {
JobConfiguration jobConfiguration = jobConfigurationService.getJobConfigurationByUid(uid);
checkConfigurable(jobConfiguration, HttpStatus.FORBIDDEN, "Job %s is a system job that cannot be executed.");
ObjectReport objectReport = new ObjectReport(JobConfiguration.class, 0);
boolean success = schedulingManager.executeNow(jobConfiguration);
if (!success) {
objectReport.addErrorReport(new ErrorReport(JobConfiguration.class, new ErrorMessage(ErrorCode.E7006, jobConfiguration.getName())));
}
return objectReport;
}
Aggregations