public DBTable getTableDescription(String dbPool, String schema, String table) { DBTable retObj = new DBTable(schema, table); if (StringUtils.isBlank(table)) { Logger.error(null, this, "getTableDescription", "Table name is empty!"); return retObj; } Connection db = null; Statement st = null; ResultSet rs = null; try { if (StringUtils.isBlank(dbPool)) { db = Utils.getDataSource().getConnection(); } else { db = Utils.getUserDataSource(dbPool).getConnection(); } st = db.createStatement(); if (StringUtils.isNotBlank(schema)) { table = schema + "." + table; } String query = "DESC " + table; if (Logger.isDebugEnabled()) { Logger.debug(null, this, "getTableDescription", "QUERY=" + query); } rs = st.executeQuery(query); DBTableHelper.clearCache(); while (rs.next()) { ResultSetMetaData data = rs.getMetaData(); for (int i = 1; i <= data.getColumnCount(); i++) { String name = data.getColumnName(i); String value = rs.getString(i); if (StringUtils.isBlank(value)) { value = ""; } DBTableHelper.addItem(retObj, name, value, -1); } } if (retObj.getFields() != null) { List<String> conds = new ArrayList<String>(); for (int i = 0; i < retObj.getFields().size(); i++) { String sKey = DBTableHelper.getListValue(retObj.getKeys(), i); boolean bCond = Utils.string2bool(DBTableHelper.getListValue(retObj.getConds(), i)); conds.add(((bCond || StringUtils.containsIgnoreCase(sKey, "PRI")) ? "1" : "0")); } retObj.setConds(conds); } DBTableHelper.clearCache(); } catch (SQLException e) { Logger.error(null, this, "getTableDescription", "SQLException caught: ", e); } finally { DatabaseInterface.closeResources(db, st, rs); } return retObj; }
/** * Executes the block main action * * @param dataSet a value of type 'DataSet' * @return the port to go to the next block */ public Port after(UserInfoInterface userInfo, ProcessData procData) { Port outPort; String login = userInfo.getUtilizador(); try { String sCondition = null; boolean bEvalResult = false; sCondition = this.getAttribute("condition"); if (StringUtils.isEmpty(sCondition)) { Logger.warning( login, this, "after", procData.getSignature() + "empty condition to evaluate!! Assuming false"); bEvalResult = false; } else { try { bEvalResult = procData.query(userInfo, sCondition); Logger.debug(login, this, "after", sCondition + " evaluated " + bEvalResult); } catch (Exception ei) { bEvalResult = false; Logger.error( login, this, "after", procData.getSignature() + "caught exception evaluation condition (assuming false): " + sCondition, ei); } } if (bEvalResult) { outPort = portTrue; } else { outPort = portFalse; } this.addToLog( "Evaluated '" + sCondition + "' to '" + bEvalResult + "', using " + outPort.getName()); } catch (Exception e) { Logger.error( login, this, "after", procData.getSignature() + "caught exception: " + e.getMessage(), e); outPort = portFalse; } this.addToLog("Using '" + outPort.getName() + "';"); this.saveLogs(userInfo, procData, this); return outPort; }
public void generate( UserInfoInterface userInfo, ProcessData process, ParserContext ch, Field field, boolean even) throws SAXException { Logger.info(userInfo.getUtilizador(), this, "generate", "Generating from template"); // TODO if disabled, return; String template = field.getProperties().get("template"); IFlowData flow = BeanFactory.getFlowHolderBean().getFlow(userInfo, process.getFlowId()); Form formTemplate = null; if (flow != null) formTemplate = flow.getFormTemplate(template); if (null == formTemplate) { // ignore or throw error? Logger.error( userInfo.getUtilizador(), this, "generate", "Could not parse template: '" + template + "'"); ch.startElement("field"); ch.addElement("type", "message"); ch.addElement("text", "Template de formulário inválida"); ch.addElement("even_field", String.valueOf(even)); ch.endElement("field"); return; } // allways get first tab Tab tab = formTemplate.getTabs().get(0); for (Field subField : tab.getFields()) { IWidget subfieldWidget = newWidget(subField.getType()); subfieldWidget.generate(userInfo, process, ch, subField, even); even = !even; } }
public void process( UserInfoInterface userInfo, ProcessData process, Field field, FormData request) { // TODO if readonly or disabled, return; String template = field.getProperties().get("template"); Form formTemplate = null; try { // FIXME obter a template formTemplate = Marshaller.create(Form.class).unmarshall(new JSONObject("{}")); } catch (JSONException e) { // ignore or throw error? Logger.error( userInfo.getUtilizador(), this, "process", "Could not parse template: '" + template + "'"); return; } Tab tab = formTemplate.getTabs().get(0); for (Field subField : tab.getFields()) { IWidget subfieldWidget = newWidget(subField.getType()); subfieldWidget.process(userInfo, process, subField, request); } }
/** * Executes the block main action * * @param dataSet a value of type 'DataSet' * @return the port to go to the next block */ public Port after(UserInfoInterface userInfo, ProcessData procData) { Port outPort = portFalse; try { String sLogin = null; String sPass = null; sLogin = this.getAttribute(LOGIN_ATTR); sLogin = procData.transform(userInfo, sLogin); try { sPass = procData.transform(userInfo, this.getAttribute(PASS_ATTR)); } catch (Exception ee) { } AuthProfile ap = BeanFactory.getAuthProfileBean(); boolean bOk = ap.checkUser(sLogin, sPass); Logger.info( userInfo.getUtilizador(), this, "after", "[" + procData.getFlowId() + "," + procData.getPid() + "," + procData.getSubPid() + "] " + "checked authentication for " + sLogin + ": " + bOk); if (bOk) { outPort = portTrue; } else { outPort = portFalse; } } catch (Exception e) { Logger.error( userInfo.getUtilizador(), this, "after", procData.getSignature(this.getId()) + "Exception caught: " + e.getMessage()); e.printStackTrace(); } return outPort; }