Search in sources :

Example 1 with UiObject

use of io.vertigo.vega.webservice.model.UiObject 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 2 with UiObject

use of io.vertigo.vega.webservice.model.UiObject in project vertigo by KleeGroup.

the class UiListDeltaDeserializer method parseUiObjectMap.

private Map<String, UiObject<D>> parseUiObjectMap(final JsonObject jsonObject, final String propertyName, final Type uiObjectType, final JsonDeserializationContext context) {
    final Map<String, UiObject<D>> uiObjectMap = new HashMap<>();
    final JsonObject jsonUiObjectMap = jsonObject.getAsJsonObject(propertyName);
    if (jsonUiObjectMap != null) {
        for (final Entry<String, JsonElement> entry : jsonUiObjectMap.entrySet()) {
            final String entryName = entry.getKey();
            final UiObject<D> inputDto = context.deserialize(entry.getValue(), uiObjectType);
            uiObjectMap.put(entryName, inputDto);
        }
    }
    return uiObjectMap;
}
Also used : UiObject(io.vertigo.vega.webservice.model.UiObject) HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 3 with UiObject

use of io.vertigo.vega.webservice.model.UiObject in project vertigo by KleeGroup.

the class ValidatorWebServiceHandlerPlugin method validateParam.

private static void validateParam(final Object value, final UiMessageStack uiMessageStack, final WebServiceParam webServiceParam, final WebServiceCallContext routeContext) {
    final Map<String, DtObject> contextKeyMap = new HashMap<>();
    if (value instanceof UiObject) {
        final UiObject<DtObject> uiObject = (UiObject<DtObject>) value;
        final List<DtObjectValidator<DtObject>> dtObjectValidators = obtainDtObjectValidators(webServiceParam);
        // Only authorized fields have already been checked (JsonConverterHandler)
        final DtObject updatedDto = uiObject.mergeAndCheckInput(dtObjectValidators, uiMessageStack);
        contextKeyMap.put(uiObject.getInputKey(), updatedDto);
        routeContext.registerUpdatedDtObjects(webServiceParam, updatedDto, contextKeyMap);
    } else if (value instanceof UiListDelta) {
        final UiListDelta<DtObject> uiListDelta = (UiListDelta<DtObject>) value;
        final List<DtObjectValidator<DtObject>> dtObjectValidators = obtainDtObjectValidators(webServiceParam);
        // Only authorized fields have already been checked (JsonConverterHandler)
        final DtList<DtObject> dtListCreates = mergeAndCheckInput(uiListDelta.getObjectType(), uiListDelta.getCreatesMap(), dtObjectValidators, uiMessageStack, contextKeyMap);
        final DtList<DtObject> dtListUpdates = mergeAndCheckInput(uiListDelta.getObjectType(), uiListDelta.getUpdatesMap(), dtObjectValidators, uiMessageStack, contextKeyMap);
        final DtList<DtObject> dtListDeletes = mergeAndCheckInput(uiListDelta.getObjectType(), uiListDelta.getDeletesMap(), dtObjectValidators, uiMessageStack, contextKeyMap);
        final DtListDelta<DtObject> dtListDelta = new DtListDelta<>(dtListCreates, dtListUpdates, dtListDeletes);
        routeContext.registerUpdatedDtObjects(webServiceParam, dtListDelta, contextKeyMap);
    } else if (value instanceof UiListModifiable) {
        final UiListModifiable<DtObject> uiList = (UiListModifiable<DtObject>) value;
        final List<DtObjectValidator<DtObject>> dtObjectValidators = obtainDtObjectValidators(webServiceParam);
        // Only authorized fields have already been checked (JsonConverterHandler)
        final DtList<DtObject> dtList = mergeAndCheckInput(uiList.getObjectType(), uiList, dtObjectValidators, uiMessageStack, contextKeyMap);
        routeContext.registerUpdatedDtObjects(webServiceParam, dtList, contextKeyMap);
    } else if (value instanceof ExtendedObject) {
        final ExtendedObject<?> extendedObject = (ExtendedObject) value;
        validateParam(extendedObject.getInnerObject(), uiMessageStack, webServiceParam, routeContext);
        final Object updatedValue = routeContext.getParamValue(webServiceParam);
        final ExtendedObject<?> updatedExtendedObject = new ExtendedObject(updatedValue);
        updatedExtendedObject.putAll(extendedObject);
        routeContext.setParamValue(webServiceParam, updatedExtendedObject);
    } else if (value instanceof Optional && ((Optional) value).isPresent()) {
        validateParam(((Optional) value).get(), uiMessageStack, webServiceParam, routeContext);
    }
}
Also used : UiListDelta(io.vertigo.vega.engines.webservice.json.UiListDelta) UiObject(io.vertigo.vega.webservice.model.UiObject) Optional(java.util.Optional) HashMap(java.util.HashMap) DtObject(io.vertigo.dynamo.domain.model.DtObject) DtObjectValidator(io.vertigo.vega.webservice.validation.DtObjectValidator) UiListModifiable(io.vertigo.vega.engines.webservice.json.UiListModifiable) DtListDelta(io.vertigo.vega.webservice.model.DtListDelta) ExtendedObject(io.vertigo.vega.webservice.model.ExtendedObject) DtList(io.vertigo.dynamo.domain.model.DtList) ArrayList(java.util.ArrayList) List(java.util.List) ExtendedObject(io.vertigo.vega.webservice.model.ExtendedObject) DtObject(io.vertigo.dynamo.domain.model.DtObject) UiObject(io.vertigo.vega.webservice.model.UiObject) DtList(io.vertigo.dynamo.domain.model.DtList)

