How to use parseBoolean method of org.cerberus.util.StringUtil class

Best Cerberus-source code snippet using org.cerberus.util.StringUtil.parseBoolean

Source:CountryEnvParamDAO.java Github

copy

Full Screen

...651 String eMailBodyRevision = resultSet.getString("eMailBodyRevision");652 String type = resultSet.getString("type");653 String eMailBodyChain = resultSet.getString("eMailBodyChain");654 String eMailBodyDisableEnvironment = resultSet.getString("eMailBodyDisableEnvironment");655 boolean active1 = StringUtil.parseBoolean(resultSet.getString("active"));656 boolean maintenanceAct = StringUtil.parseBoolean(resultSet.getString("maintenanceact"));657 String maintenanceStr = resultSet.getString("maintenancestr");658 String maintenanceEnd = resultSet.getString("maintenanceend");659 String envGp1 = resultSet.getString("gp1");660 cepList.add(factoryCountryEnvParam.create(system1, count, env, description, build1, revision1, chain, distribList, eMailBodyRevision,661 type, eMailBodyChain, eMailBodyDisableEnvironment, active1, maintenanceAct, maintenanceStr, maintenanceEnd, envGp1));662 }663 //get the total number of rows664 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");665 int nrTotalRows = 0;666 if (resultSet != null && resultSet.next()) {667 nrTotalRows = resultSet.getInt(1);668 }669 if (cepList.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.670 LOG.error("Partial Result in the query.");671 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);672 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));673 response = new AnswerList<>(cepList, nrTotalRows);674 } else if (cepList.size() <= 0) {675 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);676 response = new AnswerList<>(cepList, nrTotalRows);677 } else {678 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);679 msg.setDescription(msg.getDescription().replace("%ITEM%", "CountryEnvParam").replace("%OPERATION%", "SELECT"));680 response = new AnswerList<>(cepList, nrTotalRows);681 }682 } catch (SQLException exception) {683 LOG.error("Unable to execute query : " + exception.toString());684 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);685 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));686 } finally {687 if (resultSet != null) {688 resultSet.close();689 }690 }691 } catch (SQLException exception) {692 LOG.error("Unable to execute query : " + exception.toString());693 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);694 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));695 } finally {696 if (preStat != null) {697 preStat.close();698 }699 }700 } catch (SQLException exception) {701 LOG.error("Unable to execute query : " + exception.toString());702 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);703 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));704 } finally {705 try {706 if (!this.databaseSpring.isOnTransaction()) {707 if (connection != null) {708 connection.close();709 }710 }711 } catch (SQLException exception) {712 LOG.warn("Unable to close connection : " + exception.toString());713 }714 }715 response.setResultMessage(msg);716 response.setDataList(cepList);717 return response;718 }719 @Override720 public AnswerList<CountryEnvParam> readDistinctCountryByVariousByCriteria(List<String> systems, String country, String environment, String build, String revision, String active, String envGp, int start, int amount, String colName, String dir, String searchTerm, String individualSearch) {721 AnswerList<CountryEnvParam> response = new AnswerList<>();722 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);723 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));724 List<CountryEnvParam> cepList = new ArrayList<>();725 StringBuilder searchSQL = new StringBuilder();726 StringBuilder query = new StringBuilder();727 //SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that 728 //were applied -- used for pagination p729 query.append("SELECT SQL_CALC_FOUND_ROWS ");730 query.append(" max(cev.`system`) `system`, max(cev.Environment) Environment, Country, '' Description, ");731 query.append(" max(cev.build) build, max(cev.revision) revision, max(cev.chain) chain, '' DistribList, ");732 query.append(" '' EMailBodyRevision, max(cev.Type) type, '' EMailBodyChain, '' EMailBodyDisableEnvironment, ");733 query.append(" max(cev.Active) active, max(cev.maintenanceact) maintenanceact, max(cev.maintenancestr) maintenancestr, max(cev.maintenanceend) maintenanceend, ");734 query.append("inv.gp1");735 query.append(" FROM countryenvparam cev ");736 query.append(" LEFT OUTER JOIN invariant inv on inv.idname='COUNTRY' and inv.value=cev.country ");737 searchSQL.append(" where 1=1 ");738 if ((systems != null) && (!systems.isEmpty())) {739 searchSQL.append(" and (").append(SqlUtil.generateInClause("`System`", systems)).append(") ");740 }741// if (!StringUtil.isNullOrEmpty(system)) {742// searchSQL.append(" and (`System` = ? )");743// }744 if (!StringUtil.isNullOrEmpty(active)) {745 searchSQL.append(" and (`active` = ? )");746 }747 if (!StringUtil.isNullOrEmpty(country)) {748 searchSQL.append(" and (`country` = ? )");749 }750 if (!StringUtil.isNullOrEmpty(environment)) {751 searchSQL.append(" and (`environment` = ? )");752 }753 if (!StringUtil.isNullOrEmpty(build)) {754 searchSQL.append(" and (`build` = ? )");755 }756 if (!StringUtil.isNullOrEmpty(revision)) {757 searchSQL.append(" and (`revision` = ? )");758 }759 if (!StringUtil.isNullOrEmpty(envGp)) {760 searchSQL.append(" and (inv.`gp1` = ? )");761 }762 query.append(searchSQL);763 query.append(" group by `country` ");764 query.append(" order by `country` ");765 if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {766 query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);767 } else {768 query.append(" limit ").append(start).append(" , ").append(amount);769 }770 // Debug message on SQL.771 if (LOG.isDebugEnabled()) {772 LOG.debug("SQL : " + query.toString());773 LOG.debug("SQL.system : " + systems);774 LOG.debug("SQL.active : " + active);775 }776 Connection connection = this.databaseSpring.connect();777 try {778 PreparedStatement preStat = connection.prepareStatement(query.toString());779 try {780 int i = 1;781 if ((systems != null) && (!systems.isEmpty())) {782 for (String mysystem : systems) {783 preStat.setString(i++, mysystem);784 }785 }786// if (!StringUtil.isNullOrEmpty(system)) {787// preStat.setString(i++, system);788// }789 if (!StringUtil.isNullOrEmpty(active)) {790 preStat.setString(i++, active);791 }792 if (!StringUtil.isNullOrEmpty(country)) {793 preStat.setString(i++, country);794 }795 if (!StringUtil.isNullOrEmpty(environment)) {796 preStat.setString(i++, environment);797 }798 if (!StringUtil.isNullOrEmpty(build)) {799 preStat.setString(i++, build);800 }801 if (!StringUtil.isNullOrEmpty(revision)) {802 preStat.setString(i++, revision);803 }804 if (!StringUtil.isNullOrEmpty(envGp)) {805 preStat.setString(i++, envGp);806 }807 ResultSet resultSet = preStat.executeQuery();808 try {809 //gets the data810 while (resultSet.next()) {811 String system1 = resultSet.getString("System");812 String count = resultSet.getString("Country");813 String env = resultSet.getString("Environment");814 String description = resultSet.getString("Description");815 String build1 = resultSet.getString("Build");816 String revision1 = resultSet.getString("Revision");817 String chain = resultSet.getString("chain");818 String distribList = resultSet.getString("distribList");819 String eMailBodyRevision = resultSet.getString("eMailBodyRevision");820 String type = resultSet.getString("type");821 String eMailBodyChain = resultSet.getString("eMailBodyChain");822 String eMailBodyDisableEnvironment = resultSet.getString("eMailBodyDisableEnvironment");823 boolean active1 = StringUtil.parseBoolean(resultSet.getString("active"));824 boolean maintenanceAct = StringUtil.parseBoolean(resultSet.getString("maintenanceact"));825 String maintenanceStr = resultSet.getString("maintenancestr");826 String maintenanceEnd = resultSet.getString("maintenanceend");827 String envGp1 = resultSet.getString("gp1");828 cepList.add(factoryCountryEnvParam.create(system1, count, env, description, build1, revision1, chain, distribList, eMailBodyRevision,829 type, eMailBodyChain, eMailBodyDisableEnvironment, active1, maintenanceAct, maintenanceStr, maintenanceEnd, envGp1));830 }831 //get the total number of rows832 resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");833 int nrTotalRows = 0;834 if (resultSet != null && resultSet.next()) {835 nrTotalRows = resultSet.getInt(1);836 }837 if (cepList.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.838 LOG.error("Partial Result in the query.");839 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);840 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));841 response = new AnswerList<>(cepList, nrTotalRows);842 } else if (cepList.size() <= 0) {843 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);844 response = new AnswerList<>(cepList, nrTotalRows);845 } else {846 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);847 msg.setDescription(msg.getDescription().replace("%ITEM%", "CountryEnvParam").replace("%OPERATION%", "SELECT"));848 response = new AnswerList<>(cepList, nrTotalRows);849 }850 } catch (SQLException exception) {851 LOG.error("Unable to execute query : " + exception.toString());852 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);853 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));854 } finally {855 if (resultSet != null) {856 resultSet.close();857 }858 }859 } catch (SQLException exception) {860 LOG.error("Unable to execute query : " + exception.toString());861 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);862 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));863 } finally {864 if (preStat != null) {865 preStat.close();866 }867 }868 } catch (SQLException exception) {869 LOG.error("Unable to execute query : " + exception.toString());870 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);871 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));872 } finally {873 try {874 if (!this.databaseSpring.isOnTransaction()) {875 if (connection != null) {876 connection.close();877 }878 }879 } catch (SQLException exception) {880 LOG.warn("Unable to close connection : " + exception.toString());881 }882 }883 response.setResultMessage(msg);884 response.setDataList(cepList);885 return response;886 }887 @Override888 public Answer create(CountryEnvParam cep) {889 MessageEvent msg = null;890 StringBuilder query = new StringBuilder();891 query.append("INSERT INTO `countryenvparam` (`system`, `country`, `environment`, `build`, `revision`,`chain`, `distriblist`, `eMailBodyRevision`, `type`,`eMailBodyChain`, ");892 query.append("`eMailBodyDisableEnvironment`, `active`, `maintenanceact`, `maintenancestr`, `maintenanceend`, `description`) ");893 query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");894 // Debug message on SQL.895 if (LOG.isDebugEnabled()) {896 LOG.debug("SQL : " + query.toString());897 }898 Connection connection = this.databaseSpring.connect();899 try {900 PreparedStatement preStat = connection.prepareStatement(query.toString());901 try {902 preStat.setString(1, cep.getSystem());903 preStat.setString(2, cep.getCountry());904 preStat.setString(3, cep.getEnvironment());905 preStat.setString(4, cep.getBuild());906 preStat.setString(5, cep.getRevision());907 preStat.setString(6, cep.getChain());908 preStat.setString(7, cep.getDistribList());909 preStat.setString(8, cep.geteMailBodyRevision());910 preStat.setString(9, cep.getType());911 preStat.setString(10, cep.geteMailBodyChain());912 preStat.setString(11, cep.geteMailBodyDisableEnvironment());913 if (cep.isActive()) {914 preStat.setString(12, "Y");915 } else {916 preStat.setString(12, "N");917 }918 if (cep.isMaintenanceAct()) {919 preStat.setString(13, "Y");920 } else {921 preStat.setString(13, "N");922 }923 preStat.setString(14, cep.getMaintenanceStr());924 preStat.setString(15, cep.getMaintenanceEnd());925 preStat.setString(16, cep.getDescription());926 preStat.executeUpdate();927 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);928 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));929 } catch (SQLException exception) {930 LOG.error("Unable to execute query : " + exception.toString());931 if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) { //23000 is the sql state for duplicate entries932 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);933 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));934 } else {935 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);936 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));937 }938 } finally {939 preStat.close();940 }941 } catch (SQLException exception) {942 LOG.error("Unable to execute query : " + exception.toString());943 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);944 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));945 } finally {946 try {947 if (connection != null) {948 connection.close();949 }950 } catch (SQLException exception) {951 LOG.warn("Unable to close connection : " + exception.toString());952 }953 }954 return new Answer(msg);955 }956 @Override957 public Answer delete(CountryEnvParam cep) {958 MessageEvent msg = null;959 final String query = "DELETE FROM `countryenvparam` WHERE `system`=? and `country`=? and `environment`=?";960 // Debug message on SQL.961 if (LOG.isDebugEnabled()) {962 LOG.debug("SQL : " + query);963 }964 Connection connection = this.databaseSpring.connect();965 try {966 PreparedStatement preStat = connection.prepareStatement(query);967 try {968 preStat.setString(1, cep.getSystem());969 preStat.setString(2, cep.getCountry());970 preStat.setString(3, cep.getEnvironment());971 preStat.executeUpdate();972 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);973 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));974 } catch (SQLException exception) {975 LOG.error("Unable to execute query : " + exception.toString());976 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);977 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));978 } finally {979 preStat.close();980 }981 } catch (SQLException exception) {982 LOG.error("Unable to execute query : " + exception.toString());983 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);984 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));985 } finally {986 try {987 if (connection != null) {988 connection.close();989 }990 } catch (SQLException exception) {991 LOG.warn("Unable to close connection : " + exception.toString());992 }993 }994 return new Answer(msg);995 }996 @Override997 public Answer update(CountryEnvParam cep) {998 MessageEvent msg = null;999 final StringBuilder query = new StringBuilder("UPDATE `countryenvparam` SET `build`=?, ");1000 query.append("`revision`=?,`chain`=?, `distriblist`=?, `eMailBodyRevision`=?, `type`=?,`eMailBodyChain`=?,");1001 query.append("`eMailBodyDisableEnvironment`=?, `active`=?, `maintenanceact`=?, `maintenancestr`=?, `maintenanceend`=?, `description`=? ");1002 query.append(" where `system`=? and `country`=? and `environment`=? ");1003 // Debug message on SQL.1004 if (LOG.isDebugEnabled()) {1005 LOG.debug("SQL : " + query.toString());1006 LOG.debug("SQL.param.maintenancestr : " + cep.getMaintenanceStr());1007 }1008 Connection connection = this.databaseSpring.connect();1009 try {1010 PreparedStatement preStat = connection.prepareStatement(query.toString());1011 try {1012 preStat.setString(1, ParameterParserUtil.parseStringParam(cep.getBuild(), ""));1013 preStat.setString(2, cep.getRevision());1014 preStat.setString(3, cep.getChain());1015 preStat.setString(4, cep.getDistribList());1016 preStat.setString(5, cep.geteMailBodyRevision());1017 preStat.setString(6, cep.getType());1018 preStat.setString(7, cep.geteMailBodyChain());1019 preStat.setString(8, cep.geteMailBodyDisableEnvironment());1020 if (cep.isActive()) {1021 preStat.setString(9, "Y");1022 } else {1023 preStat.setString(9, "N");1024 }1025 if (cep.isMaintenanceAct()) {1026 preStat.setString(10, "Y");1027 } else {1028 preStat.setString(10, "N");1029 }1030 preStat.setString(11, cep.getMaintenanceStr());1031 preStat.setString(12, cep.getMaintenanceEnd());1032 preStat.setString(13, cep.getDescription());1033 preStat.setString(14, cep.getSystem());1034 preStat.setString(15, cep.getCountry());1035 preStat.setString(16, cep.getEnvironment());1036 preStat.executeUpdate();1037 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1038 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));1039 } catch (SQLException exception) {1040 LOG.error("Unable to execute query : " + exception.toString());1041 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1042 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1043 } finally {1044 preStat.close();1045 }1046 } catch (SQLException exception) {1047 LOG.error("Unable to execute query : " + exception.toString());1048 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1049 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1050 } finally {1051 try {1052 if (connection != null) {1053 connection.close();1054 }1055 } catch (SQLException exception) {1056 LOG.warn("Unable to close connection : " + exception.toString());1057 }1058 }1059 return new Answer(msg);1060 }1061 @Override1062 public AnswerList<String> readDistinctValuesByCriteria(List<String> system, String searchTerm, Map<String, List<String>> individualSearch, String columnName) {1063 AnswerList<String> answer = new AnswerList<>();1064 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1065 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));1066 List<String> distinctValues = new ArrayList<>();1067 StringBuilder searchSQL = new StringBuilder();1068 List<String> individalColumnSearchValues = new ArrayList<>();1069 StringBuilder query = new StringBuilder();1070 if (columnName.equals("envGp")) {1071 columnName = "inv.gp1";1072 }1073 query.append("SELECT distinct ");1074 query.append(columnName);1075 query.append(" as distinctValues FROM countryenvparam cev ");1076 query.append(" LEFT OUTER JOIN invariant inv on inv.idname='ENVIRONMENT' and inv.value=cev.environment ");1077 searchSQL.append(" where 1=1 ");1078 if (system != null && !system.isEmpty()) {1079 searchSQL.append(" and ");1080 searchSQL.append(SqlUtil.generateInClause("`System`", system));1081 }1082 if (!StringUtil.isNullOrEmpty(searchTerm)) {1083 searchSQL.append(" and (`system` like ?");1084 searchSQL.append(" or `country` like ?");1085 searchSQL.append(" or `environment` like ?");1086 searchSQL.append(" or `description` like ?");1087 searchSQL.append(" or `build` like ?");1088 searchSQL.append(" or `revision` like ?");1089 searchSQL.append(" or `chain` like ?");1090 searchSQL.append(" or `distriblist` like ?");1091 searchSQL.append(" or `emailbodyrevision` like ?");1092 searchSQL.append(" or `type` like ?");1093 searchSQL.append(" or `emailbodychain` like ?");1094 searchSQL.append(" or `emailbodydisableenvironment` like ?");1095 searchSQL.append(" or `active` like ?");1096 searchSQL.append(" or `maintenanceact` like ?");1097 searchSQL.append(" or `maintenancestr` like ?");1098 searchSQL.append(" or `maintenanceend` like ?)");1099 }1100 if (individualSearch != null && !individualSearch.isEmpty()) {1101 searchSQL.append(" and ( 1=1 ");1102 for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {1103 searchSQL.append(" and ");1104 searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));1105 individalColumnSearchValues.addAll(entry.getValue());1106 }1107 searchSQL.append(" )");1108 }1109 query.append(searchSQL);1110 query.append(" order by ").append(columnName).append(" asc");1111 // Debug message on SQL.1112 if (LOG.isDebugEnabled()) {1113 LOG.debug("SQL : " + query.toString());1114 }1115 try (Connection connection = databaseSpring.connect();1116 PreparedStatement preStat = connection.prepareStatement(query.toString());1117 Statement stm = connection.createStatement();) {1118 int i = 1;1119 if (system != null && !system.isEmpty()) {1120 for (String sys : system) {1121 preStat.setString(i++, sys);1122 }1123 }1124 if (!StringUtil.isNullOrEmpty(searchTerm)) {1125 preStat.setString(i++, "%" + searchTerm + "%");1126 preStat.setString(i++, "%" + searchTerm + "%");1127 preStat.setString(i++, "%" + searchTerm + "%");1128 preStat.setString(i++, "%" + searchTerm + "%");1129 preStat.setString(i++, "%" + searchTerm + "%");1130 preStat.setString(i++, "%" + searchTerm + "%");1131 preStat.setString(i++, "%" + searchTerm + "%");1132 preStat.setString(i++, "%" + searchTerm + "%");1133 preStat.setString(i++, "%" + searchTerm + "%");1134 preStat.setString(i++, "%" + searchTerm + "%");1135 preStat.setString(i++, "%" + searchTerm + "%");1136 preStat.setString(i++, "%" + searchTerm + "%");1137 preStat.setString(i++, "%" + searchTerm + "%");1138 preStat.setString(i++, "%" + searchTerm + "%");1139 preStat.setString(i++, "%" + searchTerm + "%");1140 preStat.setString(i++, "%" + searchTerm + "%");1141 }1142 for (String individualColumnSearchValue : individalColumnSearchValues) {1143 preStat.setString(i++, individualColumnSearchValue);1144 }1145 try (ResultSet resultSet = preStat.executeQuery();1146 ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()");) {1147 //gets the data1148 while (resultSet.next()) {1149 distinctValues.add(resultSet.getString("distinctValues") == null ? "" : resultSet.getString("distinctValues"));1150 }1151 int nrTotalRows = 0;1152 if (rowSet != null && rowSet.next()) {1153 nrTotalRows = rowSet.getInt(1);1154 }1155 if (distinctValues.size() >= MAX_ROW_SELECTED) { // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.1156 LOG.error("Partial Result in the query.");1157 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);1158 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));1159 answer = new AnswerList<>(distinctValues, nrTotalRows);1160 } else if (distinctValues.size() <= 0) {1161 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);1162 answer = new AnswerList<>(distinctValues, nrTotalRows);1163 } else {1164 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);1165 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));1166 answer = new AnswerList<>(distinctValues, nrTotalRows);1167 }1168 } catch (SQLException exception) {1169 LOG.error("Unable to execute query : " + exception.toString());1170 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);1171 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));1172 }1173 } catch (Exception e) {1174 LOG.warn("Unable to execute query : " + e.toString());1175 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",1176 e.toString());1177 } finally {1178 // We always set the result message1179 answer.setResultMessage(msg);1180 }1181 answer.setResultMessage(msg);1182 answer.setDataList(distinctValues);1183 return answer;1184 }1185 private CountryEnvParam loadFromResultSet(ResultSet resultSet) throws SQLException {1186 String system = resultSet.getString("cev.System");1187 String count = resultSet.getString("cev.Country");1188 String env = resultSet.getString("cev.Environment");1189 String description = resultSet.getString("cev.Description");1190 String build = resultSet.getString("cev.Build");1191 String revision = resultSet.getString("cev.Revision");1192 String chain = resultSet.getString("cev.chain");1193 String distribList = resultSet.getString("cev.distribList");1194 String eMailBodyRevision = resultSet.getString("cev.eMailBodyRevision");1195 String type = resultSet.getString("cev.type");1196 String eMailBodyChain = resultSet.getString("cev.eMailBodyChain");1197 String eMailBodyDisableEnvironment = resultSet.getString("cev.eMailBodyDisableEnvironment");1198 boolean active = StringUtil.parseBoolean(resultSet.getString("cev.active"));1199 boolean maintenanceAct = StringUtil.parseBoolean(resultSet.getString("cev.maintenanceact"));1200 String maintenanceStr = resultSet.getString("cev.maintenancestr");1201 String maintenanceEnd = resultSet.getString("cev.maintenanceend");1202 String envGp = resultSet.getString("inv.gp1");1203 return factoryCountryEnvParam.create(system, count, env, description, build, revision, chain, distribList, eMailBodyRevision,1204 type, eMailBodyChain, eMailBodyDisableEnvironment, active, maintenanceAct, maintenanceStr, maintenanceEnd, envGp);1205 }1206}...

