Example usage for org.apache.commons.beanutils BeanMap putAll

List of usage examples for org.apache.commons.beanutils BeanMap putAll

Introduction

In this page you can find the example usage for org.apache.commons.beanutils BeanMap putAll.

Prototype

public void putAll(Map<? extends K, ? extends V> m) 

Source Link

Usage

From source file:org.ms123.common.form.BaseFormServiceImpl.java

protected Map _validateForm(String namespace, String name, Map data, boolean cleanData) throws Exception {
    String json = m_gitService.searchContent(namespace, name, "sw.form");
    Map rootShape = (Map) m_ds.deserialize(json);
    Map<String, List> constraintsMeta = getConstraintsFromStencil(namespace);
    List<Map> inputShapes = new ArrayList();
    List<String> idList = new ArrayList();
    idList.add("input");
    idList.add("textarea");
    traverseElement(inputShapes, rootShape, idList);
    long time = new java.util.Date().getTime();
    BundleDelegatingClassLoader bdc = new BundleDelegatingClassLoader(m_bc.getBundle());
    ClassBuilder cb = new ClassBuilder(bdc, inputShapes, constraintsMeta);
    Class clazz = cb.getClazz();//from w w  w .java 2 s .  c o  m
    findAnnotatedFields(clazz);
    Object obj = clazz.newInstance();
    BeanMap bm = new BeanMap(obj);
    try {
        bm.putAll(cleanData(data, inputShapes, true));
    } catch (Exception e) {
        for (Object key : bm.keySet()) {
            System.out.println("\tkey:" + key + "=" + bm.getType((String) key));
        }
        e.printStackTrace();
        throw new RuntimeException("FormService._validateForm:", e);
    }
    Set cv = validate(obj);
    List<Map> errors = new ArrayList();
    if (cv.size() > 0) {
        errors = constructConstraitViolationList(cv, inputShapes, constraintsMeta);
        System.out.println("cv:" + errors);
    } else {
        StoreDesc sdesc = StoreDesc.getNamespaceData(namespace);
        SessionContext sc = m_dataLayer.getSessionContext(sdesc);
        for (Map shape : inputShapes) {
            Map filterCheck = getFilterCheck(shape);
            if (filterCheck == null) {
                continue;
            }
            String fieldName = getName(shape);
            Object value = data.get(fieldName);
            boolean ok = executeFilter(sc, filterCheck, fieldName, value);
            if (!ok) {
                Map error = new HashMap();
                errors.add(error);
                error.put("path", fieldName);
                String msg = (String) filterCheck.get("message");
                error.put("message", msg != null ? msg : "%field_not_in_database");
            }
        }
    }
    Map ret = new HashMap();
    ret.put("errors", errors);
    if (cleanData) {
        inputShapes = new ArrayList();
        idList = new ArrayList();
        idList.add("input");
        idList.add("textarea");
        idList.add("gridinput");
        idList.add("tableselect");
        idList.add("enumselect");
        idList.add("alert");
        idList.add("actionbutton");
        traverseElement(inputShapes, rootShape, idList);
        ret.put("cleanData", cleanData(data, inputShapes, false));
    }
    ret.put("postProcess", getPostProcessScript(rootShape));
    return ret;
}