Package org.yaac.server.egql.evaluator

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


  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    if (this.ops.isEmpty()) {
      return new EvaluationResult(null).withWarning(ErrorCode.W120);
    } else if (this.ops.size() == 1) {
      EvaluationResult r = this.ops.get(0).evaluate(record);
      if (r.getPayload() instanceof String) {         
        return new EvaluationResult(
            new User((String) r.getPayload(), SharedConstants.User.DEFAULT_AUTH_DOMAIN), r);
      } else {
        return r.withWarning(ErrorCode.W121);
      }
    } else if (this.ops.size() == 2) {
      EvaluationResult r0 = this.ops.get(0).evaluate(record);
      EvaluationResult r1 = this.ops.get(1).evaluate(record);
      if (r0.getPayload() instanceof String && r1.getPayload() instanceof String) {
        String email = (String)r0.getPayload();
        String authDomain = (String)r1.getPayload();
        return new EvaluationResult(new User(email, authDomain), r0, r1);
      } else {
        return r1.withWarning(ErrorCode.W121);
      }
    } else {
      return this.ops.get(0).evaluate(record).withWarning(ErrorCode.W120);
    }
  }
View Full Code Here


  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    if (this.ops.isEmpty()) {
      return new EvaluationResult(null).withWarning(ErrorCode.W122);
    } else if (this.ops.size() == 2) {
      EvaluationResult r0 = this.ops.get(0).evaluate(record);
      EvaluationResult r1 = this.ops.get(1).evaluate(record);
      if (r0.getPayload() instanceof Number && r1.getPayload() instanceof Number) {
        float lat = ((Number)r0.getPayload()).floatValue();
        float lon = ((Number)r1.getPayload()).floatValue();
       
        try {
          return new EvaluationResult(new GeoPt(lat, lon), r0, r1)
        } catch (IllegalArgumentException e) {
          // Longitude must be between -180 and 180 and Latitude must be between -90 and 90 (inclusive).
          return r1.withWarning(ErrorCode.W143);
        }
      } else {
        return r1.withWarning(ErrorCode.W123);
      }
    } else {
      return this.ops.get(0).evaluate(record).withWarning(ErrorCode.W122);
    }
  }
View Full Code Here

  }

  @Override
  public EvaluationResult evaluate(ProcessDataRecord record) {
    if (ops.isEmpty()) {
      return new EvaluationResult(null).withWarning(ErrorCode.W111);
    } else if (ops.size() == 2) {
      EvaluationResult val = ops.get(0).evaluate(record);
      EvaluationResult start = ops.get(1).evaluate(record);
     
      if (val.getPayload() instanceof String && start.getPayload() instanceof Number) {
        String str = (String) val.getPayload();
        int startI = ((Number)start.getPayload()).intValue();
        return new EvaluationResult(str.substring(startI), val, start);
      } else {
        return val.withWarning(ErrorCode.W110);
      }
    } else if (ops.size() == 3) {
      EvaluationResult val = ops.get(0).evaluate(record);
      EvaluationResult start = ops.get(1).evaluate(record);
      EvaluationResult length = ops.get(2).evaluate(record);
     
      if (val.getPayload() instanceof String &&
          start.getPayload() instanceof Number &&
          length.getPayload() instanceof Number) {
        String str = (String) val.getPayload();
        int startI = ((Number)start.getPayload()).intValue();
        int lengthI = ((Number)length.getPayload()).intValue();
        return new EvaluationResult(str.substring(startI, startI + lengthI), val, start, length);
      } else {
        return val.withWarning(ErrorCode.W110);
      }
    } else {
      return ops.get(0).evaluate(record).withWarning(ErrorCode.W111);
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) {
      PhoneNumber val = new PhoneNumber((String) r.getPayload());
      return new EvaluationResult(val, r)
    } else {
      return r.withWarning(ErrorCode.W133);
    }
  }
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 text
    // then the actual text will NEVER be passed in as ops.get(0).evaluate(context).getPayload()
    if (r.getPayload() instanceof String) {
      return new EvaluationResult(new TextStringWrapper((String) r.getPayload()), r)
    } else if (r.getPayload() instanceof BigDecimal) {
      BigDecimal bd = (BigDecimal) r.getPayload();
      int index = bd.intValue() - 1;
      return new EvaluationResult(new TextFileRefWrapper(record.lookupFileReference(index)));
    } else {
      return r.withWarning(ErrorCode.W132);
    }
  }
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) {
      Email val = new Email((String) r.getPayload());
      return new EvaluationResult(val, r)
    } else {
      return r.withWarning(ErrorCode.W136);
    }
  }
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 Number) {
      Number val = (Number) r.getPayload();
      return new EvaluationResult(val.doubleValue(), r)
    } else {
      return r.withWarning(ErrorCode.W139);
    }
  }
View Full Code Here

    FunctionUtil.ensureParamSize(ops, 0);
  }

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

  }

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

  }

  @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

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.