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);
}
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());
}
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());
}
}
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();
}
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();
}
Aggregations