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); }
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; }
@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); }
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())); } }
public String getUID() { return renderContext.getUID(); }
public Form getForm() { return renderContext.getForm(); }
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 Form getFormById( String ctxUID, long formId ) { FormRenderContext renderContext = formRenderContextManager.getRootContext( ctxUID ); if ( renderContext != null ) { try { if ( renderContext.getForm().getId().equals( new Long( formId ) ) ) { return renderContext.getForm(); } Map forms = formManagerService.getAllFormsByDeployment( renderContext.getDeploymentId() ); if ( forms == null ) forms = renderContext.getContextForms(); String header = formSerializationManager.generateHeaderFormFormId( formId ); for ( Iterator it = forms.keySet().iterator(); it.hasNext(); ) { String key = ( String ) it.next(); Object form = forms.get( key ); if ( form instanceof Form ) { if ( ( ( Form ) form ).getId().equals( formId ) ) { return ( Form ) form; } } else if ( form instanceof String && form.toString().trim().startsWith( header ) ) { Form result = formSerializationManager.loadFormFromXML( ( String ) form ); renderContext.getContextForms().put( key, result ); return result; } } } catch ( Exception e ) { log.warn( "Error getting form {} from context {}: {}", formId, ctxUID, e ); } } return null; }
if (renderContext != null) { try { if (renderContext.getForm().getId().equals(new Long(formId))) { return renderContext.getForm(); Map forms = renderContext.getContextForms(); renderContext.getContextForms().put(key, result); return result;
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)); }
@Override public void completeTaskFromContext(String ctxUID, String serverTemplateId, String containerId, Long taskId) { Map<String, Object> params = formRenderContextManager.getFormRenderContext(ctxUID).getOutputData(); formRenderContextManager.removeContext(ctxUID); taskService.completeTask(serverTemplateId, containerId, taskId, params); }
@Override public Form getFormByPath( String ctxUID, String formPath ) { FormRenderContext renderContext = formRenderContextManager.getRootContext( ctxUID ); if ( renderContext != null ) { try { Object form = formManagerService.getFormByKey( renderContext.getDeploymentId(), formPath ); if (form == null) form = renderContext.getContextForms().get( formPath ); if ( form != null ) { if ( form instanceof Form ) { return (Form) form; } else if ( form instanceof String ) { Form result = formSerializationManager.loadFormFromXML( (String) form ); renderContext.getContextForms().put( formPath, result ); return result; } } } catch ( Exception e ) { log.warn( "Error getting form {} from context {}: {}", formPath, ctxUID, e ); } } return null; }
public boolean isSubmited() { return ctx.isSubmit(); } }
@Override public Form getFormByPath(String ctxUID, String formPath) { FormRenderContext renderContext = formRenderContextManager.getRootContext(ctxUID); if (renderContext != null) { try { Object form = renderContext.getContextForms().get(formPath); if (form != null) { if (form instanceof Form) { return (Form) form; } else if (form instanceof String) { Form result = formSerializationManager.loadFormFromXML((String) form); renderContext.getContextForms().put(formPath, result); return result; } } } catch (Exception e) { log.warn("Error getting form {} from context {}: {}", formPath, ctxUID, e); } } return null; }
protected void initContext() { context = new FormRenderContext(CTX_UID, form, inputs, outputs); when(formRenderContextManager.getFormRenderContext(anyString())).thenReturn(context); when(formRenderContextManager.getRootContext(anyString())).thenReturn(context); } }
}); when(processor.getFilteredMapRepresentationToPersist(context.getForm(), context.getUID())).thenReturn(modifiedValues); Object value = context.getOutputData().get(field.getFieldName()); assertNotNull(value); assertEquals(modifiedValues.get(field.getFieldName()),