@Override public Form getForm( String ctxUID ) { FormRenderContext renderContext = formRenderContextManager.getRootContext( ctxUID ); if ( renderContext != null ) return renderContext.getForm(); return null; }
@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); }
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; }
protected void initContext() { context = new FormRenderContext(CTX_UID, form, inputs, outputs); when(formRenderContextManager.getFormRenderContext(anyString())).thenReturn(context); when(formRenderContextManager.getRootContext(anyString())).thenReturn(context); } }
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())); } }
@Override public void doStart(CommandRequest commandRequest) { String ctxUID = commandRequest.getRequestObject().getParameter("ctxUID"); if (StringUtils.isEmpty(ctxUID)) return; ctx = formRenderContextManager.getFormRenderContext(ctxUID); }
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(); }
@Override public void clear(String ctxUID) { clear(formRenderContextManager.getFormRenderContext(ctxUID)); }
@Override public Form getForm(String ctxUID) { FormRenderContext renderContext = formRenderContextManager.getRootContext(ctxUID); if (renderContext != null) { return renderContext.getForm(); } return null; }
@Override public Long startProcessFromRenderContext(String ctxUID, String serverTemplateId, String domainId, String processId, String correlationKey, Long parentProcessInstanceId) { Map<String, Object> params = formRenderContextManager.getFormRenderContext(ctxUID).getOutputData(); formRenderContextManager.removeContext(ctxUID); return processService.startProcess(serverTemplateId, domainId, processId, correlationKey, params); }
public void persist(String ctxUid) throws Exception { ctxUid = StringUtils.defaultIfEmpty(ctxUid, FormProcessor.DEFAULT_NAMESPACE); persist(formRenderContextManager.getFormRenderContext(ctxUid)); }
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 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; }
@Override public Long saveTaskStateFromRenderContext(String ctxUID, String serverTemplateId, String containerId, Long taskId, boolean clearStatus) { Map<String, Object> params = formRenderContextManager.getFormRenderContext(ctxUID).getOutputData(); if (clearStatus) { formRenderContextManager.removeContext(ctxUID); } taskService.saveTaskContent(serverTemplateId, containerId, taskId, params); return -1l; }
public FormStatusData read(String ctxUid) { FormStatusDataImpl data = null; try { FormRenderContext context = formRenderContextManager.getFormRenderContext(ctxUid); if (context == null ) return null; FormStatus formStatus = getContextFormStatus(context); boolean isNew = formStatus == null; if (isNew) { formStatus = createContextFormStatus(context); } data = new FormStatusDataImpl(formStatus, isNew); } catch (Exception e) { log.error("Error: ", e); } return data; }
@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; }
@Override public Form getFormById(String ctxUID, long formId) { FormRenderContext renderContext = formRenderContextManager.getRootContext(ctxUID); if (renderContext != null) { try {
FormRenderContext context = formRenderContextManager.newContext(form, settings.getServerTemplateId(), inputs,
@Override public Object persistFormHolder(Form form, String namespace, Map<String, Object> mapToPersist, DataHolder holder, Object loadedObject) throws Exception { if (holder == null) return null; if (loadedObject == null) { FormRenderContext context = formRenderContextManager.getRootContext(namespace); loadedObject = holder.createInstance(context); } for (Iterator it = mapToPersist.keySet().iterator(); it.hasNext();) { String fieldName = (String) it.next(); Field field = form.getField(fieldName); if (field != null && holder.isAssignableForField(field)) { String bindingString = field.getOutputBinding(); if (StringUtils.isEmpty(bindingString)) continue; bindingString = bindingExpressionUtil.extractBindingExpression(bindingString); String holderFieldId = bindingString.substring(holder.getOuputId().length() + 1); Object value = persistField(field, mapToPersist, holder, namespace); holder.writeValue(loadedObject, holderFieldId, value); } } return loadedObject; }
@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; }