Example 4 with UiObject

use of io.vertigo.vega.webservice.model.UiObject in project vertigo by KleeGroup.

the class UiListDeltaDeserializer method deserialize.

/**
 * {@inheritDoc}
 */
@Override
public UiListDelta<D> deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) {
    final Type[] typeParameters = ((ParameterizedType) typeOfT).getActualTypeArguments();
    // Id has only one parameterized type T
    final Class<D> dtoClass = (Class<D>) typeParameters[0];
    final Type uiObjectType = new KnownParameterizedType(UiObject.class, dtoClass);
    final JsonObject jsonObject = json.getAsJsonObject();
    final Map<String, UiObject<D>> collCreates = parseUiObjectMap(jsonObject, "collCreates", uiObjectType, context);
    final Map<String, UiObject<D>> collUpdates = parseUiObjectMap(jsonObject, "collUpdates", uiObjectType, context);
    final Map<String, UiObject<D>> collDeletes = parseUiObjectMap(jsonObject, "collDeletes", uiObjectType, context);
    return new UiListDelta<>(dtoClass, collCreates, collUpdates, collDeletes);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) UiObject(io.vertigo.vega.webservice.model.UiObject) JsonObject(com.google.gson.JsonObject)

Aggregations

UiObject (io.vertigo.vega.webservice.model.UiObject)4 JsonObject (com.google.gson.JsonObject)2 DtObject (io.vertigo.dynamo.domain.model.DtObject)2 UiListDelta (io.vertigo.vega.engines.webservice.json.UiListDelta)2 Type (java.lang.reflect.Type)2 HashMap (java.util.HashMap)2 JsonElement (com.google.gson.JsonElement)1 DtList (io.vertigo.dynamo.domain.model.DtList)1 UiContext (io.vertigo.vega.engines.webservice.json.UiContext)1 UiListModifiable (io.vertigo.vega.engines.webservice.json.UiListModifiable)1 DtListDelta (io.vertigo.vega.webservice.model.DtListDelta)1 ExtendedObject (io.vertigo.vega.webservice.model.ExtendedObject)1 DtObjectValidator (io.vertigo.vega.webservice.validation.DtObjectValidator)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1