Search in sources :

Example 11 with ParserExceptionWithoutContext

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

the class ParserUtils method parseExpressionDate.

/**
 * Parse a date. The input format is guaranteed by the expression parser to
 * be yyyy-m-d where m and d may be either 1 or 2 digits each.
 *
 * @param dateString the date string
 * @return the parsed date
 */
public static Date parseExpressionDate(String dateString) {
    String[] dateParts = dateString.split("-");
    String fixedDateString = dateParts[0] + "-" + (dateParts[1].length() == 1 ? "0" : "") + dateParts[1] + "-" + (dateParts[2].length() == 1 ? "0" : "") + dateParts[2];
    Date date;
    try {
        date = parseDate(fixedDateString);
    } catch (Exception e) {
        throw new ParserExceptionWithoutContext("Invalid date: " + dateString + " " + e.getMessage());
    }
    if (date == null) {
        throw new ParserExceptionWithoutContext("Invalid date: " + dateString);
    }
    return date;
}
Also used : ParserExceptionWithoutContext(org.hisp.dhis.antlr.ParserExceptionWithoutContext) Date(java.util.Date) DateUtils.parseDate(org.hisp.dhis.util.DateUtils.parseDate)

Example 12 with ParserExceptionWithoutContext

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

the class ItemConstant method getDescription.

@Override
public Object getDescription(ExprContext ctx, CommonExpressionVisitor visitor) {
    Constant constant = visitor.getConstantMap().get(ctx.uid0.getText());
    if (constant == null) {
        throw new ParserExceptionWithoutContext("No constant defined for " + ctx.uid0.getText());
    }
    visitor.getItemDescriptions().put(ctx.getText(), constant.getDisplayName());
    return DOUBLE_VALUE_IF_NULL;
}
Also used : ParserExceptionWithoutContext(org.hisp.dhis.antlr.ParserExceptionWithoutContext) Constant(org.hisp.dhis.constant.Constant)

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