Search in sources :

Example 26 with DtField

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

the class DAO method reloadAndMerge.

/**
 * Reloads entity from fragment, and keep fragment modifications.
 *
 * @param fragment  merged from datastore and input
 * @return merged root entity merged with the fragment
 */
public final E reloadAndMerge(final Fragment<E> fragment) {
    final DtDefinition fragmentDefinition = DtObjectUtil.findDtDefinition(fragment);
    final DtDefinition entityDefinition = fragmentDefinition.getFragment().get();
    final Map<String, DtField> entityFields = indexFields(entityDefinition.getFields());
    final DtField idField = entityDefinition.getIdField().get();
    // etrange on utilise l'accessor de l'entity sur le fragment
    final P entityId = (P) idField.getDataAccessor().getValue(fragment);
    final E dto = get(entityId);
    for (final DtField fragmentField : fragmentDefinition.getFields()) {
        // On vérifie la présence du champ dans l'Entity (il peut s'agir d'un champ non persistent d'UI
        if (entityFields.containsKey(fragmentField.getName())) {
            final DataAccessor fragmentDataAccessor = fragmentField.getDataAccessor();
            final DataAccessor entityDataAccessor = entityFields.get(fragmentField.getName()).getDataAccessor();
            entityDataAccessor.setValue(dto, fragmentDataAccessor.getValue(fragment));
        }
    }
    return dto;
}
Also used : DataAccessor(io.vertigo.dynamo.domain.metamodel.DataAccessor) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 27 with DtField

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

the class FacetFactory method createTermCluster.

private static <D extends DtObject> Map<FacetValue, DtList<D>> createTermCluster(final FacetDefinition facetDefinition, final DtList<D> dtList) {
    // map résultat avec les docs par FacetFilter
    final Map<FacetValue, DtList<D>> clusterValues = new LinkedHashMap<>();
    // Cas des facettes par Term
    final DtField dtField = facetDefinition.getDtField();
    // on garde un index pour incrémenter le facetFilter pour chaque Term
    final Map<Object, FacetValue> facetFilterIndex = new HashMap<>();
    FacetValue facetValue;
    for (final D dto : dtList) {
        final Object value = dtField.getDataAccessor().getValue(dto);
        facetValue = facetFilterIndex.get(value);
        if (facetValue == null) {
            final String valueAsString = dtField.getDomain().valueToString(value);
            final String label;
            if (StringUtil.isEmpty(valueAsString)) {
                label = "<==no label==>";
            } else {
                label = valueAsString;
            }
            final MessageText labelMsg = MessageText.of(label);
            // on garde la syntaxe Solr pour l'instant
            final ListFilter listFilter = ListFilter.of(dtField.getName() + ":\"" + valueAsString + "\"");
            facetValue = new FacetValue(label, listFilter, labelMsg);
            facetFilterIndex.put(value, facetValue);
            clusterValues.put(facetValue, new DtList<D>(dtList.getDefinition()));
        }
        clusterValues.get(facetValue).add(dto);
    }
    // tri des facettes
    final Comparator<FacetValue> facetComparator = new FacetComparator<>(clusterValues);
    final Map<FacetValue, DtList<D>> sortedFacetValues = new TreeMap<>(facetComparator);
    sortedFacetValues.putAll(clusterValues);
    return sortedFacetValues;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MessageText(io.vertigo.core.locale.MessageText) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) DtField(io.vertigo.dynamo.domain.metamodel.DtField) ListFilter(io.vertigo.dynamo.collections.ListFilter) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) DtObject(io.vertigo.dynamo.domain.model.DtObject) DtList(io.vertigo.dynamo.domain.model.DtList)

Example 28 with DtField

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

the class DtListURIForCriteria method createCriteria.

/**
 * Construit automatiquement un Criteria à partir d'un DtObject de critère.
 * Les noms des champs dans l'objet de critère doivent correspondre à ceux de l'objet métier.
 * @param dtoCriteria Objet de critère
 * @return Criteria resultant
 */
public static <E extends Entity> Criteria<E> createCriteria(final DtObject dtoCriteria) {
    Assertion.checkNotNull(dtoCriteria);
    // -----
    final DtDefinition dtDefinition = DtObjectUtil.findDtDefinition(dtoCriteria);
    Criteria<E> criteria = Criterions.alwaysTrue();
    for (final DtField field : dtDefinition.getFields()) {
        final String fieldName = field.getName();
        if (field.getType() != DtField.FieldType.COMPUTED) {
            final Object value = field.getDataAccessor().getValue(dtoCriteria);
            if (value instanceof String && field.getType() != DtField.FieldType.FOREIGN_KEY) {
                // si String et pas une FK : on met en préfix
                criteria = criteria.and(Criterions.startsWith(() -> fieldName, (String) value));
            } else if (value != null) {
                criteria = criteria.and(Criterions.isEqualTo(() -> fieldName, (Serializable) value));
            }
        }
    // si null, alors on ne filtre pas
    }
    return criteria;
}
Also used : Serializable(java.io.Serializable) DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 29 with DtField

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

the class DtObjectUtil method createEntityURI.

/**
 * Creates an URI of entity from an existing fragment.
 * @param fragment fragment
 * @return related entity URI
 */
public static <E extends Entity, F extends Fragment<E>> URI<E> createEntityURI(final F fragment) {
    Assertion.checkNotNull(fragment);
    // -----
    final DtDefinition dtDefinition = findDtDefinition(fragment);
    final DtDefinition entityDtDefinition = dtDefinition.getFragment().get();
    final DtField idField = entityDtDefinition.getIdField().get();
    final Object idValue = idField.getDataAccessor().getValue(fragment);
    return new URI<>(entityDtDefinition, idValue);
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtObject(io.vertigo.dynamo.domain.model.DtObject) URI(io.vertigo.dynamo.domain.model.URI) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 30 with DtField

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

the class UiErrorBuilder method checkFieldNotNull.

/**
 * Vérifie que le champ est renseigner.
 * @param dto Object a tester
 * @param fieldName Champs
 * @param messageText Message à appliquer si erreur
 */
public void checkFieldNotNull(final DtObject dto, final String fieldName, final MessageText messageText) {
    final DtField dtField = getDtField(dto, fieldName);
    final Object value = getValue(dto, dtField);
    if (value == null || value.toString().isEmpty()) {
        addError(dto, dtField, messageText);
    }
}
Also used : DtObject(io.vertigo.dynamo.domain.model.DtObject) 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