use of org.hisp.dhis.parser.expression.CommonExpressionVisitor in project dhis2-core by dhis2.
the class DefaultExpressionService method getExpressionDescription.
@Override
public String getExpressionDescription(String expression, ParseType parseType, DataType dataType) {
if (isEmpty(expression)) {
return "";
}
CommonExpressionVisitor visitor = newVisitor(ITEM_GET_DESCRIPTIONS, ExpressionParams.builder().expression(expression).parseType(parseType).dataType(dataType).missingValueStrategy(NEVER_SKIP).build());
visit(expression, dataType, visitor, false);
Map<String, String> itemDescriptions = visitor.getItemDescriptions();
String description = expression;
for (Map.Entry<String, String> entry : itemDescriptions.entrySet()) {
description = description.replace(entry.getKey(), entry.getValue());
}
return description;
}
use of org.hisp.dhis.parser.expression.CommonExpressionVisitor in project dhis2-core by dhis2.
the class ProgramSqlGeneratorFunctionsTest method test.
private Object test(String expression, AntlrExprLiteral exprLiteral, ExpressionItemMethod itemMethod) {
Set<String> dataElementsAndAttributesIdentifiers = new LinkedHashSet<>();
dataElementsAndAttributesIdentifiers.add(BASE_UID + "a");
dataElementsAndAttributesIdentifiers.add(BASE_UID + "b");
dataElementsAndAttributesIdentifiers.add(BASE_UID + "c");
ProgramExpressionParams params = ProgramExpressionParams.builder().programIndicator(programIndicator).reportingStartDate(startDate).reportingEndDate(endDate).dataElementAndAttributeIdentifiers(dataElementsAndAttributesIdentifiers).build();
CommonExpressionVisitor visitor = CommonExpressionVisitor.builder().idObjectManager(idObjectManager).dimensionService(dimensionService).programIndicatorService(programIndicatorService).programStageService(programStageService).statementBuilder(statementBuilder).i18n(new I18n(null, null)).itemMap(PROGRAM_INDICATOR_ITEMS).itemMethod(itemMethod).progParams(params).build();
visitor.setExpressionLiteral(exprLiteral);
return Parser.visit(expression, visitor);
}
use of org.hisp.dhis.parser.expression.CommonExpressionVisitor in project dhis2-core by dhis2.
the class DefaultProgramIndicatorService method _getAnalyticsSql.
private String _getAnalyticsSql(String expression, ProgramIndicator programIndicator, Date startDate, Date endDate, String tableAlias) {
Set<String> uids = getDataElementAndAttributeIdentifiers(expression, programIndicator.getAnalyticsType());
ProgramExpressionParams params = ProgramExpressionParams.builder().programIndicator(programIndicator).reportingStartDate(startDate).reportingEndDate(endDate).dataElementAndAttributeIdentifiers(uids).build();
CommonExpressionVisitor visitor = newVisitor(ITEM_GET_SQL, params);
visitor.setExpressionLiteral(new SqlLiteral());
String sql = castString(Parser.visit(expression, visitor));
return (tableAlias != null ? sql.replaceAll(ANALYTICS_TBL_ALIAS + "\\.", tableAlias + "\\.") : sql);
}
use of org.hisp.dhis.parser.expression.CommonExpressionVisitor in project dhis2-core by dhis2.
the class ProgramSqlGeneratorItemsTest method test.
private Object test(String expression, AntlrExprLiteral exprLiteral, ExpressionItemMethod itemMethod) {
Set<String> dataElementsAndAttributesIdentifiers = new LinkedHashSet<>();
dataElementsAndAttributesIdentifiers.add(BASE_UID + "a");
dataElementsAndAttributesIdentifiers.add(BASE_UID + "b");
dataElementsAndAttributesIdentifiers.add(BASE_UID + "c");
ProgramExpressionParams params = ProgramExpressionParams.builder().programIndicator(programIndicator).reportingStartDate(startDate).reportingEndDate(endDate).dataElementAndAttributeIdentifiers(dataElementsAndAttributesIdentifiers).build();
CommonExpressionVisitor visitor = CommonExpressionVisitor.builder().idObjectManager(idObjectManager).dimensionService(dimensionService).programIndicatorService(programIndicatorService).programStageService(programStageService).statementBuilder(statementBuilder).i18n(new I18n(null, null)).constantMap(constantMap).itemMap(PROGRAM_INDICATOR_ITEMS).itemMethod(itemMethod).progParams(params).build();
visitor.setExpressionLiteral(exprLiteral);
return Parser.visit(expression, visitor);
}
use of org.hisp.dhis.parser.expression.CommonExpressionVisitor in project dhis2-core by dhis2.
the class DefaultExpressionService method getExpressionInfo.
/**
* Gets the information that we need from an expression
*/
private ExpressionInfo getExpressionInfo(ExpressionParams params) {
CommonExpressionVisitor visitor = newVisitor(ITEM_GET_EXPRESSION_INFO, params);
visit(params.getExpression(), params.getDataType(), visitor, true);
return visitor.getInfo();
}
Aggregations