Example usage for org.apache.commons.beanutils DynaBean set

List of usage examples for org.apache.commons.beanutils DynaBean set

Introduction

In this page you can find the example usage for org.apache.commons.beanutils DynaBean set.

Prototype

public void set(String name, Object value);

Source Link

Document

Set the value of a simple property with the specified name.

Usage

From source file:com.xpfriend.fixture.cast.temp.Database.java

private DbResult executeQuery(DbCommand command) throws SQLException {
    command.printSQL();/* w  w w .  java  2  s.com*/
    ResultSet resultSet = command.executeQuery();
    DynaClass dynaClass = getDynaClass(resultSet);

    List<DynaBean> list = new ArrayList<DynaBean>();
    ColumnValueConverter converter = ColumnValueConverter.getInstance();
    DynaProperty[] properties = dynaClass.getDynaProperties();
    while (resultSet.next()) {
        DynaBean bean;
        try {
            bean = dynaClass.newInstance();
        } catch (Exception e) {
            throw new ConfigException(e);
        }
        for (int i = 0; i < properties.length; i++) {
            Object value = converter.getResult(resultSet, properties[i].getType(), i + 1);
            bean.set(properties[i].getName(), value);
        }
        list.add(bean);
    }
    return new DbResult(dynaClass, list);
}

From source file:com.hr.struts.controller.Employee.java

public ActionForward addEmployee(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    boolean results;
    DynaBean addEmp = (DynaActionForm) form;

    String name, ssNum, phone;//w  w  w. j  a va 2 s . co  m
    name = (String) request.getParameter("name");
    ssNum = (String) request.getParameter("ssNum");
    phone = (String) request.getParameter("phone");

    this.service.setEmployees(getEmployees(connexion(request, response)));
    results = service.add(name, ssNum, phone);

    // Cible par defaut
    String cible = new String("succes");

    // Cible en cas d'echec
    if (results == false) {
        cible = new String("echec");
        ActionMessages errors = new ActionMessages();
        errors.add(null, new ActionMessage("error.add.employees.false"));
        // Signalement des erreurs a la page d'origine
        if (!errors.isEmpty()) {
            saveErrors(request, errors);
        }
    } else {
        addEmp.set("results", results);
    }
    // Transmission a la vue appropriee
    return (mapping.findForward(cible));
}

From source file:com.hr.struts.controller.Employee.java

public ActionForward deleteEmployee(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    boolean results = true;
    DynaBean deleteEmp = (DynaBean) form;

    String ssNum;//w  w w.ja  va2  s .c  o  m
    ssNum = (String) request.getParameter("ssNum");
    ArrayList<com.hr.struts.model.entities.Employee> listEmp = service.searchBySsNum(ssNum);
    for (com.hr.struts.model.entities.Employee listEmp1 : listEmp) {
        boolean res;
        res = service.delete(listEmp1);
        if (!res) {
            results = false;
        }
    }

    // Cible par defaut
    String cible = new String("succes");

    // Cible en cas d'echec
    if (results == false) {
        cible = new String("echec");
        ActionMessages errors = new ActionMessages();
        errors.add(null, new ActionMessage("error.delete.employees.false"));
        // Signalement des erreurs a la page d'origine
        if (!errors.isEmpty()) {
            saveErrors(request, errors);
        }
    } else {
        deleteEmp.set("results", results);
    }
    // Transmission a la vue appropriee
    return (mapping.findForward(cible));
}

From source file:com.hr.struts.controller.Employee.java

