@Test public void validationDateGenerator() throws Exception { String expected = jd.get(new Path("legalEntities.0.emails.0.validation.creationDate")).asText(); GeneratedFields.initializeGeneratedFields(factory, md, jd); String s = jd.get(new Path("legalEntities.0.emails.0.validation.creationDate")).asText(); Assert.assertEquals(expected, s); jd.modify(new Path("legalEntities.0.emails.0.validation.creationDate"), null, true); Assert.assertNull(jd.get(new Path("legalEntities.0.emails.0.validation.creationDate"))); GeneratedFields.initializeGeneratedFields(factory, md, jd); s = jd.get(new Path("legalEntities.0.emails.0.validation.creationDate")).asText(); Assert.assertNotNull(s); }
public static void initializeGeneratedFields(Factory factory, EntityMetadata md, JsonDoc doc) { FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode node = cursor.getCurrentNode(); if (node instanceof SimpleField) { SimpleField field = (SimpleField) node; ValueGenerator generator = field.getValueGenerator(); if (generator != null) { Path p = cursor.getCurrentPath(); LOGGER.debug("Processing generated field {}", p); if (required(field)) { LOGGER.debug("Field {} is required", p); setRequiredField(factory, doc, field, p, 1, null, md, generator.isOverwrite()); } else { LOGGER.debug("Field {} is not required", p); KeyValueCursor<Path, JsonNode> nodeCursor = doc.getAllNodes(p); while (nodeCursor.hasNext()) { nodeCursor.next(); JsonNode valueNode = nodeCursor.getCurrentValue(); if (valueNode.isNull() || generator.isOverwrite()) { JsonNode value = generate(factory, field, md); LOGGER.debug("Setting {} to {}", nodeCursor.getCurrentKey(), value); doc.modify(nodeCursor.getCurrentKey(), value, true); } } } } } } }
GeneratedFields { public static void initializeGeneratedFields(Factory factory, EntityMetadata md, JsonDoc doc) { FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode node = cursor.getCurrentNode(); if (node instanceof SimpleField) { SimpleField field = (SimpleField) node; ValueGenerator generator = field.getValueGenerator(); if (generator != null) { Path p = cursor.getCurrentPath(); LOGGER.debug("Processing generated field {}", p); if (required(field)) { LOGGER.debug("Field {} is required", p); setRequiredField(factory, doc, field, p, 1, null, md, generator.isOverwrite()); } else { LOGGER.debug("Field {} is not required", p); KeyValueCursor<Path, JsonNode> nodeCursor = doc.getAllNodes(p); while (nodeCursor.hasNext()) { nodeCursor.next(); JsonNode valueNode = nodeCursor.getCurrentValue(); if (valueNode.isNull() || generator.isOverwrite()) { JsonNode value = generate(factory, field, md); LOGGER.debug("Setting {} to {}", nodeCursor.getCurrentKey(), value); doc.modify(nodeCursor.getCurrentKey(), value, true); } } } } } } } }
GeneratedFields { public static void initializeGeneratedFields(Factory factory, EntityMetadata md, JsonDoc doc) { FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode node = cursor.getCurrentNode(); if (node instanceof SimpleField) { SimpleField field = (SimpleField) node; ValueGenerator generator = field.getValueGenerator(); if (generator != null) { Path p = cursor.getCurrentPath(); LOGGER.debug("Processing generated field {}", p); if (required(field)) { LOGGER.debug("Field {} is required", p); setRequiredField(factory, doc, field, p, 1, null, md, generator.isOverwrite()); } else { LOGGER.debug("Field {} is not required", p); KeyValueCursor<Path, JsonNode> nodeCursor = doc.getAllNodes(p); while (nodeCursor.hasNext()) { nodeCursor.next(); JsonNode valueNode = nodeCursor.getCurrentValue(); if (valueNode.isNull() || generator.isOverwrite()) { JsonNode value = generate(factory, field, md); LOGGER.debug("Setting {} to {}", nodeCursor.getCurrentKey(), value); doc.modify(nodeCursor.getCurrentKey(), value, true); } } } } } } } private  GeneratedFields(); }
GeneratedFields { public static void initializeGeneratedFields(Factory factory, EntityMetadata md, JsonDoc doc) { FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode node = cursor.getCurrentNode(); if (node instanceof SimpleField) { SimpleField field = (SimpleField) node; ValueGenerator generator = field.getValueGenerator(); if (generator != null) { Path p = cursor.getCurrentPath(); LOGGER.debug("Processing generated field {}", p); if (required(field)) { LOGGER.debug("Field {} is required", p); setRequiredField(factory, doc, field, p, 1, null, md, generator.isOverwrite()); } else { LOGGER.debug("Field {} is not required", p); KeyValueCursor<Path, JsonNode> nodeCursor = doc.getAllNodes(p); while (nodeCursor.hasNext()) { nodeCursor.next(); JsonNode valueNode = nodeCursor.getCurrentValue(); if (valueNode.isNull() || generator.isOverwrite()) { JsonNode value = generate(factory, field, md); LOGGER.debug("Setting {} to {}", nodeCursor.getCurrentKey(), value); doc.modify(nodeCursor.getCurrentKey(), value, true); } } } } } } } private  GeneratedFields(); static void initializeGeneratedFields(Factory factory, EntityMetadata md, JsonDoc doc); static JsonNode generate(Factory factory,
                                    SimpleField field,
                                    EntityMetadata md); }
GeneratedFields { public static void initializeGeneratedFields(Factory factory, EntityMetadata md, JsonDoc doc) { FieldCursor cursor = md.getFieldCursor(); while (cursor.next()) { FieldTreeNode node = cursor.getCurrentNode(); if (node instanceof SimpleField) { SimpleField field = (SimpleField) node; ValueGenerator generator = field.getValueGenerator(); if (generator != null) { Path p = cursor.getCurrentPath(); LOGGER.debug("Processing generated field {}", p); if (required(field)) { LOGGER.debug("Field {} is required", p); setRequiredField(factory, doc, field, p, 1, null, md, generator.isOverwrite()); } else { LOGGER.debug("Field {} is not required", p); KeyValueCursor<Path, JsonNode> nodeCursor = doc.getAllNodes(p); while (nodeCursor.hasNext()) { nodeCursor.next(); JsonNode valueNode = nodeCursor.getCurrentValue(); if (valueNode.isNull() || generator.isOverwrite()) { JsonNode value = generate(factory, field, md); LOGGER.debug("Setting {} to {}", nodeCursor.getCurrentKey(), value); doc.modify(nodeCursor.getCurrentKey(), value, true); } } } } } } } private  GeneratedFields(); static void initializeGeneratedFields(Factory factory, EntityMetadata md, JsonDoc doc); static JsonNode generate(Factory factory,
                                    SimpleField field,
                                    EntityMetadata md);  }