use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class CategoryOptionGroupResolverTest method verifyExpressionIsNotResolvedWhenExpressionIsNotValid.
@Test
void verifyExpressionIsNotResolvedWhenExpressionIsNotValid() {
// arrange
dimensionalItemId = new DimensionalItemId(DimensionItemType.DATA_ELEMENT_OPERAND, uid1, uid2, uid3, createIndicatorExpression());
String expression = "lsdjflakjdflkajdslfhaglakujdhfg";
when(expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION)).thenReturn(Sets.newHashSet(dimensionalItemId));
// act
String resolvedExpression = resolver.resolve(expression);
// assert
assertEquals(expression, resolvedExpression);
}
use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class DefaultValidationService method getValidationContext.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
* Returns a new Builder with basic configuration based on the input
* parameters.
*
* @param parameters ValidationRuleParameters for creating
* ValidationRuleContext
* @return Builder with basic configuration based on input.
*/
private ValidationRunContext getValidationContext(ValidationAnalysisParams parameters) {
User currentUser = currentUserService.getCurrentUser();
OrganisationUnit parameterOrgUnit = parameters.getOrgUnit();
List<OrganisationUnit> orgUnits;
if (parameterOrgUnit == null) {
orgUnits = organisationUnitService.getAllOrganisationUnits();
} else if (parameters.isIncludeOrgUnitDescendants()) {
orgUnits = organisationUnitService.getOrganisationUnitWithChildren(parameterOrgUnit.getUid());
} else {
orgUnits = Lists.newArrayList(parameterOrgUnit);
}
Map<PeriodType, PeriodTypeExtended> periodTypeXMap = new HashMap<>();
addPeriodsToContext(periodTypeXMap, parameters.getPeriods());
Map<DimensionalItemId, DimensionalItemObject> dimensionItemMap = addRulesToContext(periodTypeXMap, parameters.getValidationRules());
Map<String, OrganisationUnitGroup> orgUnitGroupMap = getOrgUnitGroupMap(parameters.getValidationRules());
removeAnyUnneededPeriodTypes(periodTypeXMap);
ValidationRunContext.Builder builder = ValidationRunContext.newBuilder().withOrgUnits(orgUnits).withPeriodTypeXs(new ArrayList<>(periodTypeXMap.values())).withInitialResults(validationResultService.getValidationResults(parameterOrgUnit, parameters.isIncludeOrgUnitDescendants(), parameters.getValidationRules(), parameters.getPeriods())).withSendNotifications(parameters.isSendNotifications()).withPersistResults(parameters.isPersistResults()).withAttributeCombo(parameters.getAttributeOptionCombo()).withDefaultAttributeCombo(categoryService.getDefaultCategoryOptionCombo()).withItemMap(dimensionItemMap).withOrgUnitGroupMap(orgUnitGroupMap).withMaxResults(parameters.getMaxResults());
if (currentUser != null) {
builder.withCoDimensionConstraints(categoryService.getCoDimensionConstraints(currentUser)).withCogDimensionConstraints(categoryService.getCogDimensionConstraints(currentUser));
}
return builder.build();
}
use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class VectorFunction method getExpressionInfo.
@Override
public Object getExpressionInfo(ExprContext ctx, CommonExpressionVisitor visitor) {
for (int i = 0; i < ctx.expr().size() - 1; i++) {
visitor.visitExpr(ctx.expr().get(i));
}
// ItemIds in the last (or only) expr are from sampled periods.
ExpressionInfo info = visitor.getInfo();
Set<DimensionalItemId> savedItemIds = info.getItemIds();
info.setItemIds(info.getSampleItemIds());
Object result = visitor.visitExpr(ctx.expr().get(ctx.expr().size() - 1));
info.setItemIds(savedItemIds);
return castDouble(result);
}
use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class DataDimensionExtractorTest method testGetAtomicIdsForIndicator.
@Test
void testGetAtomicIdsForIndicator() {
// Given
final DimensionalItemId indicatorItem = new DimensionalItemId(INDICATOR, "id0");
final Set<DimensionalItemId> someItemIds = newHashSet(indicatorItem);
// When
final SetMap<Class<? extends IdentifiableObject>, String> result = new DataDimensionExtractor(null).getAtomicIds(someItemIds);
// Then
assertThat(result.size(), is(equalTo(1)));
assertThat(result.get(Indicator.class), containsInAnyOrder(indicatorItem.getId0()));
}
use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class DataDimensionExtractorTest method testGetAtomicIdsForProgramAttribute.
@Test
void testGetAtomicIdsForProgramAttribute() {
// Given
final DimensionalItemId programAttributeItem = new DimensionalItemId(PROGRAM_ATTRIBUTE, "id0", "id1");
final Set<DimensionalItemId> someItemIds = newHashSet(programAttributeItem);
// When
final SetMap<Class<? extends IdentifiableObject>, String> result = new DataDimensionExtractor(null).getAtomicIds(someItemIds);
// Then
assertThat(result.size(), is(equalTo(2)));
assertThat(result.get(Program.class), containsInAnyOrder(programAttributeItem.getId0()));
assertThat(result.get(TrackedEntityAttribute.class), containsInAnyOrder(programAttributeItem.getId1()));
}
Aggregations