public ActionForward updateEmployee(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    EmployeeManagement service = new EmployeeManagement();
    boolean results = true;
    DynaBean updateEmp = (DynaBean) form;

    String ssNum, name, phone;/*from  w ww . ja v  a  2  s . c  o  m*/
    ssNum = (String) request.getParameter("ssNum");
    name = (String) request.getParameter("name");
    phone = (String) request.getParameter("phone");
    ArrayList<com.hr.struts.model.entities.Employee> listEmp = service.searchBySsNum(ssNum);

    for (com.hr.struts.model.entities.Employee listEmp1 : listEmp) {
        boolean res;
        res = service.update(listEmp1, name, ssNum, phone);
        if (!res) {
            results = false;
        }
    }

    // Cible par defaut
    String cible = new String("succes");

    // Cible en cas d'echec
    if (results == false) {
        cible = new String("echec");
        ActionMessages errors = new ActionMessages();
        errors.add(null, new ActionMessage("error.update.employees.false"));
        // Signalement des erreurs a la page d'origine
        if (!errors.isEmpty()) {
            saveErrors(request, errors);
        }
    } else {
        updateEmp.set("results", results);
    }
    // Transmission a la vue appropriee
    return (mapping.findForward(cible));
}

From source file:com.xwtec.xwserver.util.json.JSONObject.java

/**
 * Creates a JSONDynaBean from a JSONObject.
 *//*from  w  ww. j  a  v  a2 s.c o  m*/
public static Object toBean(JSONObject jsonObject) {
    if (jsonObject == null || jsonObject.isNullObject()) {
        return null;
    }

    DynaBean dynaBean = null;

    JsonConfig jsonConfig = new JsonConfig();
    Map props = JSONUtils.getProperties(jsonObject);
    dynaBean = JSONUtils.newDynaBean(jsonObject, jsonConfig);
    for (Iterator entries = jsonObject.names(jsonConfig).iterator(); entries.hasNext();) {
        String name = (String) entries.next();
        String key = JSONUtils.convertToJavaIdentifier(name, jsonConfig);
        Class type = (Class) props.get(name);
        Object value = jsonObject.get(name);
        try {
            if (!JSONUtils.isNull(value)) {
                if (value instanceof JSONArray) {
                    dynaBean.set(key, JSONArray.toCollection((JSONArray) value));
                } else if (String.class.isAssignableFrom(type) || Boolean.class.isAssignableFrom(type)
                        || JSONUtils.isNumber(type) || Character.class.isAssignableFrom(type)
                        || JSONFunction.class.isAssignableFrom(type)) {
                    dynaBean.set(key, value);
                } else {
                    dynaBean.set(key, toBean((JSONObject) value));
                }
            } else {
                if (type.isPrimitive()) {
                    // assume assigned default value
                    log.warn("Tried to assign null value to " + key + ":" + type.getName());
                    dynaBean.set(key, JSONUtils.getMorpherRegistry().morph(type, null));
                } else {
                    dynaBean.set(key, null);
                }
            }
        } catch (JSONException jsone) {
            throw jsone;
        } catch (Exception e) {
            throw new JSONException("Error while setting property=" + name + " type" + type, e);
        }
    }

    return dynaBean;
}

From source file:org.agnitas.dao.impl.MailingDaoImpl.java