Full Screen

Full Screen

Source:KafkaService.java Github

copy

Full Screen

...122 // Setting timeout although does not seem to work fine as result on aiven is always 60000 ms.123 serviceContent.add(factoryAppServiceContent.create(null, ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, String.valueOf(timeoutMs), "Y", 0, "", "", null, "", null));124 serviceContent.add(factoryAppServiceContent.create(null, ProducerConfig.DELIVERY_TIMEOUT_MS_CONFIG, String.valueOf(timeoutMs), "Y", 0, "", "", null, "", null));125 for (AppServiceContent object : serviceContent) {126 if (StringUtil.parseBoolean(object.getActive())) {127 props.put(object.getKey(), object.getValue());128 }129 }130 serviceREST.setServicePath(bootstrapServers);131 serviceREST.setKafkaTopic(topic);132 serviceREST.setKafkaKey(key);133 serviceREST.setServiceRequest(eventMessage);134 serviceREST.setHeaderList(serviceHeader);135 serviceREST.setContentList(serviceContent);136 int partition = -1;137 long offset = -1;138 KafkaProducer<String, String> producer = null;139 try {140 LOG.info("Open Producer : " + getKafkaConsumerKey(topic, bootstrapServers));141 producer = new KafkaProducer<>(props);142 ProducerRecord<String, String> record = new ProducerRecord<>(topic, key, eventMessage);143 for (AppServiceHeader object : serviceHeader) {144 if (StringUtil.parseBoolean(object.getActive())) {145 record.headers().add(new RecordHeader(object.getKey(), object.getValue().getBytes()));146 }147 }148 LOG.debug("Producing Kafka message - topic : " + topic + " key : " + key + " message : " + eventMessage);149 RecordMetadata metadata = producer.send(record).get(); //Wait for a responses150 partition = metadata.partition();151 offset = metadata.offset();152 LOG.debug("Produced Kafka message - topic : " + topic + " key : " + key + " partition : " + partition + " offset : " + offset);153 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALLSERVICE_PRODUCEKAFKA);154 } catch (Exception ex) {155 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE_PRODUCEKAFKA);156 message.setDescription(message.getDescription().replace("%EX%", ex.toString() + " " + StringUtil.getExceptionCauseFromString(ex)));157 LOG.debug(ex, ex);158 } finally {159 if (producer != null) {160 producer.flush();161 if (producer != null) {162 try {163 producer.close();164 } catch (Exception e) {165 LOG.error(e, e);166 }167 }168 LOG.info("Closed Producer : " + getKafkaConsumerKey(topic, bootstrapServers));169 } else {170 LOG.info("Producer not opened : " + getKafkaConsumerKey(topic, bootstrapServers));171 }172 }173 serviceREST.setKafkaResponseOffset(offset);174 serviceREST.setKafkaResponsePartition(partition);175 serviceREST.setResponseHTTPBodyContentType(appServiceService.guessContentType(serviceREST, AppService.RESPONSEHTTPBODYCONTENTTYPE_JSON));176 result.setItem(serviceREST);177 message.setDescription(message.getDescription().replace("%SERVICEMETHOD%", AppService.METHOD_KAFKAPRODUCE));178 message.setDescription(message.getDescription().replace("%TOPIC%", topic));179 message.setDescription(message.getDescription().replace("%PART%", String.valueOf(partition)));180 message.setDescription(message.getDescription().replace("%OFFSET%", String.valueOf(offset)));181 result.setResultMessage(message);182 return result;183 }184 @SuppressWarnings("unchecked")185 @Override186 public AnswerItem<Map<TopicPartition, Long>> seekEvent(String topic, String bootstrapServers,187 List<AppServiceContent> serviceContent, int timeoutMs) {188 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALLSERVICE_SEARCHKAFKA);189 AnswerItem<Map<TopicPartition, Long>> result = new AnswerItem<>();190 KafkaConsumer consumer = null;191 try {192 Properties props = new Properties();193 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers, "Y", 0, "", "", null, "", null));194 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false", "Y", 0, "", "", null, "", null));195 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.MAX_POLL_RECORDS_CONFIG, "10", "Y", 0, "", "", null, "", null));196 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer", "Y", 0, "", "", null, "", null));197 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer", "Y", 0, "", "", null, "", null));198 // Setting timeout although does not seem to work fine as result on aiven is always 60000 ms.199 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG, String.valueOf(timeoutMs), "Y", 0, "", "", null, "", null));200 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, String.valueOf(timeoutMs), "Y", 0, "", "", null, "", null));201 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, String.valueOf(timeoutMs), "Y", 0, "", "", null, "", null));202 for (AppServiceContent object : serviceContent) {203 if (StringUtil.parseBoolean(object.getActive())) {204 props.put(object.getKey(), object.getValue());205 }206 }207 LOG.info("Open Consumer : " + getKafkaConsumerKey(topic, bootstrapServers));208 consumer = new KafkaConsumer<>(props);209 //Get a list of the topics' partitions210 List<PartitionInfo> partitionList = consumer.partitionsFor(topic);211 if (partitionList == null) {212 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE_SEEKKAFKA);213 message.setDescription(message.getDescription().replace("%EX%", "Maybe Topic does not exist.").replace("%TOPIC%", topic).replace("%HOSTS%", bootstrapServers));214 } else {215 List<TopicPartition> topicPartitionList = partitionList.stream().map(info -> new TopicPartition(topic, info.partition())).collect(Collectors.toList());216 //Assign all the partitions to this consumer217 consumer.assign(topicPartitionList);218 consumer.seekToEnd(topicPartitionList); //default to latest offset for all partitions219 HashMap<TopicPartition, Long> valueResult = new HashMap<>();220 Map<TopicPartition, Long> partitionOffset = consumer.endOffsets(topicPartitionList);221 result.setItem(partitionOffset);222 }223 } catch (Exception ex) {224 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE_SEEKKAFKA);225 message.setDescription(message.getDescription().replace("%EX%", ex.toString() + " " + StringUtil.getExceptionCauseFromString(ex)).replace("%TOPIC%", topic).replace("%HOSTS%", bootstrapServers));226 LOG.debug(ex, ex);227 } finally {228 if (consumer != null) {229 consumer.close();230 LOG.info("Closed Consumer : " + getKafkaConsumerKey(topic, bootstrapServers));231 } else {232 LOG.info("Consumer not opened : " + getKafkaConsumerKey(topic, bootstrapServers));233 }234 }235 result.setResultMessage(message);236 return result;237 }238 @SuppressWarnings("unchecked")239 @Override240 public AnswerItem<String> searchEvent(Map<TopicPartition, Long> mapOffsetPosition, String topic, String bootstrapServers,241 List<AppServiceHeader> serviceHeader, List<AppServiceContent> serviceContent, String filterPath, String filterValue, int targetNbEventsInt, int targetNbSecInt) {242 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE_SEARCHKAFKA);243 AnswerItem<String> result = new AnswerItem<>();244 Instant date1 = Instant.now();245 JSONArray resultJSON = new JSONArray();246 KafkaConsumer consumer = null;247 int nbFound = 0;248 int nbEvents = 0;249 try {250 Properties props = new Properties();251 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers, "Y", 0, "", "", null, "", null));252 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false", "Y", 0, "", "", null, "", null));253 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.MAX_POLL_RECORDS_CONFIG, "10", "Y", 0, "", "", null, "", null));254 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer", "Y", 0, "", "", null, "", null));255 serviceContent.add(factoryAppServiceContent.create(null, ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer", "Y", 0, "", "", null, "", null));256 for (AppServiceContent object : serviceContent) {257 if (StringUtil.parseBoolean(object.getActive())) {258 props.put(object.getKey(), object.getValue());259 }260 }261 LOG.info("Open Consumer : " + getKafkaConsumerKey(topic, bootstrapServers));262 consumer = new KafkaConsumer<>(props);263 //Get a list of the topics' partitions264 List<PartitionInfo> partitionList = consumer.partitionsFor(topic);265 if (partitionList == null) {266 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE_SEARCHKAFKA);267 message.setDescription(message.getDescription().replace("%EX%", "Maybe Topic does not exist.").replace("%TOPIC%", topic).replace("%HOSTS%", bootstrapServers));268 } else {269 List<TopicPartition> topicPartitionList = partitionList.stream().map(info -> new TopicPartition(topic, info.partition())).collect(Collectors.toList());270 //Assign all the partitions to this consumer271 consumer.assign(topicPartitionList);...

