Search in sources :

Example 46 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class DataApprovalAuditServiceTest method setUpTest.

// -------------------------------------------------------------------------
// Set up/tear down
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    // ---------------------------------------------------------------------
    // Add supporting data
    // ---------------------------------------------------------------------
    PeriodType periodType = PeriodType.getPeriodTypeByName("Monthly");
    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);
    superUserService = getMockCurrentUserService("SuperUser", true, sourceA, UserAuthorityGroup.AUTHORITY_ALL);
    userAService = getMockCurrentUserService("UserA", false, sourceA);
    userBService = getMockCurrentUserService("UserB", false, sourceB);
    userCService = getMockCurrentUserService("UserC", false, sourceB);
    userDService = getMockCurrentUserService("UserD", false, sourceB);
    userZ = createUser('Z');
    userService.addUser(userZ);
    UserGroup userGroupC = getUserGroup("UserGroupA", Sets.newHashSet(userCService.getCurrentUser()));
    UserGroup userGroupD = getUserGroup("UserGroupB", Sets.newHashSet(userDService.getCurrentUser()));
    optionA = new DataElementCategoryOption("CategoryOptionA");
    optionB = new DataElementCategoryOption("CategoryOptionB");
    categoryService.addDataElementCategoryOption(optionA);
    categoryService.addDataElementCategoryOption(optionB);
    categoryA = createDataElementCategory('A', optionA, optionB);
    categoryService.addDataElementCategory(categoryA);
    categoryComboA = createCategoryCombo('A', categoryA);
    categoryService.addDataElementCategoryCombo(categoryComboA);
    optionComboA = createCategoryOptionCombo('A', categoryComboA, optionA);
    optionComboB = createCategoryOptionCombo('B', categoryComboA, optionB);
    optionComboC = createCategoryOptionCombo('C', categoryComboA, optionA, optionB);
    categoryService.addDataElementCategoryOptionCombo(optionComboA);
    categoryService.addDataElementCategoryOptionCombo(optionComboB);
    categoryService.addDataElementCategoryOptionCombo(optionComboC);
    optionGroupA = createCategoryOptionGroup('A', optionA);
    optionGroupB = createCategoryOptionGroup('B', optionB);
    categoryService.saveCategoryOptionGroup(optionGroupA);
    categoryService.saveCategoryOptionGroup(optionGroupB);
    optionGroupSetB = new CategoryOptionGroupSet("OptionGroupSetB");
    categoryService.saveCategoryOptionGroupSet(optionGroupSetB);
    optionGroupSetB.addCategoryOptionGroup(optionGroupA);
    optionGroupSetB.addCategoryOptionGroup(optionGroupB);
    optionGroupA.getGroupSets().add(optionGroupSetB);
    optionGroupB.getGroupSets().add(optionGroupSetB);
    setPrivateAccess(optionA, userGroupC);
    setPrivateAccess(optionB);
    setPrivateAccess(optionGroupA);
    setPrivateAccess(optionGroupB, userGroupD);
    categoryService.updateCategoryOptionGroupSet(optionGroupSetB);
    categoryService.updateCategoryOptionGroup(optionGroupA);
    categoryService.updateCategoryOptionGroup(optionGroupB);
    userCService.getCurrentUser().getUserCredentials().getCatDimensionConstraints().add(categoryA);
    userDService.getCurrentUser().getUserCredentials().getCogsDimensionConstraints().add(optionGroupSetB);
    dateA = getDate(2017, 1, 1);
    dateB = getDate(2018, 1, 1);
    level1 = new DataApprovalLevel("01", 1, null);
    level2 = new DataApprovalLevel("02", 2, null);
    level3 = new DataApprovalLevel("03", 2, optionGroupSetB);
    dataApprovalLevelService.addDataApprovalLevel(level1);
    dataApprovalLevelService.addDataApprovalLevel(level2);
    dataApprovalLevelService.addDataApprovalLevel(level3);
    workflowA = new DataApprovalWorkflow("workflowA", periodType, newHashSet(level1));
    workflowB = new DataApprovalWorkflow("workflowB", periodType, newHashSet(level1, level2, level3));
    dataApprovalService.addWorkflow(workflowA);
    dataApprovalService.addWorkflow(workflowB);
    DataApproval approvalAA1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboA, false, dateA, userZ);
    DataApproval approvalAB1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboB, false, dateA, userZ);
    DataApproval approvalAC1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboC, false, dateA, userZ);
    DataApproval approvalBA2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboA, false, dateB, userZ);
    DataApproval approvalBB2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboB, false, dateB, userZ);
    DataApproval approvalBC2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboC, false, dateB, userZ);
    DataApproval approvalBA3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboA, false, dateB, userZ);
    DataApproval approvalBB3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboB, false, dateB, userZ);
    DataApproval approvalBC3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboC, false, dateB, userZ);
    auditAA1 = new DataApprovalAudit(approvalAA1, APPROVE);
    auditAB1 = new DataApprovalAudit(approvalAB1, UNAPPROVE);
    auditAC1 = new DataApprovalAudit(approvalAC1, ACCEPT);
    auditBA2 = new DataApprovalAudit(approvalBA2, UNACCEPT);
    auditBB2 = new DataApprovalAudit(approvalBB2, APPROVE);
    auditBC2 = new DataApprovalAudit(approvalBC2, UNAPPROVE);
    auditBA3 = new DataApprovalAudit(approvalBA3, ACCEPT);
    auditBB3 = new DataApprovalAudit(approvalBB3, UNACCEPT);
    auditBC3 = new DataApprovalAudit(approvalBC3, APPROVE);
    dataApprovalAuditStore.save(auditAA1);
    dataApprovalAuditStore.save(auditAB1);
    dataApprovalAuditStore.save(auditAC1);
    dataApprovalAuditStore.save(auditBA2);
    dataApprovalAuditStore.save(auditBB2);
    dataApprovalAuditStore.save(auditBC2);
    dataApprovalAuditStore.save(auditBA3);
    dataApprovalAuditStore.save(auditBB3);
    dataApprovalAuditStore.save(auditBC3);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) CategoryOptionGroupSet(org.hisp.dhis.dataelement.CategoryOptionGroupSet) UserGroup(org.hisp.dhis.user.UserGroup)

