use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.
the class DataValueSetServiceIntegrationTest method setUpTest.
@Override
public void setUpTest() {
userService = _userService;
deA = createDataElement('A');
deB = createDataElement('B');
deC = createDataElement('C');
deA.setUid("f7n9E0hX8qk");
deB.setUid("Ix2HsbDMLea");
deC.setUid("eY5ehpbEsB7");
idObjectManager.save(deA);
idObjectManager.save(deB);
idObjectManager.save(deC);
ptA = new MonthlyPeriodType();
dsA = createDataSet('A', ptA);
dsA.setUid("pBOMPrpg1QX");
dataSetService.addDataSet(dsA);
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));
periodService.addPeriod(peA);
periodService.addPeriod(peB);
periodService.addPeriod(peC);
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B');
ouC = createOrganisationUnit('C');
ouA.setUid("DiszpKrYNg8");
ouB.setUid("BdfsJfj87js");
ouC.setUid("j7Hg26FpoIa");
idObjectManager.save(ouA);
idObjectManager.save(ouB);
idObjectManager.save(ouC);
user = createAndInjectAdminUser();
user.setOrganisationUnits(Sets.newHashSet(ouA, ouB, ouC));
CurrentUserService currentUserService = new MockCurrentUserService(user);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataValueSetService);
}
use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.
the class PredictionServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
PeriodType.invalidatePeriodCache();
orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
orgUnitLevel2 = new OrganisationUnitLevel(2, "Level2");
orgUnitLevel3 = new OrganisationUnitLevel(3, "Level3");
organisationUnitService.addOrganisationUnitLevel(orgUnitLevel1);
organisationUnitService.addOrganisationUnitLevel(orgUnitLevel2);
organisationUnitService.addOrganisationUnitLevel(orgUnitLevel3);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementC = createDataElement('C');
dataElementD = createDataElement('D');
dataElementE = createDataElement('E', ValueType.TEXT, AggregationType.NONE);
dataElementF = createDataElement('F', ValueType.TEXT, AggregationType.NONE);
dataElementG = createDataElement('G', ValueType.DATE, AggregationType.NONE);
dataElementH = createDataElement('H', ValueType.DATE, AggregationType.NONE);
dataElementI = createDataElement('I', ValueType.BOOLEAN, AggregationType.NONE);
dataElementJ = createDataElement('J', ValueType.BOOLEAN, AggregationType.NONE);
dataElementX = createDataElement('X', ValueType.NUMBER, AggregationType.NONE);
dataElementY = createDataElement('Y', ValueType.INTEGER, AggregationType.NONE);
dataElementZ = createDataElement('Z', ValueType.INTEGER, AggregationType.NONE);
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
dataElementService.addDataElement(dataElementE);
dataElementService.addDataElement(dataElementF);
dataElementService.addDataElement(dataElementG);
dataElementService.addDataElement(dataElementH);
dataElementService.addDataElement(dataElementI);
dataElementService.addDataElement(dataElementJ);
dataElementService.addDataElement(dataElementX);
dataElementService.addDataElement(dataElementY);
dataElementService.addDataElement(dataElementZ);
// Org unit hierarchy:
//
// Level 1: A, B, G
// Level 2: C, D (children of B)
// Level 3: E, F (children of D)
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');
organisationUnitService.addOrganisationUnit(sourceA);
organisationUnitService.addOrganisationUnit(sourceB);
organisationUnitService.addOrganisationUnit(sourceC);
organisationUnitService.addOrganisationUnit(sourceD);
organisationUnitService.addOrganisationUnit(sourceE);
organisationUnitService.addOrganisationUnit(sourceF);
organisationUnitService.addOrganisationUnit(sourceG);
ouGroupA = createOrganisationUnitGroup('A');
ouGroupB = createOrganisationUnitGroup('B');
ouGroupA.addOrganisationUnit(sourceA);
ouGroupA.addOrganisationUnit(sourceC);
ouGroupB.addOrganisationUnit(sourceD);
ouGroupB.addOrganisationUnit(sourceF);
organisationUnitGroupService.addOrganisationUnitGroup(ouGroupA);
organisationUnitGroupService.addOrganisationUnitGroup(ouGroupB);
periodTypeMonthly = PeriodType.getPeriodTypeByName("Monthly");
dataSetMonthly = createDataSet('M', periodTypeMonthly);
dataSetMonthly.addDataSetElement(dataElementA);
dataSetMonthly.addDataSetElement(dataElementB);
dataSetMonthly.addDataSetElement(dataElementC);
dataSetMonthly.addDataSetElement(dataElementD);
dataSetMonthly.addDataSetElement(dataElementX);
dataSetMonthly.addDataSetElement(dataElementY);
dataSetMonthly.addOrganisationUnit(sourceA);
dataSetMonthly.addOrganisationUnit(sourceB);
dataSetMonthly.addOrganisationUnit(sourceC);
dataSetMonthly.addOrganisationUnit(sourceD);
dataSetMonthly.addOrganisationUnit(sourceE);
dataSetMonthly.addOrganisationUnit(sourceG);
dataSetService.addDataSet(dataSetMonthly);
CategoryOptionCombo categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
defaultCombo = categoryService.getDefaultCategoryOptionCombo();
altCategoryOption = new CategoryOption("AltCategoryOption");
categoryService.addCategoryOption(altCategoryOption);
altCategory = createCategory('A', altCategoryOption);
categoryService.addCategory(altCategory);
altCategoryCombo = createCategoryCombo('Y', altCategory);
categoryService.addCategoryCombo(altCategoryCombo);
altCombo = createCategoryOptionCombo(altCategoryCombo, altCategoryOption);
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
optionCombos.add(altCombo);
categoryService.addCategoryOptionCombo(altCombo);
expressionA = new Expression("avg(#{" + dataElementA.getUid() + "})+1.5*stddev(#{" + dataElementA.getUid() + "})", "descriptionA");
expressionH = new Expression("avg(#{" + dataElementA.getUid() + "})+1.5*stddevPop(#{" + dataElementA.getUid() + "})", "descriptionH");
expressionB = new Expression("avg(#{" + dataElementB.getUid() + "." + defaultCombo.getUid() + "})", "descriptionB");
expressionC = new Expression("135.79", "descriptionC");
expressionD = new Expression(SYMBOL_DAYS, "descriptionD");
expressionE = new Expression("sum(#{" + dataElementA.getUid() + "})+#{" + dataElementB.getUid() + "}", "descriptionE");
expressionF = new Expression("#{" + dataElementB.getUid() + "}", "descriptionF");
expressionG = new Expression("sum(#{" + dataElementA.getUid() + "}+#{" + dataElementB.getUid() + "})", "descriptionG");
summary = new PredictionSummary();
dataValueBatchHandler = batchHandlerFactory.createBatchHandler(DataValueBatchHandler.class).init();
Set<OrganisationUnit> units = newHashSet(sourceA, sourceB, sourceG);
CurrentUserService mockCurrentUserService = new MockCurrentUserService(true, units, units);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, mockCurrentUserService, predictionService);
}
use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.
the class ValidationServiceIntegrationTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() {
this.userService = injectUserService;
CurrentUserService currentUserService = new MockCurrentUserService(Sets.newHashSet(orgUnitA), null);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, validationService);
periodTypeMonthly = new MonthlyPeriodType();
dataElementA = createDataElement('A');
dataElementService.addDataElement(dataElementA);
periodA = createPeriod(periodTypeMonthly, getDate(2000, 3, 1), getDate(2000, 3, 31));
dayInPeriodA = periodService.getDayInPeriod(periodA, new Date());
orgUnitA = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(orgUnitA);
defaultCombo = categoryService.getDefaultCategoryOptionCombo();
}
use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.
the class DataApprovalLevelServiceTest method testGetUserReadApprovalLevels_1D.
@Test
void testGetUserReadApprovalLevels_1D() {
//
// Test 1: Like when a user may capture data within their own district
// but view data in other districts within their province.
//
// Variation D: User is assigned to two districts
//
organisationUnitService.addOrganisationUnit(organisationUnitE);
organisationUnitService.addOrganisationUnit(organisationUnitF);
organisationUnitService.addOrganisationUnit(organisationUnitG);
organisationUnitService.addOrganisationUnit(organisationUnitH);
organisationUnitService.addOrganisationUnit(organisationUnitI);
organisationUnitService.addOrganisationUnit(organisationUnitJ);
organisationUnitService.addOrganisationUnit(organisationUnitK);
dataApprovalLevelService.addDataApprovalLevel(level1, 1);
dataApprovalLevelService.addDataApprovalLevel(level2, 2);
dataApprovalLevelService.addDataApprovalLevel(level3, 3);
dataApprovalLevelService.addDataApprovalLevel(level4, 4);
dataApprovalLevelService.addDataApprovalLevel(level5, 5);
Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
assignedOrgUnits.add(organisationUnitC);
assignedOrgUnits.add(organisationUnitF);
Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
dataViewOrgUnits.add(organisationUnitB);
CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataApprovalLevelService);
Map<OrganisationUnit, Integer> readApprovalLevels = dataApprovalLevelService.getUserReadApprovalLevels();
assertEquals(3, readApprovalLevels.size());
assertEquals(4, (int) readApprovalLevels.get(organisationUnitC));
assertEquals(4, (int) readApprovalLevels.get(organisationUnitF));
assertEquals(3, (int) readApprovalLevels.get(organisationUnitB));
}
use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.
the class DataApprovalLevelServiceTest method testGetUserReadApprovalLevels_1C.
@Test
void testGetUserReadApprovalLevels_1C() {
//
// Test 1: Like when a user may capture data within their own district
// but view data in other districts within their province.
//
// Variation C: No approval level for org unit level 4.
//
organisationUnitService.addOrganisationUnit(organisationUnitE);
organisationUnitService.addOrganisationUnit(organisationUnitF);
organisationUnitService.addOrganisationUnit(organisationUnitG);
organisationUnitService.addOrganisationUnit(organisationUnitH);
// 1st
dataApprovalLevelService.addDataApprovalLevel(level1, 1);
// approval
// level
// 2nd
dataApprovalLevelService.addDataApprovalLevel(level2, 2);
// approval
// level
// 3rd
dataApprovalLevelService.addDataApprovalLevel(level3, 3);
// approval
// level
// 4th
dataApprovalLevelService.addDataApprovalLevel(level5, 4);
// approval
// level
Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
assignedOrgUnits.add(organisationUnitC);
Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
dataViewOrgUnits.add(organisationUnitB);
CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataApprovalLevelService);
Map<OrganisationUnit, Integer> readApprovalLevels = dataApprovalLevelService.getUserReadApprovalLevels();
assertEquals(2, readApprovalLevels.size());
assertEquals(4, (int) readApprovalLevels.get(organisationUnitC));
assertEquals(3, (int) readApprovalLevels.get(organisationUnitB));
}
Aggregations