Search in sources :

Example 1 with DslDefinitionEntry

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());
}
Also used : DslDefinitionBody(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody) DslDefinitionBuilder(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinitionBuilder) DslDefinitionEntry(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry)

Example 2 with DslDefinitionEntry

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);
    }
}
Also used : DslPropertyEntry(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslPropertyEntry) DslDefinitionEntry(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry)

Example 3 with DslDefinitionEntry

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);
}
Also used : DslDefinitionBody(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DslPropertyEntry(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslPropertyEntry) PegChoice(io.vertigo.commons.peg.PegChoice) DslDefinitionEntry(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry)

Example 4 with DslDefinitionEntry

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());
}
Also used : DslDefinitionEntry(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry) Test(org.junit.Test)

Example 5 with DslDefinitionEntry

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());
}
Also used : DslDefinitionEntry(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry) Test(org.junit.Test)

Aggregations

DslDefinitionEntry (io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionEntry)9 Test (org.junit.Test)5 PegChoice (io.vertigo.commons.peg.PegChoice)2 DslDefinitionBody (io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody)2 DslPropertyEntry (io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslPropertyEntry)2 DslDefinitionBuilder (io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinitionBuilder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1