Search in sources :

Example 26 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class RamLuceneIndex method getStringValue.

private static String getStringValue(final DtObject dto, final DtField field) {
    final String stringValue;
    final Object value = field.getDataAccessor().getValue(dto);
    if (value != null) {
        if (field.getType() == DtField.FieldType.FOREIGN_KEY && getStoreManager().getMasterDataConfig().containsMasterData(field.getFkDtDefinition())) {
            // TODO voir pour mise en cache de cette navigation
            final DtListURIForMasterData mdlUri = getStoreManager().getMasterDataConfig().getDtListURIForMasterData(field.getFkDtDefinition());
            final DtField displayField = mdlUri.getDtDefinition().getDisplayField().get();
            final URI<Entity> uri = new URI<>(field.getFkDtDefinition(), value);
            final DtObject fkDto = getStoreManager().getDataStore().readOne(uri);
            final Object displayValue = displayField.getDataAccessor().getValue(fkDto);
            stringValue = displayField.getDomain().valueToString(displayValue);
        } else {
            stringValue = String.valueOf(field.getDataAccessor().getValue(dto));
        }
        return stringValue.trim();
    }
    return null;
}
Also used : Entity(io.vertigo.dynamo.domain.model.Entity) DtObject(io.vertigo.dynamo.domain.model.DtObject) DtObject(io.vertigo.dynamo.domain.model.DtObject) DtListURIForMasterData(io.vertigo.dynamo.domain.model.DtListURIForMasterData) URI(io.vertigo.dynamo.domain.model.URI) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 27 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class CollectionsManagerImpl method filter.

// =========================================================================
// =======================Filtrage==========================================
// =========================================================================
private <D extends DtObject> Predicate<D> filter(final FacetedQuery facetedQuery) {
    final SelectedFacetValues selectedFacetValues = facetedQuery.getSelectedFacetValues();
    Predicate<D> predicate = list -> true;
    for (final FacetDefinition facetDefinition : facetedQuery.getDefinition().getFacetDefinitions()) {
        if (!selectedFacetValues.getFacetValues(facetDefinition).isEmpty()) {
            Predicate<D> predicateValue = list -> false;
            for (final FacetValue facetValue : selectedFacetValues.getFacetValues(facetDefinition)) {
                predicateValue = predicateValue.or(this.filter(facetValue.getListFilter()));
            }
            predicate = predicate.and(predicateValue);
        }
    }
    return predicate;
}
Also used : ListFilter(io.vertigo.dynamo.collections.ListFilter) DtField(io.vertigo.dynamo.domain.metamodel.DtField) Facet(io.vertigo.dynamo.collections.model.Facet) Inject(javax.inject.Inject) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) Home(io.vertigo.app.Home) StoreManager(io.vertigo.dynamo.store.StoreManager) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) DtListPatternFilter(io.vertigo.dynamo.impl.collections.functions.filter.DtListPatternFilter) Predicate(java.util.function.Predicate) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) FacetFactory(io.vertigo.dynamo.impl.collections.facet.model.FacetFactory) DtList(io.vertigo.dynamo.domain.model.DtList) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) List(java.util.List) FacetedQuery(io.vertigo.dynamo.collections.model.FacetedQuery) DtObject(io.vertigo.dynamo.domain.model.DtObject) Optional(java.util.Optional) IndexDtListFunctionBuilder(io.vertigo.dynamo.collections.IndexDtListFunctionBuilder) VCollectors(io.vertigo.dynamo.domain.util.VCollectors) Comparator(java.util.Comparator) Collections(java.util.Collections) CollectionsManager(io.vertigo.dynamo.collections.CollectionsManager) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) FacetValue(io.vertigo.dynamo.collections.model.FacetValue) SelectedFacetValues(io.vertigo.dynamo.collections.model.SelectedFacetValues) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition)

Example 28 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class DtObjectUtil method createURI.

/**
 * Récupération d'une URI de DTO.
 * On récupère l'URI d'un DTO référencé par une association.
 * Il est nécessaire que l'association soit simple.
 * Si l'association est multiple on ne récupère pas une URI mais une DtListURI, c'est à dire le pointeur vers une liste.
 *
 *  On recherche une URI correspondant à une association.
 *  Exemple : Une Commande possède un bénéficiaire.
 *  Dans cetexemple on recherche l'URI du bénéficiaire à partir de l'objet commande.
 * @param <E>
 *
 * @param associationDefinitionName Nom de la définition d'une association
 * @param dto  Object
 * @param dtoTargetClass Class of entity of this association
 * @return dto du DTO relié via l'association au dto passé en paramètre (Nullable)
 */
public static <E extends Entity> URI<E> createURI(final DtObject dto, final String associationDefinitionName, final Class<E> dtoTargetClass) {
    Assertion.checkNotNull(associationDefinitionName);
    Assertion.checkNotNull(dto);
    Assertion.checkNotNull(dtoTargetClass);
    // -----
    final AssociationSimpleDefinition associationSimpleDefinition = Home.getApp().getDefinitionSpace().resolve(associationDefinitionName, AssociationSimpleDefinition.class);
    // 1. On recherche le nom du champ portant l'objet référencé (Exemple : personne)
    final DtDefinition dtDefinition = associationSimpleDefinition.getPrimaryAssociationNode().getDtDefinition();
    // 2. On calcule le nom de la fk.
    final DtField fkField = associationSimpleDefinition.getFKField();
    // 3. On calcule l'URI de la clé étrangère
    final Object id = fkField.getDataAccessor().getValue(dto);
    if (id == null) {
        return null;
    }
    return new URI(dtDefinition, id);
}
Also used : DtDefinition(io.vertigo.dynamo.domain.metamodel.DtDefinition) DtObject(io.vertigo.dynamo.domain.model.DtObject) AssociationSimpleDefinition(io.vertigo.dynamo.domain.metamodel.association.AssociationSimpleDefinition) URI(io.vertigo.dynamo.domain.model.URI) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 29 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class FacetedQueryResultJsonSerializerV4 method serializeHighLight.