public PaginatedList getMailingList(int companyID, String types, boolean isTemplate, String sort,
        String direction, int page, int rownums) {

    JdbcTemplate aTemplate = new JdbcTemplate((DataSource) applicationContext.getBean("dataSource"));
    List<String> charColumns = Arrays.asList(new String[] { "shortname", "description", "mailinglist" });

    int offset = (page - 1) * rownums;

    String mailingTypes = "  AND  mailing_type in (" + types + ") ";
    if (isTemplate) {
        mailingTypes = " ";
    }/*from w  w w .  j  a  v  a 2s .  c  o m*/

    String orderby = null;
    String defaultorder = " send_null ASC, senddate DESC, mailing_id DESC  ";
    if (sort != null && !"".equals(sort.trim())) {
        orderby = getUpperSort(charColumns, sort);
        orderby = orderby + " " + direction;
    } else {
        orderby = defaultorder;
    }

    String sqlStatement = " SELECT *, case when senddate is null then 0 else 1 end as send_null "
            + " FROM (   SELECT a.mailing_id , a.shortname  , a.description ,   min(c."
            + AgnUtils.changeDateName() + ") senddate, m.shortname mailinglist "
            + " FROM  (mailing_tbl  a LEFT JOIN mailing_account_tbl c ON (a.mailing_id=c.mailing_id AND c.status_field='W')) "
            + " LEFT JOIN mailinglist_tbl m ON (  a.mailinglist_id=m.mailinglist_id AND  a.company_id=m.company_id) "
            + "  WHERE a.company_id = " + companyID + " AND a.deleted<>1 AND a.is_template="
            + (isTemplate ? 1 : 0) + mailingTypes
            + "  GROUP BY  a.mailing_id, a.shortname, a.description, m.shortname ) openemm ORDER BY " + orderby;

    int totalsize = aTemplate.queryForInt("select count(*) from ( " + sqlStatement + ") agn");

    sqlStatement = sqlStatement + " LIMIT " + offset + " , " + rownums;

    List<Map> tmpList = aTemplate.queryForList(sqlStatement);

    DynaProperty[] properties = new DynaProperty[] { new DynaProperty("mailingid", Long.class),
            new DynaProperty("shortname", String.class), new DynaProperty("description", String.class),
            new DynaProperty("mailinglist", String.class), new DynaProperty("senddate", Timestamp.class) };
    BasicDynaClass dynaClass = new BasicDynaClass("mailing", null, properties);

    List<DynaBean> result = new ArrayList<DynaBean>();
    for (Map row : tmpList) {
        DynaBean newBean;
        try {
            newBean = dynaClass.newInstance();

            newBean.set("mailingid", row.get("MAILING_ID"));
            newBean.set("shortname", row.get("SHORTNAME"));
            newBean.set("description", row.get("DESCRIPTION"));
            newBean.set("mailinglist", row.get("MAILINGLIST"));
            newBean.set("senddate", row.get("SENDDATE"));
            result.add(newBean);
        } catch (IllegalAccessException e) {
            AgnUtils.logger().error("IllegalAccessException: " + e);
            AgnUtils.logger().error(AgnUtils.getStackTrace(e));

        } catch (InstantiationException e) {
            AgnUtils.logger().error("InstantiationException: " + e);
            AgnUtils.logger().error(AgnUtils.getStackTrace(e));
        }
    }

    DynaBeanPaginatedListImpl paginatedList = new DynaBeanPaginatedListImpl(result, totalsize, rownums, page,
            sort, direction);

    return paginatedList;
}

From source file:org.agnitas.dao.impl.RecipientDaoImpl.java

@Override
public PaginatedListImpl<DynaBean> getRecipientList(Set<String> columns, String sqlStatementForCount,
        Object[] parametersForsCount, String sqlStatementForRows, Object[] parametersForsRows, String sort,
        String direction, int page, int rownums, int previousFullListSize)
        throws IllegalAccessException, InstantiationException {
    JdbcTemplate aTemplate = new JdbcTemplate((DataSource) this.applicationContext.getBean("dataSource"));
    int totalRows = aTemplate.queryForInt(sqlStatementForCount, parametersForsCount);
    if (previousFullListSize == 0 || previousFullListSize != totalRows) {
        page = 1;/*from w w w  .j a va 2  s.  c o  m*/
    }
    page = AgnUtils.getValidPageNumber(totalRows, page, rownums);

    String sortClause = "";
    if (!StringUtils.isBlank(sort)) {
        sortClause = " ORDER BY " + "lower(" + sort + ")";
        if (!StringUtils.isEmpty(direction)) {
            sortClause = sortClause + " " + direction;
        }
    }

    int offset = (page - 1) * rownums;

    if (AgnUtils.isOracleDB()) {
        sqlStatementForRows = "SELECT * from ( select " + StringUtils.join(columns, ", ") + ", rownum r from ( "
                + sqlStatementForRows + " )  where 1 = 1 " + sortClause + ") where r between " + (offset + 1)
                + " and " + (offset + rownums);
    } else {
        sqlStatementForRows = sqlStatementForRows + sortClause + " LIMIT  " + offset + " , " + rownums;
    }

    @SuppressWarnings("unchecked")
    List<Map<String, Object>> tmpList = aTemplate.queryForList(sqlStatementForRows, parametersForsRows);
    List<DynaBean> result = new ArrayList<DynaBean>();
    if (tmpList != null && !tmpList.isEmpty()) {
        DynaProperty[] properties = new DynaProperty[columns.size()];
        int i = 0;
        for (String c : columns) {
            properties[i++] = new DynaProperty(c.toLowerCase(), String.class);
        }
        BasicDynaClass dynaClass = new BasicDynaClass("recipient", null, properties);

        for (Map<String, Object> row : tmpList) {
            DynaBean bean = dynaClass.newInstance();
            for (String c : columns) {
                bean.set(c.toLowerCase(),
                        row.get(c.toUpperCase()) != null ? row.get(c.toUpperCase()).toString() : "");
            }
            result.add(bean);
        }
    }

    PaginatedListImpl<DynaBean> paginatedList = new PaginatedListImpl<DynaBean>(result, totalRows, rownums,
            page, sort, direction);
    return paginatedList;
}

