use of io.vertigo.vega.engines.webservice.json.UiListDelta 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);
}
}
use of io.vertigo.vega.engines.webservice.json.UiListDelta 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);
}
Aggregations