Search in sources :

Example 71 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class AnalyticsSecurityManagerTest method testDataViewMaxOrganisationUnitLevel.

@Test
void testDataViewMaxOrganisationUnitLevel() {
    DataQueryParams params = DataQueryParams.newBuilder().withPeriods(Lists.newArrayList(createPeriod("201801"), createPeriod("201802"))).withOrganisationUnits(Lists.newArrayList(ouD)).build();
    IllegalQueryException ex = assertThrows(IllegalQueryException.class, () -> securityManager.decideAccess(params));
    assertEquals(ErrorCode.E7120, ex.getErrorCode());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Test(org.junit.jupiter.api.Test)

Example 72 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class AnalyticsSecurityManagerTest method testDataViewOrganisationUnits.

@Test
void testDataViewOrganisationUnits() {
    DataQueryParams params = DataQueryParams.newBuilder().withPeriods(Lists.newArrayList(createPeriod("201801"), createPeriod("201802"))).withOrganisationUnits(Lists.newArrayList(ouF)).build();
    IllegalQueryException ex = assertThrows(IllegalQueryException.class, () -> securityManager.decideAccess(params));
    assertEquals(ErrorCode.E7120, ex.getErrorCode());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Test(org.junit.jupiter.api.Test)

Example 73 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class DefaultProgramMessageService method hasAccess.

@Override
@Transactional(readOnly = true)
public void hasAccess(ProgramMessageQueryParams params, User user) {
    ProgramInstance programInstance = null;
    Set<Program> programs;
    if (params.hasProgramInstance()) {
        programInstance = params.getProgramInstance();
    }
    if (params.hasProgramStageInstance()) {
        programInstance = params.getProgramStageInstance().getProgramInstance();
    }
    if (programInstance == null) {
        throw new IllegalQueryException("ProgramInstance or ProgramStageInstance has to be provided");
    }
    programs = new HashSet<>(programService.getUserPrograms(user));
    if (user != null && !programs.contains(programInstance.getProgram())) {
        throw new IllegalQueryException("User does not have access to the required program");
    }
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 74 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class DefaultProgramInstanceService method incompleteProgramInstanceStatus.

@Override
@Transactional
public void incompleteProgramInstanceStatus(ProgramInstance programInstance) {
    Program program = programInstance.getProgram();
    TrackedEntityInstance tei = programInstance.getEntityInstance();
    if (getProgramInstances(tei, program, ProgramStatus.ACTIVE).size() > 0) {
        log.warn("Program has another active enrollment going on. Not possible to incomplete");
        throw new IllegalQueryException("Program has another active enrollment going on. Not possible to incomplete");
    }
    // -----------------------------------------------------------------
    // Update program-instance
    // -----------------------------------------------------------------
    programInstance.setStatus(ProgramStatus.ACTIVE);
    programInstance.setEndDate(null);
    updateProgramInstance(programInstance);
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Transactional(org.springframework.transaction.annotation.Transactional)

Example 75 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class OutlierDetectionServiceValidationTest method testErrorValidation.

@Test
void testErrorValidation() {
    OutlierDetectionRequest request = new OutlierDetectionRequest.Builder().withDataElements(Lists.newArrayList(deA, deB, deC)).withStartEndDate(getDate(2020, 1, 1), getDate(2020, 3, 1)).build();
    IllegalQueryException ex = assertThrows(IllegalQueryException.class, () -> subject.validate(request));
    assertEquals(ErrorCode.E2203, ex.getErrorCode());
}
Also used : OutlierDetectionRequest(org.hisp.dhis.outlierdetection.OutlierDetectionRequest) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Test(org.junit.jupiter.api.Test)

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