Search in sources :

Example 1 with CurrentUserServiceTarget

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

the class DataApprovalStoreUserTest method setUpTest.

// -------------------------------------------------------------------------
// Set up/tear down
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    periodA = createPeriod("201801");
    periodService.addPeriod(periodA);
    level1 = new DataApprovalLevel("Level1", 1, null);
    level2 = new DataApprovalLevel("Level2", 2, null);
    level3 = new DataApprovalLevel("Level3", 3, null);
    dataApprovalLevelService.addDataApprovalLevel(level1);
    dataApprovalLevelService.addDataApprovalLevel(level2);
    dataApprovalLevelService.addDataApprovalLevel(level3);
    PeriodType periodType = PeriodType.getPeriodTypeByName("Monthly");
    workflowA = new DataApprovalWorkflow("workflowA", periodType, newHashSet(level1, level2, level3));
    dataApprovalService.addWorkflow(workflowA);
    DataSet dataSetA = createDataSet('A');
    dataSetA.assignWorkflow(workflowA);
    dataSetService.addDataSet(dataSetA);
    orgUnitA = createOrganisationUnit('A');
    orgUnitB = createOrganisationUnit('B', orgUnitA);
    orgUnitC = createOrganisationUnit('C', orgUnitB);
    orgUnitD = createOrganisationUnit('D', orgUnitA);
    organisationUnitService.addOrganisationUnit(orgUnitA);
    organisationUnitService.addOrganisationUnit(orgUnitB);
    organisationUnitService.addOrganisationUnit(orgUnitC);
    organisationUnitService.addOrganisationUnit(orgUnitD);
    orgUnitA.addDataSet(dataSetA);
    orgUnitB.addDataSet(dataSetA);
    orgUnitC.addDataSet(dataSetA);
    orgUnitD.addDataSet(dataSetA);
    organisationUnitService.updateOrganisationUnit(orgUnitA);
    organisationUnitService.updateOrganisationUnit(orgUnitB);
    organisationUnitService.updateOrganisationUnit(orgUnitC);
    organisationUnitService.updateOrganisationUnit(orgUnitD);
    mockCurrentUserService = new MockCurrentUserService(true, Sets.newHashSet(orgUnitA), Sets.newHashSet(orgUnitA));
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, mockCurrentUserService, dataApprovalStore, dataApprovalLevelService);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) DataSet(org.hisp.dhis.dataset.DataSet) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget)

Example 2 with CurrentUserServiceTarget

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

the class DataApprovalAuditStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Set up/tear down
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataApprovalAuditStore);
    // ---------------------------------------------------------------------
    // Add supporting data
    // ---------------------------------------------------------------------
    level1 = new DataApprovalLevel("01", 1, null);
    level2 = new DataApprovalLevel("02", 2, null);
    dataApprovalLevelService.addDataApprovalLevel(level1);
    dataApprovalLevelService.addDataApprovalLevel(level2);
    PeriodType periodType = PeriodType.getPeriodTypeByName("Monthly");
    workflowA = new DataApprovalWorkflow("workflowA", periodType, newHashSet(level1));
    workflowB = new DataApprovalWorkflow("workflowB", periodType, newHashSet(level1, level2));
    dataApprovalService.addWorkflow(workflowA);
    dataApprovalService.addWorkflow(workflowB);
    periodA = createPeriod(new MonthlyPeriodType(), getDate(2017, 1, 1), getDate(2017, 1, 31));
    periodB = createPeriod(new MonthlyPeriodType(), getDate(2018, 1, 1), getDate(2018, 1, 31));
    periodService.addPeriod(periodA);
    periodService.addPeriod(periodB);
    sourceA = createOrganisationUnit('A');
    sourceB = createOrganisationUnit('B', sourceA);
    organisationUnitService.addOrganisationUnit(sourceA);
    organisationUnitService.addOrganisationUnit(sourceB);
    userA = createUser('A');
    userService.addUser(userA);
    optionA = new CategoryOption("CategoryOptionA");
    optionB = new CategoryOption("CategoryOptionB");
    categoryService.addCategoryOption(optionA);
    categoryService.addCategoryOption(optionB);
    categoryA = createCategory('A', optionA, optionB);
    categoryService.addCategory(categoryA);
    categoryComboA = createCategoryCombo('A', categoryA);
    categoryService.addCategoryCombo(categoryComboA);
    optionComboA = createCategoryOptionCombo(categoryComboA, optionA);
    optionComboB = createCategoryOptionCombo(categoryComboA, optionA, optionB);
    categoryService.addCategoryOptionCombo(optionComboA);
    categoryService.addCategoryOptionCombo(optionComboB);
    dateA = getDate(2017, 1, 1);
    dateB = getDate(2018, 1, 1);
    DataApproval approvalA = new DataApproval(level1, workflowA, periodA, sourceA, optionComboA, false, dateA, userA);
    DataApproval approvalB = new DataApproval(level2, workflowB, periodB, sourceB, optionComboB, false, dateB, userA);
    auditA = new DataApprovalAudit(approvalA, APPROVE);
    auditB = new DataApprovalAudit(approvalB, UNAPPROVE);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) CategoryOption(org.hisp.dhis.category.CategoryOption)

Example 3 with CurrentUserServiceTarget

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

