Search in sources :

Example 1 with DslDefinitionBody

use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody 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 DslDefinitionBody

use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody 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 3 with DslDefinitionBody

use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody in project vertigo by KleeGroup.

the class DslDefinitionBodyRuleTest method test2.

// Exemple de test sur la déclaration d'un Domain
// create Domain DO_CODE_POSTAL (
// dataType : String;
// formatter : FMT_DEFAULT;
// constraint : {CK_CODE_POSTAL}
// )
@Test
public void test2() throws PegNoMatchFoundException {
    final List<DslEntity> entities = dslDefinitionRepository.getGrammar().getEntities();
    final DslEntity entity = find(entities, "Domain");
    final DslDefinitionBody definitionBody = new DslDefinitionBodyRule(entity).parse("{ dataType : String ,  formatter : FMT_DEFAULT,  constraint : [ CK_CODE_POSTAL ]    } ", 0).getValue();
    Assert.assertNotNull(definitionBody);
}
Also used : DslDefinitionBody(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody) DslEntity(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity) DslDefinitionBodyRule(io.vertigo.dynamo.plugins.environment.loaders.kpr.rules.DslDefinitionBodyRule) Test(org.junit.Test)

Example 4 with DslDefinitionBody

use of io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody in project vertigo by KleeGroup.

the class DslDefinitionBodyRuleTest method test1.

@Test
public void test1() throws PegNoMatchFoundException {
    final List<DslEntity> entities = dslDefinitionRepository.getGrammar().getEntities();
    final DslEntity entity = find(entities, "Formatter");
    final DslDefinitionBody definitionBody = new DslDefinitionBodyRule(entity).parse("{ args : \"UPPER\" }", 0).getValue();
    Assert.assertEquals(1, definitionBody.getPropertyEntries().size());
}
Also used : DslDefinitionBody(io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody) DslEntity(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity) DslDefinitionBodyRule(io.vertigo.dynamo.plugins.environment.loaders.kpr.rules.DslDefinitionBodyRule) Test(org.junit.Test)

Aggregations

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