Search in sources :

Example 21 with CurrentUserServiceTarget

use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.

the class DataValueSetServiceTest method setUpTest.

@Override
public void setUpTest() {
    CategoryOptionCombo categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
    userService = _userService;
    mockDataValueBatchHandler = new MockBatchHandler<>();
    mockDataValueAuditBatchHandler = new MockBatchHandler<>();
    mockBatchHandlerFactory = new MockBatchHandlerFactory();
    mockBatchHandlerFactory.registerBatchHandler(DataValueBatchHandler.class, mockDataValueBatchHandler);
    mockBatchHandlerFactory.registerBatchHandler(DataValueAuditBatchHandler.class, mockDataValueAuditBatchHandler);
    setDependency(BatchHandlerFactoryTarget.class, BatchHandlerFactoryTarget::setBatchHandlerFactory, mockBatchHandlerFactory, dataValueSetService);
    attribute = new Attribute("CUSTOM_ID", ValueType.TEXT);
    attribute.setUid(ATTRIBUTE_UID);
    attribute.setUnique(true);
    attribute.setOrganisationUnitAttribute(true);
    attribute.setDataElementAttribute(true);
    idObjectManager.save(attribute);
    categoryOptionA = createCategoryOption('A');
    categoryOptionB = createCategoryOption('B');
    categoryA = createCategory('A');
    categoryService.addCategory(categoryA);
    categoryOptionA.getCategories().add(categoryA);
    categoryOptionB.getCategories().add(categoryA);
    categoryService.addCategoryOption(categoryOptionB);
    categoryService.addCategoryOption(categoryOptionA);
    categoryComboA = createCategoryCombo('A', categoryA);
    categoryComboDef = categoryService.getDefaultCategoryCombo();
    ocDef = categoryService.getDefaultCategoryOptionCombo();
    ocDef.setCode("OC_DEF_CODE");
    categoryService.updateCategoryOptionCombo(ocDef);
    osA = new OptionSet("OptionSetA", ValueType.INTEGER);
    osA.getOptions().add(new Option("Blue", "1"));
    osA.getOptions().add(new Option("Green", "2"));
    osA.getOptions().add(new Option("Yellow", "3"));
    ocA = createCategoryOptionCombo(categoryComboA, categoryOptionA);
    ocB = createCategoryOptionCombo(categoryComboA, categoryOptionB);
    deA = createDataElement('A', categoryComboDef);
    deB = createDataElement('B', categoryComboDef);
    deC = createDataElement('C', categoryComboDef);
    deD = createDataElement('D', categoryComboDef);
    deE = createDataElement('E');
    deE.setOptionSet(osA);
    deF = createDataElement('F', categoryComboDef);
    deF.setValueType(ValueType.BOOLEAN);
    deG = createDataElement('G', categoryComboDef);
    deG.setValueType(ValueType.TRUE_ONLY);
    dsA = createDataSet('A', new MonthlyPeriodType());
    dsA.setCategoryCombo(categoryComboDef);
    dsB = createDataSet('B');
    dsB.setCategoryCombo(categoryComboDef);
    ouA = createOrganisationUnit('A');
    ouB = createOrganisationUnit('B');
    ouC = createOrganisationUnit('C');
    peA = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2012, 1, 1), getDate(2012, 1, 31));
    peB = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2012, 2, 1), getDate(2012, 2, 29));
    peC = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2012, 3, 1), getDate(2012, 3, 31));
    ocA.setUid("kjuiHgy67hg");
    ocB.setUid("Gad33qy67g5");
    deA.setUid("f7n9E0hX8qk");
    deB.setUid("Ix2HsbDMLea");
    deC.setUid("eY5ehpbEsB7");
    deE.setUid("jH26dja2f28");
    deF.setUid("jH26dja2f30");
    deG.setUid("jH26dja2f31");
    dsA.setUid("pBOMPrpg1QX");
    ouA.setUid("DiszpKrYNg8");
    ouB.setUid("BdfsJfj87js");
    ouC.setUid("j7Hg26FpoIa");
    ocA.setCode("OC_A");
    ocB.setCode("OC_B");
    deA.setCode("DE_A");
    deB.setCode("DE_B");
    deC.setCode("DE_C");
    deD.setCode("DE_D");
    dsA.setCode("DS_A");
    ouA.setCode("OU_A");
    ouB.setCode("OU_B");
    ouC.setCode("OU_C");
    categoryService.addCategoryCombo(categoryComboA);
    categoryService.addCategoryOptionCombo(ocA);
    categoryService.addCategoryOptionCombo(ocB);
    AttributeValue av1 = createAttributeValue(attribute, "DE1");
    dataElementService.addDataElement(deA);
    dataElementService.addDataElement(deB);
    dataElementService.addDataElement(deC);
    dataElementService.addDataElement(deD);
    dataElementService.addDataElement(deF);
    dataElementService.addDataElement(deG);
    attributeService.addAttributeValue(deA, av1);
    attributeService.addAttributeValue(deB, createAttributeValue(attribute, "DE2"));
    attributeService.addAttributeValue(deC, createAttributeValue(attribute, "DE3"));
    attributeService.addAttributeValue(deD, createAttributeValue(attribute, "DE4"));
    idObjectManager.save(osA);
    dsA.addDataSetElement(deA);
    dsA.addDataSetElement(deB);
    dsA.addDataSetElement(deC);
    dsA.addDataSetElement(deD);
    organisationUnitService.addOrganisationUnit(ouA);
    organisationUnitService.addOrganisationUnit(ouB);
    organisationUnitService.addOrganisationUnit(ouC);
    attributeService.addAttributeValue(ouA, createAttributeValue(attribute, "OU1"));
    attributeService.addAttributeValue(ouB, createAttributeValue(attribute, "OU2"));
    attributeService.addAttributeValue(ouC, createAttributeValue(attribute, "OU3"));
    dsA.addOrganisationUnit(ouA);
    dsA.addOrganisationUnit(ouC);
    periodService.addPeriod(peA);
    periodService.addPeriod(peB);
    periodService.addPeriod(peC);
    dataSetService.addDataSet(dsA);
    user = createUser('A', Lists.newArrayList(Authorities.F_SKIP_DATA_IMPORT_AUDIT.getAuthority()));
    user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
    userService.addUser(user);
    injectSecurityContext(user);
    CurrentUserService currentUserService = new MockCurrentUserService(user);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataValueSetService);
    enableDataSharing(user, dsA, AccessStringHelper.DATA_READ_WRITE);
    enableDataSharing(user, categoryOptionA, AccessStringHelper.DATA_READ_WRITE);
    enableDataSharing(user, categoryOptionB, AccessStringHelper.DATA_READ_WRITE);
    _userService.addUser(user);
    CompleteDataSetRegistration completeDataSetRegistration = new CompleteDataSetRegistration(dsA, peA, ouA, categoryOptionCombo, getDate(2012, 1, 9), "userA", new Date(), "userA", true);
    registrationService.saveCompleteDataSetRegistration(completeDataSetRegistration);
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) Attribute(org.hisp.dhis.attribute.Attribute) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) Date(java.util.Date) MockBatchHandlerFactory(org.hisp.dhis.mock.batchhandler.MockBatchHandlerFactory) BatchHandlerFactoryTarget(org.hisp.dhis.common.BatchHandlerFactoryTarget) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CategoryOption(org.hisp.dhis.category.CategoryOption) Option(org.hisp.dhis.option.Option) CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) OptionSet(org.hisp.dhis.option.OptionSet) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 22 with CurrentUserServiceTarget

