Search in sources :

Example 6 with DslDefinition

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

the class DomainDynamicRegistry method populateComputedDtField.

/**
 * Ajoute une liste de champs d'un certain type à la dtDefinition
 *
 * @param fields List
 */
private static void populateComputedDtField(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 expression = (String) field.getPropertyValue(KspProperty.EXPRESSION);
        final ComputedExpression computedExpression = new ComputedExpression(expression);
        // --
        final String fieldName = field.getName();
        dtDefinitionBuilder.addComputedField(fieldName, label, domain, computedExpression);
    }
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) ComputedExpression(io.vertigo.dynamo.domain.metamodel.ComputedExpression) Domain(io.vertigo.dynamo.domain.metamodel.Domain)

Example 7 with DslDefinition

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

the class SearchDynamicRegistry method createFacetedQueryDefinition.

private static FacetedQueryDefinition createFacetedQueryDefinition(final DefinitionSpace definitionSpace, final DslDefinition xdefinition) {
    final String definitionName = xdefinition.getName();
    final DtDefinition keyConceptDtDefinition = definitionSpace.resolve(xdefinition.getDefinitionLinkName("keyConcept"), DtDefinition.class);
    final List<String> dynamicFacetDefinitionNames = xdefinition.getDefinitionLinkNames("facets");
    final List<FacetDefinition> facetDefinitions = dynamicFacetDefinitionNames.stream().map(dynamicDefinitionName -> definitionSpace.resolve(dynamicDefinitionName, FacetDefinition.class)).collect(Collectors.toList());
    final String listFilterBuilderQuery = (String) xdefinition.getPropertyValue(SearchGrammar.LIST_FILTER_BUILDER_QUERY);
    final Class<? extends ListFilterBuilder> listFilterBuilderClass = getListFilterBuilderClass(xdefinition);
    final String criteriaDomainName = xdefinition.getDefinitionLinkName("domainCriteria");
    final Domain criteriaDomain = definitionSpace.resolve(criteriaDomainName, Domain.class);
    return new FacetedQueryDefinition(definitionName, keyConceptDtDefinition, facetDefinitions, criteriaDomain, listFilterBuilderClass, listFilterBuilderQuery);
}
Also used : Arrays(java.util.Arrays) ListFilter(io.vertigo.dynamo.collections.ListFilter) DtField(io.vertigo.dynamo.domain.metamodel.DtField) HashMap(java.util.HashMap) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) ArrayList(java.util.ArrayList) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) KspProperty(io.vertigo.dynamo.plugins.environment.KspProperty) DslEntity(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity) DslGrammar(io.vertigo.dynamo.plugins.environment.dsl.entity.DslGrammar) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) ClassUtil(io.vertigo.util.ClassUtil) Collectors(java.util.stream.Collectors) Definition(io.vertigo.core.definition.Definition) MessageText(io.vertigo.core.locale.MessageText) List(java.util.List) ListFilterBuilder(io.vertigo.dynamo.collections.metamodel.ListFilterBuilder) DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) DefinitionSupplier(io.vertigo.core.definition.DefinitionSupplier) FacetOrder(io.vertigo.dynamo.collections.metamodel.FacetDefinition.FacetOrder) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) DynamicRegistry(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DynamicRegistry) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)

Example 8 with DslDefinition

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

the class SearchDynamicRegistry method populateCopyFields.

private static Map<DtField, List<DtField>> populateCopyFields(final DslDefinition xsearchObjet, final DtDefinition indexDtDefinition) {
    // (map fromField : [toField, toField, ...])
    final Map<DtField, List<DtField>> copyToFields = new HashMap<>();
    final List<DslDefinition> copyToFieldNames = xsearchObjet.getChildDefinitions(SearchGrammar.INDEX_COPY_TO_PROPERTY);
    for (final DslDefinition copyToFieldDefinition : copyToFieldNames) {
        final DtField dtFieldTo = indexDtDefinition.getField(copyToFieldDefinition.getName());
        final String copyFromFieldNames = (String) copyToFieldDefinition.getPropertyValue(SearchGrammar.INDEX_COPY_FROM_PROPERTY);
        for (final String copyFromFieldName : copyFromFieldNames.split(",")) {
            final DtField dtFieldFrom = indexDtDefinition.getField(copyFromFieldName.trim());
            copyToFields.computeIfAbsent(dtFieldFrom, k -> new ArrayList<>()).add(dtFieldTo);
        }
    }
    return copyToFields;
}
Also used : Arrays(java.util.Arrays) ListFilter(io.vertigo.dynamo.collections.ListFilter) DtField(io.vertigo.dynamo.domain.metamodel.DtField) HashMap(java.util.HashMap) SearchIndexDefinition(io.vertigo.dynamo.search.metamodel.SearchIndexDefinition) ArrayList(java.util.ArrayList) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) KspProperty(io.vertigo.dynamo.plugins.environment.KspProperty) DslEntity(io.vertigo.dynamo.plugins.environment.dsl.entity.DslEntity) DslGrammar(io.vertigo.dynamo.plugins.environment.dsl.entity.DslGrammar) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) Domain(io.vertigo.dynamo.domain.metamodel.Domain) DefinitionSpace(io.vertigo.core.definition.DefinitionSpace) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) ClassUtil(io.vertigo.util.ClassUtil) Collectors(java.util.stream.Collectors) Definition(io.vertigo.core.definition.Definition) MessageText(io.vertigo.core.locale.MessageText) List(java.util.List) ListFilterBuilder(io.vertigo.dynamo.collections.metamodel.ListFilterBuilder) DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) DefinitionSupplier(io.vertigo.core.definition.DefinitionSupplier) FacetOrder(io.vertigo.dynamo.collections.metamodel.FacetDefinition.FacetOrder) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) DynamicRegistry(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DynamicRegistry) DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 9 with DslDefinition

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

