use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationSucceedsWhenEventAOCAndEventCOsAreSetAndBothFound.
@Test
void eventValidationSucceedsWhenEventAOCAndEventCOsAreSetAndBothFound() {
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(preheat.getCategoryOptionCombo(aoc.getUid())).thenReturn(aoc);
Event event = eventBuilder().attributeOptionCombo(aoc.getUid()).attributeCategoryOptions(co.getUid()).build();
hook.validateEvent(reporter, event);
assertFalse(reporter.hasErrors());
assertEquals(aoc, reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getEvent()), "AOC id should be cached");
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method eventValidationFailsWhenEventAOCAndEventCOsAreSetAndAOCIsSetToDefault.
@Test
void eventValidationFailsWhenEventAOCAndEventCOsAreSetAndAOCIsSetToDefault() {
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 defaultAOC = firstCategoryOptionCombo(defaultCategoryCombo());
when(preheat.getCategoryOptionCombo(defaultAOC.getUid())).thenReturn(defaultAOC);
Event event = eventBuilder().attributeOptionCombo(defaultAOC.getUid()).attributeCategoryOptions(co.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.CategoryCombo in project dhis2-core by dhis2.
the class DataApprovalController method getApprovalByCategoryOptionCombos.
@GetMapping(value = APPROVALS_PATH + "/categoryOptionCombos", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public List<Map<String, Object>> getApprovalByCategoryOptionCombos(@RequestParam(required = false) Set<String> ds, @RequestParam(required = false) Set<String> wf, @RequestParam String pe, @RequestParam(required = false) String ou) throws WebMessageException {
Set<DataApprovalWorkflow> workflows = getAndValidateWorkflows(ds, wf);
Period period = getAndValidatePeriod(pe);
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
if (orgUnit != null && orgUnit.isRoot()) {
// Look for all org units.
orgUnit = null;
}
List<DataApprovalStatus> statusList = new ArrayList<>();
for (DataApprovalWorkflow workflow : workflows) {
Set<CategoryCombo> attributeCombos = new HashSet<>();
for (DataSet dataSet : workflow.getDataSets()) {
attributeCombos.add(dataSet.getCategoryCombo());
}
for (CategoryCombo attributeCombo : attributeCombos) {
statusList.addAll(dataApprovalService.getUserDataApprovalsAndPermissions(workflow, period, orgUnit, attributeCombo));
}
}
List<Map<String, Object>> list = new ArrayList<>();
for (DataApprovalStatus status : statusList) {
Map<String, Object> item = new HashMap<>();
Map<String, String> approvalLevel = new HashMap<>();
if (status.getApprovedLevel() != null) {
approvalLevel.put("id", status.getApprovedLevel().getUid());
approvalLevel.put("level", String.valueOf(status.getApprovedLevel().getLevel()));
}
item.put("id", status.getAttributeOptionComboUid());
item.put("level", approvalLevel);
item.put("ou", status.getOrganisationUnitUid());
item.put("ouName", status.getOrganisationUnitName());
item.put("accepted", status.isAccepted());
item.put("permissions", status.getPermissions());
list.add(item);
}
return list;
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class GetDataElementsAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
canReadType(DataElement.class);
if (id != null && id != ALL) {
DataElementGroup dataElementGroup = dataElementService.getDataElementGroup(id);
if (dataElementGroup != null) {
dataElements = new ArrayList<>(dataElementGroup.getMembers());
}
} else if (categoryComboId != null && categoryComboId != ALL) {
CategoryCombo categoryCombo = categoryService.getCategoryCombo(categoryComboId);
if (categoryCombo != null) {
dataElements = new ArrayList<>(dataElementService.getDataElementByCategoryCombo(categoryCombo));
}
} else if (dataSetId != null) {
DataSet dataset = dataSetService.getDataSet(dataSetId);
if (dataset != null) {
dataElements = new ArrayList<>(dataset.getDataElements());
}
} else if (periodTypeName != null) {
PeriodType periodType = periodService.getPeriodTypeByName(periodTypeName);
if (periodType != null) {
dataElements = new ArrayList<>(dataElementService.getDataElementsByPeriodType(periodType));
}
} else if (domain != null) {
if (domain.equals(DataElementDomain.AGGREGATE.getValue())) {
dataElements = new ArrayList<>(dataElementService.getDataElementsByDomainType(DataElementDomain.AGGREGATE));
} else {
dataElements = new ArrayList<>(dataElementService.getDataElementsByDomainType(DataElementDomain.TRACKER));
}
} else {
dataElements = new ArrayList<>(dataElementService.getAllDataElements());
ContextUtils.clearIfNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), dataElements);
}
if (key != null) {
dataElements = IdentifiableObjectUtils.filterNameByKey(dataElements, key, true);
}
if (dataElements == null) {
dataElements = new ArrayList<>();
}
Collections.sort(dataElements);
if (aggregate) {
FilterUtils.filter(dataElements, new AggregatableDataElementFilter());
}
User currentUser = currentUserService.getCurrentUser();
dataElements.forEach(instance -> canReadInstance(instance, currentUser));
if (usePaging) {
this.paging = createPaging(dataElements.size());
dataElements = dataElements.subList(paging.getStartPos(), paging.getEndPos());
}
return SUCCESS;
}
use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.
the class HandleRelationshipsTrackedEntityInstanceServiceTest method setUpTest.
@Override
protected void setUpTest() throws Exception {
organisationUnitA = createOrganisationUnit('A');
trackedEntityType = createTrackedEntityType('A');
trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
trackedEntityInstanceA = createTrackedEntityInstance(organisationUnitA);
trackedEntityInstanceA.setTrackedEntityType(trackedEntityType);
trackedEntityInstanceB = createTrackedEntityInstance(organisationUnitA);
trackedEntityInstanceB.setTrackedEntityType(trackedEntityType);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setProgramType(ProgramType.WITH_REGISTRATION);
programStageA1 = createProgramStage('1', programA);
programStageA2 = createProgramStage('2', programA);
programA.setProgramStages(Stream.of(programStageA1, programStageA2).collect(Collectors.toCollection(HashSet::new)));
manager.save(organisationUnitA);
manager.save(trackedEntityInstanceA);
manager.save(trackedEntityInstanceB);
manager.save(programA);
manager.save(programStageA1);
manager.save(programStageA2);
ProgramInstance programInstanceA = programInstanceService.enrollTrackedEntityInstance(trackedEntityInstanceA, programA, null, null, organisationUnitA);
programStageInstanceA = new ProgramStageInstance(programInstanceA, programStageA1);
programStageInstanceA.setDueDate(null);
programStageInstanceA.setUid("UID-A");
CategoryCombo categoryComboA = createCategoryCombo('A');
CategoryOptionCombo categoryOptionComboA = createCategoryOptionCombo('A');
categoryOptionComboA.setCategoryCombo(categoryComboA);
manager.save(categoryComboA);
manager.save(categoryOptionComboA);
programStageInstanceA.setAttributeOptionCombo(categoryOptionComboA);
programStageInstanceService.addProgramStageInstance(programStageInstanceA);
}
Aggregations