Package org.jbpm.formapi.shared.form

Examples of org.jbpm.formapi.shared.form.FormRepresentationDecoder


            return Response.status(Status.CONFLICT).build();
        }
    }

    private MenuItemDescription toMenuItemDescription(SaveMenuItemDTO dto, boolean strict) throws MenuServiceException {
        FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
        String json = dto.getClone();
        MenuItemDescription menuItem = new MenuItemDescription();
        try {
            FormItemRepresentation item = decoder.decodeItem(json);
            menuItem.setItemRepresentation(item);
        } catch (FormEncodingException e) {
            if (strict) {
                throw new MenuServiceException("Couldn't load formRepresentation from dto", e);
            }
View Full Code Here


        abstractTestListItemsProblem(IOException.class);
    }
   
    public void testListItemsEncodingProblem() throws Exception {
        GuvnorMenuService service = createMockedService(null);
        FormRepresentationDecoder decoder = EasyMock.createMock(FormRepresentationDecoder.class);
        FormEncodingFactory.register(FormEncodingFactory.getEncoder(), decoder);
        FormEncodingException exception = new FormEncodingException("Something going wrong");
        EasyMock.expect(decoder.decodeMenuItemsMap(EasyMock.anyObject(String.class))).andThrow(exception).once();
       
        EasyMock.replay(decoder);
        try {
            service.listMenuItems();
            fail("listOptions shouldn't succeed");
View Full Code Here

        EasyMock.verify(encoder);
    }
   
    public void testSaveMenuItemOK() throws Exception {
        GuvnorMenuService service = new GuvnorMenuService();
        FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
        File dbFile = new File(getClass().getResource("/menuItems.json").getFile());
        String jsonInitial = FileUtils.readFileToString(dbFile);
        Map<String, List<MenuItemDescription>> descsInitial = decoder.decodeMenuItemsMap(jsonInitial);
        MenuItemDescription desc = new MenuItemDescription();
        desc.setClassName(CustomMenuItem.class.getName());
        List<FormEffectDescription> effects = new ArrayList<FormEffectDescription>();
        FormEffectDescription effDesc1 = new FormEffectDescription();
        effDesc1.setClassName(RemoveEffect.class.getName());
        effects.add(effDesc1);
        FormEffectDescription effDesc2 = new FormEffectDescription();
        effDesc2.setClassName(DoneEffect.class.getName());
        effects.add(effDesc2);
        desc.setEffects(effects);
        File file = new File(getClass().getResource("testSaveMenuItem.json").getFile());
        String json = FileUtils.readFileToString(file);
        FormItemRepresentation itemRepresentation = decoder.decodeItem(json);
        desc.setName("test component");
        desc.setItemRepresentation(itemRepresentation);
       
        String groupName = "Test Components";
        service.saveMenuItem(groupName, desc);
       
        String jsonResult = FileUtils.readFileToString(dbFile);
       
        Map<String, List<MenuItemDescription>> descsResult = decoder.decodeMenuItemsMap(jsonResult);
        assertNotNull("saved menu items shouldn't be null", descsResult);
        assertNotNull("saved menu items should contain a list of " + groupName, descsResult.get(groupName));
        assertFalse(groupName + " list should not be empty", descsResult.get(groupName).isEmpty());
        assertFalse("descsInitial and descsResult should not be the same", descsInitial.equals(descsResult));
       
        service.deleteMenuItem(groupName, desc);
       
        String jsonFinal = FileUtils.readFileToString(dbFile);
        Map<String, List<MenuItemDescription>> descsFinal = decoder.decodeMenuItemsMap(jsonFinal);
       
        assertEquals("descsInitial and descsFinal should be the same", descsInitial.entrySet(), descsFinal.entrySet());
    }
View Full Code Here

    @Override
    @SuppressWarnings("unchecked")
    public void setDataMap(Map<String, Object> data)
            throws FormEncodingException {
        FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
        List<Object> validationsMap = (List<Object>) data
                .get("itemValidations");
        this.itemValidations.clear();
        if (validationsMap != null) {
            for (Object obj : validationsMap) {
                Map<String, Object> validMap = (Map<String, Object>) obj;
                FBValidation validation = (FBValidation) decoder
                        .decode(validMap);
                this.itemValidations.add(validation);
            }
        }
        List<Object> effectClassesObj = (List<Object>) data
                .get("effectClasses");
        effectClasses.clear();
        if (effectClassesObj != null) {
            for (Object obj : effectClassesObj) {
                effectClasses.add(obj.toString());
            }
        }
        this.eventActions.clear();
        Map<String, Object> eventActionsMap = (Map<String, Object>) data
                .get("eventActions");
        if (eventActionsMap != null) {
            for (Map.Entry<String, Object> entry : eventActionsMap.entrySet()) {
                Map<String, Object> scriptMap = (Map<String, Object>) entry
                        .getValue();
                if (scriptMap != null) {
                    FBScript script = new FBScript();
                    script.setDataMap(scriptMap);
                    this.eventActions.put(entry.getKey(), script);
                }
            }
        }
        this.output = (OutputData) decoder.decode((Map<String, Object>) data
                .get("output"));
        this.input = (InputData) decoder.decode((Map<String, Object>) data
                .get("input"));
        this.external = (ExternalData) decoder
                .decode((Map<String, Object>) data.get("external"));
        this.width = (String) data.get("width");
        this.height = (String) data.get("height");
    }
View Full Code Here

            this.allowedEvents.clear();
            for (Object obj : allowedEventsList) {
                this.allowedEvents.add(obj.toString());
            }
        }
        FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
        Map<String, Object> itemMap = (Map<String, Object>) data.get("itemRepresentation");
        this.itemRepresentation = (FormItemRepresentation) decoder.decode(itemMap);
    }