use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.

the class PredictionServiceTest method testPredictSequentialStddevPopWithLimitedUser.

@Test
void testPredictSequentialStddevPopWithLimitedUser() {
    setupTestData();
    Set<OrganisationUnit> units = newHashSet(sourceA);
    CurrentUserService mockCurrentUserService = new MockCurrentUserService(true, units, units);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, mockCurrentUserService, predictionService);
    Predictor p = createPredictor(dataElementX, defaultCombo, "PredictSequential", expressionH, null, periodTypeMonthly, orgUnitLevel1, 3, 1, 0);
    predictionService.predict(p, monthStart(2001, 7), monthStart(2001, 12), summary);
    assertEquals("Pred 1 Ins 4 Upd 0 Del 0 Unch 0", shortSummary(summary));
    assertEquals("5.0", getDataValue(dataElementX, defaultCombo, sourceA, makeMonth(2001, 8)));
    assertEquals("5.5", getDataValue(dataElementX, defaultCombo, sourceA, makeMonth(2001, 9)));
    assertEquals("9.25", getDataValue(dataElementX, defaultCombo, sourceA, makeMonth(2001, 10)));
    assertEquals("9.0", getDataValue(dataElementX, defaultCombo, sourceA, makeMonth(2001, 11)));
    // Make sure we can do it again.
    summary = new PredictionSummary();
    predictionService.predict(p, monthStart(2001, 7), monthStart(2001, 12), summary);
    assertEquals("Pred 1 Ins 0 Upd 0 Del 0 Unch 4", shortSummary(summary));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) Test(org.junit.jupiter.api.Test)