From source file:org.agnitas.web.CampaignAction.java

/**
 * loads the campaigns//from  w w  w  . j a  v  a2 s .  c om
 * @throws InstantiationException 
 * @throws IllegalAccessException 
 *   
 * 
 */

public List<DynaBean> getCampaignList(HttpServletRequest request)
        throws IllegalAccessException, InstantiationException {
    ApplicationContext aContext = getWebApplicationContext();
    JdbcTemplate aTemplate = new JdbcTemplate((DataSource) aContext.getBean("dataSource"));

    List<Integer> charColumns = Arrays.asList(new Integer[] { 0, 1 });
    String[] columns = new String[] { "shortname", "description", "" };

    int sortcolumnindex = 0;
    if (request.getParameter(
            new ParamEncoder("campaign").encodeParameterName(TableTagParameters.PARAMETER_SORT)) != null) {
        sortcolumnindex = Integer.parseInt(request.getParameter(
                new ParamEncoder("campaign").encodeParameterName(TableTagParameters.PARAMETER_SORT)));
    }

    String sort = columns[sortcolumnindex];
    if (charColumns.contains(sortcolumnindex)) {
        sort = "upper( " + sort + " )";
    }

    int order = 1;
    if (request.getParameter(
            new ParamEncoder("campaign").encodeParameterName(TableTagParameters.PARAMETER_ORDER)) != null) {
        order = new Integer(request.getParameter(
                new ParamEncoder("campaign").encodeParameterName(TableTagParameters.PARAMETER_ORDER)));
    }

    String sqlStatement = "SELECT campaign_id, shortname, description FROM campaign_tbl WHERE company_id="
            + AgnUtils.getCompanyID(request) + " ORDER BY " + sort + " " + (order == 2 ? "DESC" : "ASC");
    List<Map> tmpList = aTemplate.queryForList(sqlStatement);

    DynaProperty[] properties = new DynaProperty[] { new DynaProperty("campaignId", Integer.class),
            new DynaProperty("shortname", String.class), new DynaProperty("description", String.class) };

    if (AgnUtils.isOracleDB()) {
        properties = new DynaProperty[] { new DynaProperty("campaignId", BigDecimal.class),
                new DynaProperty("shortname", String.class), new DynaProperty("description", String.class) };
    }

    BasicDynaClass dynaClass = new BasicDynaClass("campaign", null, properties);

    List<DynaBean> result = new ArrayList<DynaBean>();
    for (Map row : tmpList) {
        DynaBean newBean = dynaClass.newInstance();
        newBean.set("campaignId", row.get("CAMPAIGN_ID"));
        newBean.set("shortname", row.get("SHORTNAME"));
        newBean.set("description", row.get("DESCRIPTION"));
        result.add(newBean);

    }
    return result;
}

From source file:org.agnitas.web.EmmActionAction.java

