public List<CIBuild> getBuilds(CIJob job) throws PhrescoException { if (debugEnabled) { S_LOGGER.debug("Entering Method CIManagerImpl.getCIBuilds(CIJob job)"); } List<CIBuild> ciBuilds = null; try { if (debugEnabled) { S_LOGGER.debug("getCIBuilds() JobName = " + job.getName()); } JsonArray jsonArray = getBuildsArray(job); ciBuilds = new ArrayList<CIBuild>(jsonArray.size()); Gson gson = new Gson(); CIBuild ciBuild = null; for (int i = 0; i < jsonArray.size(); i++) { ciBuild = gson.fromJson(jsonArray.get(i), CIBuild.class); setBuildStatus(ciBuild, job); String buildUrl = ciBuild.getUrl(); String jenkinUrl = job.getJenkinsUrl() + ":" + job.getJenkinsPort(); buildUrl = buildUrl.replaceAll( "localhost:" + job.getJenkinsPort(), jenkinUrl); // when displaying url it should display setup machine ip ciBuild.setUrl(buildUrl); ciBuilds.add(ciBuild); } } catch (Exception e) { if (debugEnabled) { S_LOGGER.debug( "Entering Method CIManagerImpl.getCIBuilds(CIJob job) " + e.getLocalizedMessage()); } } return ciBuilds; }
private CIJob getJob(ApplicationInfo appInfo) throws PhrescoException { Gson gson = new Gson(); try { BufferedReader br = new BufferedReader(new FileReader(getCIJobPath(appInfo))); CIJob job = gson.fromJson(br, CIJob.class); br.close(); return job; } catch (FileNotFoundException e) { S_LOGGER.debug(e.getLocalizedMessage()); return null; } catch (com.google.gson.JsonParseException e) { S_LOGGER.debug("it is already adpted project !!!!! " + e.getLocalizedMessage()); return null; } catch (IOException e) { S_LOGGER.debug(e.getLocalizedMessage()); return null; } }
public List<CIJob> getJobs(ApplicationInfo appInfo) throws PhrescoException { S_LOGGER.debug("GetJobs Called!"); try { boolean adaptedProject = adaptExistingJobs(appInfo); S_LOGGER.debug("Project adapted for new feature => " + adaptedProject); Gson gson = new Gson(); BufferedReader br = new BufferedReader(new FileReader(getCIJobPath(appInfo))); Type type = new TypeToken<List<CIJob>>() {}.getType(); List<CIJob> jobs = gson.fromJson(br, type); br.close(); return jobs; } catch (FileNotFoundException e) { S_LOGGER.debug("FileNotFoundException"); return null; } catch (IOException e) { S_LOGGER.debug("IOException"); throw new PhrescoException(e); } }
private int getTotalBuilds(CIJob job) throws PhrescoException { try { S_LOGGER.debug("Entering Method CIManagerImpl.getTotalBuilds(CIJob job)"); S_LOGGER.debug("getCIBuilds() JobName = " + job.getName()); JsonArray jsonArray = getBuildsArray(job); Gson gson = new Gson(); CIBuild ciBuild = null; if (jsonArray.size() > 0) { ciBuild = gson.fromJson(jsonArray.get(0), CIBuild.class); String buildUrl = ciBuild.getUrl(); String jenkinsUrl = job.getJenkinsUrl() + ":" + job.getJenkinsPort(); // display the jenkins running url in ci buildUrl = buildUrl.replaceAll("localhost:" + job.getJenkinsPort(), jenkinsUrl); // list String response = getJsonResponse(buildUrl + API_JSON); JsonParser parser = new JsonParser(); JsonElement jsonElement = parser.parse(response); JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonElement resultJson = jsonObject.get(FrameworkConstants.CI_JOB_BUILD_RESULT); JsonArray asJsonArray = jsonObject.getAsJsonArray(FrameworkConstants.CI_JOB_BUILD_ARTIFACTS); // when build result is not known if (jsonObject.get(FrameworkConstants.CI_JOB_BUILD_RESULT).toString().equals(STRING_NULL)) { // it indicates the job is in progress and not yet completed return -1; // when build is success and build zip relative path is unknown } else if (resultJson.getAsString().equals(CI_SUCCESS_FLAG) && asJsonArray.size() < 1) { return -1; } else { return jsonArray.size(); } } else { return -1; // When the project is build first time, } } catch (ClientHandlerException ex) { S_LOGGER.error(ex.getLocalizedMessage()); throw new PhrescoException(ex); } }
private void writeJsonJobs(ApplicationInfo appInfo, List<CIJob> jobs, String status) throws PhrescoException { try { if (jobs == null) { return; } Gson gson = new Gson(); List<CIJob> existingJobs = getJobs(appInfo); if (CI_CREATE_NEW_JOBS.equals(status) || existingJobs == null) { existingJobs = new ArrayList<CIJob>(); } existingJobs.addAll(jobs); FileWriter writer = null; File ciJobFile = new File(getCIJobPath(appInfo)); String jobJson = gson.toJson(existingJobs); writer = new FileWriter(ciJobFile); writer.write(jobJson); writer.flush(); } catch (Exception e) { throw new PhrescoException(e); } }
private boolean adaptExistingJobs(ApplicationInfo appInfo) { try { CIJob existJob = getJob(appInfo); S_LOGGER.debug("Going to get existing jobs to relocate!!!!!"); if (existJob != null) { S_LOGGER.debug("Existing job found " + existJob.getName()); boolean deleteExistJob = deleteCIJobFile(appInfo); Gson gson = new Gson(); List<CIJob> existingJobs = new ArrayList<CIJob>(); existingJobs.addAll(Arrays.asList(existJob)); FileWriter writer = null; File ciJobFile = new File(getCIJobPath(appInfo)); String jobJson = gson.toJson(existingJobs); writer = new FileWriter(ciJobFile); writer.write(jobJson); writer.flush(); S_LOGGER.debug("Existing job moved to new type of project!!"); } return true; } catch (Exception e) { S_LOGGER.debug("It is already adapted !!!!! "); } return false; }
// ***************************************************** // Process the request from Member_sheet // ***************************************************** // public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); PreparedStatement pstmt3 = null; Statement stmt = null; ResultSet rs = null; HttpSession session = SystemUtils.verifyMem(req, out); // check for intruder if (session == null) { return; } Connection con = SystemUtils.getCon(session); // get DB connection if (con == null) { out.println(SystemUtils.HeadTitle("DB Connection Error")); out.println( "<BODY bgcolor=\"#ccccaa\"><CENTER><img src=\"/" + rev + "/images/foretees.gif\"><BR>"); out.println("<hr width=\"40%\">"); out.println("<BR><BR><H3>Database Connection Error</H3>"); out.println("<BR><BR>Unable to connect to the Database."); out.println("<BR>Please try again later."); out.println("<BR><BR>If problem persists, please contact customer support."); out.println("<BR><BR>"); out.println("<font size=\"2\">"); out.println("<form method=\"get\" action=\"javascript:history.back(1)\">"); out.println("<input type=\"submit\" value=\"Return\" style=\"text-decoration:underline;\">"); out.println("</form></font>"); out.println("</CENTER></BODY></HTML>"); out.close(); return; } // Create Json response for later use Gson gson_obj = new Gson(); // HashMap for later use by gson Map<String, Object> hashMap = new HashMap<String, Object>(); // Check if we will only be return json data boolean json_mode = (req.getParameter("jsonMode")) != null; // // See if we are here to VIEW a wait list // if (req.getParameter("view") != null && req.getParameter("waitListId") != null) { if (json_mode) { out.print(gson_obj.toJson(viewSignups(req, out, con, true))); } else { viewSignups(req, out, con); } return; } String jump = "0"; // jump index - default to zero (for _sheet) if (req.getParameter("jump") != null) { // if jump index provided jump = req.getParameter("jump"); } // // Get this session's username // String club = (String) session.getAttribute("club"); String user = (String) session.getAttribute("user"); String name = (String) session.getAttribute("name"); // get users full name String sindex = req.getParameter("index"); // index value of day (needed by Member_sheet when returning) String course = req.getParameter("course"); // Name of Course String id = req.getParameter("waitListId"); // uid of the wait list we are working with String returnCourse = ""; if (req.getParameter("returnCourse") != null) { // if returnCourse provided returnCourse = req.getParameter("returnCourse"); } String sdate = req.getParameter("date"); // date of the request (yyyymmdd) String day_name = req.getParameter("day"); // name of the day String p5 = req.getParameter("p5"); // 5-somes supported int index = 0; int wait_list_id = 0; int count = 0; int mm = 0; int dd = 0; int yy = 0; int date = 0; int time = SystemUtils.getTime(con); // // Convert the values from string to int // try { wait_list_id = Integer.parseInt(id); index = Integer.parseInt(sindex); date = Integer.parseInt(sdate); } catch (NumberFormatException e) { } // get our date parts yy = date / 10000; mm = date - (yy * 10000); dd = mm - (mm / 100) * 100; mm = mm / 100; // // parm block to hold the wait list parameters // parmWaitList parmWL = new parmWaitList(); // allocate a parm block parmWL.wait_list_id = wait_list_id; try { getWaitList.getParms(con, parmWL); // get the wait list config // if members can see the wait list then get the count if (parmWL.member_view == 1) { count = getWaitList.getListCount(wait_list_id, date, index, time, true, con); } } catch (Exception exp) { out.println(exp.getMessage()); } int onlist = 0; try { onlist = getWaitList.onList(user, wait_list_id, date, con); } catch (Exception exp) { out.println(exp.toString()); } String waitlist_notice = ""; if (onlist == 0) { // not on the list try { // out.println("<pre>"); waitlist_notice = getWaitList.getNotice(wait_list_id, con); // out.println("</pre>"); } catch (Exception exp) { } } if (json_mode) { // If in json mode, add data to hashmap // New skin uses Member_waitlist in json mode exclusively. // Group the data we want to send to javascript in a hash map hashMap.put("wait_list_id", wait_list_id); hashMap.put("waitlist_notice", waitlist_notice); hashMap.put("date", "" + mm + "/" + dd + "/" + yy); hashMap.put("start_time", SystemUtils.getSimpleTime(parmWL.start_time)); hashMap.put("end_time", SystemUtils.getSimpleTime(parmWL.end_time)); hashMap.put("member_access", parmWL.member_access); hashMap.put("member_view", parmWL.member_view); hashMap.put("onlist", onlist); hashMap.put("index", index); hashMap.put("course", course); hashMap.put("count", count); hashMap.put("name", parmWL.name); out.print(gson_obj.toJson(hashMap)); return; } else { // If not in json mode, output data directly to user out.println( "<!-- wait_list_id=" + wait_list_id + ", date=" + date + ", count=" + count + " -->"); // // ******************************************************************** // Build a page to display Wait List details to member // ******************************************************************** // out.println("<html>"); out.println("<head>"); out.println( "<link rel=\"stylesheet\" href=\"/" + rev + "/web utilities/foretees2.css\" type=\"text/css\">"); out.println("<title>Member Wait List Registration Page</title>"); out.println("</head>"); out.println( "<body bgcolor=\"#ccccaa\" text=\"#000000\" link=\"#FFFFFF\" vlink=\"#FFFFFF\" alink=\"#FF0000\" topmargin=\"0\">"); out.println("<font face=\"Arial, Helvetica, Sans-serif\"><center>"); out.println( "<table border=\"0\" width=\"100%\" align=\"center\" valign=\"top\">"); // large table for // whole page out.println("<tr><td valign=\"top\" align=\"center\">"); out.println( "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#336633\" align=\"center\" valign=\"top\">"); out.println("<tr><td align=\"left\" width=\"300\"> "); out.println("<img src=\"/" + rev + "/images/foretees.gif\" border=0>"); out.println("</td>"); out.println("<td align=\"center\">"); out.println("<font color=\"ffffff\" size=\"5\">Member Wait List Registration</font>"); out.println("</font></td>"); out.println("<td align=\"center\" width=\"300\">"); out.println("<font size=\"1\" color=\"#ffffff\">Copyright </font>"); out.println("<font size=\"2\" color=\"#ffffff\">© </font>"); out.println( "<font size=\"1\" color=\"#ffffff\">ForeTees, LLC <br> 2009 All rights reserved."); out.println("</font><font size=\"3\">"); out.println( "<br><br><a href=\"/" + rev + "/member_help.htm\" target=\"_blank\"><b>Help</b></a>"); out.println("</font></td>"); out.println("</tr></table>"); out.println("<br>"); out.println("<table border=\"1\" cols=\"1\" bgcolor=\"#f5f5dc\" cellpadding=\"3\">"); out.println("<tr>"); out.println("<td width=\"620\" align=\"center\">"); out.println("<font size=\"3\">"); out.println("<b>Wait List Registration</b><br></font>"); out.println("<font size=\"2\">"); out.println( "The golf shop is running a wait list " + ((index == 0) ? "today" : "on this day") + ". "); out.println( "The wait list you've selected is running from <nobr>" + SystemUtils.getSimpleTime(parmWL.start_time) + "</nobr> till <nobr>" + SystemUtils.getSimpleTime(parmWL.end_time) + ".</nobr> "); out.println("Review the information below and click on 'Continue With Request' to continue."); out.println( "<br>OR click on 'Cancel Request' to delete the request. To return without changes click on 'Go Back'."); // out.println("<br><br><b>NOTE:</b> Only the person that originates the request will be // allowed to cancel it or change these values."); out.println("</font></td></tr>"); out.println("</table>"); out.println("<br><br>"); out.println("<table border=0>"); out.println("<tr><td><font size=\"2\">"); out.println( "Date: <b>" + day_name + " " + mm + "/" + dd + "/" + yy + "</b></td>"); out.println("<td> </td><td>"); if (!course.equals("")) { out.println("<font size=\"2\">Course: <b>" + course + "</b></font>"); } out.println("</td></tr>"); out.println( "<tr><td><font size=\"2\">Wait List: <b>" + SystemUtils.getSimpleTime(parmWL.start_time) + " to " + SystemUtils.getSimpleTime(parmWL.end_time) + "</b></font></td>"); out.println("<td></td>"); out.println("<td><font size=\"2\">Signups:<b>"); out.print(((parmWL.member_view == 1) ? count : "N/A")); out.println("</b></font></td>"); out.println("</table>"); out.println("<br>"); out.println("<table border=\"0\" align=\"center\">"); // table to contain 2 tables below out.println("<tr>"); out.println("<td align=\"center\" valign=\"top\">"); out.println( "<table border=\"1\" bgcolor=\"#f5f5dc\" align=\"center\" width=\"500\" cellpadding=\"5\" cellspacing=\"5\">"); // table for request details out.println("<tr bgcolor=\"#336633\"><td align=\"center\">"); out.println("<font color=\"ffffff\" size=\"3\">"); out.println( "<b>" + ((!parmWL.name.equals("")) ? parmWL.name : "Wait List Information") + "</b>"); out.println("</font></td></tr>"); out.println("<tr>"); out.println("<form action=\"Member_waitlist_slot\" method=\"post\">"); out.println("<input type=\"hidden\" name=\"waitListId\" value=\"" + wait_list_id + "\">"); out.println("<input type=\"hidden\" name=\"sdate\" value=\"" + date + "\">"); out.println("<input type=\"hidden\" name=\"day\" value=\"" + day_name + "\">"); out.println("<input type=\"hidden\" name=\"index\" value=\"" + sindex + "\">"); out.println("<input type=\"hidden\" name=\"course\" value=\"" + course + "\">"); out.println("<input type=\"hidden\" name=\"returnCourse\" value=\"" + returnCourse + "\">"); out.println("<input type=\"hidden\" name=\"jump\" value=\"" + jump + "\">"); out.println("<td><font size=\"2\"><br>"); // see if they are already on the wait list out.println("<input type=\"hidden\" name=\"signupId\" value=\"" + onlist + "\">"); if (onlist == 0) { // not on the list // out.println("The golf shop is running a wait list " + ((index == 0) ? "today": "on this // day") + ". "); // out.println("The wait list you've selected is running from " + // SystemUtils.getSimpleTime(parmWL.start_time) + " till " + // SystemUtils.getSimpleTime(parmWL.end_time) + ". "); // try { // out.println("<pre>"); // out.print(getWaitList.getNotice(wait_list_id, con)); // out.println("</pre>"); out.print(waitlist_notice); // } catch (Exception exp) { } if (parmWL.member_access == 1) { out.println( "<br><p align=center><input type=submit value=\"Continue With Sign-up\" name=\"continue\"></p>"); } else { out.println("<p align=center><b>Contact the golf shop to get on the wait list.</b></p>"); } } else { // already on this list out.println( "<p align=center><b><i>You are already signed up for this wait list.</b></i></p>"); if (parmWL.member_access == 1) { out.println( "<br><p align=center><input type=submit value=\"Modify Your Sign-up\" name=\"continue\"></p>"); } else { out.println( "<p align=center><b>Contact the golf shop to make changes or cancel your entry.</b></p>"); } } if (parmWL.member_view == 1 && count > 0) { out.println( "<p align=center><input type=button value=\"View Wait List\" name=\"view\" onclick=\"document.forms['frmView'].submit();\"></p>"); } out.println("<br></font></td>"); out.println("</table>"); out.println("</form>"); out.println("<br>"); if (index == 999) { // out.println("<form action=\"Member_teelist\" method=\"GET\">"); out.println("<form action=\"/" + rev + "/member_teemain.htm\" method=\"GET\">"); } else if (index == 995) { // out.println("<form action=\"Member_teelist_list\" method=\"GET\">"); out.println("<form action=\"/" + rev + "/member_teemain2.htm\" method=\"GET\">"); } else { out.println("<form action=\"Member_jump\" method=\"POST\">"); out.println("<input type=\"hidden\" name=\"jump\" value=" + jump + ">"); out.println("<input type=\"hidden\" name=\"index\" value=" + index + ">"); out.println( "<input type=\"hidden\" name=\"course\" value=\"" + ((!returnCourse.equals("")) ? returnCourse : course) + "\">"); } out.println("<font size=2>Return w/o Changes:</font><br>"); out.println("<input type=\"submit\" value=\"Go Back\" name=\"cancel\"></form>"); out.println("<form action=\"Member_waitlist\" method=\"GET\" name=frmView>"); out.println("<input type=\"hidden\" name=\"view\" value=\"current\">"); out.println("<input type=\"hidden\" name=\"waitListId\" value=\"" + wait_list_id + "\">"); out.println("<input type=\"hidden\" name=\"sdate\" value=\"" + date + "\">"); out.println("<input type=\"hidden\" name=\"name\" value=\"" + parmWL.name + "\">"); // out.println("<input type=\"hidden\" name=\"day\" value=\"" + day_name + "\">"); out.println("<input type=\"hidden\" name=\"index\" value=\"" + sindex + "\">"); out.println("<input type=\"hidden\" name=\"course\" value=\"" + parmWL.course + "\">"); out.println("<input type=\"hidden\" name=\"returnCourse\" value=\"" + returnCourse + "\">"); out.println("<input type=\"hidden\" name=\"jump\" value=\"" + jump + "\">"); ; out.println( "<input type=\"hidden\" name=\"start_time\" value=\"" + parmWL.start_time + "\">"); out.println("<input type=\"hidden\" name=\"end_time\" value=\"" + parmWL.end_time + "\">"); out.println("<input type=\"hidden\" name=\"day_name\" value=\"" + day_name + "\">"); // out.println("<input type=submit value=\"View Sign-ups\" name=\"view\">"); out.println("</form>"); } // end json check } // end doPost