use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.
the class AnnotationLoader method parseAssociationDefinition.
private static void parseAssociationDefinition(final DslDefinitionRepository dynamicModelRepository, final Annotation annotation, final String packageName) {
if (annotation instanceof io.vertigo.dynamo.domain.stereotype.Association) {
final io.vertigo.dynamo.domain.stereotype.Association association = (io.vertigo.dynamo.domain.stereotype.Association) annotation;
// ============================================================
// Attention pamc inverse dans oom les déclarations des objets !!
final DslDefinition associationDefinition = DslDefinition.builder(association.name(), DomainGrammar.ASSOCIATION_ENTITY).withPackageName(packageName).addPropertyValue(MULTIPLICITY_A, association.primaryMultiplicity()).addPropertyValue(MULTIPLICITY_B, association.foreignMultiplicity()).addPropertyValue(NAVIGABILITY_A, association.primaryIsNavigable()).addPropertyValue(NAVIGABILITY_B, association.foreignIsNavigable()).addPropertyValue(ROLE_A, association.primaryRole()).addPropertyValue(LABEL_A, association.primaryLabel()).addPropertyValue(ROLE_B, association.foreignRole()).addPropertyValue(LABEL_B, association.foreignRole()).addDefinitionLink("dtDefinitionA", association.primaryDtDefinitionName()).addDefinitionLink("dtDefinitionB", association.foreignDtDefinitionName()).addPropertyValue(FK_FIELD_NAME, association.fkFieldName()).build();
if (!dynamicModelRepository.containsDefinitionName(associationDefinition.getName())) {
// Les associations peuvent être déclarées sur les deux noeuds de l'association.
dynamicModelRepository.addDefinition(associationDefinition);
}
} else if (annotation instanceof io.vertigo.dynamo.domain.stereotype.AssociationNN) {
final io.vertigo.dynamo.domain.stereotype.AssociationNN association = (io.vertigo.dynamo.domain.stereotype.AssociationNN) annotation;
// ============================================================
// Attention pamc inverse dans oom les déclarations des objets !!
final DslDefinition associationDefinition = DslDefinition.builder(association.name(), DomainGrammar.ASSOCIATION_NN_ENTITY).withPackageName(packageName).addPropertyValue(TABLE_NAME, association.tableName()).addPropertyValue(NAVIGABILITY_A, association.navigabilityA()).addPropertyValue(NAVIGABILITY_B, association.navigabilityB()).addPropertyValue(ROLE_A, association.roleA()).addPropertyValue(LABEL_A, association.labelA()).addPropertyValue(ROLE_B, association.roleB()).addPropertyValue(LABEL_B, association.labelB()).addDefinitionLink("dtDefinitionA", association.dtDefinitionA()).addDefinitionLink("dtDefinitionB", association.dtDefinitionB()).build();
if (!dynamicModelRepository.containsDefinitionName(associationDefinition.getName())) {
// Les associations peuvent être déclarées sur les deux noeuds de l'association.
dynamicModelRepository.addDefinition(associationDefinition);
}
}
}
use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.
the class AnnotationLoader method parseAnnotation.
/*
* Centralisation du parsing des annotations liées à un champ.
*/
private static void parseAnnotation(final String fieldName, final DslDefinitionBuilder dtDefinition, final io.vertigo.dynamo.domain.stereotype.Field field) {
// Si on trouve un domaine on est dans un objet dynamo.
final FieldType type = FieldType.valueOf(field.type());
final DslDefinition dtField = DslDefinition.builder(fieldName, DomainGrammar.DT_FIELD_ENTITY).addDefinitionLink("domain", field.domain()).addPropertyValue(LABEL, field.label()).addPropertyValue(NOT_NULL, field.required()).addPropertyValue(PERSISTENT, field.persistent()).build();
switch(type) {
case ID:
dtDefinition.addChildDefinition(DomainGrammar.ID, dtField);
break;
case DATA:
dtDefinition.addChildDefinition("field", dtField);
break;
case COMPUTED:
// Valeurs renseignées automatiquement parce que l'on est dans le cas d'un champ calculé
dtDefinition.addChildDefinition("computed", dtField);
break;
case FOREIGN_KEY:
// on ne fait rien puisque le champ est défini par une association.
break;
default:
throw new IllegalArgumentException("case " + type + " not implemented");
}
}
use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition 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();
}
use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.
the class SearchDynamicRegistry method createFacetDefinition.
private static FacetDefinition createFacetDefinition(final DefinitionSpace definitionSpace, final DslDefinition xdefinition) {
final String definitionName = xdefinition.getName();
final DtDefinition indexDtDefinition = definitionSpace.resolve(xdefinition.getDefinitionLinkName("dtDefinition"), DtDefinition.class);
final String dtFieldName = (String) xdefinition.getPropertyValue(SearchGrammar.FIELD_NAME);
final DtField dtField = indexDtDefinition.getField(dtFieldName);
final String label = (String) xdefinition.getPropertyValue(KspProperty.LABEL);
// Déclaration des ranges
final List<DslDefinition> rangeDefinitions = xdefinition.getChildDefinitions("range");
final MessageText labelMsg = MessageText.of(label);
final FacetDefinition facetDefinition;
if (rangeDefinitions.isEmpty()) {
facetDefinition = FacetDefinition.createFacetDefinitionByTerm(definitionName, dtField, labelMsg, isMultiSelectable(xdefinition, false), getFacetOrder(xdefinition, FacetOrder.count));
} else {
final List<FacetValue> facetValues = rangeDefinitions.stream().map(SearchDynamicRegistry::createFacetValue).collect(Collectors.toList());
facetDefinition = FacetDefinition.createFacetDefinitionByRange(definitionName, dtField, labelMsg, facetValues, isMultiSelectable(xdefinition, false), getFacetOrder(xdefinition, FacetOrder.definition));
}
return facetDefinition;
}
use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.
the class DslKspRule method handle.
@Override
protected Dummy handle(final List<Object> parsing) {
final String packageName = (String) parsing.get(1);
final List<PegChoice> declarationChoices = (List<PegChoice>) parsing.get(3);
for (final PegChoice declarationChoice : declarationChoices) {
// - à des gestion de droits.
switch(declarationChoice.getChoiceIndex()) {
case 0:
// On positionne le Package
final DslDefinition oldDynamicDefinition = (DslDefinition) declarationChoice.getValue();
final DslDefinition newDynamicDefinition = DslDefinition.builder(oldDynamicDefinition.getName(), oldDynamicDefinition.getEntity()).withPackageName(packageName).merge(oldDynamicDefinition).build();
handleDefinitionRule(newDynamicDefinition);
break;
case 1:
handleTemplateRule((DslDefinition) declarationChoice.getValue());
break;
default:
throw new IllegalArgumentException("case " + declarationChoice.getChoiceIndex() + " not implemented");
}
}
return Dummy.INSTANCE;
}
Aggregations