use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class JdbcEventAnalyticsTableManagerTest method verifyGetTableWithCategoryCombo.
@Test
void verifyGetTableWithCategoryCombo() {
Program program = createProgram('A');
Category categoryA = createCategory('A');
categoryA.setCreated(getDate(2019, 12, 3));
Category categoryB = createCategory('B');
categoryA.setCreated(getDate(2018, 8, 5));
CategoryCombo categoryCombo = createCategoryCombo('B', categoryA, categoryB);
addCategoryCombo(program, categoryCombo);
when(idObjectManager.getAllNoAcl(Program.class)).thenReturn(Lists.newArrayList(program));
when(jdbcTemplate.queryForList(getYearQueryForCurrentYear(program, true), Integer.class)).thenReturn(Lists.newArrayList(2018, 2019));
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withLastYears(2).withStartTime(START_TIME).withToday(today).build();
List<AnalyticsTable> tables = subject.getAnalyticsTables(params);
assertThat(tables, hasSize(1));
new AnalyticsTableAsserter.Builder(tables.get(0)).withTableType(AnalyticsTableType.EVENT).withTableName(TABLE_PREFIX + program.getUid().toLowerCase()).withColumnSize(52).withDefaultColumns(subject.getFixedColumns()).addColumns(periodColumns).addColumn(categoryA.getUid(), CHARACTER_11, "acs.", categoryA.getCreated()).addColumn(categoryB.getUid(), CHARACTER_11, "acs.", categoryB.getCreated()).build().verify();
}
use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class EventAnalyticsServiceTest method testDimensionRestrictionWhenUserCannotReadCategoryOptions.
@Test
void testDimensionRestrictionWhenUserCannotReadCategoryOptions() {
// Given
// A program
Program aProgram = createProgram('B', null, null, Sets.newHashSet(ouA, ouB), null);
aProgram.setUid("aProgram123");
idObjectManager.save(aProgram);
// The category options
CategoryOption coA = createCategoryOption('A');
CategoryOption coB = createCategoryOption('B');
coA.getSharing().setOwner("cannotRead");
coB.getSharing().setOwner("cannotRead");
categoryService.addCategoryOption(coA);
categoryService.addCategoryOption(coB);
// The categories
Category caA = createCategory('A', coA);
Category caB = createCategory('B', coB);
categoryService.addCategory(caA);
categoryService.addCategory(caB);
removeUserAccess(coA);
removeUserAccess(coB);
categoryService.updateCategoryOption(coA);
categoryService.updateCategoryOption(coB);
// The constraints
Set<Category> catDimensionConstraints = Sets.newHashSet(caA, caB);
// The user
User user = createUser("A", "F_VIEW_EVENT_ANALYTICS");
user.setCatDimensionConstraints(catDimensionConstraints);
userService.addUser(user);
enableDataSharing(user, aProgram, AccessStringHelper.DATA_READ_WRITE);
idObjectManager.update(user);
injectSecurityContext(user);
// All events in program B - 2017
EventQueryParams events_2017_params = new EventQueryParams.Builder().withOrganisationUnits(Lists.newArrayList(ouA)).withStartDate(getDate(2017, 1, 1)).withEndDate(getDate(2017, 12, 31)).withProgram(aProgram).build();
// Then
Throwable exception = assertThrows(IllegalQueryException.class, () -> eventAnalyticsService.getAggregatedEventData(events_2017_params));
assertThat(exception.getMessage(), containsString("Current user is constrained by a dimension but has access to no dimension items"));
}
use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class DataElementDefaultDimensionPopulator method executeInTransaction.
// -------------------------------------------------------------------------
// Execute
// -------------------------------------------------------------------------
@Override
public void executeInTransaction() {
Category defaultCategory = categoryService.getCategoryByName(Category.DEFAULT_NAME);
if (defaultCategory == null) {
categoryService.generateDefaultDimension();
defaultCategory = categoryService.getCategoryByName(Category.DEFAULT_NAME);
log.info("Added default category");
}
categoryService.updateCategory(defaultCategory);
String defaultName = CategoryCombo.DEFAULT_CATEGORY_COMBO_NAME;
CategoryCombo categoryCombo = categoryService.getCategoryComboByName(defaultName);
if (categoryCombo == null) {
categoryService.generateDefaultDimension();
log.info("Added default dataelement dimension");
categoryCombo = categoryService.getCategoryComboByName(defaultName);
}
// ---------------------------------------------------------------------
// Any data elements without dimensions need to be associated at least
// with the default dimension
// ---------------------------------------------------------------------
Collection<DataElement> dataElements = dataElementService.getAllDataElements();
for (DataElement dataElement : dataElements) {
if (dataElement.getCategoryCombo() == null) {
dataElement.setCategoryCombo(categoryCombo);
dataElementService.updateDataElement(dataElement);
}
}
}
use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class DefaultCategoryService method generateDefaultDimension.
@Override
@Transactional
public void generateDefaultDimension() {
// ---------------------------------------------------------------------
// CategoryOption
// ---------------------------------------------------------------------
CategoryOption categoryOption = new CategoryOption(CategoryOption.DEFAULT_NAME);
categoryOption.setUid("xYerKDKCefk");
categoryOption.setCode("default");
addCategoryOption(categoryOption);
categoryOption.setPublicAccess(AccessStringHelper.CATEGORY_OPTION_DEFAULT);
updateCategoryOption(categoryOption);
// ---------------------------------------------------------------------
// Category
// ---------------------------------------------------------------------
Category category = new Category(Category.DEFAULT_NAME, DataDimensionType.DISAGGREGATION);
category.setUid("GLevLNI9wkl");
category.setCode("default");
category.setShortName("default");
category.setDataDimension(false);
category.addCategoryOption(categoryOption);
addCategory(category);
category.setPublicAccess(AccessStringHelper.CATEGORY_NO_DATA_SHARING_DEFAULT);
updateCategory(category);
// ---------------------------------------------------------------------
// CategoryCombo
// ---------------------------------------------------------------------
CategoryCombo categoryCombo = new CategoryCombo(CategoryCombo.DEFAULT_CATEGORY_COMBO_NAME, DataDimensionType.DISAGGREGATION);
categoryCombo.setUid("bjDvmb4bfuf");
categoryCombo.setCode("default");
categoryCombo.setDataDimensionType(DataDimensionType.DISAGGREGATION);
categoryCombo.addCategory(category);
addCategoryCombo(categoryCombo);
categoryCombo.setPublicAccess(AccessStringHelper.CATEGORY_NO_DATA_SHARING_DEFAULT);
updateCategoryCombo(categoryCombo);
// ---------------------------------------------------------------------
// CategoryOptionCombo
// ---------------------------------------------------------------------
CategoryOptionCombo categoryOptionCombo = new CategoryOptionCombo();
categoryOptionCombo.setUid("HllvX50cXC0");
categoryOptionCombo.setCode("default");
categoryOptionCombo.setCategoryCombo(categoryCombo);
categoryOptionCombo.addCategoryOption(categoryOption);
addCategoryOptionCombo(categoryOptionCombo);
categoryOptionCombo.setPublicAccess(AccessStringHelper.CATEGORY_NO_DATA_SHARING_DEFAULT);
updateCategoryOptionCombo(categoryOptionCombo);
Set<CategoryOptionCombo> categoryOptionCombos = new HashSet<>();
categoryOptionCombos.add(categoryOptionCombo);
categoryCombo.setOptionCombos(categoryOptionCombos);
updateCategoryCombo(categoryCombo);
categoryOption.setCategoryOptionCombos(categoryOptionCombos);
updateCategoryOption(categoryOption);
}
use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class DefaultDataApprovalAuditService method retainFromDimensionConstraints.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
* Retain the DataApprovalAudits that the user can read despite any
* dimension constraints that the user my have.
*
* @param audits the list of audit records.
*/
private void retainFromDimensionConstraints(List<DataApprovalAudit> audits) {
User user = currentUserService.getCurrentUser();
Set<CategoryOptionGroupSet> cogDimensionConstraints = user.getCogsDimensionConstraints();
Set<Category> catDimensionConstraints = user.getCatDimensionConstraints();
if (currentUserService.currentUserIsSuper() || (CollectionUtils.isEmpty(cogDimensionConstraints) && CollectionUtils.isEmpty(catDimensionConstraints))) {
return;
}
// Local
Map<CategoryOptionCombo, Boolean> readableOptionCombos = new HashMap<>();
for (Iterator<DataApprovalAudit> i = audits.iterator(); i.hasNext(); ) {
CategoryOptionCombo optionCombo = i.next().getAttributeOptionCombo();
Boolean canRead = readableOptionCombos.get(optionCombo);
if (canRead == null) {
canRead = canReadOptionCombo(user, optionCombo, cogDimensionConstraints, catDimensionConstraints);
readableOptionCombos.put(optionCombo, canRead);
}
if (!canRead) {
i.remove();
}
}
}
Aggregations