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);
}
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();
}
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);
}
}
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);
}
}
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));
}
Aggregations