View Full Code Here

    @Override
    @SuppressWarnings("unchecked")
    public void setDataMap(Map<String, Object> dataMap)
            throws FormEncodingException {
        FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
        this.mimeType = (String) dataMap.get("mimeType");
        this.name = (String) dataMap.get("name");
        this.value = (String) dataMap.get("value");
        this.formatter = (Formatter) decoder
                .decode((Map<String, Object>) dataMap.get("formatter"));
    }
View Full Code Here

        this.type = (String) data.get("type");
        this.id = (String) data.get("id");
        this.dir = (String) data.get("dir");
        this.items.clear();
        List<Object> mapItems = (List<Object>) data.get("items");
        FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
        if (mapItems != null) {
            for (Object obj : mapItems) {
                Map<String, Object> itemMap = (Map<String, Object>) obj;
                FormItemRepresentation item = (FormItemRepresentation) decoder
                        .decode(itemMap);
                this.items.add(item);
            }
        }
    }
View Full Code Here

        this.cellPadding = data.get("cellPadding") == null ? null : ((Number) data.get("cellPadding")).intValue();
        this.cellSpacing = data.get("cellSpacing") == null ? null : ((Number) data.get("cellSpacing")).intValue();
        this.rows = data.get("rows") == null ? null : ((Number) data.get("rows")).intValue();
        this.title = (String) data.get("title");
        this.elements.clear();
        FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
        List<List<Map<String, Object>>> mapElements = (List<List<Map<String, Object>>>) data.get("elements");
        if (mapElements != null) {
            for (List<Map<String, Object>> mapRow : mapElements) {
                List<FormItemRepresentation> row = new ArrayList<FormItemRepresentation>();
                if (mapRow != null) {
                    for (Map<String, Object> mapCell : mapRow) {
                        row.add((FormItemRepresentation) decoder.decode(mapCell));
                    }
                }
                this.elements.add(row);
            }
        }
View Full Code Here

        this.cssClassName = (String) data.get("cssClassName");
        this.id = (String) data.get("id");
        this.cssStylesheetUrl = (String) data.get("cssStylesheetUrl");
        this.items.clear();
        List<Object> mapItems = (List<Object>) data.get("items");
        FormRepresentationDecoder decoder = FormEncodingFactory.getDecoder();
        if (mapItems != null) {
            for (Object obj : mapItems) {
                Map<String, Object> itemMap = (Map<String, Object>) obj;
                FormItemRepresentation item = (FormItemRepresentation) decoder.decode(itemMap);
                this.items.add(item);
            }
        }
    }
View Full Code Here

public class FormEncodingServerFactoryTest extends TestCase {

    public void testComplexFormDecoding() throws Exception {
        FormRepresentationEncoder encoder = FormEncodingServerFactory.getEncoder();
        FormRepresentationDecoder decoder = FormEncodingServerFactory.getDecoder();
        FormEncodingFactory.register(encoder, decoder);
       
        URL url = getClass().getResource("/org/jbpm/formapi/shared/form/testComplexFormDecoding.json");
        String json = FileUtils.readFileToString(new File(url.getFile()));
       
        assertNotNull("json shouldn't be null", json);
        assertNotSame("json shouldn't be empty", "", json);
       
       
        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

TOP

Related Classes of org.jbpm.formapi.shared.form.FormRepresentationDecoder

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.