public static void updateArraySizes(JsonNodeFactory factory, JsonNode node) { if (node instanceof ArrayNode) { updateArraySizes(factory, (ArrayNode) node); } else if (node instanceof ObjectNode) { updateArraySizes(factory, (ObjectNode) node); } }
public static void ensurePredefinedFields(EntityMetadata md) { ensureObjectType(md); // Recursively find all arrays, and add array size fields List<ParentNewChild> l = new ArrayList<>(); // We have to go through all the array fields, and queue up // the new size fields to add, otherwise the following loop // throws a concurrent modification exception FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode f = cursor.getCurrentNode(); if (f instanceof ArrayField) { ParentNewChild x = ensureArraySize(md, (ArrayField) f); if (x != null) { l.add(x); } } } for (ParentNewChild x : l) { x.parent.addNew(x.newChild); } }
&& f.getType().equals(StringType.TYPE)) { if (findConstraint(f.getConstraints(), new ConstraintSearchCB<FieldConstraint>() { public boolean checkMatch(FieldConstraint c) { return c instanceof RequiredConstraint; f.setConstraints(addConstraint(f.getConstraints(), new RequiredConstraint())); if (findConstraint(f.getConstraints(), new ConstraintSearchCB<FieldConstraint>() { public boolean checkMatch(FieldConstraint c) { if (c instanceof StringLengthConstraint && ((StringLengthConstraint) c).getType().equals(StringLengthConstraint.MINLENGTH)) { f.setConstraints(addConstraint(f.getConstraints(), new StringLengthConstraint(StringLengthConstraint.MINLENGTH, 1))); setRoleIfEmpty(f.getAccess().getFind(), MetadataConstants.ROLE_ANYONE); setRoleIfEmpty(f.getAccess().getUpdate(), MetadataConstants.ROLE_NOONE); } else { throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, OBJECTTYPE_FIELD + ":" + f.getType().getName());
PredefinedFields.ensurePredefinedFields(md);
fields = md.getFields(); String fieldName = createArrayCountFieldName(arr.getName()); Field f = fields.getField(fieldName); ParentNewChild ret; setRoleIfEmpty(f.getAccess().getFind(), MetadataConstants.ROLE_ANYONE); } else { throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, fieldName + ":" + f.getType().getName());
private static ParentNewChild ensureArraySize(EntityMetadata md, ArrayField arr) { // Get the parent. The parent is either an object field, object element, or the root FieldTreeNode parent = arr.getParent(); Fields fields; if (parent instanceof ObjectField) { fields = ((ObjectField) parent).getFields(); } else if (parent instanceof ObjectArrayElement) { fields = ((ObjectArrayElement) parent).getFields(); } else { fields = md.getFields(); } String fieldName = arr.getName() + "#"; Field f = fields.getField(fieldName); ParentNewChild ret; if (f == null) { f = new SimpleField(fieldName, IntegerType.TYPE); ret = new ParentNewChild(fields, f); } else { ret = null; } // Must be int if (f instanceof SimpleField && f.getType().equals(IntegerType.TYPE)) { setRoleIfEmpty(f.getAccess().getFind(), MetadataConstants.ROLE_ANYONE); } else { throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, fieldName + ":" + f.getType().getName()); } return ret; }
&& f.getType().equals(StringType.TYPE)) { if (findConstraint(f.getConstraints(), new ConstraintSearchCB<FieldConstraint>() { @Override public boolean checkMatch(FieldConstraint c) { f.setConstraints(addConstraint(f.getConstraints(), new RequiredConstraint())); if (findConstraint(f.getConstraints(), new ConstraintSearchCB<FieldConstraint>() { @Override public boolean checkMatch(FieldConstraint c) { f.setConstraints(addConstraint(f.getConstraints(), new StringLengthConstraint(StringLengthConstraint.MINLENGTH, 1))); setRoleIfEmpty(f.getAccess().getFind(), MetadataConstants.ROLE_ANYONE); setRoleIfEmpty(f.getAccess().getUpdate(), MetadataConstants.ROLE_NOONE); } else { throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, OBJECTTYPE_FIELD + ":" + f.getType().getName());
PredefinedFields.ensurePredefinedFields(md);
fields = md.getFields(); String fieldName = createArrayCountFieldName(arr.getName()); Field f = fields.getField(fieldName); ParentNewChild ret; setRoleIfEmpty(f.getAccess().getFind(), MetadataConstants.ROLE_ANYONE); } else { throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, fieldName + ":" + f.getType().getName());
/** * Updates all array size values in the given document */ public static void updateArraySizes(JsonNodeFactory factory, JsonDoc doc) { updateArraySizes(factory, (ObjectNode) doc.getRoot()); }
&& f.getType().equals(StringType.TYPE)) { if (findConstraint(f.getConstraints(), new ConstraintSearchCB<FieldConstraint>() { @Override public boolean checkMatch(FieldConstraint c) { f.setConstraints(addConstraint(f.getConstraints(), new RequiredConstraint())); if (findConstraint(f.getConstraints(), new ConstraintSearchCB<FieldConstraint>() { @Override public boolean checkMatch(FieldConstraint c) { f.setConstraints(addConstraint(f.getConstraints(), new StringLengthConstraint(StringLengthConstraint.MINLENGTH, 1))); setRoleIfEmpty(f.getAccess().getFind(), MetadataConstants.ROLE_ANYONE); setRoleIfEmpty(f.getAccess().getUpdate(), MetadataConstants.ROLE_NOONE); } else { throw Error.get(MetadataConstants.ERR_FIELD_WRONG_TYPE, OBJECTTYPE_FIELD + ":" + f.getType().getName());
PredefinedFields.ensurePredefinedFields(md);
public static void ensurePredefinedFields(EntityMetadata md) { ensureObjectType(md); // Recursively find all arrays, and add array size fields List<ParentNewChild> l = new ArrayList<>(); // We have to go through all the array fields, and queue up // the new size fields to add, otherwise the following loop // throws a concurrent modification exception FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode f = cursor.getCurrentNode(); if (f instanceof ArrayField) { ParentNewChild x = ensureArraySize(md, (ArrayField) f); if (x != null) { l.add(x); } } } for (ParentNewChild x : l) { x.parent.addNew(x.newChild); } }
public static void updateArraySizes(JsonNodeFactory factory, ArrayNode node) { for (Iterator<JsonNode> itr = node.elements(); itr.hasNext();) { updateArraySizes(factory, itr.next()); } }
PredefinedFields.ensurePredefinedFields(md); MetadataListener listener = factory.getCRUDController(md.getEntityInfo().getDataStore().getBackend()).getMetadataListener(); if (listener != null) {
public static void ensurePredefinedFields(EntityMetadata md) { ensureObjectType(md); // Recursively find all arrays, and add array size fields List<ParentNewChild> l = new ArrayList<>(); // We have to go through all the array fields, and queue up // the new size fields to add, otherwise the following loop // throws a concurrent modification exception FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode f = cursor.getCurrentNode(); if (f instanceof ArrayField) { ParentNewChild x = ensureArraySize(md, (ArrayField) f); if (x != null) { l.add(x); } } } for (ParentNewChild x : l) { x.parent.addNew(x.newChild); } }
/** * Updates all array size values at the subtree rooted at the given object * node * * @param factory Node factory * @param node All array size fields under this subtree will be updated */ public static void updateArraySizes(JsonNodeFactory factory, ObjectNode node) { Map<String, JsonNode> sizes = new HashMap<>(); for (Iterator<Map.Entry<String, JsonNode>> itr = node.fields(); itr.hasNext();) { Map.Entry<String, JsonNode> field = itr.next(); JsonNode value = field.getValue(); if (value instanceof ArrayNode) { sizes.put(field.getKey() + "#", factory.numberNode(((ArrayNode) value).size())); } updateArraySizes(factory, value); } for (Map.Entry<String, JsonNode> entry : sizes.entrySet()) { node.set(entry.getKey(), entry.getValue()); } }
PredefinedFields.ensurePredefinedFields(md); MetadataListener listener = factory.getCRUDController(md.getEntityInfo().getDataStore().getBackend()).getMetadataListener(); if (listener != null) {
private void updatePredefinedFields(OperationContext ctx,CRUDController controller, String entity) { for (JsonDoc doc : ctx.getDocuments()) { PredefinedFields.updateArraySizes(factory.getNodeFactory(), doc); JsonNode node = doc.get(OBJECT_TYPE_PATH); if (node == null) { doc.modify(OBJECT_TYPE_PATH, factory.getNodeFactory().textNode(entity), false); } else if (!node.asText().equals(entity)) { throw Error.get(CrudConstants.ERR_INVALID_ENTITY, node.asText()); } controller.updatePredefinedFields(ctx,doc); } } }
PredefinedFields.ensurePredefinedFields(md); MetadataListener listener = factory.getCRUDController(md.getEntityInfo().getDataStore().getBackend()).getMetadataListener(); if (listener != null) {