use of org.hisp.dhis.category.CategoryOptionGroupSet in project dhis2-core by dhis2.
the class JdbcEventAnalyticsTableManagerTest method verifyGetAnalyticsTableWithOptionGroupSets.
@Test
void verifyGetAnalyticsTableWithOptionGroupSets() {
List<CategoryOptionGroupSet> cogs = rnd.objects(CategoryOptionGroupSet.class, 2).collect(Collectors.toList());
Program programA = rnd.nextObject(Program.class);
programA.setId(0);
when(idObjectManager.getAllNoAcl(Program.class)).thenReturn(Collections.singletonList(programA));
when(categoryService.getAttributeCategoryOptionGroupSetsNoAcl()).thenReturn(cogs);
when(jdbcTemplate.queryForList(getYearQueryForCurrentYear(programA, false), Integer.class)).thenReturn(Lists.newArrayList(2018, 2019));
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime(START_TIME).build();
List<AnalyticsTable> tables = subject.getAnalyticsTables(params);
assertThat(tables, hasSize(1));
new AnalyticsTableAsserter.Builder(tables.get(0)).withTableName(TABLE_PREFIX + programA.getUid().toLowerCase()).withTableType(AnalyticsTableType.EVENT).withColumnSize(subject.getFixedColumns().size() + PeriodType.getAvailablePeriodTypes().size() + cogs.size() + (programA.isRegistration() ? 1 : 0)).addColumns(periodColumns).withDefaultColumns(subject.getFixedColumns()).addColumn(quote(cogs.get(0).getUid()), col -> match(cogs.get(0), col)).addColumn(quote(cogs.get(1).getUid()), col -> match(cogs.get(1), col)).build().verify();
}
use of org.hisp.dhis.category.CategoryOptionGroupSet in project dhis2-core by dhis2.
the class DefaultCategoryService method getCogDimensionConstraints.
@Override
@Transactional(readOnly = true)
public Set<CategoryOptionGroup> getCogDimensionConstraints(User user) {
Set<CategoryOptionGroup> groups = null;
Set<CategoryOptionGroupSet> cogsConstraints = user.getCogsDimensionConstraints();
if (cogsConstraints != null && !cogsConstraints.isEmpty()) {
groups = new HashSet<>();
for (CategoryOptionGroupSet cogs : cogsConstraints) {
groups.addAll(getCategoryOptionGroups(cogs));
}
}
return groups;
}
use of org.hisp.dhis.category.CategoryOptionGroupSet 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();
}
}
}
use of org.hisp.dhis.category.CategoryOptionGroupSet in project dhis2-core by dhis2.
the class ValidationResultStoreHqlTest method queryWithUserWithCategoryAndCategoryOptionGroupSet.
@Test
void queryWithUserWithCategoryAndCategoryOptionGroupSet() {
Category category = new Category();
category.setId(42L);
CategoryOptionGroupSet groupSet = new CategoryOptionGroupSet();
groupSet.setId(42L);
setUpUser("orgUid", category, groupSet);
store.query(new ValidationResultQuery());
assertHQLMatches("from ValidationResult vr where (locate('orgUid',vr.organisationUnit.path) <> 0) and 1 = ...", 988);
}
use of org.hisp.dhis.category.CategoryOptionGroupSet in project dhis2-core by dhis2.
the class ValidationResultStoreHqlTest method setUpUser.
private void setUpUser(String orgUnitUid, Category category, CategoryOptionGroupSet groupSet) {
User user = new User();
when(currentUserService.getCurrentUser()).thenReturn(user);
user.setGroups(emptySet());
OrganisationUnit unit = new OrganisationUnit();
unit.setUid(orgUnitUid);
user.setDataViewOrganisationUnits(singleton(unit));
// categories
Set<Category> categories = category == null ? emptySet() : singleton(category);
user.setCatDimensionConstraints(categories);
// option groups
Set<CategoryOptionGroupSet> options = groupSet == null ? emptySet() : singleton(groupSet);
user.setCogsDimensionConstraints(options);
}
Aggregations