Full Screen

Full Screen

parseBoolean

Using AI Code Generation

copy

Full Screen

1import org.cerberus.util.StringUtil;2{3public static void main(String args[])4{5System.out.println(StringUtil.parseBoolean("true"));6System.out.println(StringUtil.parseBoolean("false"));7System.out.println(StringUtil.parseBoolean("yes"));8System.out.println(StringUtil.parseBoolean("no"));9System.out.println(StringUtil.parseBoolean("on"));10System.out.println(StringUtil.parseBoolean("off"));11System.out.println(StringUtil.parseBoolean("1"));12System.out.println(StringUtil.parseBoolean("0"));13System.out.println(StringUtil.parseBoolean("anything"));14}15}

Full Screen

Full Screen

parseBoolean

Using AI Code Generation

copy

Full Screen

1import org.cerberus.util.StringUtil;2public class 3 {3 public static void main(String[] args) {4 String str = "true";5 boolean b = StringUtil.parseBoolean(str);6 System.out.println(b);7 }8}

Full Screen

Full Screen

parseBoolean

Using AI Code Generation

copy

Full Screen

1package org.cerberus.util;2public class StringUtil {3public static boolean parseBoolean(String s) {4return s != null && s.equals("true");5}6}7package org.cerberus.util;8public class StringUtil {9public static boolean parseBoolean(String s) {10return s != null && s.equals("true");11}12}13package org.cerberus.util;14public class StringUtil {15public static boolean parseBoolean(String s) {16return s != null && s.equals("true");17}18}19package org.cerberus.util;20public class StringUtil {21public static boolean parseBoolean(String s) {22return s != null && s.equals("true");23}24}25package org.cerberus.util;26public class StringUtil {27public static boolean parseBoolean(String s) {28return s != null && s.equals("true");29}30}31package org.cerberus.util;32public class StringUtil {33public static boolean parseBoolean(String s) {34return s != null && s.equals("true");35}36}37package org.cerberus.util;38public class StringUtil {39public static boolean parseBoolean(String s) {40return s != null && s.equals("true");41}42}43package org.cerberus.util;44public class StringUtil {45public static boolean parseBoolean(String s) {46return s != null && s.equals("true");47}48}49package org.cerberus.util;50public class StringUtil {51public static boolean parseBoolean(String s) {52return s != null && s.equals("true");53}54}