Example 23 with CurrentUserServiceTarget

use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.

the class EventPredictionServiceTest method setUpTest.

@Override
public void setUpTest() {
    final String DATA_ELEMENT_A_UID = "DataElemenA";
    final String DATA_ELEMENT_D_UID = "DataElemenD";
    final String DATA_ELEMENT_I_UID = "DataElemenI";
    final String DATA_ELEMENT_E_UID = "DataElemenE";
    final String DATA_ELEMENT_T_UID = "DataElemenT";
    final String DATA_ELEMENT_X_UID = "DataElemenX";
    final String TRACKED_ENTITY_ATTRIBUTE_UID = "TEAttribute";
    final String PROGRAM_UID = "ProgramUidA";
    final String PROGRAM_INDICATOR_A_UID = "ProgramIndA";
    final String PROGRAM_INDICATOR_B_UID = "ProgramIndB";
    final String PROGRAM_TRACKED_ENTITY_ATTRIBUTE_DIMENSION_ITEM = PROGRAM_UID + SEPARATOR + TRACKED_ENTITY_ATTRIBUTE_UID;
    final String PROGRAM_DATA_ELEMENT_DIMENSION_ITEM = PROGRAM_UID + SEPARATOR + DATA_ELEMENT_X_UID;
    // A
    final String EXPRESSION_A = "sum( A{" + PROGRAM_TRACKED_ENTITY_ATTRIBUTE_DIMENSION_ITEM + "} )";
    // -
    // ProgramTrackedEntityAttribute
    // D
    final String EXPRESSION_D = "sum( D{" + PROGRAM_DATA_ELEMENT_DIMENSION_ITEM + "} )";
    // -
    // ProgramDataElement
    // I
    final String EXPRESSION_I = "sum( I{" + PROGRAM_INDICATOR_A_UID + "} + I{" + PROGRAM_INDICATOR_B_UID + "} )";
    // -
    // ProgramIndicators
    // E
    final String EXPRESSION_E = "sum( #{" + DATA_ELEMENT_E_UID + "} )";
    // -
    // Data
    // element
    // T -
    final String EXPRESSION_T = EXPRESSION_A + " + " + EXPRESSION_E;
    // Two
    // things,
    // event
    // and
    // data
    // elemeent
    // Program
    final String EX_INDICATOR_A = "#{" + PROGRAM_DATA_ELEMENT_DIMENSION_ITEM + "} + 4";
    // Indicator
    // A
    // expression
    // Program
    final String EX_INDICATOR_B = "V{enrollment_count}";
    // Indicator B
    // expression
    defaultCombo = categoryService.getDefaultCategoryOptionCombo();
    orgUnitA = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(orgUnitA);
    Set<OrganisationUnit> orgUnitASet = Sets.newHashSet(orgUnitA);
    PeriodType periodTypeMonthly = new MonthlyPeriodType();
    testYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
    periodMar = createPeriod(periodTypeMonthly, getDate(testYear, 3, 1), getDate(testYear, 3, 31));
    periodApr = createPeriod(periodTypeMonthly, getDate(testYear, 4, 1), getDate(testYear, 4, 30));
    periodMay = createPeriod(periodTypeMonthly, getDate(testYear, 5, 1), getDate(testYear, 5, 31));
    periodService.addPeriod(periodMar);
    periodService.addPeriod(periodApr);
    periodService.addPeriod(periodMay);
    Date dateMar20 = getDate(testYear, 3, 20);
    Date dateApr10 = getDate(testYear, 4, 10);
    predictorOutputA = createDataElement('A');
    predictorOutputD = createDataElement('D');
    predictorOutputI = createDataElement('I');
    predictorOutputT = createDataElement('T');
    DataElement dataElementE = createDataElement('E');
    DataElement dataElementX = createDataElement('P', ValueType.INTEGER, AggregationType.SUM, DataElementDomain.TRACKER);
    predictorOutputA.setUid(DATA_ELEMENT_A_UID);
    predictorOutputD.setUid(DATA_ELEMENT_D_UID);
    predictorOutputI.setUid(DATA_ELEMENT_I_UID);
    predictorOutputT.setUid(DATA_ELEMENT_T_UID);
    dataElementE.setUid(DATA_ELEMENT_E_UID);
    dataElementX.setUid(DATA_ELEMENT_X_UID);
    dataElementService.addDataElement(predictorOutputA);
    dataElementService.addDataElement(predictorOutputD);
    dataElementService.addDataElement(predictorOutputI);
    dataElementService.addDataElement(predictorOutputT);
    dataElementService.addDataElement(dataElementE);
    dataElementService.addDataElement(dataElementX);
    TrackedEntityAttribute entityAttribute = createTrackedEntityAttribute('A');
    entityAttribute.setAggregationType(AggregationType.COUNT);
    entityAttribute.setUid(TRACKED_ENTITY_ATTRIBUTE_UID);
    entityAttributeService.addTrackedEntityAttribute(entityAttribute);
    TrackedEntityInstance entityInstance = createTrackedEntityInstance('A', orgUnitA, entityAttribute);
    entityInstanceService.addTrackedEntityInstance(entityInstance);
    TrackedEntityAttributeValue trackedEntityAttributeValue = new TrackedEntityAttributeValue(entityAttribute, entityInstance);
    trackedEntityAttributeValue.setValue("123");
    entityAttributeValueService.addTrackedEntityAttributeValue(trackedEntityAttributeValue);
    entityInstance.setTrackedEntityAttributeValues(Sets.newHashSet(trackedEntityAttributeValue));
    entityInstanceService.updateTrackedEntityInstance(entityInstance);
    Program program = createProgram('A', null, Sets.newHashSet(entityAttribute), orgUnitASet, null);
    program.setUid(PROGRAM_UID);
    programService.addProgram(program);
    ProgramStage stageA = createProgramStage('A', 0);
    stageA.setProgram(program);
    stageA.addDataElement(dataElementX, 1);
    programStageService.saveProgramStage(stageA);
    ProgramIndicator programIndicatorA = createProgramIndicator('A', program, EX_INDICATOR_A, null);
    programIndicatorA.setAggregationType(AggregationType.SUM);
    programIndicatorA.setUid(PROGRAM_INDICATOR_A_UID);
    programIndicatorService.addProgramIndicator(programIndicatorA);
    ProgramIndicator programIndicatorB = createProgramIndicator('B', program, EX_INDICATOR_B, null);
    programIndicatorB.setAnalyticsType(AnalyticsType.ENROLLMENT);
    programIndicatorB.setAggregationType(AggregationType.COUNT);
    programIndicatorB.setUid(PROGRAM_INDICATOR_B_UID);
    programIndicatorService.addProgramIndicator(programIndicatorB);
    program.setProgramStages(Sets.newHashSet(stageA));
    program.getProgramIndicators().add(programIndicatorA);
    program.getProgramIndicators().add(programIndicatorB);
    programService.updateProgram(program);
    ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, program, dateMar20, dateMar20, orgUnitA);
    programInstanceService.addProgramInstance(programInstance);
    ProgramStageInstance stageInstanceA = programStageInstanceService.createProgramStageInstance(programInstance, stageA, dateMar20, dateMar20, orgUnitA);
    ProgramStageInstance stageInstanceB = programStageInstanceService.createProgramStageInstance(programInstance, stageA, dateApr10, dateApr10, orgUnitA);
    stageInstanceA.setExecutionDate(dateMar20);
    stageInstanceB.setExecutionDate(dateApr10);
    stageInstanceA.setAttributeOptionCombo(defaultCombo);
    stageInstanceB.setAttributeOptionCombo(defaultCombo);
    programStageInstanceService.addProgramStageInstance(stageInstanceA);
    programStageInstanceService.addProgramStageInstance(stageInstanceB);
    categoryManager.addAndPruneAllOptionCombos();
    Expression expressionA = new Expression(EXPRESSION_A, "ProgramTrackedEntityAttribute");
    Expression expressionD = new Expression(EXPRESSION_D, "ProgramDataElement");
    Expression expressionI = new Expression(EXPRESSION_I, "ProgramIndicators");
    Expression expressionT = new Expression(EXPRESSION_T, "Two things");
    OrganisationUnitLevel orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
    organisationUnitService.addOrganisationUnitLevel(orgUnitLevel1);
    predictorA = createPredictor(predictorOutputA, defaultCombo, "A", expressionA, null, periodTypeMonthly, orgUnitLevel1, 2, 0, 0);
    predictorD = createPredictor(predictorOutputD, defaultCombo, "D", expressionD, null, periodTypeMonthly, orgUnitLevel1, 2, 0, 0);
    predictorI = createPredictor(predictorOutputI, defaultCombo, "I", expressionI, null, periodTypeMonthly, orgUnitLevel1, 2, 0, 0);
    predictorT = createPredictor(predictorOutputT, defaultCombo, "T", expressionT, null, periodTypeMonthly, orgUnitLevel1, 2, 0, 0);
    predictorService.addPredictor(predictorA);
    predictorService.addPredictor(predictorD);
    predictorService.addPredictor(predictorI);
    Map<String, Grid> itemGridMap = new HashMap<>();
    itemGridMap.put(PROGRAM_TRACKED_ENTITY_ATTRIBUTE_DIMENSION_ITEM, newGrid(PROGRAM_TRACKED_ENTITY_ATTRIBUTE_DIMENSION_ITEM, 1.0, 1.0));
    itemGridMap.put(PROGRAM_DATA_ELEMENT_DIMENSION_ITEM, newGrid(PROGRAM_DATA_ELEMENT_DIMENSION_ITEM, 4.0, 5.0));
    itemGridMap.put(PROGRAM_INDICATOR_A_UID, newGrid(PROGRAM_INDICATOR_A_UID, 8.0, 9.0));
    itemGridMap.put(PROGRAM_INDICATOR_B_UID, newGrid(PROGRAM_INDICATOR_B_UID, 10.0, 11.0));
    MockAnalyticsService mockAnalyticsSerivce = new MockAnalyticsService();
    mockAnalyticsSerivce.setItemGridMap(itemGridMap);
    setDependency(AnalyticsServiceTarget.class, AnalyticsServiceTarget::setAnalyticsService, mockAnalyticsSerivce, predictionService);
    CurrentUserService mockCurrentUserService = new MockCurrentUserService(true, orgUnitASet, orgUnitASet);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, mockCurrentUserService, predictionService);
    dataValueService.addDataValue(createDataValue(dataElementE, periodMar, orgUnitA, defaultCombo, defaultCombo, "100"));
    dataValueService.addDataValue(createDataValue(dataElementE, periodApr, orgUnitA, defaultCombo, defaultCombo, "200"));
    dataValueService.addDataValue(createDataValue(dataElementE, periodMay, orgUnitA, defaultCombo, defaultCombo, "300"));
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) HashMap(java.util.HashMap) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) AnalyticsServiceTarget(org.hisp.dhis.analytics.AnalyticsServiceTarget) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Date(java.util.Date) MockAnalyticsService(org.hisp.dhis.mock.MockAnalyticsService) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) Expression(org.hisp.dhis.expression.Expression) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 24 with CurrentUserServiceTarget

