public String getUID() { return renderContext.getUID(); }
public String getCtxUID() { return ctx.getUID(); }
public void removeContextEvent(@Observes ContextRemovedEvent event) { if (ctx != null && ctx.getUID().equals(event.getCtxUID())) ctx = null; }
protected void doRemovecontext(String ctxUID) { FormRenderContext context = formRenderContextMap.get(ctxUID); if (context == null) { return; } context.clear(); contextToRemove.remove(ctxUID); formProcessor.clear(context); formRenderContextMap.remove(context.getUID()); contextRemovedEventEvent.fire(new ContextRemovedEvent(ctxUID)); }
protected String renderProcessForm(ProcessDefinition process, InputStream template, Map<String, Object> renderContext) { String result = null; try { Form form = formSerializationManager.loadFormFromXML(template); Map ctx = new HashMap(); ctx.put("process", process); // Adding forms to context while forms are'nt available on marshaller classloader FormRenderContext context = formRenderContextManager.newContext(form, process.getDeploymentId(), ctx, new HashMap<String, Object>()); formRenderContentMarshaller.addContentMarshaller(context.getUID(), (ContentMarshallerContext) renderContext.get("marshallerContext")); result = context.getUID(); } catch (Exception e) { log.warn("Error rendering form: ", e); } return result; }
@Override public void afterRenderBean() { if (ctx != null) { ctx.setInUse(false); contextRenderedEventEvent.fire(new ContextRenderedEvent(ctx.getUID())); } }
public FormRenderContextTO(FormRenderContext context) { this.ctxUID = context.getUID(); this.submit = context.isSubmit(); this.errors = context.getErrors(); }
@Override public void clear(FormRenderContext context) { clear(context.getForm(), context.getUID()); }
protected FormStatus getContextFormStatus(FormRenderContext context) { return formStatusManager.getFormStatus(context.getForm(), context.getUID()); }
protected FormStatus createContextFormStatus(FormRenderContext context) throws Exception { Map<String, Object> loadedObjects = new HashMap<String, Object>(); Map values = readValuesToLoad(context.getForm(), context.getInputData(), context.getOutputData(), loadedObjects, context.getUID()); return getFormStatus(context.getForm(), context.getUID(), values, loadedObjects); }
protected String renderTaskForm(Task task, InputStream template, Map<String, Object> renderContext) { String result = null; try { Form form = formSerializationManager.loadFormFromXML(template); Map inputs = new HashMap(); Map outputs; if (task.getTaskData().getOutputContentId() == -1) outputs = new HashMap(); else outputs = (Map) renderContext.get("outputs"); Map m = (Map) renderContext.get("inputs"); if (m != null) inputs.putAll(m); inputs.put("task", task); // Adding forms to context while forms are'nt available on marshaller classloader FormRenderContext context = formRenderContextManager.newContext(form, task.getTaskData().getDeploymentId(), inputs, outputs); formRenderContentMarshaller.addContentMarshaller(context.getUID(), (ContentMarshallerContext) renderContext.get("marshallerContext")); String status = task.getTaskData().getStatus().name(); boolean readonly = !"InProgress".equals(status); context.setReadonly(readonly); result = context.getUID(); } catch (Exception e) { log.warn("Error rendering form: ", e); } return result; }
@Override public FormModelerFormRenderingSettings render(ProcessRenderingSettings settings) { if (!StringUtils.isEmpty(settings.getFormContent())) { try { Form form = formSerializationManager.loadFormFromXML(settings.getFormContent()); Map ctx = new HashMap(); ctx.put("process", settings.getProcess()); // Adding forms to context while forms are'nt available on marshaller classloader FormRenderContext context = formRenderContextManager.newContext(form, settings.getServerTemplateId(), ctx, new HashMap<>()); formRenderContentMarshaller.addContentMarshaller(context.getUID(), settings.getMarshallerContext()); return new FormModelerFormRenderingSettings(context.getUID()); } catch (Exception e) { log.warn("Error rendering form: ", e); } } return null; }
public CommandResponse actionDoResize(CommandRequest request) { String ctxUID = request.getRequestObject().getParameter("ctxUID"); if (ctx == null || ctx.getUID().equals(ctxUID)) ctx = formRenderContextManager.getFormRenderContext(ctxUID); if (ctx != null) { String width = request.getRequestObject().getParameter("width"); String height = request.getRequestObject().getParameter("height"); if (!StringUtils.isEmpty(width) && !StringUtils.isEmpty(height)) { ResizeFormcontainerEvent event = new ResizeFormcontainerEvent(); event.setContext(new FormRenderContextTO(ctx)); event.setWidth(Integer.decode(width)); event.setHeight(Integer.decode(height)); formRenderContextManager.fireContextFormResize(event); } } return new DoNothingResponse(); }
private FormRenderContext buildContext(String uid, Form form, String serverTemplateId, Map<String, Object> inputData, Map<String, Object> outputData, Map<String, Object> forms) { FormRenderContext ctx = new FormRenderContext(uid, form, inputData, outputData); ctx.setServerTemplateId(serverTemplateId); ctx.setContextForms(forms); formRenderContextMap.put(uid, ctx); formProcessor.read(ctx.getUID()); return ctx; }
public void persist(FormRenderContext context) throws Exception { Form form = context.getForm(); Map mapToPersist = getFilteredMapRepresentationToPersist(form, context.getUID()); Map<String, Object> result = context.getOutputData(); for (Iterator it = mapToPersist.keySet().iterator(); it.hasNext();) { String fieldName = (String) it.next(); Field field = form.getField(fieldName); if (field != null) { DataHolder holder = form.getDataHolderByField(field); String bindingString = field.getOutputBinding(); if (StringUtils.isEmpty(bindingString)) continue; Object value = persistField(field, mapToPersist, holder, context.getUID()); bindingString = bindingExpressionUtil.extractBindingExpression(bindingString); boolean simpleBinding = StringUtils.isEmpty(bindingString) || bindingString.indexOf("/") == -1; if (holder == null || simpleBinding) result.put(bindingString, value); else { String holderFieldId = bindingString.substring((holder.getOuputId() + "/").length()); Object holderOutputValue = result.get(holder.getOuputId()); if (holderOutputValue == null || !holder.isAssignableValue(holderOutputValue)) { holderOutputValue = context.getInputData().get(holder.getInputId()); if (holderOutputValue == null || !holder.isAssignableValue(holderOutputValue)) holderOutputValue = holder.createInstance(context); result.put(holder.getOuputId(), holderOutputValue); } holder.writeValue(holderOutputValue, holderFieldId, value); } } } }
public void actionSubmitForm(CommandRequest request) { String ctxUID = request.getRequestObject().getParameter("ctxUID"); if (ctx == null || ctx.getUID().equals(ctxUID)) ctx = formRenderContextManager.getFormRenderContext(ctxUID); if (ctx == null) return; try { Form form = ctx.getForm(); formProcessor.setValues(form, ctxUID, request.getRequestObject().getParameterMap(), request.getFilesByParamName()); FormStatusData fsd = formProcessor.read(ctxUID); ctx.setErrors(fsd.getWrongFields().size()); String persist = request.getRequestObject().getParameter("persistForm"); if (fsd.isValid()) { ctx.setSubmit(true); if (Boolean.parseBoolean(persist)) formRenderContextManager.persistContext(ctx); } formRenderContextManager.fireContextSubmit(new FormSubmittedEvent(new FormRenderContextTO(ctx))); } catch (Exception e) { log.error("Error submitting form: ", e); formRenderContextManager.fireContextSubmitError(new FormSubmitFailEvent(new FormRenderContextTO(ctx), e.getMessage())); } }
context.getUID())).thenReturn(modifiedValues);
@Test public void testPersistDataWithoutInputs() throws Exception { initContext(); FormStatusData data = processor.read(CTX_UID); assertNotNull(data); assertEquals(1, data.getCurrentValues().size()); Object actualHobbies = data.getCurrentValue(HOBBIES_FIELD); assertNotNull(actualHobbies); assertTrue(actualHobbies instanceof Map[]); assertEquals(0, ((Map[]) actualHobbies).length); when(processor.getFilteredMapRepresentationToPersist(context.getForm(), context.getUID())).thenReturn(generateExpectedValuesMap()); processor.persist(CTX_UID); assertNotNull(context.getOutputData().get(HOBBIES_FIELD)); assertTrue(context.getOutputData().get(HOBBIES_FIELD) instanceof List); List<Hobby> resultHobbies = (List<Hobby>) context.getOutputData().get(HOBBIES_FIELD); assertFalse(resultHobbies.isEmpty()); assertEquals(expectedHobbies.size(), resultHobbies.size()); assertEquals(expectedHobbies, resultHobbies); }
@Test public void testPersistComplexDataWithoutInputs() throws Exception { initContext(); FormStatusData data = processor.read(CTX_UID); assertNotNull(data); Object name = data.getCurrentValue(NAME_FIELD); assertNull(name); Object surname = data.getCurrentValue(SURNAME_FIELD); assertNull(surname); Object birthday = data.getCurrentValue(BIRTHDAY_FIELD); assertNull(birthday); Object address = data.getCurrentValue(ADDRESS_FIELD); assertNotNull(address); assertTrue(address instanceof Map); assertTrue(((Map) address).isEmpty()); Object hobbies = data.getCurrentValue(HOBBIES_FIELD); assertNotNull(hobbies); assertTrue(hobbies instanceof Map[]); assertEquals(0, ((Map[]) hobbies).length); when(processor.getFilteredMapRepresentationToPersist(context.getForm(), context.getUID())).thenReturn(generateExpectedValuesMap()); processor.persist(CTX_UID); assertNotNull(context.getOutputData().get(PERSON_DATAHOLDER)); assertTrue(context.getOutputData().get(PERSON_DATAHOLDER) instanceof Person); Person person = (Person) context.getOutputData().get(PERSON_DATAHOLDER); assertEquals(expectedPerson, person); }