use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class TrackedEntityCriteriaMapperTest method verifyCriteriaMappingFailOnMissingOrgUnit.
@Test
void verifyCriteriaMappingFailOnMissingOrgUnit() {
TrackedEntityInstanceCriteria criteria = new TrackedEntityInstanceCriteria();
criteria.setOu(organisationUnit.getUid() + "A");
IllegalQueryException e = assertThrows(IllegalQueryException.class, () -> trackedEntityCriteriaMapper.map(criteria));
assertEquals("Organisation unit does not exist: " + organisationUnit.getUid() + "A", e.getMessage());
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class TrackedEntityCriteriaMapperTest method verifyCriteriaMappingFailOnMissingFilter.
@Test
void verifyCriteriaMappingFailOnMissingFilter() {
TrackedEntityInstanceCriteria criteria = new TrackedEntityInstanceCriteria();
criteria.setFilter(newHashSet(filtF.getUid(), filtG.getUid(), "missing"));
IllegalQueryException e = assertThrows(IllegalQueryException.class, () -> trackedEntityCriteriaMapper.map(criteria));
assertEquals("Attribute does not exist: missing", e.getMessage());
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class TrackedEntityCriteriaMapperTest method verifyCriteriaMappingFailOnUserNonInOuHierarchy.
@Test
void verifyCriteriaMappingFailOnUserNonInOuHierarchy() {
// Force Current User Service to return a User without search org unit
ReflectionTestUtils.setField(trackedEntityCriteriaMapper, "currentUserService", new MockCurrentUserService(createUser("testUser2")));
TrackedEntityInstanceCriteria criteria = new TrackedEntityInstanceCriteria();
criteria.setOu(organisationUnit.getUid());
IllegalQueryException e = assertThrows(IllegalQueryException.class, () -> trackedEntityCriteriaMapper.map(criteria));
assertEquals("Organisation unit is not part of the search scope: " + organisationUnit.getUid(), e.getMessage());
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class TrackedEntityCriteriaMapperTest method verifyCriteriaMappingFailOnMissingTrackerEntityType.
@Test
void verifyCriteriaMappingFailOnMissingTrackerEntityType() {
TrackedEntityInstanceCriteria criteria = new TrackedEntityInstanceCriteria();
criteria.setTrackedEntityType(trackedEntityTypeA.getUid() + "A");
IllegalQueryException e = assertThrows(IllegalQueryException.class, () -> trackedEntityCriteriaMapper.map(criteria));
assertEquals("Tracked entity type does not exist: " + trackedEntityTypeA.getUid() + "A", e.getMessage());
}
use of org.hisp.dhis.common.IllegalQueryException 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()));
}
}
Aggregations