Package org.jbpm.formapi.shared.api

Examples of org.jbpm.formapi.shared.api.FormRepresentation


    @DoNotUseJAXBProvider
    public Response saveForm(String jsonBody, @PathParam("pkgName") String pkgName, @Context HttpServletRequest request) {
        setContext(request.getSession().getServletContext());
        FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
        try {
            FormRepresentation form = decoder.decode(jsonBody);
            String formId = formService.saveForm(pkgName, form);
            return Response.ok("<formId>"+formId+"</formId>", MediaType.APPLICATION_XML).
                status(Status.CREATED).build();
        } catch (FormEncodingException e) {
            return error("Problem decoding form", e);
View Full Code Here


   
   
    private URL createTemplate(String language, FormPreviewDTO dto) throws FormEncodingException, TranslatorException {
        FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
        String json = dto.getRepresentation();
        FormRepresentation form = decoder.decode(json);
        dto.setForm(form);
        Translator translator = getTranslator(language);
        URL url = translator.translateForm(form);
        return url;
    }
View Full Code Here

        if (list != null) {
            for (int index = 0; index < list.getLength(); index++) {
                Node node = list.item(index);
                String json = getText(node);
                try {
                    FormRepresentation form = decoder.decode(json);
                    retval.add(form);
                } catch (FormEncodingException e) {
                    FormRepresentation error = new FormRepresentation();
                    error.setName(i18n.Error(e.getLocalizedMessage()));
                    retval.add(error);
                }
            }
        }
        return retval;
View Full Code Here

       
        this.bus.addHandler(GetFormRepresentationEvent.TYPE, new GetFormRepresentationHandler() {
            @Override
            public void onEvent(GetFormRepresentationEvent event) {
                FBForm formDisplay = layoutView.getFormDisplay();
                FormRepresentation rep = formDisplay.createRepresentation();
                bus.fireEvent(new GetFormRepresentationResponseEvent(rep, event.getSaveType()));
            }
        });
       
        this.bus.addHandler(GetFormDisplayEvent.TYPE, new GetFormDisplayHandler() {
            @Override
            public void onEvent(GetFormDisplayEvent event) {
                event.setFormDisplay(layoutView.getFormDisplay());
            }
        });
       
        this.bus.addHandler(FormDataPopulatedEvent.TYPE, new FormDataPopulatedHandler() {
            @Override
            public void onEvent(FormDataPopulatedEvent event) {
                Map<String, Object> dataSnapshot = new HashMap<String, Object>();
                dataSnapshot.put("oldName", layoutView.getFormDisplay().getName());
                dataSnapshot.put("oldAction", layoutView.getFormDisplay().getAction());
                dataSnapshot.put("oldProcessId", layoutView.getFormDisplay().getProcessId());
                dataSnapshot.put("oldTaskId", layoutView.getFormDisplay().getTaskId());
                dataSnapshot.put("oldMethod", layoutView.getFormDisplay().getMethod());
                dataSnapshot.put("oldEnctype", layoutView.getFormDisplay().getEnctype());
                dataSnapshot.put("newName", event.getName());
                dataSnapshot.put("newAction", event.getAction());
                dataSnapshot.put("newProcessId", event.getProcessId());
                dataSnapshot.put("newTaskId", event.getTaskId());
                dataSnapshot.put("newMethod", event.getMethod());
                dataSnapshot.put("newEnctype", event.getEnctype());
                bus.fireEvent(new UndoableEvent(dataSnapshot, new UndoableHandler() {
                    @Override
                    public void onEvent(UndoableEvent event) {  }
                    @Override
                    public void undoAction(UndoableEvent event) {
                        String name = (String) event.getData("oldName");
                        String action = (String) event.getData("oldAction");
                        String taskId = (String) event.getData("oldTaskId");
                        String processId = (String) event.getData("oldProcessId");
                        String method = (String) event.getData("oldMethod");
                        String enctype = (String) event.getData("oldEnctype");
                        populateFormData(action, processId, taskId, name, method, enctype);
                    }
                    @Override
                    public void doAction(UndoableEvent event) {
                        String name = (String) event.getData("newName");
                        String action = (String) event.getData("newAction");
                        String taskId = (String) event.getData("newTaskId");
                        String processId = (String) event.getData("newProcessId");
                        String method = (String) event.getData("newMethod");
                        String enctype = (String) event.getData("newEnctype");
                        populateFormData(action, processId, taskId, name, method, enctype);
                    }
                }));
            }
        });
        this.bus.addHandler(TaskSelectedEvent.TYPE, new TaskSelectedHandler() {
            @Override
            public void onSelectedTask(TaskSelectedEvent event) {
                Map<String, Object> dataSnapshot = new HashMap<String, Object>();
                dataSnapshot.put("oldTaskID", layoutView.getFormDisplay().getTaskId());
                dataSnapshot.put("oldProcessID", layoutView.getFormDisplay().getProcessId());
                dataSnapshot.put("oldTaskInputs", layoutView.getFormDisplay().getInputs());
                dataSnapshot.put("oldTaskOutputs", layoutView.getFormDisplay().getOutputs());
                if (event.getSelectedTask() != null) {
                    dataSnapshot.put("newTaskID", event.getSelectedTask().getTaskId());
                    Map<String, InputData> inputs = new HashMap<String, InputData>();
                    Map<String, OutputData> outputs = new HashMap<String, OutputData>();
                    if (event.getSelectedTask().getInputs() != null) {
                        for (TaskPropertyRef input : event.getSelectedTask().getInputs()) {
                            InputData in = new InputData();
                            in.setName(input.getName());
                            in.setValue(input.getSourceExpresion());
                            inputs.put(input.getName(), in);
                        }
                    }
                    if (event.getSelectedTask().getOutputs() != null) {
                        for (TaskPropertyRef output : event.getSelectedTask().getOutputs()) {
                            OutputData out = new OutputData();
                            out.setName(output.getName());
                            out.setValue(output.getSourceExpresion());
                            outputs.put(output.getName(), out);
                        }
                    }
                    dataSnapshot.put("newTaskInputs", inputs);
                    dataSnapshot.put("newTaskOutputs", outputs);
                }
                dataSnapshot.put("newTaskID", event.getSelectedTask() == null ? null : event.getSelectedTask().getTaskId());
                dataSnapshot.put("newProcessID", event.getSelectedTask() == null ? null : event.getSelectedTask().getProcessId());
                dataSnapshot.put("newTaskInputs", event.getSelectedTask() == null ? null : event.getSelectedTask().getInputs());
                dataSnapshot.put("newTaskOutputs", event.getSelectedTask() == null ? null : event.getSelectedTask().getOutputs());
                bus.fireEvent(new UndoableEvent(dataSnapshot, new UndoableHandler() {
                    @Override
                    public void onEvent(UndoableEvent event) { }
                    @Override
                    @SuppressWarnings("unchecked")
                    public void doAction(UndoableEvent event) {
                        String value = (String) event.getData("newTaskID");
                        String procId = (String) event.getData("newProcessID");
                        List<TaskPropertyRef> inputs = (List<TaskPropertyRef>) event.getData("newTaskInputs");
                        List<TaskPropertyRef> outputs = (List<TaskPropertyRef>) event.getData("newTaskOutputs");
                        layoutView.getFormDisplay().setTaskId(value);
                        layoutView.getFormDisplay().setProcessId(procId);
                        layoutView.getFormDisplay().setInputs(toInputs(inputs));
                        layoutView.getFormDisplay().setOutputs(toOutputs(outputs));
                    }
                    @Override
                    @SuppressWarnings("unchecked")
                    public void undoAction(UndoableEvent event) {
                        String value = (String) event.getData("oldTaskID");
                        String procId = (String) event.getData("oldProcessID");
                        List<TaskPropertyRef> inputs = (List<TaskPropertyRef>) event.getData("oldTaskInputs");
                        List<TaskPropertyRef> outputs = (List<TaskPropertyRef>) event.getData("oldTaskOutputs");
                        layoutView.getFormDisplay().setTaskId(value);
                        layoutView.getFormDisplay().setProcessId(procId);
                        layoutView.getFormDisplay().setInputs(toInputs(inputs));
                        layoutView.getFormDisplay().setOutputs(toOutputs(outputs));
                    }
                }));
            }
        });
       
        bus.addHandler(FormSavedEvent.TYPE, new FormSavedHandler() {
            @Override
            public void onEvent(FormSavedEvent event) {
                layoutView.getFormDisplay().setSaved(true);
            }
        });
       
        bus.addHandler(UpdateFormViewEvent.TYPE, new UpdateFormViewHandler() {
            @Override
            public void onEvent(UpdateFormViewEvent event) {
                Map<String, Object> dataSnapshot = new HashMap<String, Object>();
                dataSnapshot.put("newForm", event.getFormRepresentation());
                dataSnapshot.put("oldForm", layoutView.getFormDisplay().createRepresentation());
                bus.fireEvent(new UndoableEvent(dataSnapshot, new UndoableHandler() {
                    @Override
                    public void undoAction(UndoableEvent event) {
                        FormRepresentation oldForm = (FormRepresentation) event.getData("oldForm");
                        try {
                            layoutView.getFormDisplay().populate(oldForm);
                        } catch (FormBuilderException e) {
                            bus.fireEvent(new NotificationEvent(Level.ERROR, i18n.CouldntPopulateWithForm(), e));
                        }
                    }
                    @Override
                    public void onEvent(UndoableEvent event) { }
                    @Override
                    public void doAction(UndoableEvent event) {
                        FormRepresentation newForm = (FormRepresentation) event.getData("newForm");
                        try {
                            layoutView.getFormDisplay().populate(newForm);
                        } catch (FormBuilderException e) {
                            bus.fireEvent(new NotificationEvent(Level.ERROR, i18n.CouldntPopulateWithForm(), e));
                        }
View Full Code Here

            if (notEmpty(profile) && "jbpm".equals(profile)) {
                String uuid = req.getParameter("uuid");
                TaskDefinitionService taskService = createTaskService(req);
                FormDefinitionService formService = createFormService(req);
                String packageName = taskService.getContainingPackage(uuid);
                FormRepresentation form = formService.getFormByUUID(packageName, uuid);
                if (notEmpty(form.getProcessName()) || notEmpty(form.getTaskId())) {
                    Translator translator = TranslatorFactory.getInstance().getTranslator("ftl");
                    URL url = translator.translateForm(form);
                    String content = IOUtils.toString(url.openStream());
                    String templateName = "";
                    if (!notEmpty(form.getTaskId()) || ProcessGetInputHandler.PROCESS_INPUT_NAME.equals(form.getTaskId())) {
                        templateName = form.getProcessName();
                    } else {
                        templateName = form.getTaskId();
                    }
                    if (templateName != null && !"".equals(templateName)) {
                        templateName += "-taskform.ftl";
                        templateName = URLEncoder.encode(templateName, "UTF-8");
                        formService.saveTemplate(packageName, templateName, content);
View Full Code Here

        return obj;
    }

    @Override
    public FormRepresentation decode(String code) throws FormEncodingException {
        FormRepresentation form = new FormRepresentation();
        JSONValue json = JSONParser.parseLenient(code);
        if (json.isObject() != null) {
            JSONObject jsonObj = json.isObject();
            if (jsonObj.get("action").isString() != null) {
                form.setAction(jsonObj.get("action").isString().stringValue());
            }
            if (jsonObj.get("documentation").isString() != null) {
                form.setDocumentation(jsonObj.get("documentation").isString()
                        .stringValue());
            }
            if (jsonObj.get("enctype").isString() != null) {
                form.setEnctype(jsonObj.get("enctype").isString().stringValue());
            }
            if (jsonObj.get("lastModified").isNumber() != null) {
                form.setLastModified(Double.valueOf(
                        jsonObj.get("lastModified").isNumber().doubleValue())
                        .longValue());
            } else if (jsonObj.get("lastModified").isString() != null) {
                form.setLastModified(Double.valueOf(
                        jsonObj.get("lastModified").isString().stringValue())
                        .longValue());
            }
            if (jsonObj.get("method").isString() != null) {
                form.setMethod(jsonObj.get("method").isString().stringValue());
            }
            if (jsonObj.get("name").isString() != null) {
                form.setName(jsonObj.get("name").isString().stringValue());
            }
            if (jsonObj.get("taskId").isString() != null) {
                form.setTaskId(jsonObj.get("taskId").isString().stringValue());
            }
            if (jsonObj.get("processName").isString() != null) {
                form.setProcessName(jsonObj.get("processName").isString()
                        .stringValue());
            }
            form.setFormItems(decodeItems(jsonObj.get("formItems")));
            form.setFormValidations(decodeValidations(jsonObj
                    .get("formValidations")));
            form.setInputs(decodeInputs(jsonObj.get("inputs")));
            form.setOutputs(decodeOutputs(jsonObj.get("outputs")));
            form.setOnLoadScripts(decodeScripts(jsonObj.get("onLoadScripts")));
            form.setOnSubmitScripts(decodeScripts(jsonObj
                    .get("onSubmitScripts")));
        }
        return form;
    }
View Full Code Here

            props.load(method.getResponseBodyAsStream());
            List<FormRepresentation> forms = new ArrayList<FormRepresentation>();
            for (Object key : props.keySet()) {
                String assetId = key.toString();
                if (isFormName(assetId)) {
                    FormRepresentation form = getForm(pkgName, assetId.replace(".formdef", ""));
                    forms.add(form);
                }
            }
            return forms;
        } catch (IOException e) {
View Full Code Here

    }
   
    @Override
    public FormRepresentation getAssociatedForm(String pkgName, TaskRef task) throws FormServiceException {
        List<FormRepresentation> forms = getForms(pkgName);
        FormRepresentation retval = null;
        for (FormRepresentation form : forms) {
            if (form.getTaskId() != null && form.getTaskId().equals(task.getTaskId())) {
                retval = form;
                break;
            }
View Full Code Here

*
*/
public class RenderTranslatorAbstractTest extends TestCase {

    protected FormRepresentation createBasicForm() {
        FormRepresentation form = new FormRepresentation();
        form.setTaskId("taskNameXXX");
        ComboBoxRepresentation combo = new ComboBoxRepresentation();
        combo.setName("comboName");
        List<OptionRepresentation> options = new ArrayList<OptionRepresentation>();
        OptionRepresentation option1 = new OptionRepresentation();
        option1.setLabel("Label 1");
        option1.setValue("l1");
        OptionRepresentation option2 = new OptionRepresentation();
        option2.setLabel("Label 2");
        option2.setValue("l2");
        options.add(option1);
        options.add(option2);
        combo.setElements(options);
        CheckBoxRepresentation checkbox = new CheckBoxRepresentation();
        checkbox.setFormValue("S");
        checkbox.setName("checkboxName");
        form.addFormItem(combo);
        form.addFormItem(checkbox);
        return form;
    }
View Full Code Here

        responses.put("POST " + helper.getApiSearchUrl("somePackage") + "form1AutoForm.formdef", "OK");
        EasyMock.expect(client.executeMethod(EasyMock.anyObject(MockGetMethod.class))).
            andAnswer(new MockAnswer(responses, new IllegalArgumentException("unexpected call"))).anyTimes();
        GuvnorFormDefinitionService service = createService(baseUrl, "", "");
        service.getHelper().setClient(client);
        FormRepresentation form = RESTAbstractTest.createMockForm("form1", "oneParam");
       
        EasyMock.replay(client);
        String formId = service.saveForm("somePackage", form);
        EasyMock.verify(client);
       
View Full Code Here

TOP

Related Classes of org.jbpm.formapi.shared.api.FormRepresentation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.