Examples of EvaluationResult


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

  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    if (this.ops.isEmpty()) {
      return new EvaluationResult(null).withWarning(ErrorCode.W124);
    } else if (this.ops.size() == 1) {  // KEY('encoded key')
      EvaluationResult r = this.ops.get(0).evaluate(record);
      if (r.getPayload() instanceof String) {
        try {
          return new EvaluationResult(
              KeyFactory.stringToKey((String) r.getPayload()), r)
        } catch (IllegalArgumentException e) {  // invalid input key string
          return r.withWarning(ErrorCode.W129);
        }
      } else {
        return r.withWarning(ErrorCode.W125);
      }
    } else if (this.ops.size() % 2 == 0) { //TODO KEY('kind', 'name'/ID [, 'kind', 'name'/ID...])
      Key key = null;
     
      // evaluation results, used at last to construct all previous results
      List<EvaluationResult> rs = new ArrayList<EvaluationResult>(this.ops.size());
     
      Iterator<Evaluator> i = this.ops.iterator();
      while (i.hasNext()) {
        EvaluationResult kindR = i.next().evaluate(record);
        EvaluationResult nameIdR = i.next().evaluate(record);
       
        if (!(kindR.getPayload() instanceof String)) {
          return kindR.withWarning(ErrorCode.W126);
        }
       
        if (nameIdR.getPayload() instanceof String) {
          key = KeyFactory.createKey(key,
              (String)kindR.getPayload(),
              (String)nameIdR.getPayload());
        } else if (nameIdR.getPayload() instanceof Number) {
          key = KeyFactory.createKey(key,
              (String)kindR.getPayload(),
              ((Number)nameIdR.getPayload()).longValue());
        } else {
          return kindR.withWarning(ErrorCode.W127)
        }
       
        rs.add(kindR);
        rs.add(nameIdR);
      }
     
      EvaluationResult [] rsArray = new EvaluationResult[rs.size()];
      rs.toArray(rsArray);
      return new EvaluationResult(key, rsArray);
    } else {
      return this.ops.get(0).evaluate(record).withWarning(ErrorCode.W128);
    }
  }
View Full Code Here

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

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

  }
 
  @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

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

    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

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

  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

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

  }

  @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

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

  }

  @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

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

  }

  @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

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

    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

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

    FunctionUtil.ensureParamSize(ops, 0);
  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    return new EvaluationResult(new Date());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.