SystemFields systemFields = SystemFields.getInstance(repository.getTypeManager(), repository.getIdGenerator());
for (int i = 0; i < conditions.size(); i++) {
JsonNode conditionNode = conditions.get(i);
if (!conditionNode.isObject()) {
throw new JsonFormatException("Each element in the conditions array should be an object.");
}
QName fieldName = QNameConverter.fromJson(JsonUtil.getString(conditionNode, "field"), namespaces);
JsonNode valueNode = conditionNode.get("value");
Object value = null;
if (!valueNode.isNull()) {
FieldType fieldType = systemFields.isSystemField(fieldName) ? systemFields.get(fieldName) :
repository.getTypeManager().getFieldTypeByName(fieldName);
value = RecordReader.INSTANCE.readValue(
new RecordReader.ValueHandle(valueNode, "value", fieldType.getValueType()),
new RecordReader.ReadContext(repositoryMgr.getDefaultRepository(), namespaces,linkTransformer));
}
boolean allowMissing = JsonUtil.getBoolean(conditionNode, "allowMissing", false);
String operator = JsonUtil.getString(conditionNode, "operator", null);
CompareOp op = CompareOp.EQUAL;
if (operator != null) {
try {
op = CompareOp.valueOf(operator.toUpperCase());
} catch (IllegalArgumentException e) {
throw new JsonFormatException("Invalid comparison operator in mutation condition: " + operator);
}
}
MutationCondition condition = new MutationCondition(fieldName, op, value, allowMissing);
result.add(condition);