Package org.jbpm.formapi.shared.api

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


        assertNotSame("json shouldn't be empty", "", json);
       
        FormRepresentationEncoder encoder = FormEncodingClientFactory.getEncoder();
        FormRepresentationDecoder decoder = FormEncodingClientFactory.getDecoder();
       
        FormRepresentation form = decoder.decode(json);
        assertNotNull("form shouldn't be null", form);
        String json2 = encoder.encode(form);
        FormRepresentation form2 = decoder.decode(json2);
        assertNotNull("json2 shouldn't be null", json2);
        assertNotSame("json2 shouldn't be empty", "", json2);
       
        assertNotNull("form2 shouldn't be null", form2);
        assertEquals("both forms should be the same in contents", form, form2);
View Full Code Here


        json.addProperty("embedded", profile);
        try {
            if (profile != null && "guvnor".equals(profile)) {
                String uuid = request.getParameter("uuid");
                String packageName = taskService.getContainingPackage(uuid);
                FormRepresentation form = formService.getFormByUUID(packageName, uuid);
                json.addProperty("uuid", uuid);
                json.addProperty("packageName", packageName);
                if (form != null) {
                    json.addProperty("formjson", encoder.encode(form));
                }
View Full Code Here

                String processName = request.getParameter("processName");
                String bpmn2Process = IOUtils.toString(request.getReader());
                TaskRef task = taskService.getBPMN2Task(bpmn2Process, processName, userTask);
                if (task != null) {
                    //get associated form if it exists
                    FormRepresentation form = formService.getAssociatedForm(task.getPackageName(), task);
                    if (form != null) {
                        json.addProperty("formjson", encoder.encode(form));
                    }
                    json.add("task", toJsonObject(task));
                    json.addProperty("packageName", task.getPackageName());
View Full Code Here

        return null;
    }
   
    private static FormRepresentation toForm(String json) throws FormEncodingException {
        FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
        FormRepresentation form = decoder.decode(json);
        return form;
    }
View Full Code Here

        return retval;
    }

    @Override
    public FormRepresentation decode(String code) throws FormEncodingException {
        FormRepresentation form = new FormRepresentation();
        JsonElement json = new JsonParser().parse(code);
        if (json.isJsonObject()) {
            JsonObject jsonObj = json.getAsJsonObject();
            if (jsonObj.entrySet().isEmpty()) {
                return null;
            }
            if (jsonObj.get("action") != null
                    && jsonObj.get("action").isJsonPrimitive()
                    && jsonObj.get("action").getAsJsonPrimitive().isString()) {
                form.setAction(jsonObj.get("action").getAsString());
            }
            if (jsonObj.get("documentation") != null
                    && jsonObj.get("documentation").isJsonPrimitive()
                    && jsonObj.get("documentation").getAsJsonPrimitive()
                            .isString()) {
                form.setDocumentation(jsonObj.get("documentation")
                        .getAsString());
            }
            if (jsonObj.get("enctype") != null
                    && jsonObj.get("enctype").isJsonPrimitive()
                    && jsonObj.get("enctype").getAsJsonPrimitive().isString()) {
                form.setEnctype(jsonObj.get("enctype").getAsString());
            }
            if (jsonObj.get("lastModified") != null
                    && jsonObj.get("lastModified").isJsonPrimitive()
                    && jsonObj.get("lastModified").getAsJsonPrimitive()
                            .isString()) {
                form.setLastModified(Double.valueOf(
                        jsonObj.get("lastModified").getAsString()).longValue());
            } else if (jsonObj.get("lastModified") != null
                    && jsonObj.get("lastModified").isJsonPrimitive()
                    && jsonObj.get("lastModified").getAsJsonPrimitive()
                            .isNumber()) {
                form.setLastModified(jsonObj.get("lastModified").getAsNumber()
                        .longValue());
            }
            if (jsonObj.get("method") != null
                    && jsonObj.get("method").isJsonPrimitive()
                    && jsonObj.get("method").getAsJsonPrimitive().isString()) {
                form.setMethod(jsonObj.get("method").getAsString());
            }
            if (jsonObj.get("name") != null
                    && jsonObj.get("name").isJsonPrimitive()
                    && jsonObj.get("name").getAsJsonPrimitive().isString()) {
                form.setName(jsonObj.get("name").getAsString());
            }
            if (jsonObj.get("taskId") != null
                    && jsonObj.get("taskId").isJsonPrimitive()
                    && jsonObj.get("taskId").getAsJsonPrimitive().isString()) {
                form.setTaskId(jsonObj.get("taskId").getAsString());
            }
            if (jsonObj.get("processName") != null
                    && jsonObj.get("processName").isJsonPrimitive()
                    && jsonObj.get("processName").getAsJsonPrimitive()
                            .isString()) {
                form.setProcessName(jsonObj.get("processName").getAsString());
            }
            form.setFormItems(decodeList(jsonObj.get("formItems"),
                    FormItemRepresentation.class));
            form.setFormValidations(decodeList(jsonObj.get("formValidations"),
                    FBValidation.class));
            form.setInputs(decodeStringIndexedMap(jsonObj.get("inputs"),
                    InputData.class));
            form.setOutputs(decodeStringIndexedMap(jsonObj.get("outputs"),
                    OutputData.class));
            form.setOnLoadScripts(decodeList(jsonObj.get("onLoadScripts"),
                    FBScript.class));
            form.setOnSubmitScripts(decodeList(jsonObj.get("onSubmitScripts"),
                    FBScript.class));
        }
        return form;
    }
View Full Code Here

    public PreviewFormCommand(final String saveType) {
        this.saveType = saveType;
        this.bus.addHandler(GetFormRepresentationResponseEvent.TYPE, new GetFormRepresentationResponseHandler() {
            @Override
            public void onEvent(GetFormRepresentationResponseEvent event) {
                FormRepresentation form = event.getRepresentation();
                String type = event.getSaveType();
                if (saveType.equals(type)) {
                    popupInputMapPanel(form);
                }
            }
View Full Code Here

public class RendererTest extends RenderTranslatorAbstractTest {

    public void testFormBasic() throws Exception {
        Translator lang = new Translator();
        FormRepresentation form = createBasicForm();
        URL url = lang.translateForm(form);
        assertNotNull("url shouldn't be null", url);
       
        Renderer renderer = new Renderer();
        Map<String, Object> inputData = new HashMap<String, Object>();
View Full Code Here

public class TranslatorTest extends RenderTranslatorAbstractTest {

    public void testFormBasic() throws Exception {
        Translator lang = new Translator();
        FormRepresentation form = createBasicForm();
        URL url = lang.translateForm(form);
        String script = FileUtils.readFileToString(new File(url.getFile()));
        assertNotNull("script shouldn't be null", script);
        assertTrue("script should contain checkbox", script.contains("checkbox"));
        assertTrue("script should contain select", script.contains("select"));
View Full Code Here

        List<String> tableActions = get(this.actionsForItem, "TableLayoutMenuItem");
        List<String> labelActions = get(this.actionsForItem, "LabelMenuItem");
        List<String> textfieldActions = get(this.actionsForItem, "TextFieldMenuItem");
        List<String> completeButtonActions = get(this.actionsForItem, "CompleteButtonMenuItem");
       
        FormRepresentation form = new FormRepresentation();
        form.setInputs(toInputDataMap(task.getInputs()));
        form.setOutputs(toOutputDataMap(task.getOutputs()));
        if (task.getTaskId() != null) {
            HeaderRepresentation header = new HeaderRepresentation();
            header.setValue("Task: " + task.getTaskId());
            header.setEffectClasses(headerEffects);
            header.setEventActions(asMapOfNull(headerActions, FBScript.class));
            form.addFormItem(header);
        }
        List<TaskPropertyRef> inputs = task.getInputs();
        if (inputs != null && !inputs.isEmpty()) {
            TableRepresentation tableOfInputs = new TableRepresentation();
            tableOfInputs.setRows(inputs.size());
            tableOfInputs.setColumns(2);
            tableOfInputs.setHeight("" + (inputs.size() * 30) + "px");
            tableOfInputs.setEffectClasses(tableEffects);
            tableOfInputs.setEventActions(asMapOfNull(tableActions, FBScript.class));
            for (int index = 0; index < inputs.size(); index++) {
                TaskPropertyRef input = inputs.get(index);
                LabelRepresentation labelName = new LabelRepresentation();
                labelName.setEventActions(asMapOfNull(labelActions, FBScript.class));
                labelName.setEffectClasses(labelEffects);
                labelName.setValue(input.getName());
                labelName.setWidth("100px");
                tableOfInputs.setElement(index, 0, labelName);
                LabelRepresentation labelValue = new LabelRepresentation();
                labelValue.setEventActions(asMapOfNull(labelActions, FBScript.class));
                labelValue.setEffectClasses(labelEffects);
                labelValue.setWidth("200px");
                InputData data = new InputData();
                data.setName(input.getName());
                data.setValue(input.getSourceExpresion());
                data.setMimeType("multipart/form-data");
                data.setFormatter(new Formatter() {
                    @Override
                    public Object format(Object object) {
                        return object;
                    }
                    @Override
                    public Map<String, Object> getDataMap() {
                        return new HashMap<String, Object>();
                    }
                });
                labelValue.setInput(data);
                labelValue.setValue("{variable}");
                tableOfInputs.setElement(index, 1, labelValue);
            }
            LabelRepresentation labelInputs = new LabelRepresentation();
            labelInputs.setEventActions(asMapOfNull(labelActions, FBScript.class));
            labelInputs.setEffectClasses(labelEffects);
            labelInputs.setValue("Inputs:");
            form.addFormItem(labelInputs);
            form.addFormItem(tableOfInputs);
        }
        List<TaskPropertyRef> outputs = task.getOutputs();
        if (outputs != null && !outputs.isEmpty()) {
            TableRepresentation tableOfOutputs = new TableRepresentation();
            tableOfOutputs.setRows(outputs.size());
            tableOfOutputs.setColumns(2);
            tableOfOutputs.setHeight("" + (outputs.size() * 30) + "px");
            tableOfOutputs.setEffectClasses(tableEffects);
            tableOfOutputs.setEventActions(asMapOfNull(tableActions, FBScript.class));
            for (int index = 0; index < outputs.size(); index++) {
                TaskPropertyRef output = outputs.get(index);
                LabelRepresentation labelName = new LabelRepresentation();
                labelName.setEventActions(asMapOfNull(labelActions, FBScript.class));
                labelName.setEffectClasses(labelEffects);
                labelName.setValue(output.getName());
                labelName.setWidth("100px");
                tableOfOutputs.setElement(index, 0, labelName);
                TextFieldRepresentation textField = new TextFieldRepresentation();
                textField.setEventActions(asMapOfNull(textfieldActions, FBScript.class));
                textField.setWidth("200px");
                textField.setEffectClasses(textfieldEffects);
                OutputData data = new OutputData();
                data.setName(output.getName());
                data.setValue(output.getSourceExpresion());
                data.setMimeType("multipart/form-data");
                data.setFormatter(new Formatter() {
                    @Override
                    public Object format(Object object) {
                        return object;
                    }
                    @Override
                    public Map<String, Object> getDataMap() {
                        return new HashMap<String, Object>();
                    }
                });
                textField.setOutput(data);
                tableOfOutputs.setElement(index, 1, textField);
            }
            LabelRepresentation labelOutputs = new LabelRepresentation();
            labelOutputs.setEventActions(asMapOfNull(labelActions, FBScript.class));
            labelOutputs.setEffectClasses(labelEffects);
            labelOutputs.setValue("Outputs:");
            form.addFormItem(labelOutputs);
            form.addFormItem(tableOfOutputs);
        }
        CompleteButtonRepresentation completeButton = new CompleteButtonRepresentation();
        completeButton.setText("Complete");
        completeButton.setEffectClasses(completeButtonEffects);
        completeButton.setEventActions(asMapOfNull(completeButtonActions, FBScript.class));
        form.addFormItem(completeButton);
        form.setAction("complete");
        form.setEnctype("multipart/form-data");
        form.setMethod("POST");
        form.setName(task.getTaskId() + "AutoForm");
        form.setProcessName(task.getProcessId());
        form.setTaskId(task.getTaskId());
        return form;
    }
View Full Code Here

   
    @GET @Path("/definitions/package/{pkgName}/id/{formId}")
    public Response getForm(@PathParam("pkgName") String pkgName, @PathParam("formId") String formId, @Context ServletContext context) {
        setContext(context);
        try {
            FormRepresentation form = formService.getForm(pkgName, formId);
            ListFormsDTO dto = new ListFormsDTO(form);
            return Response.ok(dto, MediaType.APPLICATION_XML).build();
        } catch (FormServiceException e) {
            return error("Problem reading form " + formId, e);
        } catch (FormEncodingException e) {
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.