Full Screen

Full Screen

parseBoolean

Using AI Code Generation

copy

Full Screen

1package org.cerberus.util;2import java.util.Scanner;3public class 3 {4 public static void main(String[] args) {5 Scanner input = new Scanner(System.in);6 System.out.println("Enter the string to be checked");7 String str = input.nextLine();8 boolean res = StringUtil.parseBoolean(str);9 System.out.println(res);10 }11}12package org.cerberus.util;13public class StringUtil {14 public static boolean parseBoolean(String str) {15 if (str == null) {16 return false;17 }18 str = str.trim();19 return str.equalsIgnoreCase("true") || str.equalsIgnoreCase("yes") || str.equalsIgnoreCase("on") || str.equalsIgnoreCase("1") || str.equalsIgnoreCase("y");20 }21}

Full Screen

Full Screen

parseBoolean

Using AI Code Generation

copy

Full Screen

1import org.cerberus.util.StringUtil;2public class 3 {3 public static void main(String[] args) {4 String s = "true";5 if(StringUtil.parseBoolean(s)){6 System.out.println("String is converted to boolean");7 }8 }9}

Full Screen

Full Screen

parseBoolean

Using AI Code Generation

copy

Full Screen

1package org.cerberus.util;2import java.lang.*;3public class Test {4 public static void main(String[] args) {5 String[] str = {"true","false","True","False","TRUE","FALSE"};6 for (int i = 0; i < str.length; i++) {7 boolean b = StringUtil.parseBoolean(str[i]);8 System.out.println(str[i] + " = " + b);9 }10 }11}