the class DataApprovalAuditStoreTest method TestGetDataApprovalAudits.

@Test
void TestGetDataApprovalAudits() throws Exception {
    dataApprovalAuditStore.save(auditA);
    dataApprovalAuditStore.save(auditB);
    DataApprovalAuditQueryParams params;
    List<DataApprovalAudit> audits;
    params = new DataApprovalAuditQueryParams();
    params.setWorkflows(Sets.newHashSet(workflowA));
    audits = dataApprovalAuditStore.getDataApprovalAudits(params);
    assertEquals(1, audits.size());
    assertEquals(auditA, audits.get(0));
    params = new DataApprovalAuditQueryParams();
    params.setLevels(Sets.newHashSet(level1));
    audits = dataApprovalAuditStore.getDataApprovalAudits(params);
    assertEquals(1, audits.size());
    assertEquals(auditA, audits.get(0));
    params = new DataApprovalAuditQueryParams();
    params.setOrganisationUnits(Sets.newHashSet(sourceA));
    audits = dataApprovalAuditStore.getDataApprovalAudits(params);
    assertEquals(1, audits.size());
    assertEquals(auditA, audits.get(0));
    params = new DataApprovalAuditQueryParams();
    params.setAttributeOptionCombos(Sets.newHashSet(optionComboA));
    audits = dataApprovalAuditStore.getDataApprovalAudits(params);
    assertEquals(1, audits.size());
    assertEquals(auditA, audits.get(0));
    params = new DataApprovalAuditQueryParams();
    params.setStartDate(dateB);
    audits = dataApprovalAuditStore.getDataApprovalAudits(params);
    assertEquals(1, audits.size());
    assertEquals(auditB, audits.get(0));
    params = new DataApprovalAuditQueryParams();
    params.setEndDate(dateB);
    audits = dataApprovalAuditStore.getDataApprovalAudits(params);
    assertEquals(1, audits.size());
    assertEquals(auditA, audits.get(0));
    CurrentUserService mockUserService = new MockCurrentUserService(Sets.newHashSet(sourceB), null);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, mockUserService, dataApprovalAuditStore);
    params = new DataApprovalAuditQueryParams();
    audits = dataApprovalAuditStore.getDataApprovalAudits(params);
    assertEquals(1, audits.size());
    assertEquals(auditB, audits.get(0));
}
Also used : 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) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 4 with CurrentUserServiceTarget

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

the class DataApprovalLevelServiceTest method testGetUserDataApprovalLevelsApproveHere.

// TODO: add tests for getUserDataApprovalLevels where the user can access
// the CategoryOptionGroupSets
@Test
void testGetUserDataApprovalLevelsApproveHere() {
    dataApprovalLevelService.addDataApprovalLevel(level4B);
    dataApprovalLevelService.addDataApprovalLevel(level4A);
    dataApprovalLevelService.addDataApprovalLevel(level4);
    dataApprovalLevelService.addDataApprovalLevel(level3B);
    dataApprovalLevelService.addDataApprovalLevel(level3A);
    dataApprovalLevelService.addDataApprovalLevel(level3);
    dataApprovalLevelService.addDataApprovalLevel(level2B);
    dataApprovalLevelService.addDataApprovalLevel(level2A);
    dataApprovalLevelService.addDataApprovalLevel(level2);
    dataApprovalLevelService.addDataApprovalLevel(level1B);
    dataApprovalLevelService.addDataApprovalLevel(level1A);
    dataApprovalLevelService.addDataApprovalLevel(level1);
    Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
    assignedOrgUnits.add(organisationUnitB);
    Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
    dataViewOrgUnits.add(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits, DataApproval.AUTH_APPROVE);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataApprovalLevelService);
    List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels(currentUserService.getCurrentUser());
    assertEquals("02 2A 2B 03 3A 3B 04 4A 4B", levelNames(levels));
}
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) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with CurrentUserServiceTarget

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

the class DataApprovalLevelServiceTest method testGetUserDataApprovalLevelsApproveLower.

@Test
void testGetUserDataApprovalLevelsApproveLower() {
    dataApprovalLevelService.addDataApprovalLevel(level4B);
    dataApprovalLevelService.addDataApprovalLevel(level4A);
    dataApprovalLevelService.addDataApprovalLevel(level4);
    dataApprovalLevelService.addDataApprovalLevel(level3B);
    dataApprovalLevelService.addDataApprovalLevel(level3A);
    dataApprovalLevelService.addDataApprovalLevel(level3);
    dataApprovalLevelService.addDataApprovalLevel(level2B);
    dataApprovalLevelService.addDataApprovalLevel(level2A);
    dataApprovalLevelService.addDataApprovalLevel(level2);
    dataApprovalLevelService.addDataApprovalLevel(level1B);
    dataApprovalLevelService.addDataApprovalLevel(level1A);
    dataApprovalLevelService.addDataApprovalLevel(level1);
    Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
    assignedOrgUnits.add(organisationUnitB);
    Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
    dataViewOrgUnits.add(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits, DataApproval.AUTH_APPROVE_LOWER_LEVELS);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataApprovalLevelService);
    List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels(currentUserService.getCurrentUser());
    assertEquals("02 2A 2B 03 3A 3B 04 4A 4B", levelNames(levels));
}
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) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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