Search in sources :

Example 21 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField 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 22 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField 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 23 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class BrokerBatchImpl method getMap.

/**
 * {@inheritDoc}
 */
@Override
public Map<P, E> getMap(final DtDefinition dtDefinition, final Collection<P> idList) {
    Assertion.checkNotNull(dtDefinition);
    Assertion.checkNotNull(idList);
    // -----
    final DtField idField = dtDefinition.getIdField().get();
    final Map<P, E> map = new HashMap<>();
    for (final E entity : getList(dtDefinition, idList)) {
        map.put((P) idField.getDataAccessor().getValue(entity), entity);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 24 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class BrokerBatchImpl method getMapByField.

/**
 * {@inheritDoc}
 */
@Override
public <O> Map<O, DtList<E>> getMapByField(final DtDefinition dtDefinition, final String fieldName, final Collection<O> value) {
    Assertion.checkNotNull(dtDefinition);
    Assertion.checkNotNull(fieldName);
    // -----
    final DtField field = dtDefinition.getField(fieldName);
    final Map<O, DtList<E>> map = new HashMap<>();
    for (final E entity : getListByField(dtDefinition, fieldName, value)) {
        final O key = (O) field.getDataAccessor().getValue(entity);
        map.computeIfAbsent(key, k -> new DtList<>(dtDefinition)).add(entity);
    }
    return map;
}
Also used : DtField(io.vertigo.dynamo.domain.metamodel.DtField) TaskDefinition(io.vertigo.dynamo.task.metamodel.TaskDefinition) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtObjectUtil(io.vertigo.dynamo.domain.util.DtObjectUtil) Collection(java.util.Collection) HashMap(java.util.HashMap) Domain(io.vertigo.dynamo.domain.metamodel.Domain) Task(io.vertigo.dynamo.task.model.Task) DtList(io.vertigo.dynamo.domain.model.DtList) Definition(io.vertigo.core.definition.Definition) ArrayList(java.util.ArrayList) Home(io.vertigo.app.Home) List(java.util.List) Entity(io.vertigo.dynamo.domain.model.Entity) DefinitionUtil(io.vertigo.core.definition.DefinitionUtil) TaskManager(io.vertigo.dynamo.task.TaskManager) Map(java.util.Map) TaskEngineSelect(io.vertigo.dynamox.task.TaskEngineSelect) Assertion(io.vertigo.lang.Assertion) HashMap(java.util.HashMap) DtList(io.vertigo.dynamo.domain.model.DtList) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 25 with DtField

use of io.vertigo.dynamo.domain.metamodel.DtField in project vertigo by KleeGroup.

the class BrokerBatchImpl method getList.

/**
 * {@inheritDoc}
 */
@Override
public DtList<E> getList(final DtDefinition dtDefinition, final Collection<P> idList) {
    Assertion.checkNotNull(dtDefinition);
    Assertion.checkNotNull(idList);
    // -----
    final DtList<E> dtc = new DtList<>(dtDefinition);
    // On regarde s'il y a quelquechose à faire
    if (idList.isEmpty()) {
        // Rien à faire
        return dtc;
    }
    // On génère une DTC d'identifiant
    final DtField idField = dtDefinition.getIdField().get();
    for (final P id : idList) {
        Assertion.checkNotNull(id);
        final E entity = (E) DtObjectUtil.createDtObject(dtDefinition);
        idField.getDataAccessor().setValue(entity, id);
        dtc.add(entity);
    }
    return getList(dtDefinition, idField.getName(), dtc);
}
Also used : DtList(io.vertigo.dynamo.domain.model.DtList) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Aggregations

DtField (io.vertigo.dynamo.domain.metamodel.DtField)77 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)28 DtObject (io.vertigo.dynamo.domain.model.DtObject)14 DtList (io.vertigo.dynamo.domain.model.DtList)13 URI (io.vertigo.dynamo.domain.model.URI)12 HashMap (java.util.HashMap)11 Map (java.util.Map)8 TaskDefinition (io.vertigo.dynamo.task.metamodel.TaskDefinition)7 Task (io.vertigo.dynamo.task.model.Task)7 ArrayList (java.util.ArrayList)7 Entity (io.vertigo.dynamo.domain.model.Entity)6 TaskEngineSelect (io.vertigo.dynamox.task.TaskEngineSelect)6 Serializable (java.io.Serializable)6 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 MessageText (io.vertigo.core.locale.MessageText)5 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)5 Date (java.util.Date)4 SearchHit (org.elasticsearch.search.SearchHit)4 JsonObject (com.google.gson.JsonObject)3