use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class DataApprovalController method getDataApprovalList.
private List<DataApproval> getDataApprovalList(ApprovalsDto approvals) throws WebMessageException {
Set<DataApprovalWorkflow> workflows = getAndValidateWorkflows(approvals.getDs(), approvals.getWf());
List<Period> periods = PeriodType.getPeriodsFromIsoStrings(approvals.getPe());
periods = periodService.reloadPeriods(periods);
if (periods.isEmpty()) {
throw new WebMessageException(conflict("Approvals must have periods"));
}
User user = currentUserService.getCurrentUser();
CategoryOptionCombo defaultOptionCombo = categoryService.getDefaultCategoryOptionCombo();
Date date = new Date();
List<DataApproval> dataApprovals = new ArrayList<>();
List<CategoryOptionCombo> optionCombos = categoryService.getAllCategoryOptionCombos();
Map<String, CategoryOptionCombo> comboMap = optionCombos.stream().collect(Collectors.toMap(CategoryOptionCombo::getUid, c -> c));
Map<String, OrganisationUnit> ouCache = new HashMap<>();
for (ApprovalDto approval : approvals.getApprovals()) {
CategoryOptionCombo atributeOptionCombo = comboMap.get(approval.getAoc());
atributeOptionCombo = ObjectUtils.firstNonNull(atributeOptionCombo, defaultOptionCombo);
OrganisationUnit unit = ouCache.get(approval.getOu());
if (unit == null) {
unit = getAndValidateOrgUnit(approval.getOu());
ouCache.put(approval.getOu(), unit);
}
for (DataApprovalWorkflow workflow : workflows) {
for (Period period : periods) {
dataApprovals.add(new DataApproval(null, workflow, period, unit, atributeOptionCombo, false, date, user));
}
}
}
return dataApprovals;
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenEventAOCAndEventCOsAreSetAndInProgramCCButDoNotMatch.
@Test
void eventValidationFailsWhenEventAOCAndEventCOsAreSetAndInProgramCCButDoNotMatch() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
CategoryCombo cc = categoryCombo();
program.setCategoryCombo(cc);
CategoryOptionCombo aoc1 = cc.getSortedOptionCombos().get(0);
CategoryOption co1 = (CategoryOption) aoc1.getCategoryOptions().toArray()[0];
when(preheat.getCategoryOption(co1.getUid())).thenReturn(co1);
CategoryOptionCombo aoc2 = cc.getSortedOptionCombos().get(1);
when(preheat.getCategoryOptionCombo(aoc2.getUid())).thenReturn(aoc2);
Event event = eventBuilder().attributeOptionCombo(aoc2.getUid()).attributeCategoryOptions(co1.getUid()).build();
hook.validateEvent(reporter, event);
assertEquals(1, reporter.getReportList().size());
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1053 && r.getErrorMessage().contains(co1.getUid()) && r.getErrorMessage().contains(aoc2.getUid())));
assertNull(reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should not be cached");
verify(preheat, times(0)).put(any(), (IdentifiableObject) any());
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method categoryComboWithTwoCategories.
private CategoryCombo categoryComboWithTwoCategories() {
char uniqueIdentifier = 'A';
CategoryOption co1 = createCategoryOption(uniqueIdentifier);
Category ca1 = createCategory(uniqueIdentifier, co1);
CategoryOption co2 = createCategoryOption(uniqueIdentifier);
Category ca2 = createCategory(uniqueIdentifier, co2);
CategoryCombo cc = createCategoryCombo(uniqueIdentifier, ca1, ca2);
cc.setDataDimensionType(DataDimensionType.ATTRIBUTE);
CategoryOptionCombo aoc1 = createCategoryOptionCombo(cc, co1, co2);
cc.setOptionCombos(Sets.newHashSet(aoc1));
return cc;
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenOnlyAOCIsSetToDefaultAOCNotInProgramCC.
@Test
void eventValidationFailsWhenOnlyAOCIsSetToDefaultAOCNotInProgramCC() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
program.setCategoryCombo(categoryCombo('A'));
CategoryOptionCombo defaultAOC = firstCategoryOptionCombo(defaultCategoryCombo());
when(preheat.getCategoryOptionCombo(defaultAOC.getUid())).thenReturn(defaultAOC);
Event event = eventBuilder().attributeOptionCombo(defaultAOC.getUid()).build();
hook.validateEvent(reporter, event);
assertEquals(1, reporter.getReportList().size());
assertTrue(reporter.hasErrorReport(r -> r.getErrorCode() == TrackerErrorCode.E1055));
assertNull(reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should not be cached");
}
use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationSucceedsWhenOnlyCOsAreSetAndExist.
@Test
void eventValidationSucceedsWhenOnlyCOsAreSetAndExist() {
OrganisationUnit orgUnit = setupOrgUnit();
Program program = setupProgram(orgUnit);
CategoryCombo cc = categoryCombo();
program.setCategoryCombo(cc);
CategoryOption co = cc.getCategoryOptions().get(0);
when(preheat.getCategoryOption(co.getUid())).thenReturn(co);
CategoryOptionCombo aoc = firstCategoryOptionCombo(cc);
when(categoryService.getCategoryOptionCombo(cc, Sets.newHashSet(co))).thenReturn(aoc);
when(preheat.getIdentifiers()).thenReturn(TrackerIdentifierParams.builder().categoryOptionComboIdScheme(TrackerIdentifier.NAME).build());
Event event = eventBuilder().attributeOptionCombo(null).attributeCategoryOptions(co.getUid()).build();
hook.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
assertEquals(aoc, reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should be cached");
assertEquals(aoc.getName(), event.getAttributeOptionCombo(), "AOC id should be set by the validation");
verify(preheat, times(1)).put(TrackerIdentifier.NAME, aoc);
}
Aggregations