@Override public String get() throws Exception { if (this.checkpermission("get")) { int id = ParameterCook.prepareId(oRequest); String data = null; Connection oConnection = null; ConnectionInterface oDataConnectionSource = null; try { oDataConnectionSource = getSourceConnection(); oConnection = oDataConnectionSource.newConnection(); EstadoDao oEstadoDao = new EstadoDao(oConnection); EstadoBean oEstadoBean = new EstadoBean(id); oEstadoBean = oEstadoDao.get(oEstadoBean, AppConfigurationHelper.getJsonDepth()); Gson gson = AppConfigurationHelper.getGson(); data = JsonMessage.getJson("200", AppConfigurationHelper.getGson().toJson(oEstadoBean)); } catch (Exception ex) { ExceptionBooster.boost( new Exception(this.getClass().getName() + ":get ERROR: " + ex.getMessage())); } finally { if (oConnection != null) { oConnection.close(); } if (oDataConnectionSource != null) { oDataConnectionSource.disposeConnection(); } } return data; } else { return JsonMessage.getJsonMsg("401", "Unauthorized"); } }
@Override public String getcount() throws Exception { if (this.checkpermission("getcount")) { String data = null; ArrayList<FilterBeanHelper> alFilter = ParameterCook.prepareFilter(oRequest); Connection oConnection = null; ConnectionInterface oDataConnectionSource = null; try { oDataConnectionSource = getSourceConnection(); oConnection = oDataConnectionSource.newConnection(); EstadoDao oEstadoDao = new EstadoDao(oConnection); data = JsonMessage.getJson("200", Integer.toString(oEstadoDao.getCount(alFilter))); } catch (Exception ex) { ExceptionBooster.boost( new Exception(this.getClass().getName() + ":getCount ERROR: " + ex.getMessage())); } finally { if (oConnection != null) { oConnection.close(); } if (oDataConnectionSource != null) { oDataConnectionSource.disposeConnection(); } } return data; } else { return JsonMessage.getJsonMsg("401", "Unauthorized"); } }
@Override public String remove() throws Exception { if (this.checkpermission("remove")) { Integer id = ParameterCook.prepareId(oRequest); String resultado = null; Connection oConnection = null; ConnectionInterface oDataConnectionSource = null; try { oDataConnectionSource = getSourceConnection(); oConnection = oDataConnectionSource.newConnection(); oConnection.setAutoCommit(false); EstadoDao oEstadoDao = new EstadoDao(oConnection); resultado = JsonMessage.getJson("200", (String) oEstadoDao.remove(id).toString()); oConnection.commit(); } catch (Exception ex) { if (oConnection != null) { oConnection.rollback(); } ExceptionBooster.boost( new Exception(this.getClass().getName() + ":remove ERROR: " + ex.getMessage())); } finally { if (oConnection != null) { oConnection.close(); } if (oDataConnectionSource != null) { oDataConnectionSource.disposeConnection(); } } return resultado; } else { return JsonMessage.getJsonMsg("401", "Unauthorized"); } }
@Override public String getpage() throws Exception { if (this.checkpermission("getpage")) { int intRegsPerPag = ParameterCook.prepareRpp(oRequest); int intPage = ParameterCook.preparePage(oRequest); ArrayList<FilterBeanHelper> alFilter = ParameterCook.prepareFilter(oRequest); HashMap<String, String> hmOrder = ParameterCook.prepareOrder(oRequest); String data = null; Connection oConnection = null; ConnectionInterface oDataConnectionSource = null; try { oDataConnectionSource = getSourceConnection(); oConnection = oDataConnectionSource.newConnection(); EstadoDao oEstadoDao = new EstadoDao(oConnection); List<EstadoBean> arrBeans = oEstadoDao.getPage( intRegsPerPag, intPage, alFilter, hmOrder, AppConfigurationHelper.getJsonDepth()); data = JsonMessage.getJson("200", AppConfigurationHelper.getGson().toJson(arrBeans)); } catch (Exception ex) { ExceptionBooster.boost( new Exception(this.getClass().getName() + ":getPage ERROR: " + ex.getMessage())); } finally { if (oConnection != null) { oConnection.close(); } if (oDataConnectionSource != null) { oDataConnectionSource.disposeConnection(); } } return data; } else { return JsonMessage.getJsonMsg("401", "Unauthorized"); } }
@Override public String set() throws Exception { if (this.checkpermission("set")) { String jason = ParameterCook.prepareJson(oRequest); String resultado = null; Connection oConnection = null; ConnectionInterface oDataConnectionSource = null; try { oDataConnectionSource = getSourceConnection(); oConnection = oDataConnectionSource.newConnection(); oConnection.setAutoCommit(false); EstadoDao oEstadoDao = new EstadoDao(oConnection); EstadoBean oEstadoBean = new EstadoBean(); oEstadoBean = AppConfigurationHelper.getGson().fromJson(jason, oEstadoBean.getClass()); if (oEstadoBean != null) { Integer iResult = oEstadoDao.set(oEstadoBean); if (iResult >= 1) { resultado = JsonMessage.getJson("200", iResult.toString()); } else { resultado = JsonMessage.getJson("500", "Error during registry set"); } } else { resultado = JsonMessage.getJson("500", "Error during registry set"); } oConnection.commit(); } catch (Exception ex) { if (oConnection != null) { oConnection.rollback(); } ExceptionBooster.boost( new Exception(this.getClass().getName() + ":set ERROR: " + ex.getMessage())); } finally { if (oConnection != null) { oConnection.close(); } if (oDataConnectionSource != null) { oDataConnectionSource.disposeConnection(); } } return resultado; } else { return JsonMessage.getJsonMsg("401", "Unauthorized"); } }