use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslPropertyEntry 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.DslPropertyEntry 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.DslPropertyEntry in project vertigo by KleeGroup.
the class DslPropertyDeclarationRuleTest method test2.
@Test
public void test2() throws PegNoMatchFoundException {
final String text = "label : \" vert \"";
final PegResult<DslPropertyEntry> cursor = MAIN.parse(text, 0);
// On ne met pas de séparateur final et on met un espace
final DslPropertyEntry propertyEntry = cursor.getValue();
Assert.assertEquals(LABEL, propertyEntry.getPropertyName());
// l'espace doit être conservé
Assert.assertEquals(" vert ", propertyEntry.getPropertyValueAsString());
Assert.assertEquals(text.length(), cursor.getIndex());
}
use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslPropertyEntry in project vertigo by KleeGroup.
the class DslPropertyDeclarationRuleTest method test.
@Test
public void test() throws PegNoMatchFoundException {
final String text = "label : \"BLeU\", non reconnu";
final PegResult<DslPropertyEntry> cursor = MAIN.parse(text, 0);
final DslPropertyEntry propertyEntry = cursor.getValue();
Assert.assertEquals(LABEL, propertyEntry.getPropertyName());
Assert.assertEquals("BLeU", propertyEntry.getPropertyValueAsString());
// On vérfifie que le pointeur a avancé jusqu'à 'non reconnu'
Assert.assertEquals(text.length() - " non reconnu".length(), cursor.getIndex());
}
use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslPropertyEntry in project vertigo by KleeGroup.
the class DslPropertyDeclarationRuleTest method test3.
@Test
public void test3() throws PegNoMatchFoundException {
final String text = "size : \"54\",";
final PegResult<DslPropertyEntry> cursor = MAIN.parse(text, 0);
final DslPropertyEntry propertyEntry = cursor.getValue();
Assert.assertEquals(SIZE, propertyEntry.getPropertyName());
Assert.assertEquals("54", propertyEntry.getPropertyValueAsString());
Assert.assertEquals(text.length(), cursor.getIndex());
}
Aggregations