Search in sources :

Example 1 with DslDefinition

use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.

the class AnnotationLoader method parseDynamicDefinitionBuilder.

private static void parseDynamicDefinitionBuilder(final Class<DtObject> clazz, final DslDefinitionBuilder dtDefinitionBuilder, final DslDefinitionRepository dynamicModelRepository) {
    final String packageName = clazz.getPackage().getName();
    // Le tri des champs et des méthodes par ordre alphabétique est important car classe.getMethods() retourne
    // un ordre relativement aléatoire et la lecture des annotations peut donc changer l'ordre
    // des fields d'une lecture à l'autre (ou d'une compilation à l'autre).
    // Cela devient alors bloquant pour une communication par sérialisation entre 2 instances.
    final List<Field> fields = new ArrayList<>(ClassUtil.getAllFields(clazz));
    fields.sort(Comparator.comparing(Field::getName));
    for (final Field field : fields) {
        // On regarde si il s'agit d'un champ
        parseFieldAnnotations(field, dtDefinitionBuilder);
        parseAssociationDefinition(dynamicModelRepository, field, packageName);
    }
    final Method[] methods = clazz.getMethods();
    Arrays.sort(methods, Comparator.comparing(Method::getName));
    for (final Method method : methods) {
        parseMethodAnnotations(method, dtDefinitionBuilder);
        // On regarde si il s'agit d'une associations
        parseAssociationDefinition(dynamicModelRepository, method, packageName);
    }
    final DslDefinition dtDefinition = dtDefinitionBuilder.build();
    dynamicModelRepository.addDefinition(dtDefinition);
}
Also used : Field(java.lang.reflect.Field) DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method)

Example 2 with DslDefinition

use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.

the class DomainDynamicRegistry method createFragmentDtDefinition.

private static DtDefinition createFragmentDtDefinition(final DefinitionSpace definitionSpace, final DslDefinition xdtDefinition) {
    final DtDefinition from = definitionSpace.resolve(xdtDefinition.getDefinitionLinkName("from"), DtDefinition.class);
    final String sortFieldName = (String) xdtDefinition.getPropertyValue(KspProperty.SORT_FIELD);
    final String displayFieldName = (String) xdtDefinition.getPropertyValue(KspProperty.DISPLAY_FIELD);
    // 0. clones characteristics
    final DtDefinitionBuilder dtDefinitionBuilder = DtDefinition.builder(xdtDefinition.getName()).withFragment(from).withPackageName(xdtDefinition.getPackageName()).withDataSpace(from.getDataSpace()).withPackageName(from.getPackageName()).withSortField(sortFieldName).withDisplayField(displayFieldName);
    // 1. adds aliases
    for (final DslDefinition alias : xdtDefinition.getChildDefinitions("alias")) {
        final DtField aliasDtField = from.getField(alias.getName());
        // --- REQUIRED
        final Boolean overiddenRequired = (Boolean) alias.getPropertyValue(KspProperty.NOT_NULL);
        final boolean required = overiddenRequired != null ? overiddenRequired : aliasDtField.isRequired();
        // --- LABEL
        final String overiddenLabel = (String) alias.getPropertyValue(KspProperty.LABEL);
        final String label = overiddenLabel != null ? overiddenLabel : aliasDtField.getLabel().getDisplay();
        dtDefinitionBuilder.addDataField(aliasDtField.getName(), label, aliasDtField.getDomain(), required, aliasDtField.isPersistent());
    }
    // 2. adds data and computed fields
    // Déclaration des champs du DT
    final List<DslDefinition> fields = xdtDefinition.getChildDefinitions(DomainGrammar.FIELD);
    populateDataDtField(definitionSpace, dtDefinitionBuilder, fields);
    // Déclaration des champs calculés
    final List<DslDefinition> computedFields = xdtDefinition.getChildDefinitions(DomainGrammar.COMPUTED);
    populateComputedDtField(definitionSpace, dtDefinitionBuilder, computedFields);
    final DtDefinition dtDefinition = dtDefinitionBuilder.build();
    // 0. adds ID field -->>> Should be first, but needs an already build DtDefinition
    if (from.getIdField().isPresent()) {
        final DtField idField = from.getIdField().get();
        dtDefinitionBuilder.addForeignKey(idField.getName(), idField.getLabel().getDisplay(), idField.getDomain(), true, from.getName());
    }
    return dtDefinition;
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) DtDefinitionBuilder(io.vertigo.dynamo.domain.metamodel.DtDefinitionBuilder) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 3 with DslDefinition

use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.

the class DomainDynamicRegistry method createDtDefinition.

/**
 * @param xdtDefinition Définition de DT
 */
