use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.
the class DataSetServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
userService = _userService;
periodType = new MonthlyPeriodType();
period = createPeriod(periodType, getDate(2000, 3, 1), getDate(2000, 3, 31));
periodService.addPeriod(period);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
unitA = createOrganisationUnit('A');
unitB = createOrganisationUnit('B');
unitC = createOrganisationUnit('C');
unitD = createOrganisationUnit('D');
unitE = createOrganisationUnit('E');
unitF = createOrganisationUnit('F');
organisationUnitService.addOrganisationUnit(unitA);
organisationUnitService.addOrganisationUnit(unitB);
organisationUnitService.addOrganisationUnit(unitC);
organisationUnitService.addOrganisationUnit(unitD);
organisationUnitService.addOrganisationUnit(unitE);
organisationUnitService.addOrganisationUnit(unitF);
attributeOptionCombo = categoryService.getDefaultCategoryOptionCombo();
mockCurrentUserService = new MockCurrentUserService(true, newHashSet(unitA), newHashSet(unitA), UserAuthorityGroup.AUTHORITY_ALL);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, mockCurrentUserService, approvalService, approvalStore, levelService);
User user = mockCurrentUserService.getCurrentUser();
user.setFirstName("John");
user.setSurname("Doe");
userService.addUser(mockCurrentUserService.getCurrentUser());
}
use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.
the class TrackerOwnershipManagerTest method setUpTest.
@Override
protected void setUpTest() throws Exception {
userService = _userService;
organisationUnitA = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnitA);
organisationUnitB = createOrganisationUnit('B');
organisationUnitService.addOrganisationUnit(organisationUnitB);
CurrentUserService mockCurrentUserService = new MockCurrentUserService(false, newHashSet(organisationUnitA), newHashSet(organisationUnitA), "");
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, mockCurrentUserService, trackerOwnershipAccessManager);
entityInstanceA1 = createTrackedEntityInstance(organisationUnitA);
entityInstanceB1 = createTrackedEntityInstance(organisationUnitB);
entityInstanceService.addTrackedEntityInstance(entityInstanceA1);
entityInstanceService.addTrackedEntityInstance(entityInstanceB1);
programA = createProgram('A');
programA.setAccessLevel(AccessLevel.PROTECTED);
programService.addProgram(programA);
userA = mockCurrentUserService.getCurrentUser();
userB = createUser("userB");
userB.addOrganisationUnit(organisationUnitB);
userService.addUser(userA);
userService.addUser(userB);
}
use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.
the class AdxDataServiceIntegrationTest method setUpTest.
@Override
public void setUpTest() {
// UserService
userService = _userService;
// Category Option
coUnder5 = new CategoryOption("Under 5");
coOver5 = new CategoryOption("Over 5");
coF = new CategoryOption("Female");
coM = new CategoryOption("Male");
coPepfar = new CategoryOption("PEPFAR mechanism");
coMcDonalds = new CategoryOption("McDonalds mechanism");
coUnder5.setCode("under5");
coOver5.setCode("over5");
coF.setCode("F");
coM.setCode("M");
coPepfar.setCode("PEPFAR");
coMcDonalds.setCode("McDonalds");
coUnder5.setUid("under555555");
coOver5.setUid("over5555555");
coF.setUid("FFFFFFFFFFF");
coM.setUid("MMMMMMMMMMM");
coPepfar.setUid("PEPFARRRRRR");
coMcDonalds.setUid("McDonaldsss");
idObjectManager.save(coUnder5);
idObjectManager.save(coOver5);
idObjectManager.save(coF);
idObjectManager.save(coM);
idObjectManager.save(coPepfar);
idObjectManager.save(coMcDonalds);
// Category
cAge = createCategory('A', coUnder5, coOver5);
cSex = createCategory('B', coF, coM);
cMechanism = createCategory('C', coPepfar, coMcDonalds);
cAge.setName("Age_category");
cSex.setName("Sex_category");
cMechanism.setName("Mechanism_category");
cAge.setCode("age");
cSex.setCode("sex");
cMechanism.setCode("mechanism");
cAge.setUid("ageeeeeeeee");
cSex.setUid("sexxxxxxxxx");
cMechanism.setUid("mechanismmm");
idObjectManager.save(cAge);
idObjectManager.save(cSex);
idObjectManager.save(cMechanism);
// Category Combo
ccAgeAndSex = createCategoryCombo('A', cAge, cSex);
ccMechanism = createCategoryCombo('B', cMechanism);
ccAgeAndSex.setName("Age and Sex Category Combo");
ccMechanism.setName("Mechanism Category Combo");
idObjectManager.save(ccAgeAndSex);
idObjectManager.save(ccMechanism);
cAge.setCategoryCombos(Lists.newArrayList(ccAgeAndSex));
cSex.setCategoryCombos(Lists.newArrayList(ccAgeAndSex));
cMechanism.setCategoryCombos(Lists.newArrayList(ccMechanism));
idObjectManager.update(cAge);
idObjectManager.update(cSex);
idObjectManager.update(cMechanism);
// Category Option Combo
cocFUnder5 = createCategoryOptionCombo(ccAgeAndSex, coF, coUnder5);
cocMUnder5 = createCategoryOptionCombo(ccAgeAndSex, coM, coUnder5);
cocFOver5 = createCategoryOptionCombo(ccAgeAndSex, coF, coOver5);
cocMOver5 = createCategoryOptionCombo(ccAgeAndSex, coM, coOver5);
cocPepfar = createCategoryOptionCombo(ccMechanism, coPepfar);
cocMcDonalds = createCategoryOptionCombo(ccMechanism, coMcDonalds);
cocFUnder5.setName("Female Under 5");
cocMUnder5.setName("Male Under 5");
cocFOver5.setName("Female Over 5");
cocMOver5.setName("Male Over 5");
cocPepfar.setName("PEPFAR CategoryOptionCombo");
cocMcDonalds.setName("McDonalds CategoryOptionCombo");
cocFUnder5.setCode("F_Under5");
cocMUnder5.setCode("M_Under5");
cocFOver5.setCode("F_Over5");
cocMOver5.setCode("M_Over5");
cocPepfar.setCode("coc_PEPFAR");
cocMcDonalds.setCode("coc_McDonalds");
cocFUnder5.setUid("FUnder55555");
cocMUnder5.setUid("MUnder55555");
cocFOver5.setUid("FOver555555");
cocMOver5.setUid("MOver555555");
cocPepfar.setUid("cocPEPFARRR");
cocMcDonalds.setUid("cocMcDonald");
idObjectManager.save(cocFUnder5);
idObjectManager.save(cocMUnder5);
idObjectManager.save(cocFOver5);
idObjectManager.save(cocMOver5);
idObjectManager.save(cocPepfar);
idObjectManager.save(cocMcDonalds);
ccAgeAndSex.getOptionCombos().add(cocFUnder5);
ccAgeAndSex.getOptionCombos().add(cocMUnder5);
ccAgeAndSex.getOptionCombos().add(cocFOver5);
ccAgeAndSex.getOptionCombos().add(cocMOver5);
ccMechanism.getOptionCombos().add(cocPepfar);
ccMechanism.getOptionCombos().add(cocMcDonalds);
idObjectManager.update(ccAgeAndSex);
idObjectManager.update(ccMechanism);
cocDefault = categoryService.getDefaultCategoryOptionCombo();
// Data Element
deA = createDataElement('A');
deB = createDataElement('B');
deA.setName("Malaria numeric");
deB.setName("Malaria text");
deA.setCode("Mal_num");
deB.setCode("Mal_text");
deA.setUid("MalNummmmmm");
deB.setUid("MalTexttttt");
deA.setCategoryCombo(ccAgeAndSex);
deB.setValueType(ValueType.TEXT);
idObjectManager.save(deA);
idObjectManager.save(deB);
// Period
pe202001 = PeriodType.getPeriodFromIsoString("202001");
pe202002 = PeriodType.getPeriodFromIsoString("202002");
pe2021Q1 = PeriodType.getPeriodFromIsoString("2021Q1");
periodService.addPeriod(pe202001);
periodService.addPeriod(pe202002);
periodService.addPeriod(pe2021Q1);
// Data Set
dsA = createDataSet('A', PeriodType.getPeriodTypeByName("Monthly"));
dsB = createDataSet('B', PeriodType.getPeriodTypeByName("Quarterly"));
dsA.setName("Malaria DS");
dsB.setName("Malaria Mechanism DS");
dsA.setCode("MalariaDS");
dsB.setCode("MalariaMechanismDS");
dsA.setUid("MalariaDSSS");
dsB.setUid("MalariaMech");
dsA.addDataSetElement(deA);
dsA.addDataSetElement(deB);
dsB.addDataSetElement(deA);
dsB.addDataSetElement(deB);
dsB.setCategoryCombo(ccMechanism);
idObjectManager.save(dsA);
idObjectManager.save(dsB);
// Organisation Unit
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B', ouA);
ouA.setName("Provincial Hospital");
ouB.setName("District Hospital");
ouA.setCode("123");
ouB.setCode("456");
ouA.setUid("P1233333333");
ouB.setUid("D4566666666");
idObjectManager.save(ouA);
idObjectManager.save(ouB);
// Organisation Unit Group
ougA = createOrganisationUnitGroup('A');
ougA.addOrganisationUnit(ouA);
ougA.addOrganisationUnit(ouB);
organisationUnitGroupService.addOrganisationUnitGroup(ougA);
// User & Current User Service
user = createAndInjectAdminUser();
user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
userService.addUser(user);
CurrentUserService currentUserService = new MockCurrentUserService(user);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataValueSetService, organisationUnitService);
}
use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.
the class DataValueSetExportAccessControlTest method setCurrentUser.
/**
* Inject current user in relevant services.
*
* @param user the user to inject.
*/
private void setCurrentUser(User user) {
userService.addUser(user);
CurrentUserService currentUserService = new MockCurrentUserService(user);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataValueSetService, dataValueSetStore, organisationUnitService);
}
use of org.hisp.dhis.user.CurrentUserServiceTarget in project dhis2-core by dhis2.
the class DataValueSetServiceExportTest method setUpTest.
@Override
public void setUpTest() {
userService = _userService;
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));
periodService.addPeriod(peA);
periodService.addPeriod(peB);
peAUid = peA.getUid();
peBUid = peB.getUid();
deA = createDataElement('A');
deB = createDataElement('B');
deC = createDataElement('C');
dataElementService.addDataElement(deA);
dataElementService.addDataElement(deB);
dataElementService.addDataElement(deC);
ccA = createCategoryCombo('A');
categoryService.addCategoryCombo(ccA);
cocA = createCategoryOptionCombo('A');
cocB = createCategoryOptionCombo('B');
cocA.setCategoryCombo(ccA);
cocB.setCategoryCombo(ccA);
categoryService.addCategoryOptionCombo(cocA);
categoryService.addCategoryOptionCombo(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);
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B', ouA);
// Not in hierarchy of A
ouC = createOrganisationUnit('C');
organisationUnitService.addOrganisationUnit(ouA);
organisationUnitService.addOrganisationUnit(ouB);
organisationUnitService.addOrganisationUnit(ouC);
ogA = createOrganisationUnitGroup('A');
idObjectManager.save(ogA);
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
// Service mocks
user = createUser('A');
user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
userService.addUser(user);
CurrentUserService currentUserService = new MockCurrentUserService(user);
setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataValueSetService, organisationUnitService);
enableDataSharing(user, dsA, AccessStringHelper.DATA_READ_WRITE);
enableDataSharing(user, dsB, AccessStringHelper.DATA_READ_WRITE);
dataSetService.updateDataSet(dsA);
dataSetService.updateDataSet(dsB);
}
Aggregations