Search in sources :

Example 6 with ParserExceptionWithoutContext

use of org.hisp.dhis.antlr.ParserExceptionWithoutContext in project dhis2-core by dhis2.

the class ProgramItemStageElement method getDescription.

@Override
public Object getDescription(ExprContext ctx, CommonExpressionVisitor visitor) {
    assumeStageElementSyntax(ctx);
    String programStageId = ctx.uid0.getText();
    String dataElementId = ctx.uid1.getText();
    ProgramStageService stageService = visitor.getProgramStageService();
    ProgramStage programStage = stageService.getProgramStage(programStageId);
    DataElement dataElement = visitor.getIdObjectManager().get(DataElement.class, dataElementId);
    if (programStage == null) {
        throw new ParserExceptionWithoutContext("Program stage " + programStageId + " not found");
    }
    if (dataElement == null) {
        throw new ParserExceptionWithoutContext("Data element " + dataElementId + " not found");
    }
    if (isNonDefaultStageOffset(visitor.getState().getStageOffset()) && !isRepeatableStage(stageService, programStageId)) {
        throw new ParserException(getErrorMessage(programStageId));
    }
    String description = programStage.getDisplayName() + ProgramIndicator.SEPARATOR_ID + dataElement.getDisplayName();
    visitor.getItemDescriptions().put(ctx.getText(), description);
    return ValidationUtils.getNullReplacementValue(dataElement.getValueType());
}
Also used : ParserExceptionWithoutContext(org.hisp.dhis.antlr.ParserExceptionWithoutContext) DataElement(org.hisp.dhis.dataelement.DataElement) ParserException(org.hisp.dhis.antlr.ParserException) ProgramStageService(org.hisp.dhis.program.ProgramStageService) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 7 with ParserExceptionWithoutContext

use of org.hisp.dhis.antlr.ParserExceptionWithoutContext in project dhis2-core by dhis2.

the class ProgramItemStageElement method getSql.

@Override
public Object getSql(ExprContext ctx, CommonExpressionVisitor visitor) {
    assumeStageElementSyntax(ctx);
    String programStageId = ctx.uid0.getText();
    String dataElementId = ctx.uid1.getText();
    ProgramExpressionParams params = visitor.getProgParams();
    int stageOffset = visitor.getState().getStageOffset();
    String column;
    if (isNonDefaultStageOffset(stageOffset)) {
        if (isRepeatableStage(visitor.getProgramStageService(), programStageId)) {
            column = visitor.getStatementBuilder().getProgramIndicatorEventColumnSql(programStageId, Integer.valueOf(stageOffset).toString(), SqlUtils.quote(dataElementId), params.getReportingStartDate(), params.getReportingEndDate(), params.getProgramIndicator());
        } else {
            throw new ParserException(getErrorMessage(programStageId));
        }
    } else {
        column = visitor.getStatementBuilder().getProgramIndicatorDataValueSelectSql(programStageId, dataElementId, params.getReportingStartDate(), params.getReportingEndDate(), params.getProgramIndicator());
    }
    if (visitor.getState().isReplaceNulls()) {
        DataElement dataElement = visitor.getIdObjectManager().get(DataElement.class, dataElementId);
        if (dataElement == null) {
            throw new ParserExceptionWithoutContext("Data element " + dataElementId + " not found during SQL generation.");
        }
        column = replaceNullSqlValues(column, dataElement.getValueType());
    }
    return column;
}
Also used : ParserExceptionWithoutContext(org.hisp.dhis.antlr.ParserExceptionWithoutContext) ProgramExpressionParams(org.hisp.dhis.parser.expression.ProgramExpressionParams) ParserException(org.hisp.dhis.antlr.ParserException) DataElement(org.hisp.dhis.dataelement.DataElement)

Example 8 with ParserExceptionWithoutContext

use of org.hisp.dhis.antlr.ParserExceptionWithoutContext in project dhis2-core by dhis2.

the class ItemOrgUnitGroupCount method getDescription.

@Override
public Object getDescription(ExprContext ctx, CommonExpressionVisitor visitor) {
    OrganisationUnitGroup orgUnitGroup = visitor.getIdObjectManager().get(OrganisationUnitGroup.class, ctx.uid0.getText());
    if (orgUnitGroup == null) {
        throw new ParserExceptionWithoutContext("No organization unit group defined for " + ctx.uid0.getText());
    }
    visitor.getItemDescriptions().put(ctx.getText(), orgUnitGroup.getDisplayName());
    return DOUBLE_VALUE_IF_NULL;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) ParserExceptionWithoutContext(org.hisp.dhis.antlr.ParserExceptionWithoutContext)

Example 9 with ParserExceptionWithoutContext

use of org.hisp.dhis.antlr.ParserExceptionWithoutContext in project dhis2-core by dhis2.

the class FunctionOrgUnitGroup method getDescription.

@Override
public Object getDescription(ExpressionParser.ExprContext ctx, CommonExpressionVisitor visitor) {
    for (TerminalNode uid : ctx.UID()) {
        OrganisationUnitGroup orgUnitGroup = visitor.getIdObjectManager().get(OrganisationUnitGroup.class, uid.getText());
        if (orgUnitGroup == null) {
            throw new ParserExceptionWithoutContext("No organization unit group defined for " + uid.getText());
        }
        visitor.getItemDescriptions().put(uid.getText(), orgUnitGroup.getDisplayName());
    }
    return false;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) ParserExceptionWithoutContext(org.hisp.dhis.antlr.ParserExceptionWithoutContext) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode)

Example 10 with ParserExceptionWithoutContext

use of org.hisp.dhis.antlr.ParserExceptionWithoutContext in project dhis2-core by dhis2.

the class D2RelationshipCount method getDescription.

@Override
public Object getDescription(ExprContext ctx, CommonExpressionVisitor visitor) {
    if (ctx.QUOTED_UID() != null) {
        String relationshipId = trimQuotes(ctx.QUOTED_UID().getText());
        RelationshipType relationshipType = visitor.getIdObjectManager().get(RelationshipType.class, relationshipId);
        if (relationshipType == null) {
            throw new ParserExceptionWithoutContext("Relationship type " + relationshipId + " not found");
        }
        visitor.getItemDescriptions().put(ctx.QUOTED_UID().getText(), relationshipType.getDisplayName());
    }
    return DEFAULT_DOUBLE_VALUE;
}
Also used : ParserExceptionWithoutContext(org.hisp.dhis.antlr.ParserExceptionWithoutContext) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Aggregations

ParserExceptionWithoutContext (org.hisp.dhis.antlr.ParserExceptionWithoutContext)12 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)2 ParserException (org.hisp.dhis.antlr.ParserException)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)2 ProgramStage (org.hisp.dhis.program.ProgramStage)2 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)2 Date (java.util.Date)1 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 ValueTypedDimensionalItemObject (org.hisp.dhis.common.ValueTypedDimensionalItemObject)1 Constant (org.hisp.dhis.constant.Constant)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 ProgramExpressionParams (org.hisp.dhis.parser.expression.ProgramExpressionParams)1 ProgramStageService (org.hisp.dhis.program.ProgramStageService)1 RelationshipType (org.hisp.dhis.relationship.RelationshipType)1 DateUtils.parseDate (org.hisp.dhis.util.DateUtils.parseDate)1