How to use findDistinctValuesOfColumn method of org.cerberus.servlet.crud.buildrevisionchange.ReadBuildRevisionParameters class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.buildrevisionchange.ReadBuildRevisionParameters.findDistinctValuesOfColumn

Source:ReadBuildRevisionParameters.java Github

copy

Full Screen

...125 } else if ((request.getParameter("system") != null) && (request.getParameter("build") != null) && (request.getParameter("revision") != null) && (request.getParameter("getNonSVNRelease") != null)) { // getNonSVNRelease parameter trigger the list of Manual Release with corresponding links.126 answer = findManualBuildRevisionParametersBySystem(request.getParameter("system"), request.getParameter("build"), request.getParameter("revision"), request.getParameter("lastbuild"), request.getParameter("lastrevision"), appContext, userHasPermissions);127 jsonResponse = (JSONObject) answer.getItem();128 } else if ((request.getParameter("system") != null) && !Strings.isNullOrEmpty(columnName)) {129 answer = findDistinctValuesOfColumn(request.getParameter("system"), appContext, request, columnName);130 jsonResponse = (JSONObject) answer.getItem();131 } else { // Default behaviour, we return the list of objects.132 answer = findBuildRevisionParametersList(request.getParameter("system"), request.getParameter("build"), request.getParameter("revision"), request.getParameter("application"), appContext, userHasPermissions, request);133 jsonResponse = (JSONObject) answer.getItem();134 }135 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());136 jsonResponse.put("message", answer.getResultMessage().getDescription());137 jsonResponse.put("sEcho", echo);138 response.getWriter().print(jsonResponse.toString());139 } catch (JSONException e) {140 LOG.warn(e);141 //returns a default error message with the json format that is able to be parsed by the client-side142 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());143 }144 }145 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">146 /**147 * Handles the HTTP <code>GET</code> method.148 *149 * @param request servlet request150 * @param response servlet response151 * @throws ServletException if a servlet-specific error occurs152 * @throws IOException if an I/O error occurs153 */154 @Override155 protected void doGet(HttpServletRequest request, HttpServletResponse response)156 throws ServletException, IOException {157 try {158 processRequest(request, response);159 } catch (CerberusException ex) {160 LOG.warn(ex);161 }162 }163 /**164 * Handles the HTTP <code>POST</code> method.165 *166 * @param request servlet request167 * @param response servlet response168 * @throws ServletException if a servlet-specific error occurs169 * @throws IOException if an I/O error occurs170 */171 @Override172 protected void doPost(HttpServletRequest request, HttpServletResponse response)173 throws ServletException, IOException {174 try {175 processRequest(request, response);176 } catch (CerberusException ex) {177 LOG.warn(ex);178 }179 }180 /**181 * Returns a short description of the servlet.182 *183 * @return a String containing servlet description184 */185 @Override186 public String getServletInfo() {187 return "Short description";188 }// </editor-fold>189 private AnswerItem findBuildRevisionParametersList(String system, String build, String revision, String application, ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {190 AnswerItem item = new AnswerItem();191 JSONObject object = new JSONObject();192 brpService = appContext.getBean(BuildRevisionParametersService.class);193 int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));194 int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));195 /*int sEcho = Integer.valueOf(request.getParameter("sEcho"));*/196 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");197 int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "1"));198 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "ID,Build,Revision,Release,Application,Project,TicketIDFixed,BugIDFixed,Link,ReleaseOwner,Subject,datecre,jenkinsbuildid,mavengroupid,mavenartifactid,mavenversion");199 String columnToSort[] = sColumns.split(",");200 String columnName = columnToSort[columnToSortParameter];201 String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");202 List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));203 204 Map<String, List<String>> individualSearch = new HashMap<String, List<String>>();205 for (int a = 0; a < columnToSort.length; a++) {206 if (null!=request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {207 List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));208 if(individualLike.contains(columnToSort[a])) {209 individualSearch.put(columnToSort[a]+":like", search);210 }else {211 individualSearch.put(columnToSort[a], search);212 } 213 }214 }215 216 AnswerList resp = brpService.readByVarious1ByCriteria(system, application, build, revision, startPosition, length, columnName, sort, searchParameter, individualSearch);217 JSONArray jsonArray = new JSONArray();218 if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values219 for (BuildRevisionParameters brp : (List<BuildRevisionParameters>) resp.getDataList()) {220 jsonArray.put(convertBuildRevisionParametersToJSONObject(brp));221 }222 }223 object.put("hasPermissions", userHasPermissions);224 object.put("contentTable", jsonArray);225 object.put("iTotalRecords", resp.getTotalRows());226 object.put("iTotalDisplayRecords", resp.getTotalRows());227 item.setItem(object);228 item.setResultMessage(resp.getResultMessage());229 return item;230 }231 private AnswerItem findBuildRevisionParametersByKey(Integer id, ApplicationContext appContext, boolean userHasPermissions) throws JSONException, CerberusException {232 AnswerItem item = new AnswerItem();233 JSONObject object = new JSONObject();234 IBuildRevisionParametersService libService = appContext.getBean(IBuildRevisionParametersService.class);235 //finds the project 236 AnswerItem answer = libService.readByKeyTech(id);237 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {238 //if the service returns an OK message then we can get the item and convert it to JSONformat239 BuildRevisionParameters brp = (BuildRevisionParameters) answer.getItem();240 JSONObject response = convertBuildRevisionParametersToJSONObject(brp);241 object.put("contentTable", response);242 }243 object.put("hasPermissions", userHasPermissions);244 item.setItem(object);245 item.setResultMessage(answer.getResultMessage());246 return item;247 }248 private AnswerItem findlastBuildRevisionParametersBySystem(String system, ApplicationContext appContext, boolean userHasPermissions) throws JSONException, CerberusException {249 AnswerItem item = new AnswerItem();250 JSONObject object = new JSONObject();251 IBuildRevisionParametersService libService = appContext.getBean(IBuildRevisionParametersService.class);252 //finds the project 253 AnswerItem answer = libService.readLastBySystem(system);254 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {255 //if the service returns an OK message then we can get the item and convert it to JSONformat256 BuildRevisionParameters brp = (BuildRevisionParameters) answer.getItem();257 JSONObject response = convertBuildRevisionParametersToJSONObject(brp);258 object.put("contentTable", response);259 }260 object.put("hasPermissions", userHasPermissions);261 item.setItem(object);262 item.setResultMessage(answer.getResultMessage());263 return item;264 }265 private AnswerItem findSVNBuildRevisionParametersBySystem(String system, String country, String environment, String build, String revision, String lastbuild, String lastrevision, ApplicationContext appContext, boolean userHasPermissions) throws JSONException {266 AnswerItem item = new AnswerItem();267 JSONObject object = new JSONObject();268 brpService = appContext.getBean(IBuildRevisionParametersService.class);269 appService = appContext.getBean(IApplicationService.class);270 cedtService = appContext.getBean(ICountryEnvDeployTypeService.class);271 if (StringUtil.isNullOrEmpty(lastbuild)) {272 lastbuild = build;273 }274 AnswerList resp = brpService.readMaxSVNReleasePerApplication(system, build, revision, lastbuild, lastrevision);275 JSONArray jsonArray = new JSONArray();276 JSONObject newSubObj = new JSONObject();277 if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values278 for (BuildRevisionParameters brp : (List<BuildRevisionParameters>) resp.getDataList()) {279 newSubObj = convertBuildRevisionParametersToJSONObject(brp);280 // We get here the links of all corresponding deployTypes.281 Application app;282 try {283 app = appService.convert(appService.readByKey(brp.getApplication()));284 for (CountryEnvDeployType JenkinsAgent : cedtService.convert(cedtService.readByVarious(system, country, environment, app.getDeploytype()))) {285 String DeployURL = "JenkinsDeploy?application=" + brp.getApplication() + "&jenkinsagent=" + JenkinsAgent.getJenkinsAgent() + "&country=" + country + "&deploytype=" + app.getDeploytype() + "&release=" + brp.getRelease() + "&jenkinsbuildid=" + brp.getJenkinsBuildId() + "&repositoryurl=" + brp.getRepositoryUrl();286 JSONObject newSubObjContent = new JSONObject();287 newSubObjContent.put("jenkinsAgent", JenkinsAgent.getJenkinsAgent());288 newSubObjContent.put("link", DeployURL);289 newSubObj.append("install", newSubObjContent);290 }291 } catch (CerberusException ex) {292 LOG.warn(ex);293 }294 jsonArray.put(newSubObj);295 }296 }297 object.put("contentTable", jsonArray);298 object.put("iTotalRecords", resp.getTotalRows());299 object.put("iTotalDisplayRecords", resp.getTotalRows());300 object.put("hasPermissions", userHasPermissions);301 item.setItem(object);302 item.setResultMessage(resp.getResultMessage());303 return item;304 }305 private AnswerItem findManualBuildRevisionParametersBySystem(String system, String build, String revision, String lastbuild, String lastrevision, ApplicationContext appContext, boolean userHasPermissions) throws JSONException {306 AnswerItem item = new AnswerItem();307 JSONObject object = new JSONObject();308 brpService = appContext.getBean(BuildRevisionParametersService.class);309 if (StringUtil.isNullOrEmpty(lastbuild)) {310 lastbuild = build;311 }312 AnswerList resp = brpService.readNonSVNRelease(system, build, revision, lastbuild, lastrevision);313 JSONArray jsonArray = new JSONArray();314 if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values315 for (BuildRevisionParameters brp : (List<BuildRevisionParameters>) resp.getDataList()) {316 jsonArray.put(convertBuildRevisionParametersToJSONObject(brp));317 }318 }319 object.put("contentTable", jsonArray);320 object.put("iTotalRecords", resp.getTotalRows());321 object.put("iTotalDisplayRecords", resp.getTotalRows());322 object.put("hasPermissions", userHasPermissions);323 item.setItem(object);324 item.setResultMessage(resp.getResultMessage());325 return item;326 }327 private JSONObject convertBuildRevisionParametersToJSONObject(BuildRevisionParameters brp) throws JSONException {328 Gson gson = new Gson();329 JSONObject result = new JSONObject(gson.toJson(brp));330 return result;331 }332 private AnswerItem findDistinctValuesOfColumn(String system, ApplicationContext appContext, HttpServletRequest request, String columnName) throws JSONException {333 AnswerItem answer = new AnswerItem();334 JSONObject object = new JSONObject();335 brpService = appContext.getBean(IBuildRevisionParametersService.class);336 337 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");338 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "ID,Build,Revision,Release,Application,Project,TicketIDFixed,BugIDFixed,Link,ReleaseOwner,Subject,datecre,jenkinsbuildid,mavengroupid,mavenartifactid,mavenversion");339 String columnToSort[] = sColumns.split(",");340 List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));341 Map<String, List<String>> individualSearch = new HashMap<>();342 for (int a = 0; a < columnToSort.length; a++) {343 if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {344 List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));345 if(individualLike.contains(columnToSort[a])) {346 individualSearch.put(columnToSort[a]+":like", search);...

Full Screen

Full Screen

findDistinctValuesOfColumn

Using AI Code Generation

copy

Full Screen

1public List<String> findDistinctValuesOfColumn(String system, String country, String env, String build, String revision, String column) throws CerberusException {2 List<String> list = new ArrayList<String>();3 StringBuilder query = new StringBuilder();4 query.append("SELECT DISTINCT `").append(column).append("` FROM `buildrevisionparameters` WHERE 1=1 ");5 boolean parameter = false;6 if (!StringUtil.isNullOrEmpty(system)) {7 query.append(" and `system` = ?");8 parameter = true;9 }10 if (!StringUtil.isNullOrEmpty(country)) {11 query.append(" and `country` = ?");12 parameter = true;13 }14 if (!StringUtil.isNullOrEmpty(env)) {15 query.append(" and `environment` = ?");16 parameter = true;17 }18 if (!StringUtil.isNullOrEmpty(build)) {19 query.append(" and `build` = ?");20 parameter = true;21 }22 if (!StringUtil.isNullOrEmpty(revision)) {23 query.append(" and `revision` = ?");24 parameter = true;25 }26 if (parameter) {27 try (Connection connection = this.databaseSpring.connect();28 PreparedStatement preStat = connection.prepareStatement(query.toString());) {29 int i = 1;30 if (!StringUtil.isNullOrEmpty(system)) {31 preStat.setString(i++, system);32 }33 if (!StringUtil.isNullOrEmpty(country)) {34 preStat.setString(i++, country);35 }36 if (!StringUtil.isNullOrEmpty(env)) {37 preStat.setString(i++, env);38 }39 if (!StringUtil.isNullOrEmpty(build)) {40 preStat.setString(i++, build);41 }42 if (!StringUtil.isNullOrEmpty(revision)) {43 preStat.setString(i++, revision);44 }45 try (ResultSet resultSet = preStat.executeQuery()) {46 while (resultSet.next()) {47 list.add(resultSet.getString(1));48 }49 }50 } catch (SQLException exception) {51 LOG.error("Unable to execute query : " + query.toString(), exception);52 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));53 }54 }55 return list;56 }

Full Screen

Full Screen

findDistinctValuesOfColumn

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.buildrevisionchange.ReadBuildRevisionParameters;2public class TestReadBuildRevisionParameters {3 public static void main(String[] args) {4 ReadBuildRevisionParameters readBuildRevisionParameters = new ReadBuildRevisionParameters();5 String[] distinctValues = readBuildRevisionParameters.findDistinctValuesOfColumn("application", "buildrevisionparameters");6 for (String distinctValue : distinctValues) {7 System.out.println(distinctValue);8 }9 }10}

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