private DtDefinition createDtDefinition(final DefinitionSpace definitionSpace, final DslDefinition xdtDefinition) {
    // Déclaration de la définition
    final String sortFieldName = (String) xdtDefinition.getPropertyValue(KspProperty.SORT_FIELD);
    final String displayFieldName = (String) xdtDefinition.getPropertyValue(KspProperty.DISPLAY_FIELD);
    // -----
    final String tmpStereotype = (String) xdtDefinition.getPropertyValue(KspProperty.STEREOTYPE);
    // Si Stereotype est non renseigné on suppose que la définition est DtStereotype.Data.
    final DtStereotype stereotype = tmpStereotype != null ? DtStereotype.valueOf(tmpStereotype) : null;
    // -----
    final String dataSpace = (String) xdtDefinition.getPropertyValue(KspProperty.DATA_SPACE);
    // -----
    final String fragmentOf = (String) xdtDefinition.getPropertyValue(KspProperty.FRAGMENT_OF);
    // -----
    // -----
    final String dtDefinitionName = xdtDefinition.getName();
    final DtDefinitionBuilder dtDefinitionBuilder = DtDefinition.builder(dtDefinitionName).withPackageName(xdtDefinition.getPackageName()).withDataSpace(dataSpace).withSortField(sortFieldName).withDisplayField(displayFieldName);
    if (stereotype != null) {
        dtDefinitionBuilder.withStereoType(stereotype);
    }
    if (!StringUtil.isEmpty(fragmentOf)) {
        dtDefinitionBuilder.withFragment(definitionSpace.resolve(fragmentOf, DtDefinition.class));
    }
    // On enregistre les Builder pour pouvoir les mettre à jour sur les associations.
    Assertion.checkArgument(!dtDefinitionBuilders.containsKey(dtDefinitionName), "Definition '{0}' already registered", dtDefinitionName);
    dtDefinitionBuilders.put(dtDefinitionName, dtDefinitionBuilder);
    // Déclaration de la clé primaire
    final List<DslDefinition> keys = xdtDefinition.getChildDefinitions(DomainGrammar.ID);
    populateIdDtField(definitionSpace, dtDefinitionBuilder, keys);
    // Déclaration des champs du DT
    final List<DslDefinition> fields = xdtDefinition.getChildDefinitions(DomainGrammar.FIELD);
    populateDataDtField(definitionSpace, dtDefinitionBuilder, fields);
    // Déclaration des champs calculés
    final List<DslDefinition> computedFields = xdtDefinition.getChildDefinitions(DomainGrammar.COMPUTED);
    populateComputedDtField(definitionSpace, dtDefinitionBuilder, computedFields);
    return dtDefinitionBuilder.build();
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) DtDefinitionBuilder(io.vertigo.dynamo.domain.metamodel.DtDefinitionBuilder) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtStereotype(io.vertigo.dynamo.domain.metamodel.DtStereotype)

Example 4 with DslDefinition

use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.

the class DomainDynamicRegistry method populateIdDtField.

/**
 * Ajoute une liste de champs d'un certain type à la dtDefinition
 *
 * @param fields List
 */
private static void populateIdDtField(final DefinitionSpace definitionSpace, final DtDefinitionBuilder dtDefinitionBuilder, final List<DslDefinition> fields) {
    for (final DslDefinition field : fields) {
        final Domain domain = definitionSpace.resolve(field.getDefinitionLinkName("domain"), Domain.class);
        // --
        Assertion.checkArgument(field.getPropertyNames().contains(KspProperty.LABEL), "Label est une propriété obligatoire");
        final String label = (String) field.getPropertyValue(KspProperty.LABEL);
        // --
        final String fieldName = field.getName();
        // -----
        dtDefinitionBuilder.addIdField(fieldName, label, domain);
    }
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain)

Example 5 with DslDefinition

use of io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition in project vertigo by KleeGroup.

the class DomainDynamicRegistry method populateDataDtField.

/**
 * Ajoute une liste de champs d'un certain type à la dtDefinition
 *
 * @param fields List
 */
private static void populateDataDtField(final DefinitionSpace definitionSpace, final DtDefinitionBuilder dtDefinitionBuilder, final List<DslDefinition> fields) {
    for (final DslDefinition field : fields) {
        final Domain domain = definitionSpace.resolve(field.getDefinitionLinkName("domain"), Domain.class);
        // --
        Assertion.checkArgument(field.getPropertyNames().contains(KspProperty.LABEL), "Label est une propriété obligatoire");
        final String label = (String) field.getPropertyValue(KspProperty.LABEL);
        // --
        final boolean notNull = (Boolean) field.getPropertyValue(KspProperty.NOT_NULL);
        Assertion.checkArgument(field.getPropertyNames().contains(KspProperty.NOT_NULL), "Not null est une propriété obligatoire.");
        // --
        final Boolean tmpPersistent = (Boolean) field.getPropertyValue(KspProperty.PERSISTENT);
        // Si PERSISTENT est non renseigné on suppose que le champ est à priori persistant .
        final boolean persistent = tmpPersistent == null || tmpPersistent;
        // --
        final String fieldName = field.getName();
        // -----
        dtDefinitionBuilder.addDataField(fieldName, label, domain, notNull, persistent);
    }
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain)

Aggregations

DslDefinition (io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition)20 Domain (io.vertigo.dynamo.domain.metamodel.Domain)6 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)5 DtField (io.vertigo.dynamo.domain.metamodel.DtField)4 DefinitionSpace (io.vertigo.core.definition.DefinitionSpace)3 MessageText (io.vertigo.core.locale.MessageText)3 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)3 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)3 DynamicRegistry (io.vertigo.dynamo.plugins.environment.dsl.dynamic.DynamicRegistry)3 DslEntity (io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Definition (io.vertigo.core.definition.Definition)2 DefinitionSupplier (io.vertigo.core.definition.DefinitionSupplier)2 ListFilter (io.vertigo.dynamo.collections.ListFilter)2 FacetOrder (io.vertigo.dynamo.collections.metamodel.FacetDefinition.FacetOrder)2 FacetedQueryDefinition (io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)2 ListFilterBuilder (io.vertigo.dynamo.collections.metamodel.ListFilterBuilder)2 DtDefinitionBuilder (io.vertigo.dynamo.domain.metamodel.DtDefinitionBuilder)2 KspProperty (io.vertigo.dynamo.plugins.environment.KspProperty)2