Full Screen

Full Screen

parseBoolean

Using AI Code Generation

copy

Full Screen

1package org.cerberus.util;2public class StringUtil {3 public static boolean parseBoolean(String s) {4 if (s == null) {5 return false;6 }7 if (s.equalsIgnoreCase("true")) {8 return true;9 }10 if (s.equalsIgnoreCase("false")) {11 return false;12 }13 if (s.equalsIgnoreCase("yes")) {14 return true;15 }16 if (s.equalsIgnoreCase("no")) {17 return false;18 }19 if (s.equalsIgnoreCase("on")) {20 return true;21 }22 if (s.equalsIgnoreCase("off")) {23 return false;24 }25 if (s.equalsIgnoreCase("1")) {26 return true;27 }28 if (s.equalsIgnoreCase("0")) {29 return false;30 }31 throw new IllegalArgumentException("Cannot convert '" + s + "' to a boolean");32 }33}34package org.cerberus.util;35public class StringUtil {36 public static boolean parseBoolean(String s) {37 if (s == null) {38 return false;39 }40 if (s.equalsIgnoreCase("true")) {41 return true;42 }43 if (s.equalsIgnoreCase("false")) {44 return false;45 }46 if (s.equalsIgnoreCase("yes")) {47 return true;48 }49 if (s.equalsIgnoreCase("no")) {50 return false;51 }52 if (s.equalsIgnoreCase("on")) {53 return true;54 }55 if (s.equalsIgnoreCase("off")) {56 return false;57 }58 if (s.equalsIgnoreCase("1")) {59 return true;60 }61 if (s.equalsIgnoreCase("0")) {62 return false;63 }64 throw new IllegalArgumentException("Cannot convert '" + s + "' to a boolean");65 }66}67package org.cerberus.util;

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful