protected String convertObjectToString(Object value) { return chartSerializer.toJson(value); }
public CubaAmchartsIntegration() { serializer = new ChartSettingsSerializer(); }
protected ChartJsonSerializationContext createChartJsonSerializationContext(AbstractChart chart) { if (itemKeyMapper == null) { throw new IllegalStateException("itemKeyMapper can't be null"); } return new ChartJsonSerializationContext(chartGson, chart, itemKeyMapper); }
protected static void setDefaultProperties(GsonBuilder builder) { // uncomment if you wish to debug generated json // builder.setPrettyPrinting(); builder.registerTypeHierarchyAdapter(JsonEnum.class, new JsonEnumSerializer()); builder.registerTypeHierarchyAdapter(Color.class, new ColorSerializer()); builder.registerTypeHierarchyAdapter(JsFunction.class, new JsFunctionSerializer()); builder.registerTypeHierarchyAdapter(Date.class, new ConfigDateSerializer()); builder.registerTypeHierarchyAdapter(Rule.class, new ResponsiveRuleSerializer()); }
protected void addChangedItems(IncrementalUpdateType type, List<DataItem> items) { if (changedItems == null) { changedItems = new ChartIncrementalChanges(); } switch (type) { case ADD: changedItems.registerAddedItem(items); break; case REMOVE: changedItems.registerRemovedItems(items); break; case UPDATE: changedItems.registerUpdatedItems(items); break; } markAsDirty(); }
@Override public String serializeChanges(AbstractChart chart, ChartIncrementalChanges changes) { JsonObject jsonChangedItemsElement = new JsonObject(); ChartJsonSerializationContext context = createChartJsonSerializationContext(chart); if (changes.getAddedItems() != null) { jsonChangedItemsElement.add("add", itemsSerializer.serialize(changes.getAddedItems(), context)); } if (changes.getRemovedItems() != null) { jsonChangedItemsElement.add("remove", itemsSerializer.serialize(changes.getRemovedItems(), context)); } if (changes.getUpdatedItems() != null) { jsonChangedItemsElement.add("update", itemsSerializer.serialize(changes.getUpdatedItems(), context)); } return chartGson.toJson(jsonChangedItemsElement); }
String jsonString = chartSerializer.serialize(chart); log.trace("Chart full JSON:\n{}", jsonString); } else if (changedItems != null && !changedItems.isEmpty()) { String jsonString = chartSerializer.serializeChanges(chart, changedItems); log.trace("Chart update JSON:\n{}", jsonString); List<DataItem> removedItems = changedItems.getRemovedItems(); if (removedItems != null) { for (DataItem removedItem : removedItems) {
String jsonString = chartSerializer.serialize(chart); log.trace("Chart full JSON:\n{}", jsonString); String jsonString = chartSerializer.serializeChanges(chart, changedItems); log.trace("Chart update JSON:\n{}", jsonString); List<DataItem> removedItems = changes.getRemovedItems(); if (removedItems != null) { for (DataItem removedItem : removedItems) {
public JsonArray serialize(List<DataItem> items, ChartJsonSerializationContext context) { JsonArray serialized = new JsonArray(); Function<DataItem, String> itemKeyMapper = context.getItemKeyMapper(); itemElement.add(ITEM_KEY_PROPERTY_NAME, context.serialize(itemKey)); for (String property : context.getProperties()) { Object propertyValue = item.getValue(property); if (context.getChartModel() instanceof GanttChart) { GanttChart chart = (GanttChart) context.getChartModel(); segment.add("$i", context.serialize(segmentIndex));
/** * Returns default GSON builder for configuration serializer. */ public static GsonBuilder createGsonBuilder() { GsonBuilder builder = new GsonBuilder(); builder.setExclusionStrategies(new ExclusionStrategy() { @Override public boolean shouldSkipField(FieldAttributes f) { Expose expose = f.getAnnotation(Expose.class); return expose != null && !expose.serialize(); } @Override public boolean shouldSkipClass(Class<?> clazz) { return false; } }); setDefaultProperties(builder); return builder; }
@Override public void beforeClientResponse(boolean initial) { super.beforeClientResponse(initial); if (settings != null) { getState().json = serializer.serialize(settings); } }
public CubaAmchartsScene(ChartSerializer chartSerializer) { // enable amcharts integration CubaAmchartsIntegration.get(); dataItemKeyMapper = item -> { if (item instanceof DataItem.HasId) { return dataItemKeys.key(((DataItem.HasId) item).getId()); } return null; }; this.chartSerializer = chartSerializer; this.chartSerializer.setDataItemKeyMapper(dataItemKeyMapper); registerRpc(new CubaAmchartsServerRpcImpl(), CubaAmchartsServerRpc.class); }
public CubaAmStockChartScene(StockChartSerializer chartSerializer) { // enable amcharts integration CubaAmchartsIntegration.get(); dataItemKeyMapper = item -> { if (item instanceof DataItem.HasId) { return dataItemKeys.key(((DataItem.HasId) item).getId()); } return null; }; this.chartSerializer = chartSerializer; this.chartSerializer.setDataItemKeyMapper(dataItemKeyMapper); registerRpc(new CubaAmStockChartServerRpcImpl(), CubaAmStockChartServerRpc.class); }
private static void setDefaultProperties(GsonBuilder builder) { // uncomment if you wish to debug generated json // builder.setPrettyPrinting(); builder.registerTypeHierarchyAdapter(JsonEnum.class, new JsonEnumSerializer()); builder.registerTypeHierarchyAdapter(Color.class, new ColorSerializer()); builder.registerTypeHierarchyAdapter(JsFunction.class, new JsFunctionSerializer()); builder.registerTypeHierarchyAdapter(Date.class, new ConfigDateSerializer()); builder.registerTypeHierarchyAdapter(Rule.class, new ResponsiveRuleSerializer()); }
protected void addChangedItems(IncrementalUpdateType type, DataSet dataSet, List<DataItem> items) { if (changedItems == null) { changedItems = new HashMap<>(); } ChartIncrementalChanges dataSetChanges = changedItems.computeIfAbsent(dataSet, k -> new ChartIncrementalChanges()); switch (type) { case ADD: dataSetChanges.registerAddedItem(items); break; case REMOVE: dataSetChanges.registerRemovedItems(items); break; case UPDATE: dataSetChanges.registerUpdatedItems(items); break; } markAsDirty(); }
@Override public String serializeChanges(StockChartGroup chart, Map<DataSet, ChartIncrementalChanges> changedItems) { JsonObject jsonChangedDataSetElement = new JsonObject(); ChartJsonSerializationContext context = createChartJsonSerializationContext(chart); for (Map.Entry<DataSet, ChartIncrementalChanges> changesEntry : changedItems.entrySet()) { JsonObject jsonChangedItemsElement = new JsonObject(); ChartIncrementalChanges changes = changesEntry.getValue(); if (changes.getAddedItems() != null) { jsonChangedItemsElement.add("add", itemsSerializer.serialize(changes.getAddedItems(), context)); } if (changes.getRemovedItems() != null) { jsonChangedItemsElement.add("remove", itemsSerializer.serialize(changes.getRemovedItems(), context)); } if (changes.getUpdatedItems() != null) { jsonChangedItemsElement.add("update", itemsSerializer.serialize(changes.getUpdatedItems(), context)); } String dataSetId = changesEntry.getKey().getId(); if (dataSetId != null) { jsonChangedDataSetElement.add(dataSetId, jsonChangedItemsElement); } else { logger.warn("DataSet of StockChart does not have id. Incremental updated will not be performed."); } } return chartGson.toJson(jsonChangedDataSetElement); }
protected ChartJsonSerializationContext createChartJsonSerializationContext(StockChartGroup chart) { if (itemKeyMapper == null) { throw new IllegalStateException("itemKeyMapper can't be null"); } return new ChartJsonSerializationContext(chartGson, chart, itemKeyMapper); }
protected static void setDefaultProperties(GsonBuilder builder) { // uncomment if you wish to debug generated json // builder.setPrettyPrinting(); builder.registerTypeHierarchyAdapter(JsonEnum.class, new JsonEnumSerializer()); builder.registerTypeHierarchyAdapter(Color.class, new ColorSerializer()); builder.registerTypeHierarchyAdapter(JsFunction.class, new JsFunctionSerializer()); builder.registerTypeHierarchyAdapter(Date.class, new ConfigDateSerializer()); builder.registerTypeHierarchyAdapter(Rule.class, new ResponsiveRuleSerializer()); }