private Object getRootPrimitive() { if (commandData instanceof Map) { errors.add(StrUtils.formatString("The value has to be a string for command : ''{0}'' ", name)); return null; } return commandData; }
public Map<String, Object> getDataMap() { if (commandData instanceof Map) { //noinspection unchecked return (Map<String, Object>) commandData; } addError(StrUtils.formatString("The command ''{0}'' should have the values as a json object '{'key:val'}' format but is ''{1}''", name, commandData)); return Collections.emptyMap(); }
public List<String> getStrs(String key) { List<String> val = getStrs(key, null); if (val == null) { errors.add(StrUtils.formatString(REQD, key)); } return val; }
public void unknownOperation() { addError(formatString("Unknown operation ''{0}'' ", name)); }
public void throwExp(Map<String, Object> clause, String msg, Object... args) { throw new IllegalArgumentException("syntax error in clause :"+ toJSONString(clause)+ " , msg: "+ formatString(msg, args)); }
/** * Get a required field. If missing it adds to the errors */ public String getStr(String key) { if (ROOT_OBJ.equals(key)) { Object obj = getRootPrimitive(); if (obj == null) { errors.add(StrUtils.formatString(REQD, name)); } return obj == null ? null : String.valueOf(obj); } String s = getStr(key, null); if (s == null) errors.add(StrUtils.formatString(REQD, key)); return s; }
public Integer getInt(String name, Integer def) { Object o = getVal(name); if (o == null) return def; if (o instanceof Number) { Number number = (Number) o; return number.intValue(); } else { try { return Integer.parseInt(o.toString()); } catch (NumberFormatException e) { addError(StrUtils.formatString("{0} is not a valid integer", name)); return null; } } }
private void doPostValidate(Condition... conditions) { for (Condition condition : conditions) { if (condition == null) continue; String err = condition.varType.postValidate(condition); if (err != null) { throw new IllegalArgumentException(formatString("Error in clause : {0}, caused by : {1}", toJSONString(original), err)); } } }
public Preference(Map<String, Object> m, int idx) { this.idx = idx; this.original = Utils.getDeepCopy(m, 3); sort = Policy.Sort.get(m); name = Policy.SortParam.get(m.get(sort.name()).toString()); Object p = m.getOrDefault("precision", 0); precision = p instanceof Number ? ((Number) p).intValue() : Integer.parseInt(p.toString()); if (precision < 0) { throw new RuntimeException("precision must be a positive value "); } if (precision < name.min || precision > name.max) { throw new RuntimeException(StrUtils.formatString("invalid precision value {0} , must lie between {1} and {2}", precision, name.min, name.max)); } }
static SortParam get(String m) { for (SortParam p : values()) if (p.name().equals(m)) return p; throw new RuntimeException(StrUtils.formatString("Invalid sort {0} Sort must be on one of these {1}", m, Arrays.asList(values()))); } }
public Map getMap(String key, Map def) { Object o = getMapVal(key); if (o == null) return def; if (!(o instanceof Map)) { addError(StrUtils.formatString("''{0}'' must be a map", key)); return def; } else { return (Map) o; } }
String trim = ((String) it).trim(); if (trim.isEmpty()) throw new IllegalArgumentException(formatString("{0} cannot have an empty string value in clause : {1}", conditionName, toJSONString(m))); return trim; .collect(Collectors.toList()); if (list.isEmpty()) throw new IllegalArgumentException(formatString("{0} cannot have an empty list value in clause : {1}", conditionName, toJSONString(m))); for (Object o : list) { if (o instanceof String) { if (getOperand((String) o) != EQUAL) { throw new IllegalArgumentException(formatString("No operators are supported in collection values in condition : {0} in clause : {1}", conditionName, toJSONString(m))); throw new IllegalArgumentException(formatString("Array should have more than one value in condition : {0} in clause : {1}", conditionName, toJSONString(m)));
shard = parse(SHARD, m); if (m.get(REPLICA) == null) { throw new IllegalArgumentException(formatString("'replica' is required in {0}", toJSONString(m)));
@Override public String postValidate(Condition condition) { if (condition.computedType == ComputedType.EQUAL) { if (condition.getClause().tag != null && // condition.getClause().tag.varType == NODE && (condition.getClause().tag.op == Operand.WILDCARD || condition.getClause().tag.op == Operand.IN)) { return null; } else { return "'replica': '#EQUAL` must be used with 'node':'#ANY'"; } } else if (condition.computedType == ComputedType.ALL) { if (condition.getClause().tag != null && (condition.getClause().getTag().op == Operand.IN || condition.getClause().getTag().op == Operand.WILDCARD)) { return StrUtils.formatString("array value or wild card cannot be used for tag {0} with replica : '#ALL'", condition.getClause().tag.getName()); } } else { return checkNonEqualOp(condition); } return null; }