use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry in project vertigo by KleeGroup.
the class DslInnerDefinitionRule method handle.
@Override
protected DslDefinitionEntry handle(final List<Object> parsing) {
// Dans le cas des sous définition :: field [PRD_XXX]
final String definitionName = (String) parsing.get(2);
final DslDefinitionBody definitionBody = (DslDefinitionBody) parsing.get(4);
final DslDefinitionBuilder dslDefinitionBuilder = DslDefinition.builder(definitionName, entity);
populateDefinition(definitionBody, dslDefinitionBuilder);
// ---
return new DslDefinitionEntry(entityName, dslDefinitionBuilder.build());
}
use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry in project vertigo by KleeGroup.
the class DslInnerDefinitionRule method populateDefinition.
/**
* Peuple la définition à partir des éléments trouvés.
*/
private static void populateDefinition(final DslDefinitionBody definitionBody, final DslDefinitionBuilder dslDefinitionBuilder) {
for (final DslDefinitionEntry fieldDefinitionEntry : definitionBody.getDefinitionEntries()) {
// -----
if (fieldDefinitionEntry.containsDefinition()) {
// On ajoute la définition par sa valeur.
dslDefinitionBuilder.addChildDefinition(fieldDefinitionEntry.getFieldName(), fieldDefinitionEntry.getDefinition());
} else {
// On ajoute les définitions par leur clé.
dslDefinitionBuilder.addAllDefinitionLinks(fieldDefinitionEntry.getFieldName(), fieldDefinitionEntry.getDefinitionNames());
}
}
for (final DslPropertyEntry dslPropertyEntry : definitionBody.getPropertyEntries()) {
// // On vérifie que la propriété est enregistrée sur la metaDefinition
// Assertion.precondition(definition.getEntity().getPropertySet().contains(fieldPropertyEntry.getProperty()), "Propriété {0} non enregistré sur {1}",
// fieldPropertyEntry.getProperty(), definition.getEntity().getName());
// -----
final Object value = readProperty(dslDefinitionBuilder.getEntity(), dslPropertyEntry);
dslDefinitionBuilder.addPropertyValue(dslPropertyEntry.getPropertyName(), value);
}
}
use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry in project vertigo by KleeGroup.
the class DslDefinitionBodyRule method handle.
@Override
protected DslDefinitionBody handle(final List<Object> parsing) {
final List<PegChoice> many = (List<PegChoice>) parsing.get(2);
final List<DslDefinitionEntry> fieldDefinitionEntries = new ArrayList<>();
final List<DslPropertyEntry> fieldPropertyEntries = new ArrayList<>();
for (final PegChoice item : many) {
switch(item.getChoiceIndex()) {
case 0:
// Soit on est en présence d'une propriété standard
final DslPropertyEntry propertyEntry = (DslPropertyEntry) item.getValue();
fieldPropertyEntries.add(propertyEntry);
break;
case 1:
final DslDefinitionEntry xDefinitionEntry = (DslDefinitionEntry) item.getValue();
fieldDefinitionEntries.add(xDefinitionEntry);
break;
case 2:
final PegChoice subTuple = (PegChoice) item.getValue();
fieldDefinitionEntries.add((DslDefinitionEntry) subTuple.getValue());
break;
case 3:
break;
default:
throw new IllegalArgumentException("Type of rule not supported");
}
}
return new DslDefinitionBody(fieldDefinitionEntries, fieldPropertyEntries);
}
use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry in project vertigo by KleeGroup.
the class DslDefinitionEntryRuleTest method test0.
@Test
public void test0() throws PegNoMatchFoundException {
final String text = "myFirstProperty : [BLEU ], non reconnu";
final PegResult<DslDefinitionEntry> cursor = MAIN.parse(text, 0);
final DslDefinitionEntry xDefinitionEntry = cursor.getValue();
Assert.assertEquals("myFirstProperty", xDefinitionEntry.getFieldName());
Assert.assertEquals(1, xDefinitionEntry.getDefinitionNames().size());
Assert.assertTrue(xDefinitionEntry.getDefinitionNames().contains("BLEU"));
Assert.assertEquals(text.length() - " non reconnu".length(), cursor.getIndex());
}
use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry in project vertigo by KleeGroup.
the class DslDefinitionEntryRuleTest method test3.
@Test
public void test3() throws PegNoMatchFoundException {
final String text = "myFirstProperty : [BLEU,VerT, ROUGE ]";
final PegResult<DslDefinitionEntry> cursor = MAIN.parse(text, 0);
final DslDefinitionEntry xDefinitionEntry = cursor.getValue();
Assert.assertEquals("myFirstProperty", xDefinitionEntry.getFieldName());
Assert.assertEquals(3, xDefinitionEntry.getDefinitionNames().size());
Assert.assertTrue(xDefinitionEntry.getDefinitionNames().contains("VerT"));
Assert.assertEquals(text.length(), cursor.getIndex());
}
Aggregations