use of org.hisp.dhis.webapi.webdomain.form.Option in project dhis2-core by dhis2.
the class FormUtils method getCategoryCombo.
private static CategoryCombo getCategoryCombo(DataSet dataset, Set<OrganisationUnit> userOrganisationUnits) {
if (dataset.hasCategoryCombo()) {
org.hisp.dhis.category.CategoryCombo categoryCombo = dataset.getCategoryCombo();
CategoryCombo catCombo = new CategoryCombo();
catCombo.setId(categoryCombo.getUid());
List<org.hisp.dhis.category.Category> cats = categoryCombo.getCategories();
if (cats != null && cats.size() > 0) {
for (org.hisp.dhis.category.Category cat : cats) {
if (cat.getAccess() != null && !cat.getAccess().isRead()) {
continue;
}
Category c = new Category();
c.setId(cat.getUid());
c.setLabel(cat.getName());
List<CategoryOption> options = cat.getCategoryOptions();
if (options != null && options.size() > 0) {
for (CategoryOption option : options) {
if (option.getAccess() != null && !option.getAccess().isRead()) {
continue;
}
Option o = new Option();
o.setId(option.getUid());
o.setLabel(option.getDisplayName());
o.setStartDate(option.getStartDate());
o.setEndDate(option.getEndDate());
Set<OrganisationUnit> catOptionOUs = option.getOrganisationUnits();
if (userOrganisationUnits == null || userOrganisationUnits.isEmpty() || catOptionOUs == null || catOptionOUs.isEmpty()) {
c.getOptions().add(o);
} else if (userOrganisationUnits != null && catOptionOUs != null && !Collections.disjoint(userOrganisationUnits, catOptionOUs)) {
HashSet<OrganisationUnit> organisationUnits = new HashSet<>();
catOptionOUs.stream().filter(ou -> userOrganisationUnits.contains(ou)).forEach(ou -> {
organisationUnits.add(ou);
organisationUnits.addAll(getChildren(ou, new HashSet<>()));
});
o.setOrganisationUnits(organisationUnits);
c.getOptions().add(o);
}
}
}
catCombo.getCategories().add(c);
}
}
return catCombo;
}
return null;
}
Aggregations