Search in sources :

Example 1 with DslEntity

use of io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity 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 2 with DslEntity

use of io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity 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)

Example 3 with DslEntity

use of io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity in project vertigo by KleeGroup.

the class DslDefinitionBodyRuleTest method testError.

@Test
public void testError() {
    final List<DslEntity> entities = dslDefinitionRepository.getGrammar().getEntities();
    final DslEntity entity = find(entities, "Domain");
    final String testValue = "{ dataType : String ,  formatter : FMT_DEFAULT,  constraint : [ CK_CODE_POSTAL ] , maxLengh:\"true\"   } ";
    try {
        new DslDefinitionBodyRule(entity).parse(testValue, 0);
        Assert.fail();
    } catch (final PegNoMatchFoundException e) {
        // System.out.println(e.getFullMessage());
        Assert.assertEquals(testValue.indexOf("maxLengh") + "maxLengh".length() - 1, e.getIndex());
    }
}
Also used : PegNoMatchFoundException(io.vertigo.commons.peg.PegNoMatchFoundException) 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 DslEntity

use of io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity in project vertigo by KleeGroup.

the class AbstractXmlLoader method toDynamicDefinition.

private static DslDefinition toDynamicDefinition(final XmlAssociation association, final DslDefinitionRepository dynamicModelrepository) {
    final DslEntity associationEntity = DomainGrammar.ASSOCIATION_ENTITY;
    final DslEntity associationNNEntity = DomainGrammar.ASSOCIATION_NN_ENTITY;
    final String name = association.getCode().toUpperCase(Locale.ENGLISH);
    // On regarde si on est dans le cas d'une association simple ou multiple
    final boolean isAssociationNN = AssociationUtil.isMultiple(association.getMultiplicityA()) && AssociationUtil.isMultiple(association.getMultiplicityB());
    final DslEntity dynamicMetaDefinition;
    if (isAssociationNN) {
        dynamicMetaDefinition = associationNNEntity;
    } else {
        dynamicMetaDefinition = associationEntity;
    }
    // On crée l'association
    final DslDefinitionBuilder associationDefinitionBuilder = DslDefinition.builder(name, dynamicMetaDefinition).withPackageName(association.getPackageName()).addPropertyValue(KspProperty.NAVIGABILITY_A, association.isNavigableA()).addPropertyValue(KspProperty.NAVIGABILITY_B, association.isNavigableB()).addPropertyValue(KspProperty.LABEL_A, association.getRoleLabelA()).addPropertyValue(KspProperty.ROLE_A, XmlUtil.french2Java(association.getRoleLabelA())).addPropertyValue(KspProperty.LABEL_B, association.getRoleLabelB()).addPropertyValue(KspProperty.ROLE_B, XmlUtil.french2Java(association.getRoleLabelB())).addDefinitionLink("dtDefinitionA", getDtDefinitionName(association.getCodeA())).addDefinitionLink("dtDefinitionB", getDtDefinitionName(association.getCodeB()));
    if (isAssociationNN) {
        // Dans le cas d'une association NN il faut établir le nom de la table intermédiaire qui porte les relations
        final String tableName = association.getCode();
        associationDefinitionBuilder.addPropertyValue(KspProperty.TABLE_NAME, tableName);
        LOGGER.trace("isAssociationNN:Code=" + association.getCode());
    } else {
        LOGGER.trace("!isAssociationNN:Code=" + association.getCode());
        // Dans le cas d'une NN ses deux propriétés sont redondantes ;
        // elles ne font donc pas partie de la définition d'une association de type NN
        associationDefinitionBuilder.addPropertyValue(KspProperty.MULTIPLICITY_A, association.getMultiplicityA()).addPropertyValue(KspProperty.MULTIPLICITY_B, association.getMultiplicityB()).addPropertyValue(KspProperty.FK_FIELD_NAME, buildFkFieldName(association, dynamicModelrepository));
    }
    return associationDefinitionBuilder.build();
}
Also used : DslEntity(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity) DslDefinitionBuilder(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinitionBuilder)

Example 5 with DslEntity

use of io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity in project vertigo by KleeGroup.

the class AbstractXmlLoader method toDynamicDefinition.

private static DslDefinition toDynamicDefinition(final XmlClass clazz) {
    final DslEntity dtDefinitionEntity = DomainGrammar.DT_DEFINITION_ENTITY;
    final DslDefinitionBuilder dtDefinitionBuilder = DslDefinition.builder(getDtDefinitionName(clazz.getCode()), dtDefinitionEntity).withPackageName(clazz.getPackageName()).addPropertyValue(KspProperty.STEREOTYPE, clazz.getStereotype());
    for (final XmlAttribute attribute : clazz.getKeyAttributes()) {
        final DslDefinition dtField = toDynamicDefinition(attribute);
        dtDefinitionBuilder.addChildDefinition(DomainGrammar.ID, dtField);
    }
    for (final XmlAttribute tagAttribute : clazz.getFieldAttributes()) {
        final DslDefinition dtField = toDynamicDefinition(tagAttribute);
        dtDefinitionBuilder.addChildDefinition(DomainGrammar.FIELD, dtField);
    }
    return dtDefinitionBuilder.build();
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) DslEntity(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity) DslDefinitionBuilder(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinitionBuilder)

Aggregations

DslEntity (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity)7 DslDefinitionBodyRule (io.vertigo.dynamo.plugins.environment.loaders.kpr.rules.DslDefinitionBodyRule)3 Test (org.junit.Test)3 DslDefinitionBuilder (io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinitionBuilder)2 DslDefinitionBody (io.vertigo.dynamo.plugins.environment.loaders.kpr.definition.DslDefinitionBody)2 PegChoice (io.vertigo.commons.peg.PegChoice)1 PegNoMatchFoundException (io.vertigo.commons.peg.PegNoMatchFoundException)1 PegRule (io.vertigo.commons.peg.PegRule)1 DslDefinition (io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition)1 DslEntityField (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityField)1 DslEntityLink (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntityLink)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1