Search in sources :

Example 16 with CategoryOption

use of org.hisp.dhis.category.CategoryOption 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 17 with CategoryOption

use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.

the class DataApprovalServiceCategoryOptionGroupTest method setUpTest.

// -------------------------------------------------------------------------
// Set up/tear down
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    userService = _userService;
    // ---------------------------------------------------------------------
    // Add supporting data
    // ---------------------------------------------------------------------
    global = createOrganisationUnit("Global");
    americas = createOrganisationUnit("Americas", global);
    asia = createOrganisationUnit("Asia", global);
    brazil = createOrganisationUnit("Brazil", americas);
    china = createOrganisationUnit("China", asia);
    india = createOrganisationUnit("India", asia);
    organisationUnitService.addOrganisationUnit(global);
    organisationUnitService.addOrganisationUnit(americas);
    organisationUnitService.addOrganisationUnit(asia);
    organisationUnitService.addOrganisationUnit(brazil);
    organisationUnitService.addOrganisationUnit(china);
    organisationUnitService.addOrganisationUnit(india);
    userA = createUser('A');
    userService.addUser(userA);
    dateA = new Date();
    superUser = mockUser("SuperUser", global, AUTHORITY_ALL);
    superUser.setSuperUserFlag(true);
    globalConsultant = mockUser("GlobalConsultant", global, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS, AUTH_APPROVE_LOWER_LEVELS);
    globalUser = mockUser("GlobalUser", global, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
    globalApproveOnly = mockUser("GlobalApproveOnly", global, AUTH_APPROVE);
    globalAcceptOnly = mockUser("GlobalAcceptOnly", global, AUTH_ACCEPT_LOWER_LEVELS);
    globalReadAll = mockUser("GlobalReadEverything", global, AUTH_VIEW_UNAPPROVED_DATA);
    globalAgencyAUser = mockUser("GlobalAgencyAUser", global, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
    globalAgencyBUser = mockUser("GlobalAgencyBUser", global, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
    brazilInteragencyUser = mockUser("BrazilInteragencyUser", brazil, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
    chinaInteragencyUser = mockUser("ChinaInteragencyUser", china, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
    chinaInteragencyApproveOnly = mockUser("ChinaInteragencyApproveOnly", china, AUTH_APPROVE);
    chinalInteragencyAcceptOnly = mockUser("ChinalInteragencyAcceptOnly", china, AUTH_ACCEPT_LOWER_LEVELS);
    indiaInteragencyUser = mockUser("IndiaInteragencyUser", india, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
    brazilAgencyAUser = mockUser("BrazilAgencyAUser", brazil, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
    chinaAgencyAUser = mockUser("ChinaAgencyAUser", china, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
    chinaAgencyAApproveOnly = mockUser("ChinaAgencyAApproveOnly", china, AUTH_APPROVE);
    chinaAgencyAAcceptOnly = mockUser("ChinaAgencyAAcceptOnly", china, AUTH_ACCEPT_LOWER_LEVELS);
    chinaAgencyBUser = mockUser("ChinaAgencyBUser", china, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
    indiaAgencyAUser = mockUser("IndiaAgencyAUser", india, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
    brazilPartner1User = mockUser("BrazilPartner1User", brazil, AUTH_APPROVE);
    chinaPartner1User = mockUser("ChinaPartner1User", china, AUTH_APPROVE);
    chinaPartner2User = mockUser("ChinaPartner2User", china, AUTH_APPROVE);
    indiaPartner1User = mockUser("IndiaPartner1User", india, AUTH_APPROVE);
    currentMockUserService = null;
    UserGroup globalUsers = getUserGroup("GlobalUsers", userSet(globalUser, globalApproveOnly, globalAcceptOnly, globalConsultant, globalReadAll));
    UserGroup globalAgencyAUsers = getUserGroup("GlobalAgencyAUsers", userSet(globalAgencyAUser));
    UserGroup globalAgencyBUsers = getUserGroup("GlobalAgencyBUsers", userSet(globalAgencyBUser));
    UserGroup brazilInteragencyUsers = getUserGroup("BrazilInteragencyUsers", userSet(brazilInteragencyUser));
    UserGroup chinaInteragencyUsers = getUserGroup("ChinaInteragencyUsers", userSet(chinaInteragencyUser, chinaInteragencyApproveOnly, chinalInteragencyAcceptOnly));
    UserGroup indiaInteragencyUsers = getUserGroup("IndiaInteragencyUsers", userSet(indiaInteragencyUser));
    UserGroup brazilAgencyAUsers = getUserGroup("BrazilAgencyAUsers", userSet(brazilAgencyAUser));
    UserGroup chinaAgencyAUsers = getUserGroup("ChinaAgencyAUsers", userSet(chinaAgencyAUser, chinaAgencyAApproveOnly, chinaAgencyAAcceptOnly));
    UserGroup chinaAgencyBUsers = getUserGroup("ChinaAgencyBUsers", userSet(chinaAgencyBUser));
    UserGroup indiaAgencyAUsers = getUserGroup("IndiaAgencyAUsers", userSet(indiaAgencyAUser));
    UserGroup brazilPartner1Users = getUserGroup("BrazilPartner1Users", userSet(brazilPartner1User));
    UserGroup chinaPartner1Users = getUserGroup("ChinaPartner1Users", userSet(chinaPartner1User));
    UserGroup chinaPartner2Users = getUserGroup("ChinaPartner2Users", userSet(chinaPartner2User));
    UserGroup indiaPartner1Users = getUserGroup("IndiaPartner1Users", userSet(indiaPartner1User));
    brazilA1 = new CategoryOption("BrazilA1");
    chinaA1_1 = new CategoryOption("ChinaA1_1");
    chinaA1_2 = new CategoryOption("ChinaA1_2");
    chinaA2 = new CategoryOption("ChinaA2");
    chinaB2 = new CategoryOption("ChinaB2");
    indiaA1 = new CategoryOption("IndiaA1");
    brazilA1.setOrganisationUnits(Sets.newHashSet(brazil));
    chinaA1_1.setOrganisationUnits(Sets.newHashSet(china));
    chinaA1_2.setOrganisationUnits(Sets.newHashSet(china));
    chinaA2.setOrganisationUnits(Sets.newHashSet(china));
    chinaB2.setOrganisationUnits(Sets.newHashSet(china));
    indiaA1.setOrganisationUnits(Sets.newHashSet(india));
    categoryService.addCategoryOption(brazilA1);
    categoryService.addCategoryOption(chinaA1_1);
    categoryService.addCategoryOption(chinaA1_2);
    categoryService.addCategoryOption(chinaA2);
    categoryService.addCategoryOption(chinaB2);
    categoryService.addCategoryOption(indiaA1);
    setAccess(brazilA1, globalUsers, globalAgencyAUsers, brazilInteragencyUsers, brazilAgencyAUsers, brazilPartner1Users);
    setAccess(chinaA1_1, globalUsers, globalAgencyAUsers, chinaInteragencyUsers, chinaAgencyAUsers, chinaPartner1Users);
    setAccess(chinaA1_2, globalUsers, globalAgencyAUsers, chinaInteragencyUsers, chinaAgencyAUsers, chinaPartner1Users);
    setAccess(chinaA2, globalUsers, globalAgencyAUsers, chinaInteragencyUsers, chinaAgencyAUsers, chinaPartner2Users);
    setAccess(chinaB2, globalUsers, globalAgencyBUsers, chinaInteragencyUsers, chinaAgencyBUsers, chinaPartner2Users);
    setAccess(indiaA1, globalUsers, globalAgencyAUsers, indiaInteragencyUsers, indiaAgencyAUsers, indiaPartner1Users);
    mechanismCategory = createCategory('A', brazilA1, chinaA1_1, chinaA1_2, chinaA2, chinaB2, indiaA1);
    categoryService.addCategory(mechanismCategory);
    mechanismCategoryCombo = createCategoryCombo('A', mechanismCategory);
    categoryService.addCategoryCombo(mechanismCategoryCombo);
    constrainByMechanism(globalAgencyAUser);
    constrainByMechanism(globalAgencyBUser);
    constrainByMechanism(brazilAgencyAUser);
    constrainByMechanism(chinaAgencyAUser);
    constrainByMechanism(chinaAgencyAApproveOnly);
    constrainByMechanism(chinaAgencyAAcceptOnly);
    constrainByMechanism(chinaAgencyBUser);
    constrainByMechanism(indiaAgencyAUser);
    constrainByMechanism(brazilPartner1User);
    constrainByMechanism(chinaPartner1User);
    constrainByMechanism(chinaPartner2User);
    constrainByMechanism(indiaPartner1User);
    userService.updateUser(globalAgencyAUser.getCurrentUser());
    userService.updateUser(globalAgencyBUser.getCurrentUser());
    userService.updateUser(brazilAgencyAUser.getCurrentUser());
    userService.updateUser(chinaAgencyAUser.getCurrentUser());
    userService.updateUser(chinaAgencyAApproveOnly.getCurrentUser());
    userService.updateUser(chinaAgencyAAcceptOnly.getCurrentUser());
    userService.updateUser(chinaAgencyBUser.getCurrentUser());
    userService.updateUser(indiaAgencyAUser.getCurrentUser());
    userService.updateUser(brazilPartner1User.getCurrentUser());
    userService.updateUser(chinaPartner1User.getCurrentUser());
    userService.updateUser(chinaPartner2User.getCurrentUser());
    userService.updateUser(indiaPartner1User.getCurrentUser());
    brazilA1Combo = createCategoryOptionCombo(mechanismCategoryCombo, brazilA1);
    chinaA1_1Combo = createCategoryOptionCombo(mechanismCategoryCombo, chinaA1_1);
    chinaA1_2Combo = createCategoryOptionCombo(mechanismCategoryCombo, chinaA1_2);
    chinaA2Combo = createCategoryOptionCombo(mechanismCategoryCombo, chinaA2);
    chinaB2Combo = createCategoryOptionCombo(mechanismCategoryCombo, chinaB2);
    indiaA1Combo = createCategoryOptionCombo(mechanismCategoryCombo, indiaA1);
    categoryService.addCategoryOptionCombo(brazilA1Combo);
    categoryService.addCategoryOptionCombo(chinaA1_1Combo);
    categoryService.addCategoryOptionCombo(chinaA1_2Combo);
    categoryService.addCategoryOptionCombo(chinaA2Combo);
    categoryService.addCategoryOptionCombo(chinaB2Combo);
    categoryService.addCategoryOptionCombo(indiaA1Combo);
    mechanismCategoryCombo.getOptionCombos().add(brazilA1Combo);
    mechanismCategoryCombo.getOptionCombos().add(chinaA1_1Combo);
    mechanismCategoryCombo.getOptionCombos().add(chinaA1_2Combo);
    mechanismCategoryCombo.getOptionCombos().add(chinaA2Combo);
    mechanismCategoryCombo.getOptionCombos().add(chinaB2Combo);
    mechanismCategoryCombo.getOptionCombos().add(indiaA1Combo);
    categoryService.updateCategoryCombo(mechanismCategoryCombo);
    agencyA = createCategoryOptionGroup('A', brazilA1, chinaA1_1, chinaA1_2, chinaA2, indiaA1);
    agencyB = createCategoryOptionGroup('B', chinaB2);
    partner1 = createCategoryOptionGroup('1', brazilA1, chinaA1_1, chinaA1_2, indiaA1);
    partner2 = createCategoryOptionGroup('2', chinaA2, chinaB2);
    categoryService.saveCategoryOptionGroup(agencyA);
    categoryService.saveCategoryOptionGroup(agencyB);
    categoryService.saveCategoryOptionGroup(partner1);
    categoryService.saveCategoryOptionGroup(partner2);
    setAccess(agencyA, globalUsers, globalAgencyAUsers, brazilInteragencyUsers, chinaInteragencyUsers, indiaInteragencyUsers, brazilAgencyAUsers, chinaAgencyAUsers, indiaAgencyAUsers);
    setAccess(agencyB, globalUsers, globalAgencyBUsers, chinaInteragencyUsers, chinaAgencyBUsers);
    setAccess(partner1, globalUsers, brazilInteragencyUsers, chinaInteragencyUsers, indiaInteragencyUsers, brazilAgencyAUsers, chinaAgencyAUsers, indiaAgencyAUsers, brazilPartner1Users, chinaPartner1Users, indiaPartner1Users);
    setAccess(partner2, globalUsers, chinaInteragencyUsers, chinaAgencyAUsers, chinaPartner2Users);
    agencies = new CategoryOptionGroupSet("Agencies");
    partners = new CategoryOptionGroupSet("Partners");
    categoryService.saveCategoryOptionGroupSet(partners);
    categoryService.saveCategoryOptionGroupSet(agencies);
    setAccess(agencies, globalUsers, globalAgencyAUsers, globalAgencyBUsers, brazilInteragencyUsers, chinaInteragencyUsers, indiaInteragencyUsers, brazilAgencyAUsers, chinaAgencyAUsers, chinaAgencyBUsers, chinaAgencyBUsers, indiaAgencyAUsers);
    setAccess(partners, globalUsers, brazilInteragencyUsers, chinaInteragencyUsers, indiaInteragencyUsers, brazilAgencyAUsers, chinaAgencyAUsers, chinaAgencyBUsers, chinaAgencyBUsers, indiaAgencyAUsers, brazilPartner1Users, chinaPartner1Users, chinaPartner2Users, indiaPartner1Users);
    agencies.addCategoryOptionGroup(agencyA);
    agencies.addCategoryOptionGroup(agencyB);
    partners.addCategoryOptionGroup(partner1);
    partners.addCategoryOptionGroup(partner2);
    agencyA.getGroupSets().add(agencies);
    agencyB.getGroupSets().add(agencies);
    partner1.getGroupSets().add(partners);
    partner2.getGroupSets().add(partners);
    categoryService.updateCategoryOptionGroupSet(partners);
    categoryService.updateCategoryOptionGroupSet(agencies);
    categoryService.updateCategoryOptionGroup(agencyA);
    categoryService.updateCategoryOptionGroup(agencyB);
    categoryService.updateCategoryOptionGroup(partner1);
    categoryService.updateCategoryOptionGroup(partner2);
    globalLevel1 = new DataApprovalLevel("GlobalLevel1", 1, null);
    globalAgencyLevel2 = new DataApprovalLevel("GlobalAgencyLevel2", 1, agencies);
    countryLevel3 = new DataApprovalLevel("CountryLevel3", 3, null);
    agencyLevel4 = new DataApprovalLevel("AgencyLevel4", 3, agencies);
    partnerLevel5 = new DataApprovalLevel("PartnerLevel5", 3, partners);
    dataApprovalLevelService.addDataApprovalLevel(globalLevel1, 1);
    dataApprovalLevelService.addDataApprovalLevel(globalAgencyLevel2, 2);
    dataApprovalLevelService.addDataApprovalLevel(countryLevel3, 3);
    dataApprovalLevelService.addDataApprovalLevel(agencyLevel4, 4);
    dataApprovalLevelService.addDataApprovalLevel(partnerLevel5, 5);
    periodType = periodService.reloadPeriodType(PeriodType.getPeriodTypeByName("Monthly"));
    periodA = createPeriod("201801");
    periodService.addPeriod(periodA);
    workflow1 = new DataApprovalWorkflow("workflow1", periodType, newHashSet(globalLevel1, countryLevel3, agencyLevel4, partnerLevel5));
    workflow2 = new DataApprovalWorkflow("workflow2", periodType, newHashSet(globalLevel1, globalAgencyLevel2, agencyLevel4, partnerLevel5));
    dataApprovalService.addWorkflow(workflow1);
    dataApprovalService.addWorkflow(workflow2);
    dataSetA = createDataSet('A', periodType, mechanismCategoryCombo);
    dataSetB = createDataSet('B', periodType, mechanismCategoryCombo);
    dataSetA.assignWorkflow(workflow1);
    dataSetB.assignWorkflow(workflow2);
    dataSetA.addOrganisationUnit(global);
    dataSetA.addOrganisationUnit(americas);
    dataSetA.addOrganisationUnit(asia);
    dataSetA.addOrganisationUnit(brazil);
    dataSetA.addOrganisationUnit(china);
    dataSetA.addOrganisationUnit(india);
    dataSetB.addOrganisationUnit(global);
    dataSetB.addOrganisationUnit(americas);
    dataSetB.addOrganisationUnit(asia);
    dataSetB.addOrganisationUnit(brazil);
    dataSetB.addOrganisationUnit(china);
    dataSetB.addOrganisationUnit(india);
    dataSetService.addDataSet(dataSetA);
    dataSetService.addDataSet(dataSetB);
    systemSettingManager.saveSystemSetting(SettingKey.IGNORE_ANALYTICS_APPROVAL_YEAR_THRESHOLD, 0);
    systemSettingManager.saveSystemSetting(SettingKey.ACCEPTANCE_REQUIRED_FOR_APPROVAL, true);
}
Also used : CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) CategoryOption(org.hisp.dhis.category.CategoryOption) Date(java.util.Date) UserGroup(org.hisp.dhis.user.UserGroup)

Example 18 with CategoryOption

use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.

the class CategoryComboTest method createCategoryOptionCombo.

private static CategoryOptionCombo createCategoryOptionCombo(CategoryCombo categoryCombo, CategoryOption... categoryOptions) {
    CategoryOptionCombo categoryOptionCombo = new CategoryOptionCombo();
    categoryOptionCombo.setCategoryCombo(categoryCombo);
    for (CategoryOption categoryOption : categoryOptions) {
        categoryOptionCombo.getCategoryOptions().add(categoryOption);
    }
    return categoryOptionCombo;
}
Also used : CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 19 with CategoryOption

use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.

the class CategoryComboTest method before.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@BeforeEach
void before() {
    categoryOptionA = new CategoryOption("OptionA");
    categoryOptionB = new CategoryOption("OptionB");
    categoryOptionC = new CategoryOption("OptionC");
    categoryOptionD = new CategoryOption("OptionD");
    categoryOptionE = new CategoryOption("OptionE");
    categoryOptionF = new CategoryOption("OptionF");
    categoryA = new Category("CategoryA", DataDimensionType.DISAGGREGATION);
    categoryB = new Category("CategoryB", DataDimensionType.DISAGGREGATION);
    categoryC = new Category("CategoryC", DataDimensionType.DISAGGREGATION);
    categoryA.getCategoryOptions().add(categoryOptionA);
    categoryA.getCategoryOptions().add(categoryOptionB);
    categoryB.getCategoryOptions().add(categoryOptionC);
    categoryB.getCategoryOptions().add(categoryOptionD);
    categoryC.getCategoryOptions().add(categoryOptionE);
    categoryC.getCategoryOptions().add(categoryOptionF);
    categoryOptionA.getCategories().add(categoryA);
    categoryOptionB.getCategories().add(categoryA);
    categoryOptionC.getCategories().add(categoryB);
    categoryOptionD.getCategories().add(categoryB);
    categoryOptionE.getCategories().add(categoryC);
    categoryOptionF.getCategories().add(categoryC);
    categoryCombo = new CategoryCombo("CategoryCombo", DataDimensionType.DISAGGREGATION);
    categoryCombo.getCategories().add(categoryA);
    categoryCombo.getCategories().add(categoryB);
    categoryCombo.getCategories().add(categoryC);
}
Also used : Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 20 with CategoryOption

use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.

the class EventAnalyticsServiceTest method testDimensionRestrictionSuccessfully.

@Test
void testDimensionRestrictionSuccessfully() {
    // Given
    // A program
    Program aProgram = createProgram('B', null, null, Sets.newHashSet(ouA, ouB), null);
    aProgram.setUid("aProgram123");
    idObjectManager.save(aProgram);
    // The category options
    CategoryOption coA = createCategoryOption('A');
    CategoryOption coB = createCategoryOption('B');
    categoryService.addCategoryOption(coA);
    categoryService.addCategoryOption(coB);
    // The categories
    Category caA = createCategory('A', coA);
    Category caB = createCategory('B', coB);
    categoryService.addCategory(caA);
    categoryService.addCategory(caB);
    // The constraints
    Set<Category> catDimensionConstraints = Sets.newHashSet(caA, caB);
    // The user
    User user = createUser("A", "F_VIEW_EVENT_ANALYTICS");
    user.setCatDimensionConstraints(catDimensionConstraints);
    userService.addUser(user);
    enableDataSharing(user, aProgram, AccessStringHelper.DATA_READ_WRITE);
    idObjectManager.update(user);
    injectSecurityContext(user);
    // All events in program B - 2017
    EventQueryParams events_2017_params = new EventQueryParams.Builder().withOrganisationUnits(Lists.newArrayList(ouA)).withStartDate(getDate(2017, 1, 1)).withEndDate(getDate(2017, 12, 31)).withProgram(aProgram).build();
    // When
    Grid aggregatedDataValueGrid = eventAnalyticsService.getAggregatedEventData(events_2017_params);
    // Then
    boolean noCategoryRestrictionExceptionIsThrown = true;
    assertThat(aggregatedDataValueGrid, is(notNullValue()));
    assert (noCategoryRestrictionExceptionIsThrown);
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) Program(org.hisp.dhis.program.Program) Category(org.hisp.dhis.category.Category) User(org.hisp.dhis.user.User) Grid(org.hisp.dhis.common.Grid) CategoryOption(org.hisp.dhis.category.CategoryOption) Test(org.junit.jupiter.api.Test)

Aggregations

CategoryOption (org.hisp.dhis.category.CategoryOption)87 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)47 CategoryCombo (org.hisp.dhis.category.CategoryCombo)38 Category (org.hisp.dhis.category.Category)34 Test (org.junit.jupiter.api.Test)33 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)26 Program (org.hisp.dhis.program.Program)19 ArrayList (java.util.ArrayList)18 Event (org.hisp.dhis.tracker.domain.Event)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15 HashSet (java.util.HashSet)14 Collectors (java.util.stream.Collectors)13 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)13 DataElement (org.hisp.dhis.dataelement.DataElement)13 Collections (java.util.Collections)12 DataSet (org.hisp.dhis.dataset.DataSet)12 CodeGenerator (org.hisp.dhis.common.CodeGenerator)11 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)11 CategoryService (org.hisp.dhis.category.CategoryService)10 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)10