private static JsonArray serializeHighLight(final DtList<?> dtList, final FacetedQueryResult<DtObject, ?> facetedQueryResult) {
    final JsonArray jsonHighlightList = new JsonArray();
    final Map<DtField, String> ccFieldNames = new HashMap<>();
    for (final DtObject document : dtList) {
        final Map<DtField, String> highlights = (facetedQueryResult).getHighlights(document);
        final JsonObject jsonHighlight = new JsonObject();
        for (final Map.Entry<DtField, String> entry : highlights.entrySet()) {
            final String ccFieldName = obtainCcFieldName(entry.getKey(), ccFieldNames);
            jsonHighlight.addProperty(ccFieldName, entry.getValue());
        }
        jsonHighlightList.add(jsonHighlight);
    }
    return jsonHighlightList;
}
Also used : JsonArray(com.google.gson.JsonArray) HashMap(java.util.HashMap) DtObject(io.vertigo.dynamo.domain.model.DtObject) JsonObject(com.google.gson.JsonObject) HashMap(java.util.HashMap) Map(java.util.Map) DtField(io.vertigo.dynamo.domain.metamodel.DtField)

Example 30 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject in project vertigo by KleeGroup.

the class GoogleJsonEngine method uiContextFromJson.

/**
 * {@inheritDoc}
 */
@Override
public UiContext uiContextFromJson(final String json, final Map<String, Type> paramTypes) {
    final UiContext result = new UiContext();
    try {
        final JsonElement jsonElement = new JsonParser().parse(json);
        final JsonObject jsonObject = jsonElement.getAsJsonObject();
        for (final Entry<String, Type> entry : paramTypes.entrySet()) {
            final String key = entry.getKey();
            final Type paramType = entry.getValue();
            final JsonElement jsonSubElement = jsonObject.get(key);
            final Serializable value;
            if (WebServiceTypeUtil.isAssignableFrom(DtObject.class, paramType)) {
                final Type typeOfDest = new KnownParameterizedType(UiObject.class, paramType);
                value = gson.fromJson(jsonSubElement, typeOfDest);
            } else if (WebServiceTypeUtil.isAssignableFrom(DtListDelta.class, paramType)) {
                // we known that DtListDelta has one parameterized type
                final Class<DtObject> dtoClass = (Class<DtObject>) ((ParameterizedType) paramType).getActualTypeArguments()[0];
                final Type typeOfDest = new KnownParameterizedType(UiListDelta.class, dtoClass);
                value = gson.fromJson(jsonSubElement, typeOfDest);
            } else if (WebServiceTypeUtil.isAssignableFrom(DtList.class, paramType)) {
                // we known that DtList has one parameterized type
                final Class<DtObject> dtoClass = (Class<DtObject>) ((ParameterizedType) paramType).getActualTypeArguments()[0];
                final Type typeOfDest = new KnownParameterizedType(UiListModifiable.class, dtoClass);
                value = gson.fromJson(jsonSubElement, typeOfDest);
            } else {
                value = gson.fromJson(jsonSubElement, paramType);
            }
            result.put(key, value);
        }
        return result;
    } catch (final IllegalStateException e) {
        throw new JsonSyntaxException("JsonObject expected", e);
    }
}
Also used : Serializable(java.io.Serializable) DtObject(io.vertigo.dynamo.domain.model.DtObject) JsonObject(com.google.gson.JsonObject) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ParameterizedType(java.lang.reflect.ParameterizedType) FieldType(io.vertigo.dynamo.domain.metamodel.DtField.FieldType) JsonSyntaxException(com.google.gson.JsonSyntaxException) DtListDelta(io.vertigo.vega.webservice.model.DtListDelta) JsonElement(com.google.gson.JsonElement) JsonParser(com.google.gson.JsonParser)

Aggregations

DtObject (io.vertigo.dynamo.domain.model.DtObject)32 DtField (io.vertigo.dynamo.domain.metamodel.DtField)14 Entity (io.vertigo.dynamo.domain.model.Entity)9 URI (io.vertigo.dynamo.domain.model.URI)8 Type (java.lang.reflect.Type)8 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)5 DtList (io.vertigo.dynamo.domain.model.DtList)5 ParameterizedType (java.lang.reflect.ParameterizedType)5 VFile (io.vertigo.dynamo.file.model.VFile)4 UiContext (io.vertigo.vega.engines.webservice.json.UiContext)4 UiListDelta (io.vertigo.vega.engines.webservice.json.UiListDelta)4 FileInfoURI (io.vertigo.dynamo.domain.model.FileInfoURI)3 Instant (java.time.Instant)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 JsonObject (com.google.gson.JsonObject)2 CollectionsManager (io.vertigo.dynamo.collections.CollectionsManager)2