Search in sources :

Example 1 with ExtendedObject

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

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

the class AdvancedTestWebServices method testGetExtended.

@GET("/contactExtended/{conId}")
public ExtendedObject<Contact> testGetExtended(@PathParam("conId") final long conId) {
    final Contact contact = contactDao.get(conId);
    final ExtendedObject<Contact> result = new ExtendedObject<>(contact);
    result.put("vanillaUnsupportedMultipleIds", new int[] { 1, 2, 3 });
    // 200
    return result;
}
Also used : ExtendedObject(io.vertigo.vega.webservice.model.ExtendedObject) Contact(io.vertigo.vega.webservice.data.domain.Contact) GET(io.vertigo.vega.webservice.stereotype.GET)

Example 3 with ExtendedObject

use of io.vertigo.vega.webservice.model.ExtendedObject 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)

Aggregations

ExtendedObject (io.vertigo.vega.webservice.model.ExtendedObject)3 DtObject (io.vertigo.dynamo.domain.model.DtObject)2 UiObject (io.vertigo.vega.webservice.model.UiObject)2 DtList (io.vertigo.dynamo.domain.model.DtList)1 UiContext (io.vertigo.vega.engines.webservice.json.UiContext)1 UiListDelta (io.vertigo.vega.engines.webservice.json.UiListDelta)1 UiListModifiable (io.vertigo.vega.engines.webservice.json.UiListModifiable)1 Contact (io.vertigo.vega.webservice.data.domain.Contact)1 DtListDelta (io.vertigo.vega.webservice.model.DtListDelta)1 GET (io.vertigo.vega.webservice.stereotype.GET)1 DtObjectValidator (io.vertigo.vega.webservice.validation.DtObjectValidator)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1