use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.
the class DataApprovalAuditServiceTest method getMockCurrentUserService.
// -------------------------------------------------------------------------
// Set up/tear down helper methods
// -------------------------------------------------------------------------
private CurrentUserService getMockCurrentUserService(String userName, boolean superUserFlag, OrganisationUnit orgUnit, String... auths) {
CurrentUserService mockCurrentUserService = new MockCurrentUserService(superUserFlag, Sets.newHashSet(orgUnit), Sets.newHashSet(orgUnit), auths);
User user = mockCurrentUserService.getCurrentUser();
user.setFirstName("Test");
user.setSurname(userName);
UserCredentials credentials = user.getUserCredentials();
credentials.setUsername(userName);
for (UserAuthorityGroup role : credentials.getUserAuthorityGroups()) {
// Give the role an arbitrary name
role.setName(CodeGenerator.generateUid());
userService.addUserAuthorityGroup(role);
}
userService.addUserCredentials(credentials);
userService.addUser(user);
return mockCurrentUserService;
}
use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.
the class PredictorServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
organisationUnitService.addOrganisationUnitLevel(orgUnitLevel1);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementC = createDataElement('C');
dataElementD = createDataElement('D');
dataElementX = createDataElement('X', ValueType.NUMBER, AggregationType.NONE);
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
dataElementService.addDataElement(dataElementX);
dataElements = new HashSet<>();
dataElements.add(dataElementA);
dataElements.add(dataElementB);
dataElements.add(dataElementC);
dataElements.add(dataElementD);
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);
periodTypeMonthly = PeriodType.getPeriodTypeByName("Monthly");
dataSetMonthly = createDataSet('M', periodTypeMonthly);
dataSetMonthly.addDataSetElement(dataElementA);
dataSetMonthly.addDataSetElement(dataElementB);
dataSetMonthly.addDataSetElement(dataElementC);
dataSetMonthly.addDataSetElement(dataElementD);
dataSetMonthly.addDataSetElement(dataElementX);
dataSetMonthly.addOrganisationUnit(sourceA);
dataSetMonthly.addOrganisationUnit(sourceB);
dataSetMonthly.addOrganisationUnit(sourceC);
dataSetMonthly.addOrganisationUnit(sourceD);
dataSetMonthly.addOrganisationUnit(sourceE);
dataSetMonthly.addOrganisationUnit(sourceG);
dataSetService.addDataSet(dataSetMonthly);
DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
defaultCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
altCategoryOption = new DataElementCategoryOption("AltCategoryOption");
categoryService.addDataElementCategoryOption(altCategoryOption);
altDataElementCategory = createDataElementCategory('A', altCategoryOption);
categoryService.addDataElementCategory(altDataElementCategory);
altDataElementCategoryCombo = createCategoryCombo('Y', altDataElementCategory);
categoryService.addDataElementCategoryCombo(altDataElementCategoryCombo);
altCombo = createCategoryOptionCombo('Z', altDataElementCategoryCombo, altCategoryOption);
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
optionCombos.add(altCombo);
categoryService.addDataElementCategoryOptionCombo(altCombo);
expressionA = new Expression("AVG(#{" + dataElementA.getUid() + "})+1.5*STDDEV(#{" + dataElementA.getUid() + "})", "descriptionA");
expressionB = new Expression("AVG(#{" + dataElementB.getUid() + "." + defaultCombo.getUid() + "})", "descriptionB");
expressionC = new Expression("1234", "descriptionC");
expressionD = new Expression(SYMBOL_DAYS, "descriptionD");
expressionService.addExpression(expressionA);
expressionService.addExpression(expressionB);
expressionService.addExpression(expressionC);
expressionService.addExpression(expressionD);
Set<OrganisationUnit> units = newHashSet(sourceA, sourceB, sourceG);
CurrentUserService mockCurrentUserService = new MockCurrentUserService(true, units, units);
setDependency(predictorService, "currentUserService", mockCurrentUserService, CurrentUserService.class);
}
use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.
the class DataValueSetServiceExportTest method setUpTest.
@Override
public void setUpTest() {
deA = createDataElement('A');
deB = createDataElement('B');
deC = createDataElement('C');
idObjectManager.save(deA);
idObjectManager.save(deB);
idObjectManager.save(deC);
ccA = createCategoryCombo('A');
categoryService.addDataElementCategoryCombo(ccA);
cocA = createCategoryOptionCombo('A');
cocB = createCategoryOptionCombo('B');
cocA.setCategoryCombo(ccA);
cocB.setCategoryCombo(ccA);
categoryService.addDataElementCategoryOptionCombo(cocA);
categoryService.addDataElementCategoryOptionCombo(cocB);
atA = createAttribute('A');
atA.setDataElementAttribute(true);
atA.setOrganisationUnitAttribute(true);
atA.setCategoryOptionComboAttribute(true);
idObjectManager.save(atA);
dsA = createDataSet('A');
dsA.addDataSetElement(deA);
dsA.addDataSetElement(deB);
dsB = createDataSet('B');
dsB.addDataSetElement(deA);
dataSetService.addDataSet(dsA);
dataSetService.addDataSet(dsB);
peA = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2016, 3, 1), getDate(2016, 3, 31));
peB = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2016, 4, 1), getDate(2016, 4, 30));
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B', ouA);
organisationUnitService.addOrganisationUnit(ouA);
organisationUnitService.addOrganisationUnit(ouB);
avA = new AttributeValue("AttributeValueA", atA);
avB = new AttributeValue("AttributeValueB", atA);
avC = new AttributeValue("AttributeValueC", atA);
avD = new AttributeValue("AttributeValueD", atA);
attributeService.addAttributeValue(deA, avA);
attributeService.addAttributeValue(ouA, avB);
attributeService.addAttributeValue(cocA, avC);
attributeService.addAttributeValue(cocB, avD);
// Data values
dataValueService.addDataValue(new DataValue(deA, peA, ouA, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peA, ouA, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deA, peA, ouB, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peA, ouB, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouA, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouA, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouB, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouB, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouA, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouA, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouB, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouB, cocB, cocB, "1"));
// Flush session to make data values visible to JDBC query
dbmsManager.flushSession();
// Service mocks
user = createUser('A');
user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
CurrentUserService currentUserService = new MockCurrentUserService(user);
setDependency(dataValueSetService, "currentUserService", currentUserService);
setDependency(organisationUnitService, "currentUserService", currentUserService);
}
use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.
the class DataValueSetServiceTest method setUpTest.
@Override
public void setUpTest() {
mockDataValueBatchHandler = new MockBatchHandler<>();
mockDataValueAuditBatchHandler = new MockBatchHandler<>();
mockBatchHandlerFactory = new MockBatchHandlerFactory();
mockBatchHandlerFactory.registerBatchHandler(DataValueBatchHandler.class, mockDataValueBatchHandler);
mockBatchHandlerFactory.registerBatchHandler(DataValueAuditBatchHandler.class, mockDataValueAuditBatchHandler);
setDependency(dataValueSetService, "batchHandlerFactory", mockBatchHandlerFactory);
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 = createDataElementCategory('A', categoryOptionA, categoryOptionB);
categoryComboA = createCategoryCombo('A', categoryA);
categoryComboDef = categoryService.getDefaultDataElementCategoryCombo();
ocDef = categoryService.getDefaultDataElementCategoryOptionCombo();
ocDef.setCode("OC_DEF_CODE");
categoryService.updateDataElementCategoryOptionCombo(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);
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.addDataElementCategoryOption(categoryOptionA);
categoryService.addDataElementCategoryOption(categoryOptionB);
categoryService.addDataElementCategory(categoryA);
categoryService.addDataElementCategoryCombo(categoryComboA);
categoryService.addDataElementCategoryOptionCombo(ocA);
categoryService.addDataElementCategoryOptionCombo(ocB);
attributeService.addAttributeValue(deA, createAttributeValue(attribute, "DE1"));
dataElementService.addDataElement(deA);
attributeService.addAttributeValue(deB, createAttributeValue(attribute, "DE2"));
dataElementService.addDataElement(deB);
attributeService.addAttributeValue(deC, createAttributeValue(attribute, "DE3"));
dataElementService.addDataElement(deC);
attributeService.addAttributeValue(deD, createAttributeValue(attribute, "DE4"));
dataElementService.addDataElement(deD);
dataElementService.addDataElement(deF);
dataElementService.addDataElement(deG);
idObjectManager.save(osA);
dsA.addDataSetElement(deA);
dsA.addDataSetElement(deB);
dsA.addDataSetElement(deC);
dsA.addDataSetElement(deD);
attributeService.addAttributeValue(ouA, createAttributeValue(attribute, "OU1"));
organisationUnitService.addOrganisationUnit(ouA);
attributeService.addAttributeValue(ouB, createAttributeValue(attribute, "OU2"));
organisationUnitService.addOrganisationUnit(ouB);
attributeService.addAttributeValue(ouC, createAttributeValue(attribute, "OU3"));
organisationUnitService.addOrganisationUnit(ouC);
dsA.addOrganisationUnit(ouA);
dsA.addOrganisationUnit(ouC);
dataSetService.addDataSet(dsA);
periodService.addPeriod(peA);
periodService.addPeriod(peB);
periodService.addPeriod(peC);
user = createUser('A');
user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
CurrentUserService currentUserService = new MockCurrentUserService(user);
setDependency(dataValueSetService, "currentUserService", currentUserService);
}
use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.
the class ValidationServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
CurrentUserService currentUserService = new MockCurrentUserService(allSources, null);
setDependency(validationService, "currentUserService", currentUserService, CurrentUserService.class);
periodTypeWeekly = new WeeklyPeriodType();
periodTypeMonthly = new MonthlyPeriodType();
periodTypeYearly = 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);
optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
String suffix = SEPARATOR + optionCombo.getUid();
optionCombos = new HashSet<>();
optionCombos.add(optionCombo);
expressionA = new Expression("#{" + dataElementA.getUid() + suffix + "} + #{" + dataElementB.getUid() + suffix + "}", "expressionA");
expressionB = new Expression("#{" + dataElementC.getUid() + suffix + "} - #{" + dataElementD.getUid() + suffix + "}", "expressionB");
expressionC = new Expression("#{" + dataElementB.getUid() + suffix + "} * 2", "expressionC");
expressionD = new Expression("#{" + dataElementB.getUid() + suffix + "}", "expressionD");
expressionE = new Expression("AVG(#{" + dataElementB.getUid() + suffix + "} * 1.5)", "expressionE");
expressionF = new Expression("#{" + dataElementB.getUid() + suffix + "} / #{" + dataElementE.getUid() + suffix + "}", "expressionF");
expressionG = new Expression("AVG(#{" + dataElementB.getUid() + suffix + "} * 1.5 / #{" + dataElementE.getUid() + suffix + "})", "expressionG");
expressionH = new Expression("AVG(#{" + dataElementB.getUid() + suffix + "}) + 1.5*STDDEV(#{" + dataElementB.getUid() + suffix + "})", "expressionH");
expressionI = new Expression("#{" + dataElementA.getUid() + suffix + "}", "expressionI");
expressionJ = new Expression("#{" + dataElementB.getUid() + suffix + "}", "expressionJ");
expressionK = new Expression("#{" + dataElementC.getUid() + "}", "expressionK", NEVER_SKIP);
expressionL = new Expression("#{" + dataElementD.getUid() + "}", "expressionL", NEVER_SKIP);
expressionP = new Expression(SYMBOL_DAYS, "expressionP", NEVER_SKIP);
expressionQ = new Expression("#{" + dataElementE.getUid() + "}", "expressionQ", NEVER_SKIP);
expressionService.addExpression(expressionA);
expressionService.addExpression(expressionB);
expressionService.addExpression(expressionC);
expressionService.addExpression(expressionD);
expressionService.addExpression(expressionE);
expressionService.addExpression(expressionF);
expressionService.addExpression(expressionG);
expressionService.addExpression(expressionH);
expressionService.addExpression(expressionI);
expressionService.addExpression(expressionJ);
expressionService.addExpression(expressionK);
expressionService.addExpression(expressionL);
expressionService.addExpression(expressionP);
expressionService.addExpression(expressionQ);
periodA = createPeriod(periodTypeMonthly, getDate(2000, 3, 1), getDate(2000, 3, 31));
periodB = createPeriod(periodTypeMonthly, getDate(2000, 4, 1), getDate(2000, 4, 30));
periodY = createPeriod(periodTypeYearly, getDate(2000, 1, 1), getDate(2000, 12, 31));
dayInPeriodA = periodService.getDayInPeriod(periodA, new Date());
dayInPeriodB = periodService.getDayInPeriod(periodB, new Date());
dayInPeriodY = periodService.getDayInPeriod(periodY, new Date());
dataSetWeekly = createDataSet('W', periodTypeWeekly);
dataSetMonthly = createDataSet('M', periodTypeMonthly);
dataSetYearly = createDataSet('Y', periodTypeYearly);
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');
sourcesA.add(sourceA);
sourcesA.add(sourceB);
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);
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
validationRuleA = createValidationRule("A", equal_to, expressionA, expressionB, periodTypeMonthly);
// deC - deD > deB * 2
validationRuleB = createValidationRule("B", greater_than, expressionB, expressionC, periodTypeMonthly);
// deC - deD <= deA + deB
validationRuleC = createValidationRule("C", less_than_or_equal_to, expressionB, expressionA, periodTypeMonthly);
// deA + deB < deB * 2
validationRuleD = createValidationRule("D", less_than, expressionA, expressionC, periodTypeMonthly);
// deA [Compulsory pair] deB
validationRuleE = createValidationRule("E", compulsory_pair, expressionI, expressionJ, periodTypeMonthly);
// deA [Exclusive pair] deB
validationRuleF = createValidationRule("F", exclusive_pair, expressionI, expressionJ, periodTypeMonthly);
// deC = deD
validationRuleG = createValidationRule("G", equal_to, expressionK, expressionL, periodTypeMonthly);
// deA = [days]
validationRuleP = createValidationRule("P", equal_to, expressionI, expressionP, periodTypeMonthly);
// deE = [days]
validationRuleQ = createValidationRule("Q", equal_to, expressionQ, expressionP, periodTypeYearly);
// deA + deB = deB * 2
validationRuleX = createValidationRule("X", equal_to, expressionA, expressionC, periodTypeMonthly);
group = createValidationRuleGroup('A');
defaultCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
}
Aggregations