Search in sources :

Example 21 with DimensionalItemId

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);
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 22 with DimensionalItemId

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();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) PeriodType(org.hisp.dhis.period.PeriodType) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) User(org.hisp.dhis.user.User) HashMap(java.util.HashMap) OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject)

Example 23 with DimensionalItemId

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);
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ExpressionInfo(org.hisp.dhis.expression.ExpressionInfo)

Example 24 with DimensionalItemId

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()));
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test)

Example 25 with DimensionalItemId

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()));
}
Also used : DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) Program(org.hisp.dhis.program.Program) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test)

Aggregations

DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)46 Test (org.junit.jupiter.api.Test)32 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)21 DhisSpringTest (org.hisp.dhis.DhisSpringTest)13 Indicator (org.hisp.dhis.indicator.Indicator)12 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 HashMap (java.util.HashMap)11 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)9 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)9 IndicatorValue (org.hisp.dhis.indicator.IndicatorValue)8 IndicatorType (org.hisp.dhis.indicator.IndicatorType)6 DataElement (org.hisp.dhis.dataelement.DataElement)5 List (java.util.List)4 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)4 Period (org.hisp.dhis.period.Period)4 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 AllArgsConstructor (lombok.AllArgsConstructor)3