use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class TypedIndexedObjectContainerTest method merge.
@Test
void merge() {
final Attribute attribute1 = new Attribute();
final Attribute attribute2 = new Attribute();
final Attribute attribute3 = new Attribute();
final Category category1 = new Category();
final Category category2 = new Category();
Assertions.assertEquals((Integer) 0, container.mergeObjectIndex(attribute1));
Assertions.assertEquals((Integer) 1, container.mergeObjectIndex(attribute2));
Assertions.assertEquals((Integer) 2, container.mergeObjectIndex(attribute3));
Assertions.assertEquals((Integer) 0, container.mergeObjectIndex(category1));
Assertions.assertEquals((Integer) 1, container.mergeObjectIndex(category2));
}
use of org.hisp.dhis.category.Category in project dhis2-core by dhis2.
the class EventAnalyticsServiceTest method testDimensionRestrictionSuccessfully.
@Test
void testDimensionRestrictionSuccessfully() {
// 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');
categoryService.addCategoryOption(coA);
categoryService.addCategoryOption(coB);
// The categories
Category caA = createCategory('A', coA);
Category caB = createCategory('B', coB);
categoryService.addCategory(caA);
categoryService.addCategory(caB);
// 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();
// When
Grid aggregatedDataValueGrid = eventAnalyticsService.getAggregatedEventData(events_2017_params);
// Then
boolean noCategoryRestrictionExceptionIsThrown = true;
assertThat(aggregatedDataValueGrid, is(notNullValue()));
assert (noCategoryRestrictionExceptionIsThrown);
}
use of org.hisp.dhis.category.Category 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.Category 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.Category in project dhis2-core by dhis2.
the class ValidationResultStoreHqlTest method queryWithUserWithCategory.
@Test
void queryWithUserWithCategory() {
Category category = new Category();
category.setId(42L);
setUpUser("orgUid", category, null);
store.query(new ValidationResultQuery());
assertHQLMatches("from ValidationResult vr where (locate('orgUid',vr.organisationUnit.path) <> 0) and 1 = ...", 523);
}
Aggregations