Search in sources :

Example 81 with IllegalQueryException

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());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstanceCriteria(org.hisp.dhis.webapi.controller.event.webrequest.TrackedEntityInstanceCriteria) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.jupiter.api.Test)

Example 82 with IllegalQueryException

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());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstanceCriteria(org.hisp.dhis.webapi.controller.event.webrequest.TrackedEntityInstanceCriteria) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.jupiter.api.Test)

Example 83 with IllegalQueryException

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());
}
Also used : MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstanceCriteria(org.hisp.dhis.webapi.controller.event.webrequest.TrackedEntityInstanceCriteria) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.jupiter.api.Test)

Example 84 with IllegalQueryException

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());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstanceCriteria(org.hisp.dhis.webapi.controller.event.webrequest.TrackedEntityInstanceCriteria) DhisWebSpringTest(org.hisp.dhis.webapi.DhisWebSpringTest) Test(org.junit.jupiter.api.Test)

Example 85 with IllegalQueryException

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()));
    }
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) Date(java.util.Date)

Aggregations

IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)98 Test (org.junit.jupiter.api.Test)26 ErrorMessage (org.hisp.dhis.feedback.ErrorMessage)22 HashSet (java.util.HashSet)17 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)17 User (org.hisp.dhis.user.User)14 QueryItem (org.hisp.dhis.common.QueryItem)13 ArrayList (java.util.ArrayList)12 Date (java.util.Date)11 Program (org.hisp.dhis.program.Program)11 QueryFilter (org.hisp.dhis.common.QueryFilter)10 TrackedEntityInstanceCriteria (org.hisp.dhis.webapi.controller.event.webrequest.TrackedEntityInstanceCriteria)10 Transactional (org.springframework.transaction.annotation.Transactional)10 QueryOperator (org.hisp.dhis.common.QueryOperator)9 List (java.util.List)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 DataElement (org.hisp.dhis.dataelement.DataElement)8 DhisWebSpringTest (org.hisp.dhis.webapi.DhisWebSpringTest)7 Map (java.util.Map)6 Set (java.util.Set)6