public List<DynaBean> getActionList(HttpServletRequest request)
        throws IllegalAccessException, InstantiationException {
    ApplicationContext aContext = getWebApplicationContext();
    JdbcTemplate aTemplate = new JdbcTemplate((DataSource) aContext.getBean("dataSource"));
    List<Integer> charColumns = Arrays.asList(new Integer[] { 0, 1 });
    String[] columns = new String[] { "r.shortname", "r.description", "", "" };

    int sortcolumnindex = 0;
    if (request.getParameter(
            new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_SORT)) != null) {
        sortcolumnindex = Integer.parseInt(request.getParameter(
                new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_SORT)));
    }//from ww  w.j av  a 2s .  com

    String sort = columns[sortcolumnindex];
    if (charColumns.contains(sortcolumnindex)) {
        sort = "upper( " + sort + " )";
    }

    int order = 1;
    if (request.getParameter(
            new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_ORDER)) != null) {
        order = new Integer(request.getParameter(
                new ParamEncoder("emmaction").encodeParameterName(TableTagParameters.PARAMETER_ORDER)));
    }

    String sqlStatement = "SELECT r.action_id, r.shortname, r.description, count(u.form_id) used "
            + " FROM rdir_action_tbl r LEFT JOIN userform_tbl u ON (u.startaction_id = r.action_id or u.endaction_id = r.action_id) "
            + " WHERE r.company_id= " + AgnUtils.getCompanyID(request)
            + " GROUP BY  r.action_id, r.shortname, r.description " + " ORDER BY " + sort + " "
            + (order == 1 ? "ASC" : "DESC");

    List<Map> tmpList = aTemplate.queryForList(sqlStatement);
    DynaProperty[] properties = new DynaProperty[] { new DynaProperty("actionId", Long.class),
            new DynaProperty("shortname", String.class), new DynaProperty("description", String.class),
            new DynaProperty("used", Long.class) };

    if (AgnUtils.isOracleDB()) {
        properties = new DynaProperty[] { new DynaProperty("actionId", BigDecimal.class),
                new DynaProperty("shortname", String.class), new DynaProperty("description", String.class),
                new DynaProperty("used", BigDecimal.class) };
    }

    BasicDynaClass dynaClass = new BasicDynaClass("emmaction", null, properties);

    List<DynaBean> result = new ArrayList<DynaBean>();
    for (Map row : tmpList) {
        DynaBean newBean = dynaClass.newInstance();
        newBean.set("actionId", row.get("ACTION_ID"));
        newBean.set("shortname", row.get("SHORTNAME"));
        newBean.set("description", row.get("DESCRIPTION"));
        newBean.set("used", row.get("USED"));
        result.add(newBean);
    }
    return result;
}

From source file:org.agnitas.web.MailingStatAction.java

public List<DynaBean> getMailingStats(HttpServletRequest request)
        throws IllegalAccessException, InstantiationException {

    ApplicationContext aContext = getWebApplicationContext();
    JdbcTemplate aTemplate = new JdbcTemplate((DataSource) aContext.getBean("dataSource"));

    String sqlStatement = "SELECT a.mailing_id, a.shortname, a.description, b.shortname AS listname "
            + "FROM mailing_tbl a, mailinglist_tbl b WHERE a.company_id=" + AgnUtils.getCompanyID(request) + " "
            + "AND a.mailinglist_id=b.mailinglist_id AND a.deleted=0 AND a.is_template=0 ORDER BY mailing_id DESC";

    List<Map> tmpList = aTemplate.queryForList(sqlStatement);
    DynaProperty[] properties = new DynaProperty[] { new DynaProperty("mailingid", Long.class),
            new DynaProperty("shortname", String.class), new DynaProperty("description", String.class),
            new DynaProperty("listname", String.class), };
    if (AgnUtils.isOracleDB()) {
        properties = new DynaProperty[] { new DynaProperty("mailingid", BigDecimal.class),
                new DynaProperty("shortname", String.class), new DynaProperty("description", String.class),
                new DynaProperty("listname", String.class), };
    }//from ww w.j  a v a 2  s .  c  o  m
    BasicDynaClass dynaClass = new BasicDynaClass("mailingstat", null, properties);
    List<DynaBean> result = new ArrayList<DynaBean>();
    for (Map row : tmpList) {
        DynaBean newBean = dynaClass.newInstance();
        newBean.set("mailingid", row.get("MAILING_ID"));
        newBean.set("shortname", row.get("SHORTNAME"));
        newBean.set("description", row.get("DESCRIPTION"));
        newBean.set("listname", row.get("LISTNAME"));
        result.add(newBean);
    }

    return result;
}