public KieWorkbenchFormRenderingSettings generateRenderingContext(T settings) { if (!StringUtils.isEmpty(settings.getFormContent())) { try { MapModelRenderingContext renderingContext = new MapModelRenderingContext(); initializeContextForms(settings, renderingContext); if (!isValid(renderingContext.getRootForm())) { return null; } Map<String, Object> rawData = generateRawFormData(settings, renderingContext); BackendFormRenderingContext context = contextManager.registerContext( renderingContext, rawData, settings.getMarshallerContext().getClassloader()); Map<String, Object> formData = generateFormData(rawData, context); renderingContext.setModel(formData); prepareContext(settings, renderingContext); return new KieWorkbenchFormRenderingSettings(context.getTimestamp(), renderingContext); } catch (Exception ex) { getLogger().debug("Unable to generate render form: ", ex); } } return null; }
protected void initializeContextForms(T settings, MapModelRenderingContext renderingContext) { JsonParser parser = new JsonParser(); Gson gson = new Gson(); JsonElement element = parser.parse(settings.getFormContent()); JsonArray forms = element.getAsJsonArray(); forms.forEach( jsonForm -> { String content = gson.toJson(jsonForm); if (!StringUtils.isEmpty(content)) { FormDefinition formDefinition = formSerializer.deserialize(content); if (formDefinition != null) { if (formDefinition.getName().startsWith(getFormName(settings) + "-taskform")) { renderingContext.setRootForm(formDefinition); } else { renderingContext.getAvailableForms().put(formDefinition.getId(), formDefinition); } } } }); }