Search in sources :

Example 6 with UiContext

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

the class AdvancedTestWebServices method testInnerBody.

@Doc("Test ws returning UiContext. Send a body with an object of to field : contactId1, contactId2. Each one should be an json of long. You get partial Contacts with clientId in each one")
@ServerSideSave
@ExcludedFields({ "conId", "email", "birthday", "address", "tels" })
@POST("/uiContext")
public UiContext testInnerBody(@InnerBodyParam("contactId1") final long contactIdFrom, @InnerBodyParam("contactId2") final long contactIdTo) {
    final UiContext uiContext = new UiContext();
    uiContext.put("contactFrom", contactDao.get(contactIdFrom));
    uiContext.put("contactTo", contactDao.get(contactIdTo));
    uiContext.put("testLong", 12);
    uiContext.put("testString", "the String test");
    uiContext.put("testDate", DateUtil.newDate());
    uiContext.put("testEscapedString", "the EscapedString \",} test");
    // code 200
    return uiContext;
}
Also used : UiContext(io.vertigo.vega.engines.webservice.json.UiContext) POST(io.vertigo.vega.webservice.stereotype.POST) Doc(io.vertigo.vega.webservice.stereotype.Doc) ServerSideSave(io.vertigo.vega.webservice.stereotype.ServerSideSave) ExcludedFields(io.vertigo.vega.webservice.stereotype.ExcludedFields)

Example 7 with UiContext

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

the class InnerBodyJsonReader method extractData.

/**
 * {@inheritDoc}
 */
@Override
public UiContext extractData(final Request request, final WebServiceParam webServiceParam, final WebServiceCallContext routeContext) {
    Assertion.checkArgument(getSupportedInput()[0].equals(webServiceParam.getParamType()), "This JsonReader can't read the asked request ParamType {0}. Only {1} is supported", webServiceParam.getParamType(), Arrays.toString(getSupportedInput()));
    // -----
    UiContext uiContext = routeContext.getRequest().attribute("InnerBodyValues");
    if (uiContext == null) {
        uiContext = readInnerBodyValue(request.body(), routeContext.getWebServiceDefinition().getWebServiceParams());
        routeContext.getRequest().attribute("InnerBodyValues", uiContext);
    }
    return uiContext;
}
Also used : UiContext(io.vertigo.vega.engines.webservice.json.UiContext)

Example 8 with UiContext

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

the class SimplerTestWebServices method testDate.

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

Example 9 with UiContext

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

the class SimplerTestWebServices method putZonedDateTime.

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

Example 10 with UiContext

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

the class DtListDeltaJsonConverter method populateWebServiceCallContext.

/**
 * {@inheritDoc}
 */
@Override
public void populateWebServiceCallContext(final Object input, final WebServiceParam webServiceParam, final WebServiceCallContext routeContext) {
    final Class<?> paramClass = webServiceParam.getType();
    Assertion.checkArgument(canHandle(paramClass), "This JsonConverter can't read the asked type {0}. Only {1} is supported", paramClass.getSimpleName(), UiListDelta.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 UiListDelta<DtObject> uiListDelta;
    if (input instanceof String) {
        uiListDelta = jsonReaderEngine.uiListDeltaFromJson((String) input, paramGenericType);
        objectPath = "";
    } else if (input instanceof UiContext) {
        uiListDelta = (UiListDelta<DtObject>) ((UiContext) input).get(webServiceParam.getName());
        Assertion.checkNotNull(uiListDelta, "InnerParam not found : {0}", webServiceParam);
        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()));
    }
    UiObjectUtil.postReadUiListDelta(uiListDelta, objectPath, webServiceParam);
    routeContext.setParamValue(webServiceParam, uiListDelta);
}
Also used : UiListDelta(io.vertigo.vega.engines.webservice.json.UiListDelta) Type(java.lang.reflect.Type) 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