the class AbstractXmlLoader method buildFkFieldName.

private static String buildFkFieldName(final XmlAssociation association, final DslDefinitionRepository dynamicModelrepository) {
    // Dans le cas d'une association simple, on recherche le nom de la FK
    // recherche de code de contrainte destiné à renommer la fk selon convention du vbsript PowerAMC
    // Cas de la relation 1-n : où le nom de la FK est redéfini.
    // Exemple : DOS_UTI_LIQUIDATION (relation entre dossier et utilisateur : FK >> UTILISATEUR_ID_LIQUIDATION)
    final DslDefinition dtDefinitionA = dynamicModelrepository.getDefinition(getDtDefinitionName(association.getCodeA()));
    final DslDefinition dtDefinitionB = dynamicModelrepository.getDefinition(getDtDefinitionName(association.getCodeB()));
    final DslDefinition foreignDefinition = AssociationUtil.isAPrimaryNode(association.getMultiplicityA(), association.getMultiplicityB()) ? dtDefinitionA : dtDefinitionB;
    final List<DslDefinition> primaryKeys = foreignDefinition.getChildDefinitions(DomainGrammar.ID);
    if (primaryKeys.isEmpty()) {
        throw new IllegalArgumentException("Pour l'association '" + association.getCode() + "' aucune clé primaire sur la définition '" + foreignDefinition.getName() + "'");
    }
    if (primaryKeys.size() > 1) {
        throw new IllegalArgumentException("Pour l'association '" + association.getCode() + "' clé multiple non géré sur '" + foreignDefinition.getName() + "'");
    }
    if (dtDefinitionA.getName().equals(dtDefinitionB.getName()) && association.getCodeName() == null) {
        throw new IllegalArgumentException("Pour l'association '" + association.getCode() + "' le nom de la clé est obligatoire (AutoJointure) '" + foreignDefinition.getName() + "'. Ce nom est déduit du code l'association, le code doit être composé ainsi : {Trigramme Table1}_{Trigramme Table2}_{Code association}." + " Par exemple : DOS_UTI_EMMETEUR, DOS_UTI_DESTINATAIRE, DOS_DOS_PARENT, ...");
    }
    // On récupère le nom de LA clé primaire .
    final String pkFieldName = primaryKeys.get(0).getName();
    // Par défaut le nom de la clé étrangère est constituée de la clé primaire référencée.
    String fkFieldName = pkFieldName;
    // Si l'association possède une nom défini par l'utilisateur, alors on l'ajoute à la FK avec un séparateur.
    if (association.getCodeName() != null) {
        // On construit le nom de la clé étrangère.
        fkFieldName = fkFieldName + '_' + association.getCodeName();
    }
    // On raccourci le nom de la clé étrangère.
    if (fkFieldName.length() > MAX_COLUMN_LENGTH) {
        // 30 est le max de dynamo (et de Oracle)
        fkFieldName = fkFieldName.substring(0, MAX_COLUMN_LENGTH);
        while (fkFieldName.endsWith("_")) {
            fkFieldName = fkFieldName.substring(0, fkFieldName.length() - 1);
        }
    }
    LOGGER.trace(KspProperty.FK_FIELD_NAME + "=" + fkFieldName);
    // -----
    Assertion.checkNotNull(fkFieldName, "La clé primaire n''a pas pu être définie pour l'association '{0}'", association.getCode());
    return fkFieldName;
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition)

Example 10 with DslDefinition

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

the class TaskDynamicRegistry method createTaskDefinition.

private static TaskDefinition createTaskDefinition(final DslDefinition xtaskDefinition) {
    final String taskDefinitionName = xtaskDefinition.getName();
    final String request = (String) xtaskDefinition.getPropertyValue(KspProperty.REQUEST);
    Assertion.checkNotNull(taskDefinitionName);
    final Class<? extends TaskEngine> taskEngineClass = getTaskEngineClass(xtaskDefinition);
    final String dataSpace = (String) xtaskDefinition.getPropertyValue(KspProperty.DATA_SPACE);
    final TaskDefinitionBuilder taskDefinitionBuilder = TaskDefinition.builder(taskDefinitionName).withEngine(taskEngineClass).withDataSpace(dataSpace).withRequest(request).withPackageName(xtaskDefinition.getPackageName());
    for (final DslDefinition xtaskAttribute : xtaskDefinition.getChildDefinitions(TaskGrammar.TASK_ATTRIBUTE)) {
        final String attributeName = xtaskAttribute.getName();
        Assertion.checkNotNull(attributeName);
        final String domainName = xtaskAttribute.getDefinitionLinkName("domain");
        final Domain domain = Home.getApp().getDefinitionSpace().resolve(domainName, Domain.class);
        // -----
        final boolean required = (Boolean) xtaskAttribute.getPropertyValue(KspProperty.NOT_NULL);
        if (isInValue((String) xtaskAttribute.getPropertyValue(KspProperty.IN_OUT))) {
            if (required) {
                taskDefinitionBuilder.addInRequired(attributeName, domain);
            } else {
                taskDefinitionBuilder.addInOptional(attributeName, domain);
            }
        } else {
            if (required) {
                taskDefinitionBuilder.withOutRequired(attributeName, domain);
            } else {
                taskDefinitionBuilder.withOutOptional(attributeName, domain);
            }
        }
    }
    return taskDefinitionBuilder.build();
}
Also used : DslDefinition(io.vertigo.dynamo.plugins.environment.dsl.dynamic.DslDefinition) TaskDefinitionBuilder(io.vertigo.dynamo.task.metamodel.TaskDefinitionBuilder) 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