use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class GetMetaDataAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
User user = currentUserService.getCurrentUser();
Date lastUpdated = DateUtils.max(Sets.newHashSet(identifiableObjectManager.getLastUpdated(DataElement.class), identifiableObjectManager.getLastUpdated(OptionSet.class), identifiableObjectManager.getLastUpdated(Indicator.class), identifiableObjectManager.getLastUpdated(DataSet.class), identifiableObjectManager.getLastUpdated(CategoryCombo.class), identifiableObjectManager.getLastUpdated(Category.class), identifiableObjectManager.getLastUpdated(CategoryOption.class)));
String tag = lastUpdated != null && user != null ? (DateUtils.getLongDateString(lastUpdated) + SEP + user.getUid()) : null;
if (ContextUtils.isNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), tag)) {
return SUCCESS;
}
if (user != null && user.getOrganisationUnits().isEmpty()) {
emptyOrganisationUnits = true;
return SUCCESS;
}
significantZeros = dataElementService.getDataElementsByZeroIsSignificant(true);
dataElements = dataElementService.getDataElementsWithDataSets();
for (DataElement dataElement : dataElements) {
if (dataElement != null && dataElement.getOptionSet() != null) {
dataElementsWithOptionSet.add(dataElement);
}
}
indicators = indicatorService.getIndicatorsWithDataSets();
expressionService.substituteIndicatorExpressions(indicators);
dataSets = dataSetService.getUserDataWrite(user);
Set<CategoryCombo> categoryComboSet = new HashSet<>();
Set<Category> categorySet = new HashSet<>();
for (DataSet dataSet : dataSets) {
if (dataSet.getCategoryCombo() != null) {
categoryComboSet.add(dataSet.getCategoryCombo());
}
}
for (CategoryCombo categoryCombo : categoryComboSet) {
if (categoryCombo.getCategories() != null) {
categorySet.addAll(categoryCombo.getCategories());
}
}
categoryCombos = new ArrayList<>(categoryComboSet);
categories = new ArrayList<>(categorySet);
for (Category category : categories) {
List<CategoryOption> categoryOptions = new ArrayList<>(categoryService.getDataWriteCategoryOptions(category, user));
Collections.sort(categoryOptions);
categoryOptionMap.put(category.getUid(), categoryOptions);
}
Set<String> nonAccessibleDataSetIds = new HashSet<>();
for (DataSet dataSet : dataSets) {
CategoryCombo categoryCombo = dataSet.getCategoryCombo();
if (categoryCombo != null && categoryCombo.getCategories() != null) {
for (Category category : categoryCombo.getCategories()) {
if (!categoryOptionMap.containsKey(category.getUid()) || categoryOptionMap.get(category.getUid()).isEmpty()) {
nonAccessibleDataSetIds.add(dataSet.getUid());
break;
}
}
}
}
dataSets = dataSets.stream().filter(dataSet -> !nonAccessibleDataSetIds.contains(dataSet.getUid())).collect(Collectors.toList());
lockExceptions = dataSetService.getAllLockExceptions();
Collections.sort(dataSets);
Collections.sort(categoryCombos);
Collections.sort(categories);
defaultCategoryCombo = categoryService.getDefaultCategoryCombo();
return SUCCESS;
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DefaultCascadeSharingService method handleCategoryDimension.
/**
* Check if can merge sharing from given source to given analyticalObject's
* {@link CategoryDimension} and all related objects that has Sharing
* enabled.
*
* @param sourceSharing {@link Sharing}
* @param analyticalObject any object extends {@link BaseAnalyticalObject}
* @param listUpdateObjects Set of objects need to be updated
* @param parameters {@link CascadeSharingParameters}
*/
private void handleCategoryDimension(final Sharing sourceSharing, BaseAnalyticalObject analyticalObject, Set<IdentifiableObject> listUpdateObjects, CascadeSharingParameters parameters) {
List<CategoryDimension> catDimensions = analyticalObject.getCategoryDimensions();
if (CollectionUtils.isEmpty(catDimensions)) {
return;
}
catDimensions.forEach(catDimension -> {
Category category = catDimension.getDimension();
handleIdentifiableObject(sourceSharing, Category.class, category, listUpdateObjects, parameters);
List<CategoryOption> catOptions = catDimension.getItems();
if (CollectionUtils.isEmpty(catOptions)) {
return;
}
catOptions.forEach(catOption -> handleIdentifiableObject(sourceSharing, CategoryOption.class, catOption, listUpdateObjects, parameters));
});
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class DefaultDataSetReportService method getSectionDataSetReport.
private List<Grid> getSectionDataSetReport(DataSet dataSet, List<Period> periods, OrganisationUnit unit, Set<String> filters, boolean selectedUnitOnly) {
I18nFormat format = i18nManager.getI18nFormat();
I18n i18n = i18nManager.getI18n();
List<Section> sections = new ArrayList<>(dataSet.getSections());
sections.sort(new SectionOrderComparator());
Map<String, Object> valueMap = dataSetReportStore.getAggregatedValues(dataSet, periods, unit, filters);
Map<String, Object> subTotalMap = dataSetReportStore.getAggregatedSubTotals(dataSet, periods, unit, filters);
Map<String, Object> totalMap = dataSetReportStore.getAggregatedTotals(dataSet, periods, unit, filters);
List<Grid> grids = new ArrayList<>();
for (Section section : sections) {
for (CategoryCombo categoryCombo : section.getCategoryCombos()) {
Grid grid = new ListGrid().setTitle(section.getName() + SPACE + categoryCombo.getName()).setSubtitle(unit.getName() + SPACE + formatPeriods(periods, format));
// -----------------------------------------------------------------
// Grid headers
// -----------------------------------------------------------------
grid.addHeader(new GridHeader(i18n.getString("dataelement"), false, true));
List<CategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
for (CategoryOptionCombo optionCombo : optionCombos) {
grid.addHeader(new GridHeader(optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false));
}
if (// Sub-total
categoryCombo.doSubTotals() && !selectedUnitOnly) {
for (CategoryOption categoryOption : categoryCombo.getCategoryOptions()) {
grid.addHeader(new GridHeader(categoryOption.getName(), false, false));
}
}
if (// Total
categoryCombo.doTotal() && !selectedUnitOnly) {
grid.addHeader(new GridHeader(TOTAL_HEADER, false, false));
}
// -----------------------------------------------------------------
// Grid values
// -----------------------------------------------------------------
List<DataElement> dataElements = new ArrayList<>(section.getDataElementsByCategoryCombo(categoryCombo));
FilterUtils.filter(dataElements, AggregatableDataElementFilter.INSTANCE);
for (DataElement dataElement : dataElements) {
grid.addRow();
// Data
grid.addValue(new GridValue(dataElement.getFormNameFallback()));
for (// Values
CategoryOptionCombo optionCombo : // Values
optionCombos) {
Map<Object, Object> attributes = new HashMap<>();
attributes.put(ATTR_DE, dataElement.getUid());
attributes.put(ATTR_CO, optionCombo.getUid());
Object value;
if (selectedUnitOnly) {
value = getSelectedUnitValue(dataElement, periods, unit, optionCombo);
} else {
value = valueMap.get(dataElement.getUid() + SEPARATOR + optionCombo.getUid());
}
grid.addValue(new GridValue(value, attributes));
}
if (// Sub-total
categoryCombo.doSubTotals() && !selectedUnitOnly) {
for (CategoryOption categoryOption : categoryCombo.getCategoryOptions()) {
Object value = subTotalMap.get(dataElement.getUid() + SEPARATOR + categoryOption.getUid());
grid.addValue(new GridValue(value));
}
}
if (// Total
categoryCombo.doTotal() && !selectedUnitOnly) {
Object value = totalMap.get(String.valueOf(dataElement.getUid()));
grid.addValue(new GridValue(value));
}
}
grids.add(grid);
}
}
return grids;
}
use of org.hisp.dhis.category.CategoryOption in project dhis2-core by dhis2.
the class ValidationResultStoreTest method setUpTest.
@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(2017, 2, 1), getDate(2017, 2, 28));
periodService.addPeriod(periodA);
periodService.addPeriod(periodB);
sourceA = createOrganisationUnit('A');
sourceB = createOrganisationUnit('B', sourceA);
sourceC = createOrganisationUnit('C');
organisationUnitService.addOrganisationUnit(sourceA);
organisationUnitService.addOrganisationUnit(sourceB);
organisationUnitService.addOrganisationUnit(sourceC);
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 = createUserGroup('A', Sets.newHashSet(userCService.getCurrentUser()));
UserGroup userGroupD = createUserGroup('B', Sets.newHashSet(userDService.getCurrentUser()));
userGroupService.addUserGroup(userGroupC);
userGroupService.addUserGroup(userGroupD);
userCService.getCurrentUser().getGroups().add(userGroupC);
userService.updateUser(userCService.getCurrentUser());
userDService.getCurrentUser().getGroups().add(userGroupD);
userService.updateUser(userDService.getCurrentUser());
optionA = new CategoryOption("CategoryOptionA");
optionB = new CategoryOption("CategoryOptionB");
categoryService.addCategoryOption(optionA);
categoryService.addCategoryOption(optionB);
categoryA = createCategory('A', optionA, optionB);
categoryService.addCategory(categoryA);
categoryComboA = createCategoryCombo('A', categoryA);
categoryService.addCategoryCombo(categoryComboA);
optionComboA = createCategoryOptionCombo(categoryComboA, optionA);
optionComboB = createCategoryOptionCombo(categoryComboA, optionB);
optionComboC = createCategoryOptionCombo(categoryComboA, optionA, optionB);
categoryService.addCategoryOptionCombo(optionComboA);
categoryService.addCategoryOptionCombo(optionComboB);
categoryService.addCategoryOptionCombo(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().getCatDimensionConstraints().add(categoryA);
userDService.getCurrentUser().getCogsDimensionConstraints().add(optionGroupSetB);
expressionA = new Expression("expressionA", "descriptionA");
expressionB = new Expression("expressionB", "descriptionB");
validationRuleA = createValidationRule('A', equal_to, expressionA, expressionB, periodType);
validationRuleB = createValidationRule('B', equal_to, expressionB, expressionA, periodType);
validationRuleStore.save(validationRuleA);
validationRuleStore.save(validationRuleB);
validationResultAA = new ValidationResult(validationRuleA, periodA, sourceA, optionComboA, 1.0, 2.0, 3);
validationResultAB = new ValidationResult(validationRuleA, periodA, sourceA, optionComboB, 1.0, 2.0, 3);
validationResultAC = new ValidationResult(validationRuleA, periodA, sourceA, optionComboC, 1.0, 2.0, 3);
validationResultBA = new ValidationResult(validationRuleB, periodB, sourceB, optionComboA, 1.0, 2.0, 3);
validationResultBB = new ValidationResult(validationRuleB, periodB, sourceB, optionComboB, 1.0, 2.0, 3);
validationResultBC = new ValidationResult(validationRuleB, periodB, sourceB, optionComboC, 1.0, 2.0, 3);
validationResultCA = new ValidationResult(validationRuleB, periodB, sourceC, optionComboA, 1.0, 2.0, 3);
validationResultAB.setNotificationSent(true);
}
use of org.hisp.dhis.category.CategoryOption 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