Search in sources :

Example 1 with UiContext

use of io.vertigo.vega.engines.webservice.json.UiContext in project vertigo by KleeGroup.

the class ServerSideStateWebServiceHandlerPlugin method writeServerSideObject.

private Serializable writeServerSideObject(final Object returnValue) {
    Assertion.checkNotNull(returnValue, "Return null value can't be saved ServerSide");
    Assertion.checkArgument(DtObject.class.isInstance(returnValue) || DtList.class.isInstance(returnValue) || UiContext.class.isInstance(returnValue) || ExtendedObject.class.isInstance(returnValue), "Return type can't be saved ServerSide : {0}", returnValue.getClass().getSimpleName());
    // Object sauvé coté serveur
    final Object savedObject;
    // Object retourné au client (globalement l'objet sauvé + le tokenId)
    final Map<String, Serializable> overridedReturnValue;
    if (returnValue instanceof UiContext) {
        overridedReturnValue = new UiContext();
        for (final Entry<String, Serializable> entry : ((UiContext) returnValue).entrySet()) {
            final Serializable overridedEntry;
            // On enregistre et on ajoute le token sur les objets qui le supportent mais on accepte les autres.
            if (DtObject.class.isInstance(entry.getValue()) || DtList.class.isInstance(entry.getValue()) || ExtendedObject.class.isInstance(entry.getValue())) {
                overridedEntry = writeServerSideObject(entry.getValue());
            } else {
                overridedEntry = entry.getValue();
            }
            overridedReturnValue.put(entry.getKey(), overridedEntry);
        }
        savedObject = overridedReturnValue;
    } else if (returnValue instanceof ExtendedObject) {
        overridedReturnValue = (ExtendedObject<Object>) returnValue;
        savedObject = ((ExtendedObject<Object>) returnValue).getInnerObject();
        Assertion.checkArgument(DtObject.class.isInstance(savedObject) || DtList.class.isInstance(savedObject) || UiContext.class.isInstance(savedObject), "Return type can't be saved ServerSide : {0}", savedObject.getClass().getSimpleName());
    } else {
        overridedReturnValue = new ExtendedObject<>(returnValue);
        savedObject = returnValue;
    }
    final String tokenId = tokenManager.put(Serializable.class.cast(savedObject));
    overridedReturnValue.put(JsonEngine.SERVER_SIDE_TOKEN_FIELDNAME, tokenId);
    return Serializable.class.cast(overridedReturnValue);
}
Also used : Serializable(java.io.Serializable) ExtendedObject(io.vertigo.vega.webservice.model.ExtendedObject) ExtendedObject(io.vertigo.vega.webservice.model.ExtendedObject) DtObject(io.vertigo.dynamo.domain.model.DtObject) UiObject(io.vertigo.vega.webservice.model.UiObject) UiContext(io.vertigo.vega.engines.webservice.json.UiContext)

Example 2 with UiContext

use of io.vertigo.vega.engines.webservice.json.UiContext in project vertigo by KleeGroup.

the class SearchTestWebServices method testSelectedFacetValues.

@POST("/selectedFacetValues")
public UiContext testSelectedFacetValues(final SelectedFacetValues selectedFacetValues) {
    final FacetedQueryDefinition facetedQueryDefinition = Home.getApp().getDefinitionSpace().resolve("QRY_CONTACT_FACET", FacetedQueryDefinition.class);
    final UiContext uiContext = new UiContext();
    for (final FacetDefinition facetDefinition : facetedQueryDefinition.getFacetDefinitions()) {
        if (!selectedFacetValues.getFacetValues(facetDefinition).isEmpty()) {
            uiContext.put(facetDefinition.getName(), selectedFacetValues.getFacetValues(facetDefinition).stream().map(FacetValue::getCode).collect(Collectors.joining(",")));
        }
    }
    return uiContext;
}
Also used : FacetValue(io.vertigo.dynamo.collections.model.FacetValue) FacetDefinition(io.vertigo.dynamo.collections.metamodel.FacetDefinition) FacetedQueryDefinition(io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition) UiContext(io.vertigo.vega.engines.webservice.json.UiContext) POST(io.vertigo.vega.webservice.stereotype.POST)

Example 3 with UiContext

use of io.vertigo.vega.engines.webservice.json.UiContext in project vertigo by KleeGroup.

the class SimplerTestWebServices method putLocalDate.

@PUT("/localDate")
public UiContext putLocalDate(@QueryParam("date") final LocalDate localDate) {
    final UiContext result = new UiContext();
    result.put("input", localDate);
    result.put("inputAsString", localDate.toString());
    return result;
}
Also used : UiContext(io.vertigo.vega.engines.webservice.json.UiContext) PUT(io.vertigo.vega.webservice.stereotype.PUT)

Example 4 with UiContext

use of io.vertigo.vega.engines.webservice.json.UiContext in project vertigo by KleeGroup.

the class SimplerTestWebServices method putInstant.

@PUT("/instant")
public UiContext putInstant(@QueryParam("date") final Instant instant) {
    final UiContext result = new UiContext();
    result.put("input", instant);
    result.put("inputAsString", instant.toString());
    return result;
}
Also used : UiContext(io.vertigo.vega.engines.webservice.json.UiContext) PUT(io.vertigo.vega.webservice.stereotype.PUT)

Example 5 with UiContext

use of io.vertigo.vega.engines.webservice.json.UiContext 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)

Aggregations

UiContext (io.vertigo.vega.engines.webservice.json.UiContext)11 DtObject (io.vertigo.dynamo.domain.model.DtObject)4 UiListDelta (io.vertigo.vega.engines.webservice.json.UiListDelta)3 PUT (io.vertigo.vega.webservice.stereotype.PUT)3 Type (java.lang.reflect.Type)3 UiObject (io.vertigo.vega.webservice.model.UiObject)2 POST (io.vertigo.vega.webservice.stereotype.POST)2 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)1 FacetedQueryDefinition (io.vertigo.dynamo.collections.metamodel.FacetedQueryDefinition)1 FacetValue (io.vertigo.dynamo.collections.model.FacetValue)1 DtList (io.vertigo.dynamo.domain.model.DtList)1 UiListModifiable (io.vertigo.vega.engines.webservice.json.UiListModifiable)1 ExtendedObject (io.vertigo.vega.webservice.model.ExtendedObject)1 Doc (io.vertigo.vega.webservice.stereotype.Doc)1 ExcludedFields (io.vertigo.vega.webservice.stereotype.ExcludedFields)1 GET (io.vertigo.vega.webservice.stereotype.GET)1 ServerSideSave (io.vertigo.vega.webservice.stereotype.ServerSideSave)1 Serializable (java.io.Serializable)1