Example 47 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class DataApprovalStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Set up/tear down
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    // ---------------------------------------------------------------------
    // 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");
    workflowA1 = new DataApprovalWorkflow("workflowA1", periodType, newHashSet(level1));
    workflowA12 = new DataApprovalWorkflow("workflowA12", periodType, newHashSet(level1, level2));
    workflowB12 = new DataApprovalWorkflow("workflowB12", periodType, newHashSet(level1, level2));
    dataApprovalService.addWorkflow(workflowA1);
    dataApprovalService.addWorkflow(workflowA12);
    dataApprovalService.addWorkflow(workflowB12);
    periodA = createPeriod(getDay(5), getDay(6));
    periodB = createPeriod(getDay(6), getDay(7));
    periodService.addPeriod(periodA);
    periodService.addPeriod(periodB);
    sourceA = createOrganisationUnit('A');
    sourceB = createOrganisationUnit('B', sourceA);
    sourceC = createOrganisationUnit('C', sourceB);
    sourceD = createOrganisationUnit('D', sourceC);
    organisationUnitService.addOrganisationUnit(sourceA);
    organisationUnitService.addOrganisationUnit(sourceB);
    organisationUnitService.addOrganisationUnit(sourceC);
    organisationUnitService.addOrganisationUnit(sourceD);
    userA = createUser('A');
    userB = createUser('B');
    userService.addUser(userA);
    userService.addUser(userB);
    categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType)

Example 48 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class ValidationRuleObjectBundleHook method preCreate.

@Override
public void preCreate(IdentifiableObject object, ObjectBundle bundle) {
    if (!ValidationRule.class.isInstance(object)) {
        return;
    }
    ValidationRule validationRule = (ValidationRule) object;
    if (validationRule.getPeriodType() != null) {
        PeriodType periodType = bundle.getPreheat().getPeriodTypeMap().get(validationRule.getPeriodType().getName());
        validationRule.setPeriodType(periodType);
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) ValidationRule(org.hisp.dhis.validation.ValidationRule)

Example 49 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class ProgramStageObjectBundleHook method preCreate.

@Override
public <T extends IdentifiableObject> void preCreate(T object, ObjectBundle bundle) {
    if (!ProgramStage.class.isInstance(object))
        return;
    ProgramStage programStage = (ProgramStage) object;
    if (programStage.getPeriodType() != null) {
        PeriodType periodType = bundle.getPreheat().getPeriodTypeMap().get(programStage.getPeriodType().getName());
        programStage.setPeriodType(periodType);
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 50 with PeriodType

use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.

the class UniqueArrayListTest method testCollectionConstructor.

@Test
public void testCollectionConstructor() {
    List<Period> list = new ArrayList<>();
    PeriodType periodType = new MonthlyPeriodType();
    Period peA = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    // Duplicate
    Period peB = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
    Period peC = periodType.createPeriod(new DateTime(2000, 2, 1, 0, 0).toDate());
    list.add(peA);
    list.add(peB);
    list.add(peC);
    assertEquals(3, list.size());
    List<Period> uniqueList = new UniqueArrayList<>(list);
    assertEquals(2, uniqueList.size());
    assertTrue(uniqueList.contains(peA));
    assertTrue(uniqueList.contains(peB));
    assertTrue(uniqueList.contains(peC));
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

PeriodType (org.hisp.dhis.period.PeriodType)67 Period (org.hisp.dhis.period.Period)21 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)13 ArrayList (java.util.ArrayList)12 DataSet (org.hisp.dhis.dataset.DataSet)12 DataElement (org.hisp.dhis.dataelement.DataElement)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)9 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)7 UniqueArrayList (org.hisp.dhis.commons.collection.UniqueArrayList)6 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)6 ProgramStage (org.hisp.dhis.program.ProgramStage)6 Test (org.junit.Test)6 Date (java.util.Date)5 HashSet (java.util.HashSet)5 QuarterlyPeriodType (org.hisp.dhis.period.QuarterlyPeriodType)5 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)5 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)4 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)4 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)4 DailyPeriodType (org.hisp.dhis.period.DailyPeriodType)4