use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.

the class ValidationServiceTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    this.userService = injectUserService;
    CurrentUserService currentUserService = new MockCurrentUserService(allSources, null);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, validationService);
    ptWeekly = new WeeklyPeriodType();
    ptMonthly = new MonthlyPeriodType();
    ptYearly = new YearlyPeriodType();
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementC = createDataElement('C');
    dataElementD = createDataElement('D');
    dataElementE = createDataElement('E');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataElementService.addDataElement(dataElementD);
    dataElementService.addDataElement(dataElementE);
    CategoryOption optionX = createCategoryOption('X');
    Category categoryX = createCategory('X', optionX);
    categoryComboX = createCategoryCombo('X', categoryX);
    optionComboX = createCategoryOptionCombo(categoryComboX, optionX);
    categoryComboX.getOptionCombos().add(optionComboX);
    categoryService.addCategoryOption(optionX);
    categoryService.addCategory(categoryX);
    categoryService.addCategoryCombo(categoryComboX);
    categoryService.addCategoryOptionCombo(optionComboX);
    optionCombo = categoryService.getDefaultCategoryOptionCombo();
    String suffixX = SEPARATOR + optionComboX.getUid();
    String suffix = SEPARATOR + optionCombo.getUid();
    optionCombos = new HashSet<>();
    optionCombos.add(optionCombo);
    Expression expressionA = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA");
    Expression expressionA2 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA2");
    Expression expressionA3 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA3");
    Expression expressionA4 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA4");
    Expression expressionA5 = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA5");
    Expression expressionB = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB");
    Expression expressionB2 = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB2");
    Expression expressionB3 = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB3");
    Expression expressionC = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC");
    Expression expressionC2 = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC2");
    Expression expressionC3 = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC3");
    Expression expressionI = new Expression("#{" + dataElementA.getUid() + suffix + "}", "expressionI");
    Expression expressionI2 = new Expression("#{" + dataElementA.getUid() + suffix + "}", "expressionI2");
    Expression expressionI3 = new Expression("#{" + dataElementA.getUid() + suffix + "}", "expressionI3");
    Expression expressionJ = new Expression("#{" + dataElementB.getUid() + suffix + "}", "expressionJ");
    Expression expressionJ2 = new Expression("#{" + dataElementB.getUid() + suffix + "}", "expressionJ2");
    Expression expressionK = new Expression("#{" + dataElementC.getUid() + "}", "expressionK", NEVER_SKIP);
    Expression expressionL = new Expression("#{" + dataElementD.getUid() + "}", "expressionL", NEVER_SKIP);
    Expression expressionP = new Expression(SYMBOL_DAYS, "expressionP", NEVER_SKIP);
    Expression expressionP2 = new Expression(SYMBOL_DAYS, "expressionP2", NEVER_SKIP);
    Expression expressionQ = new Expression("#{" + dataElementE.getUid() + "}", "expressionQ", NEVER_SKIP);
    Expression expressionR = new Expression("#{" + dataElementA.getUid() + "} + #{" + dataElementB.getUid() + "}", "expressionR");
    Expression expressionS = new Expression("#{" + dataElementA.getUid() + suffixX + "} + #{" + dataElementB.getUid() + suffixX + "}", "expressionS");
    Expression expressionT = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffixX + "}", "expressionT");
    Expression expressionU = new Expression("1000", "expressionU");
    Expression expressionU2 = new Expression("1000", "expressionU2");
    Expression expressionU3 = new Expression("1000", "expressionU3");
    Expression expressionU4 = new Expression("1000", "expressionU4");
    periodA = createPeriod(ptMonthly, getDate(2000, 3, 1), getDate(2000, 3, 31));
    periodB = createPeriod(ptMonthly, getDate(2000, 4, 1), getDate(2000, 4, 30));
    periodC = createPeriod(ptMonthly, getDate(2000, 5, 1), getDate(2000, 5, 31));
    periodY = createPeriod(ptYearly, getDate(2000, 1, 1), getDate(2000, 12, 31));
    dayInPeriodA = periodService.getDayInPeriod(periodA, new Date());
    dayInPeriodB = periodService.getDayInPeriod(periodB, new Date());
    dayInPeriodC = periodService.getDayInPeriod(periodC, new Date());
    dayInPeriodY = periodService.getDayInPeriod(periodY, new Date());
    dataSetWeekly = createDataSet('W', ptWeekly);
    dataSetMonthly = createDataSet('M', ptMonthly);
    dataSetYearly = createDataSet('Y', ptYearly);
    sourceA = createOrganisationUnit('A');
    sourceB = createOrganisationUnit('B');
    sourceC = createOrganisationUnit('C', sourceB);
    sourceD = createOrganisationUnit('D', sourceB);
    sourceE = createOrganisationUnit('E', sourceD);
    sourceF = createOrganisationUnit('F', sourceD);
    sourceG = createOrganisationUnit('G');
    allSources.add(sourceA);
    allSources.add(sourceB);
    allSources.add(sourceC);
    allSources.add(sourceD);
    allSources.add(sourceE);
    allSources.add(sourceF);
    allSources.add(sourceG);
    dataSetMonthly.addOrganisationUnit(sourceA);
    dataSetMonthly.addOrganisationUnit(sourceB);
    dataSetMonthly.addOrganisationUnit(sourceC);
    dataSetMonthly.addOrganisationUnit(sourceD);
    dataSetMonthly.addOrganisationUnit(sourceE);
    dataSetMonthly.addOrganisationUnit(sourceF);
    dataSetWeekly.addOrganisationUnit(sourceB);
    dataSetWeekly.addOrganisationUnit(sourceC);
    dataSetWeekly.addOrganisationUnit(sourceD);
    dataSetWeekly.addOrganisationUnit(sourceE);
    dataSetWeekly.addOrganisationUnit(sourceF);
    dataSetWeekly.addOrganisationUnit(sourceG);
    dataSetYearly.addOrganisationUnit(sourceB);
    dataSetYearly.addOrganisationUnit(sourceC);
    dataSetYearly.addOrganisationUnit(sourceD);
    dataSetYearly.addOrganisationUnit(sourceE);
    dataSetYearly.addOrganisationUnit(sourceF);
    organisationUnitService.addOrganisationUnit(sourceA);
    organisationUnitService.addOrganisationUnit(sourceB);
    organisationUnitService.addOrganisationUnit(sourceC);
    organisationUnitService.addOrganisationUnit(sourceD);
    organisationUnitService.addOrganisationUnit(sourceE);
    organisationUnitService.addOrganisationUnit(sourceF);
    organisationUnitService.addOrganisationUnit(sourceG);
    orgUnitGroupA = createOrganisationUnitGroup('A');
    orgUnitGroupB = createOrganisationUnitGroup('B');
    orgUnitGroupC = createOrganisationUnitGroup('C');
    orgUnitGroupA.addOrganisationUnit(sourceB);
    orgUnitGroupA.addOrganisationUnit(sourceC);
    orgUnitGroupB.addOrganisationUnit(sourceD);
    orgUnitGroupB.addOrganisationUnit(sourceE);
    orgUnitGroupC.addOrganisationUnit(sourceE);
    orgUnitGroupC.addOrganisationUnit(sourceF);
    organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupA);
    organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupB);
    organisationUnitGroupService.addOrganisationUnitGroup(orgUnitGroupC);
    dataSetMonthly.addDataSetElement(dataElementA);
    dataSetMonthly.addDataSetElement(dataElementB);
    dataSetMonthly.addDataSetElement(dataElementC);
    dataSetMonthly.addDataSetElement(dataElementD);
    dataSetWeekly.addDataSetElement(dataElementE);
    dataSetYearly.addDataSetElement(dataElementE);
    dataSetService.addDataSet(dataSetWeekly);
    dataSetService.addDataSet(dataSetMonthly);
    dataSetService.addDataSet(dataSetYearly);
    dataElementService.updateDataElement(dataElementA);
    dataElementService.updateDataElement(dataElementB);
    dataElementService.updateDataElement(dataElementC);
    dataElementService.updateDataElement(dataElementD);
    dataElementService.updateDataElement(dataElementE);
    // deA + deB = deC - deD
    ruleA = createValidationRule("A", equal_to, expressionA, expressionB, ptMonthly);
    // deC - deD > deB * 2
    ruleB = createValidationRule("B", greater_than, expressionB2, expressionC, ptMonthly);
    // deC - deD <= deA + deB
    ruleC = createValidationRule("C", less_than_or_equal_to, expressionB3, expressionA2, ptMonthly);
    // deA + deB < deB * 2
    ruleD = createValidationRule("D", less_than, expressionA3, expressionC2, ptMonthly);
    // deA [Compulsory pair] deB
    ruleE = createValidationRule("E", compulsory_pair, expressionI, expressionJ, ptMonthly);
    // deA [Exclusive pair] deB
    ruleF = createValidationRule("F", exclusive_pair, expressionI2, expressionJ2, ptMonthly);
    // deC = DeD
    ruleG = createValidationRule("G", equal_to, expressionK, expressionL, ptMonthly);
    // deA = [days]
    ruleP = createValidationRule("P", equal_to, expressionI3, expressionP, ptMonthly);
    // deE = [days]
    ruleQ = createValidationRule("Q", equal_to, expressionQ, expressionP2, ptYearly);
    // deA(sum) + deB(sum) = 1000
    ruleR = createValidationRule("R", equal_to, expressionR, expressionU, ptMonthly);
    // deA.optionComboX + deB.optionComboX = 1000
    ruleS = createValidationRule("S", equal_to, expressionS, expressionU2, ptMonthly);
    // deA.default + deB.optionComboX = 1000
    ruleT = createValidationRule("T", equal_to, expressionT, expressionU3, ptMonthly);
    // deA.default + deB.default = 1000
    ruleU = createValidationRule("U", equal_to, expressionA4, expressionU4, ptMonthly);
    // deA + deB = deB * 2
    ruleX = createValidationRule("X", equal_to, expressionA5, expressionC3, ptMonthly);
    group = createValidationRuleGroup('A');
    defaultCombo = categoryService.getDefaultCategoryOptionCombo();
}
Also used : WeeklyPeriodType(org.hisp.dhis.period.WeeklyPeriodType) Category(org.hisp.dhis.category.Category) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) Expression(org.hisp.dhis.expression.Expression) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) CategoryOption(org.hisp.dhis.category.CategoryOption) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Date(java.util.Date)

Aggregations

CurrentUserServiceTarget (org.hisp.dhis.user.CurrentUserServiceTarget)24 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)23 CurrentUserService (org.hisp.dhis.user.CurrentUserService)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Test (org.junit.jupiter.api.Test)11 DhisSpringTest (org.hisp.dhis.DhisSpringTest)10 HashSet (java.util.HashSet)9 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)7 CategoryOption (org.hisp.dhis.category.CategoryOption)5 Date (java.util.Date)4 Expression (org.hisp.dhis.expression.Expression)3 PeriodType (org.hisp.dhis.period.PeriodType)3 AttributeValue (org.hisp.dhis.attribute.AttributeValue)2 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)2 HashMap (java.util.HashMap)1 AnalyticsServiceTarget (org.hisp.dhis.analytics.AnalyticsServiceTarget)1 Attribute (org.hisp.dhis.attribute.Attribute)1 Category (org.hisp.dhis.category.Category)1 BatchHandlerFactoryTarget (org.hisp.dhis.common.BatchHandlerFactoryTarget)1