Search in sources :

Example 6 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject 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 7 with DtObject

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

the class DtObjectJsonConverter method populateWebServiceCallContext.

/**
 * {@inheritDoc}
 */
@Override
public void populateWebServiceCallContext(final Object input, final WebServiceParam webServiceParam, final WebServiceCallContext routeContext) {
    final Class<?> paramClass = webServiceParam.getType();
    Assertion.checkArgument(DtObject.class.isAssignableFrom(paramClass), "This JsonConverter can't read the asked type {0}. Only {1} is supported", paramClass.getSimpleName(), DtObject.class.getSimpleName());
    Assertion.checkArgument(getSupportedInputs()[0].isInstance(input) || getSupportedInputs()[1].isInstance(input), "This JsonConverter doesn't support this input type {0}. Only {1} is supported", input.getClass().getSimpleName(), Arrays.toString(getSupportedInputs()));
    // -----
    final Type paramGenericType = webServiceParam.getGenericType();
    final String objectPath;
    final UiObject<DtObject> uiObject;
    if (input instanceof String) {
        uiObject = jsonReaderEngine.uiObjectFromJson((String) input, paramGenericType);
        objectPath = "";
    } else if (input instanceof UiContext) {
        // cas des innerBodyParam
        uiObject = (UiObject<DtObject>) ((UiContext) input).get(webServiceParam.getName());
        objectPath = webServiceParam.getName();
    } else {
        throw new IllegalArgumentException(String.format("This JsonConverter can't read the asked type %s. Only %s is supported", paramClass.getSimpleName(), UiListDelta.class.getSimpleName()));
    }
    // -----
    if (uiObject != null) {
        // uiObject peut être null ici si optional
        UiObjectUtil.postReadUiObject(uiObject, objectPath, webServiceParam);
    }
    routeContext.setParamValue(webServiceParam, uiObject);
}
Also used : UiListDelta(io.vertigo.vega.engines.webservice.json.UiListDelta) Type(java.lang.reflect.Type) UiObject(io.vertigo.vega.webservice.model.UiObject) DtObject(io.vertigo.dynamo.domain.model.DtObject) UiContext(io.vertigo.vega.engines.webservice.json.UiContext)

Example 8 with DtObject

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

the class SwaggerApiBuilder method createSchemaObject.

private Map<String, Object> createSchemaObject(final Type type) {
    if (type == null) {
        // Si le type est null, on a pas réussi à récupérer la class : souvant dans le cas des generics
        return unknownObjectRef;
    }
    // -----
    final Map<String, Object> schema = new LinkedHashMap<>();
    final Class<?> objectClass = WebServiceTypeUtil.castAsClass(type);
    final String[] typeAndFormat = toSwaggerType(objectClass);
    schema.put("type", typeAndFormat[0]);
    if (typeAndFormat[1] != null) {
        schema.put("format", typeAndFormat[1]);
    }
    if (WebServiceTypeUtil.isAssignableFrom(Collection.class, type)) {
        // we known that List has one parameterized type
        final Type itemsType = ((ParameterizedType) type).getActualTypeArguments()[0];
        // Si le itemsType est null, on prend le unknownObject
        // type argument can't be void
        schema.put("items", createSchemaObject(itemsType));
    } else if ("object".equals(typeAndFormat[0])) {
        final String objectName;
        final Class<?> parameterClass;
        if (type instanceof ParameterizedType && (((ParameterizedType) type).getActualTypeArguments().length == 1 || FacetedQueryResult.class.isAssignableFrom(objectClass)) && !(((ParameterizedType) type).getActualTypeArguments()[0] instanceof WildcardType)) {
            // We have checked there is one parameter or we known that FacetedQueryResult has two parameterized type
            final Type itemsType = ((ParameterizedType) type).getActualTypeArguments()[0];
            parameterClass = WebServiceTypeUtil.castAsClass(itemsType);
            objectName = objectClass.getSimpleName() + "&lt;" + parameterClass.getSimpleName() + "&gt;";
        } else {
            objectName = objectClass.getSimpleName();
            parameterClass = null;
        }
        schema.put("$ref", "#/definitions/" + objectName);
        schema.remove("type");
        if (!builderDefinitions.containsKey(objectName)) {
            final Map<String, Object> definition = new LinkedHashMap<>();
            // we put definitions first to avoid infinite resolution loop
            builderDefinitions.put(objectName, definition);
            if (DtObject.class.isAssignableFrom(objectClass)) {
                final Class<? extends DtObject> dtClass = (Class<? extends DtObject>) objectClass;
                appendPropertiesDtObject(definition, dtClass);
            } else {
                appendPropertiesObject(definition, objectClass, parameterClass);
            }
        }
    }
    return schema;
}
Also used : DtObject(io.vertigo.dynamo.domain.model.DtObject) FacetedQueryResult(io.vertigo.dynamo.collections.model.FacetedQueryResult) LinkedHashMap(java.util.LinkedHashMap) ParameterizedType(java.lang.reflect.ParameterizedType) WildcardType(java.lang.reflect.WildcardType) WebServiceParamType(io.vertigo.vega.webservice.metamodel.WebServiceParam.WebServiceParamType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WildcardType(java.lang.reflect.WildcardType) DtObject(io.vertigo.dynamo.domain.model.DtObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 9 with DtObject

use of io.vertigo.dynamo.domain.model.DtObject 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)

Example 10 with DtObject

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

the class GoogleJsonEngine method uiListFromJson.

/**
 * {@inheritDoc}
 */
@Override
public <D extends DtObject> UiListModifiable<D> uiListFromJson(final String json, final Type paramType) {
    // we known that DtList has one parameterized type
    final Class<DtObject> dtoClass = (Class<DtObject>) ((ParameterizedType) paramType).getActualTypeArguments()[0];
    final Type typeOfDest = createParameterizedType(UiListModifiable.class, dtoClass);
    return gson.fromJson(json, typeOfDest);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ParameterizedType(java.lang.reflect.ParameterizedType) FieldType(io.vertigo.dynamo.domain.metamodel.DtField.FieldType) DtObject(io.vertigo.dynamo.domain.model.DtObject)

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