Package org.yaac.server.egql.evaluator

Examples of org.yaac.server.egql.evaluator.EvaluationResult


    FunctionUtil.ensureParamSize(ops, 2);
  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    EvaluationResult orig = ops.get(0).evaluate(record);
    EvaluationResult format = ops.get(1).evaluate(record);
   
    if (format.getPayload() instanceof String) {
      if (orig.getPayload() instanceof Number) {
        BigDecimal val = (BigDecimal) orig.getPayload();
        String formattedVal =
          new DecimalFormat((String) format.getPayload()).format(val);
        return new EvaluationResult(formattedVal, orig, format);
      } else if (orig.getPayload() instanceof Date) {
        Date d = (Date) orig.getPayload();
        String formattedDt =
          new SimpleDateFormat((String) format.getPayload()).format(d);
        return new EvaluationResult(formattedDt, orig, format);
      } else {
        return orig.withWarning(ErrorCode.W105);
      }
    } else {
      return orig.withWarning(ErrorCode.W106);
View Full Code Here


  }
 
  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    if (this.ops.isEmpty()) {
      return new EvaluationResult(null).withWarning(ErrorCode.W115);
    } else {
      EvaluationResult r = ops.get(0).evaluate(record);
      if (r.getPayload() == null) {
        return new EvaluationResult(PropertyType.NULL.getRepresentation(), r);
      } else {
        return new EvaluationResult(TYPE_MAP.get(r.getPayload().getClass()), r);
      }
    }
  }
View Full Code Here

    FunctionUtil.ensureParamSize(ops, 1);
  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    EvaluationResult r = ops.get(0).evaluate(record);
   
    if (r.getPayload() instanceof String) {
      ShortBlob val = new ShortBlob(((String) r.getPayload()).getBytes());
      return new EvaluationResult(val, r)
    } else {
      return r.withWarning(ErrorCode.W131);
    }
  }
View Full Code Here

  public EvaluationResult evaluate(ProcessDataRecord record) {
    // default formats
    List<String> defaultFormats = Arrays.asList("yyyyMMdd", "yyyyMMddHHmmss");
   
    if (this.ops.isEmpty()) {
      return new EvaluationResult(null).withWarning(ErrorCode.W119);
    } else if (this.ops.size() == 1) {
      EvaluationResult r = ops.get(0).evaluate(record);
     
      if (r.getPayload() instanceof String) {
        String str = (String) r.getPayload();
        for (String defaultFormat : defaultFormats) {
          if (str.length() == defaultFormat.length()) {
            try {
              return new EvaluationResult(
                  new SimpleDateFormat(defaultFormat).parse(str), r);
            } catch (ParseException e) {
              // simply ignore parsing if failed
            }
          }
        }
       
        // non of them are successful, return error message
        return r.withWarning(ErrorCode.W116);
      } else {
        return r.withWarning(ErrorCode.W117);
      }
    } else if (this.ops.size() == 2) {
      EvaluationResult r = ops.get(0).evaluate(record);
      EvaluationResult formatR = ops.get(1).evaluate(record);
     
      if (r.getPayload() instanceof String && formatR.getPayload() instanceof String) {
        String str = (String) r.getPayload();
        String formatStr = (String) formatR.getPayload();
       
        try {
          return new EvaluationResult(
              new SimpleDateFormat(formatStr).parse(str), r, formatR);
        } catch (ParseException e) {
          // simply ignore parsing if failed
          return r.withWarning(ErrorCode.W118);
        }
View Full Code Here

  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    if (this.ops.isEmpty()) {
      return new EvaluationResult(null).withWarning(ErrorCode.W109);
    } else if (this.ops.size() == 1) {
      EvaluationResult r = ops.get(0).evaluate(record);
      Object payload = r.getPayload();
     
      int len = 0;
      if (payload instanceof String) {
        len = ((String)r.getPayload()).length();
      } else if (payload instanceof Text) {
        len = ((Text)r.getPayload()).getValue().length();
      } else if (payload instanceof ShortBlob) {
        len = ((ShortBlob) payload).getBytes().length;
      } else if (payload instanceof Blob) {
        len = ((Blob) payload).getBytes().length;
      } else if (payload instanceof List<?>) {
        len = ((List<?>) payload).size();
      } else {
        return r.withWarning(ErrorCode.W108);
      }
     
      // only long / double / bigdecimal is supported
      return new EvaluationResult(new Long(len), r);
    } else {
      return ops.get(0).evaluate(record).withWarning(ErrorCode.W109);
    }
  }
View Full Code Here

  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    if (this.ops.isEmpty()) {
      return new EvaluationResult(null).withWarning(ErrorCode.W102);
    } else if (this.ops.size() == 1) {
      EvaluationResult r = ops.get(0).evaluate(record);
      if (r.getPayload() instanceof String) {
        return new EvaluationResult(((String)r.getPayload()).toLowerCase(), r);
      } else {
        return r.withWarning(ErrorCode.W104);
      }
    } else {
      return this.ops.get(0).evaluate(record).withWarning(ErrorCode.W102);
    }
  }
View Full Code Here

  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    if (this.ops.isEmpty()) {
      return new EvaluationResult(null).withWarning(ErrorCode.W114);
    } else if (this.ops.size() == 2) {
      EvaluationResult r = ops.get(0).evaluate(record);
      EvaluationResult scale = ops.get(1).evaluate(record);
      if (r.getPayload() instanceof Number && scale.getPayload() instanceof Number) {
        BigDecimal bd = (BigDecimal) r.getPayload();
        BigDecimal scaleBd = (BigDecimal) scale.getPayload();
        return new EvaluationResult(
            bd.setScale(scaleBd.intValue(), BigDecimal.ROUND_HALF_UP), r, scale);
      } else {
        return r.withWarning(ErrorCode.W113);
      }
    } else {
View Full Code Here

    FunctionUtil.ensureParamSize(ops, 1);
  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    EvaluationResult r = ops.get(0).evaluate(record);
   
    // since this will only be used when user is trying to execute an expression with function blob
    // then the actual blob will NEVER be passed in as ops.get(0).evaluate(context).getPayload()
    if (r.getPayload() instanceof String) {
      return new EvaluationResult(new BlobStringWrapper((String) r.getPayload()), r)
    } else if (r.getPayload() instanceof BigDecimal) {
      BigDecimal bd = (BigDecimal) r.getPayload();
      int index = bd.intValue() - 1;
     
      try {
        return new EvaluationResult(new BlobFileRefWrapper(record.lookupFileReference(index)))
      } catch (IndexOutOfBoundsException e) {
        throw new YaacException(ErrorCode.E303, null);
      }
    } else {
      return r.withWarning(ErrorCode.W137);
    }
  }
View Full Code Here

    FunctionUtil.ensureParamSize(ops, 0);
  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    return new EvaluationResult(new Date());
  }
View Full Code Here

    FunctionUtil.ensureParamSize(ops, 1);
  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    EvaluationResult r = ops.get(0).evaluate(record);
   
    if (r.getPayload() instanceof String) {
      Category val = new Category((String) r.getPayload());
      return new EvaluationResult(val, r)
    } else {
      return r.withWarning(ErrorCode.W134);
    }
  }
View Full Code Here

TOP

Related Classes of org.yaac.server.egql.evaluator.EvaluationResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.