PageRenderTime 65ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/myproject/src/com/bp/pensionline/publishing/database/PublishingToolbarSQLHandler.java

https://bitbucket.org/tuannguyen/mytest
Java | 3542 lines | 2649 code | 387 blank | 506 comment | 225 complexity | f69505f78083af3cec80e6a20f2c90cd MD5 | raw file
  1. package com.bp.pensionline.publishing.database;
  2. /*
  3. * This class handle all Database transaction for publishing actions
  4. */
  5. import java.sql.Connection;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.util.ArrayList;
  11. import java.util.HashSet;
  12. import java.util.Vector;
  13. import org.apache.commons.logging.Log;
  14. import org.opencms.main.CmsLog;
  15. import com.bp.pensionline.constants.Environment;
  16. import com.bp.pensionline.database.DBConnector;
  17. import com.bp.pensionline.publishing.dto.ReleasePackageDTO;
  18. import com.bp.pensionline.publishing.dto.ReleasePageDTO;
  19. import com.bp.pensionline.publishing.util.DateTimeUtil;
  20. public class PublishingToolbarSQLHandler
  21. {
  22. public static final Log LOG = CmsLog.getLog(PublishingToolbarSQLHandler.class);
  23. /**
  24. * Get page DTO object from URI
  25. * @param con
  26. * @param pageURI
  27. * @return
  28. */
  29. public static ReleasePageDTO getReleasePageByURI (String pageURI)
  30. {
  31. String getReleasePageSQL = "Select page_id, mode, status, bug_id, notes, last_update, self_edited from bp_release_pages " +
  32. "where page_uri = ?";
  33. ReleasePageDTO pageDTO = null;
  34. Connection con = null;
  35. DBConnector connector = DBConnector.getInstance();
  36. try
  37. {
  38. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  39. //con = connector.getDBConnFactory(Environment.SQL);
  40. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  41. PreparedStatement pstm = con.prepareStatement(getReleasePageSQL);
  42. pstm.setString(1, pageURI);
  43. ResultSet rs = pstm.executeQuery();
  44. if (rs.next())
  45. {
  46. pageDTO = new ReleasePageDTO();
  47. pageDTO.setPageId(rs.getInt("page_id"));
  48. pageDTO.setPageURI(pageURI);
  49. pageDTO.setMode(rs.getString("mode"));
  50. pageDTO.setStatus(rs.getString("status"));
  51. pageDTO.setBugId(rs.getString("bug_id"));
  52. pageDTO.setNotes(rs.getString("notes"));
  53. pageDTO.setLastUpdate(rs.getLong("last_update"));
  54. pageDTO.setSelfEdited(rs.getString("self_edited"));
  55. }
  56. pstm.close();
  57. }
  58. catch (SQLException sqle)
  59. {
  60. LOG.error("Error in getReleasePageByURI: " + sqle.toString()+"\n$SQL: "+getReleasePageSQL);
  61. }
  62. finally
  63. {
  64. if (con != null)
  65. {
  66. try
  67. {
  68. connector.close(con);
  69. }
  70. catch (Exception e)
  71. {
  72. LOG.error("Error in closing MySQL connection: " + e.toString());
  73. }
  74. }
  75. }
  76. return pageDTO;
  77. }
  78. /**
  79. * Get page DTO object from URI in bp_release_pages
  80. * @param con
  81. * @param pageURI
  82. * @return
  83. */
  84. public static ReleasePageDTO getReleaseChildPageByURI (String pageURI)
  85. {
  86. String getReleasePageSQL = "Select page_id, mode, last_update from bp_release_child_pages " +
  87. "where page_uri = '" + pageURI + "'";
  88. ReleasePageDTO pageDTO = null;
  89. Connection con = null;
  90. DBConnector connector = DBConnector.getInstance();
  91. try
  92. {
  93. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  94. //con = connector.getDBConnFactory(Environment.SQL);
  95. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  96. PreparedStatement pstm = con.prepareStatement(getReleasePageSQL);
  97. ResultSet rs = pstm.executeQuery();
  98. if (rs.next())
  99. {
  100. pageDTO = new ReleasePageDTO();
  101. pageDTO.setPageId(rs.getInt("page_id"));
  102. pageDTO.setPageURI(pageURI);
  103. pageDTO.setMode(rs.getString("mode"));
  104. pageDTO.setLastUpdate(rs.getLong("last_update"));
  105. }
  106. }
  107. catch (SQLException sqle)
  108. {
  109. LOG.error("Error in getReleaseChildPageByURI: " + sqle.toString());
  110. }
  111. finally
  112. {
  113. if (con != null)
  114. {
  115. try
  116. {
  117. connector.close(con);
  118. }
  119. catch (Exception e)
  120. {
  121. LOG.error("Error in closing MySQL connection: " + e.toString());
  122. }
  123. }
  124. }
  125. return pageDTO;
  126. }
  127. /**
  128. * Get all child page in bp_release_page_child of a parent
  129. * @param con
  130. * @param pageURI
  131. * @return
  132. */
  133. public static Vector<ReleasePageDTO> getChildPagesByParent (int parentId)
  134. {
  135. String getReleasePageSQL = "Select page_id, page_uri, mode, last_update " +
  136. "from bp_release_child_pages c, bp_release_childparent cp " +
  137. "where c.page_id = cp.child_id and cp.parent_id = '" + parentId + "'";
  138. Vector<ReleasePageDTO> childPageDTOs = new Vector<ReleasePageDTO>();
  139. Connection con = null;
  140. DBConnector connector = DBConnector.getInstance();
  141. try
  142. {
  143. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  144. //con = connector.getDBConnFactory(Environment.SQL);
  145. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  146. PreparedStatement pstm = con.prepareStatement(getReleasePageSQL);
  147. ResultSet rs = pstm.executeQuery();
  148. while (rs.next())
  149. {
  150. ReleasePageDTO pageDTO = new ReleasePageDTO();
  151. pageDTO = new ReleasePageDTO();
  152. pageDTO.setPageId(rs.getInt("page_id"));
  153. pageDTO.setPageURI(rs.getString("page_uri"));
  154. pageDTO.setMode(rs.getString("mode"));
  155. pageDTO.setLastUpdate(rs.getLong("last_update"));
  156. childPageDTOs.add(pageDTO);
  157. }
  158. }
  159. catch (SQLException sqle)
  160. {
  161. LOG.error("Error in getReleaseChildPageByParent: " + sqle.toString());
  162. }
  163. finally
  164. {
  165. if (con != null)
  166. {
  167. try
  168. {
  169. connector.close(con);
  170. }
  171. catch (Exception e)
  172. {
  173. LOG.error("Error in closing MySQL connection: " + e.toString());
  174. }
  175. }
  176. }
  177. return childPageDTOs;
  178. }
  179. /**
  180. * Get page status from Id
  181. * @param con
  182. * @param pageURI
  183. * @return
  184. */
  185. public static String getReleasePageStatus (String pageURI)
  186. {
  187. String getPageStatusSQL = "Select status from bp_release_pages where page_uri = '" +
  188. pageURI + "'";
  189. String status = null;
  190. Connection con = null;
  191. DBConnector connector = DBConnector.getInstance();
  192. try
  193. {
  194. //con = connector.getDBConnFactory(Environment.SQL);
  195. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  196. PreparedStatement pstm = con.prepareStatement(getPageStatusSQL);
  197. ResultSet rs = pstm.executeQuery();
  198. if (rs.next())
  199. {
  200. status = rs.getString("status");
  201. }
  202. }
  203. catch (SQLException sqle)
  204. {
  205. LOG.error("Error in getReleasePageStatus " + sqle.toString());
  206. }
  207. finally
  208. {
  209. if (con != null)
  210. {
  211. try
  212. {
  213. connector.close(con);
  214. }
  215. catch (Exception e)
  216. {
  217. LOG.error("Error in closing MySQL connection: " + e.toString());
  218. }
  219. }
  220. }
  221. return status;
  222. }
  223. /**
  224. * Get page last update of page
  225. * @param con
  226. * @param pageURI
  227. * @return
  228. */
  229. public static long getReleasePageLastUpdate (int pageId)
  230. {
  231. String getPageStatusSQL = "Select last_update from bp_release_pages where page_id = '" +
  232. pageId + "'";
  233. long lastUpdate = -1;
  234. Connection con = null;
  235. DBConnector connector = DBConnector.getInstance();
  236. try
  237. {
  238. //con = connector.getDBConnFactory(Environment.SQL);
  239. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  240. PreparedStatement pstm = con.prepareStatement(getPageStatusSQL);
  241. ResultSet rs = pstm.executeQuery();
  242. if (rs.next())
  243. {
  244. lastUpdate = rs.getLong("last_update");
  245. }
  246. }
  247. catch (SQLException sqle)
  248. {
  249. LOG.error("Error in getReleasePageLastUpdate: " + sqle.toString());
  250. }
  251. finally
  252. {
  253. if (con != null)
  254. {
  255. try
  256. {
  257. connector.close(con);
  258. }
  259. catch (Exception e)
  260. {
  261. LOG.error("Error in closing MySQL connection: " + e.toString());
  262. }
  263. }
  264. }
  265. return lastUpdate;
  266. }
  267. /**
  268. * Update page's status for HTML page
  269. * @param con
  270. * @param pageURI
  271. * @return
  272. */
  273. public static boolean updateReleasePageStatus (int pageId, String status)
  274. {
  275. String updatePageStatusSQL = "Update bp_release_pages set status = ? " +
  276. "where page_id = '" + pageId + "' ";
  277. String updateImpactPageStatusSQL = null;
  278. if (status != null && status.equals("Editing"))
  279. {
  280. updatePageStatusSQL = "Update bp_release_pages set status = ? " +
  281. "where page_id = '" + pageId + "' and mode != 'Impacted'";
  282. updateImpactPageStatusSQL = "Update bp_release_pages set status = 'Edited' " +
  283. "where page_id = '" + pageId + "' and mode = 'Impacted'";
  284. }
  285. boolean updateOk = false;
  286. Connection con = null;
  287. DBConnector connector = DBConnector.getInstance();
  288. try
  289. {
  290. //con = connector.getDBConnFactory(Environment.SQL);
  291. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  292. con.setAutoCommit(false);
  293. PreparedStatement pstm = con.prepareStatement(updatePageStatusSQL);
  294. pstm.setString(1, status);
  295. pstm.executeUpdate();
  296. if (updateImpactPageStatusSQL != null)
  297. {
  298. pstm = con.prepareStatement(updateImpactPageStatusSQL);
  299. pstm.executeUpdate();
  300. }
  301. con.commit();
  302. con.setAutoCommit(true);
  303. updateOk = true;
  304. }
  305. catch (SQLException sqle)
  306. {
  307. LOG.error("Error in updateReleasePageStatus: " + sqle.toString());
  308. try
  309. {
  310. con.rollback();
  311. }
  312. catch (Exception e)
  313. {
  314. LOG.error("Error in updateReleasePageStatus rollback: " + e.toString());
  315. }
  316. }
  317. finally
  318. {
  319. if (con != null)
  320. {
  321. try
  322. {
  323. connector.close(con);
  324. }
  325. catch (Exception e)
  326. {
  327. LOG.error("Error in closing MySQL connection: " + e.toString());
  328. }
  329. }
  330. }
  331. return updateOk;
  332. }
  333. /**
  334. * Update page's status for HTML page
  335. * @param con
  336. * @param pageURI
  337. * @return
  338. */
  339. public static boolean updateReleasePageToUneditedState (int pageId, boolean isEdited, long lastUpdate)
  340. {
  341. String updatePageSelfEditedSQL = "Update bp_release_pages set self_edited = ?, last_update =? " +
  342. "where page_id = '" + pageId + "' ";
  343. String selfEdited = isEdited ? "Y" : "N";
  344. boolean updateOk = false;
  345. Connection con = null;
  346. DBConnector connector = DBConnector.getInstance();
  347. try
  348. {
  349. //con = connector.getDBConnFactory(Environment.SQL);
  350. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  351. con.setAutoCommit(false);
  352. PreparedStatement pstm = con.prepareStatement(updatePageSelfEditedSQL);
  353. pstm.setString(1, selfEdited);
  354. pstm.setLong(2, lastUpdate);
  355. pstm.executeUpdate();
  356. con.commit();
  357. con.setAutoCommit(true);
  358. updateOk = true;
  359. }
  360. catch (SQLException sqle)
  361. {
  362. LOG.error("Error in updateReleasePageSelfEdited: " + sqle.toString());
  363. try
  364. {
  365. con.rollback();
  366. }
  367. catch (Exception e)
  368. {
  369. LOG.error("Error in updateReleasePageSelfEdited rollback: " + e.toString());
  370. }
  371. }
  372. finally
  373. {
  374. if (con != null)
  375. {
  376. try
  377. {
  378. connector.close(con);
  379. }
  380. catch (Exception e)
  381. {
  382. LOG.error("Error in closing MySQL connection: " + e.toString());
  383. }
  384. }
  385. }
  386. return updateOk;
  387. }
  388. /**
  389. * Update page's last_update and status for HTML page
  390. * @param con
  391. * @param pageURI
  392. * @return
  393. */
  394. public static boolean updateReleasePageStatus (int pageId, String status, long lastUpdate)
  395. {
  396. String updatePageLastUpdateSQL = "Update bp_release_pages set mode = 'Edited', status = ?, last_update = ?, self_edited = 'Y' " +
  397. "where page_id = '" + pageId + "' ";
  398. boolean updateOk = false;
  399. Connection con = null;
  400. DBConnector connector = DBConnector.getInstance();
  401. try
  402. {
  403. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  404. con.setAutoCommit(false);
  405. PreparedStatement pstm = con.prepareStatement(updatePageLastUpdateSQL);
  406. pstm.setString(1, status);
  407. pstm.setLong(2, lastUpdate);
  408. pstm.executeUpdate();
  409. con.commit();
  410. con.setAutoCommit(true);
  411. updateOk = true;
  412. }
  413. catch (SQLException sqle)
  414. {
  415. LOG.error("Error in updateReleasePageStatus: " + sqle.toString());
  416. try
  417. {
  418. con.rollback();
  419. }
  420. catch (Exception e)
  421. {
  422. LOG.error("Error in updateReleasePageStatus rollback: " + e.toString());
  423. }
  424. }
  425. finally
  426. {
  427. if (con != null)
  428. {
  429. try
  430. {
  431. connector.close(con);
  432. }
  433. catch (Exception e)
  434. {
  435. LOG.error("Error in closing MySQL connection: " + e.toString());
  436. }
  437. }
  438. }
  439. return updateOk;
  440. }
  441. /**
  442. * Update status for all child page
  443. * @param con
  444. * @param pageURI
  445. * @return
  446. */
  447. public static boolean updateAllReleaseChildPageInfo (int parentId, String status, String notes, String bugId)
  448. {
  449. String updateAllReleaseChildInfoSQL = "Update bp_release_child_pages set status = ?, bug_id = ?, notes = ?" +
  450. "where parent_id = '" + parentId + "' ";
  451. boolean updateOk = false;
  452. Connection con = null;
  453. DBConnector connector = DBConnector.getInstance();
  454. try
  455. {
  456. //con = connector.getDBConnFactory(Environment.SQL);
  457. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  458. con.setAutoCommit(false);
  459. PreparedStatement pstm = con.prepareStatement(updateAllReleaseChildInfoSQL);
  460. pstm.setString(1, status);
  461. pstm.setString(2, bugId);
  462. pstm.setString(3, notes);
  463. pstm.executeUpdate();
  464. con.commit();
  465. con.setAutoCommit(true);
  466. updateOk = true;
  467. }
  468. catch (SQLException sqle)
  469. {
  470. LOG.error("Error in updateAllReleaseChildPageInfo: " + sqle.toString());
  471. try
  472. {
  473. con.rollback();
  474. }
  475. catch (Exception e)
  476. {
  477. LOG.error("Error in updateAllReleaseChildPageInfo rollback: " + e.toString());
  478. }
  479. }
  480. finally
  481. {
  482. if (con != null)
  483. {
  484. try
  485. {
  486. connector.close(con);
  487. }
  488. catch (Exception e)
  489. {
  490. LOG.error("Error in closing MySQL connection: " + e.toString());
  491. }
  492. }
  493. }
  494. return updateOk;
  495. }
  496. /**
  497. * Update page's last_update and status for child page
  498. * @param con
  499. * @param pageURI
  500. * @return
  501. */
  502. public static boolean updateReleaseChildPageMode (int pageId, String mode, long lastUpdate)
  503. {
  504. String updatePageLastUpdateSQL = "Update bp_release_child_pages set mode = ?, last_update = ? " +
  505. "where page_id = '" + pageId + "' ";
  506. boolean updateOk = false;
  507. Connection con = null;
  508. DBConnector connector = DBConnector.getInstance();
  509. try
  510. {
  511. //con = connector.getDBConnFactory(Environment.SQL);
  512. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  513. con.setAutoCommit(false);
  514. PreparedStatement pstm = con.prepareStatement(updatePageLastUpdateSQL);
  515. pstm.setString(1, mode);
  516. pstm.setLong(2, lastUpdate);
  517. pstm.executeUpdate();
  518. con.commit();
  519. con.setAutoCommit(true);
  520. updateOk = true;
  521. }
  522. catch (SQLException sqle)
  523. {
  524. LOG.error("Error in updateReleaseChildPageStatus: " + sqle.toString());
  525. try
  526. {
  527. con.rollback();
  528. }
  529. catch (Exception e)
  530. {
  531. LOG.error("Error in updateReleaseChildPageStatus rollback: " + e.toString());
  532. }
  533. }
  534. finally
  535. {
  536. if (con != null)
  537. {
  538. try
  539. {
  540. connector.close(con);
  541. }
  542. catch (Exception e)
  543. {
  544. LOG.error("Error in closing MySQL connection: " + e.toString());
  545. }
  546. }
  547. }
  548. return updateOk;
  549. }
  550. // /**
  551. // * Update status for all child page
  552. // * @param con
  553. // * @param pageURI
  554. // * @return
  555. // */
  556. // public static boolean updateAllReleaseChildPageStatus (int parentId, String status)
  557. // {
  558. // String updatePageLastUpdateSQL = "Update bp_release_child_pages set status = ? " +
  559. // "where parent_id = '" + parentId + "' ";
  560. //
  561. // boolean updateOk = false;
  562. // Connection con = null;
  563. // DBConnector connector = DBConnector.getInstance();
  564. // try
  565. // {
  566. // //con = connector.getDBConnFactory(Environment.SQL);
  567. // con = connector.getDBConnFactory(Environment.PENSIONLINE);
  568. //
  569. // con.setAutoCommit(false);
  570. // PreparedStatement pstm = con.prepareStatement(updatePageLastUpdateSQL);
  571. // pstm.setString(1, status);
  572. // pstm.executeUpdate();
  573. //
  574. // con.commit();
  575. // con.setAutoCommit(true);
  576. //
  577. // updateOk = true;
  578. // }
  579. // catch (SQLException sqle)
  580. // {
  581. // LOG.error("Error in updateAllReleaseChildPageStatus: " + sqle.toString());
  582. // try
  583. // {
  584. // con.rollback();
  585. // }
  586. // catch (Exception e)
  587. // {
  588. // LOG.error("Error in updateAllReleaseChildPageStatus rollback: " + e.toString());
  589. // }
  590. // }
  591. // finally
  592. // {
  593. // if (con != null)
  594. // {
  595. // try
  596. // {
  597. // connector.close(con);
  598. // }
  599. // catch (Exception e)
  600. // {
  601. // LOG.error("Error in closing MySQL connection: " + e.toString());
  602. // }
  603. // }
  604. // }
  605. //
  606. // return updateOk;
  607. // }
  608. /**
  609. * Set child page parentId if not existed
  610. * @param con
  611. * @param pageURI
  612. * @return: true if a record is updated, false otherwise
  613. */
  614. public static boolean addChildToPage (int parentId, int childId)
  615. {
  616. String checkChildParentExistedSQL = "Select count(*) as num from bp_release_childparent " +
  617. "where parent_id = '" + parentId + "' and child_id = '" + childId + "'";
  618. String addChildToPageSQL = "Insert into bp_release_childparent values (?, ?)";
  619. boolean updateOk = false;
  620. Connection con = null;
  621. DBConnector connector = DBConnector.getInstance();
  622. try
  623. {
  624. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  625. PreparedStatement pstmSelect = con.prepareStatement(checkChildParentExistedSQL);
  626. ResultSet rsSelect = pstmSelect.executeQuery();
  627. if (rsSelect.next())
  628. {
  629. int numRecord = rsSelect.getInt("num");
  630. if (numRecord == 0)
  631. {
  632. con.setAutoCommit(false);
  633. PreparedStatement pstm = con.prepareStatement(addChildToPageSQL);
  634. pstm.setInt(1, parentId);
  635. pstm.setInt(2, childId);
  636. pstm.executeUpdate();
  637. con.commit();
  638. con.setAutoCommit(true);
  639. updateOk = true;
  640. }
  641. }
  642. }
  643. catch (SQLException sqle)
  644. {
  645. LOG.error("Error in addChildToPage: " + sqle.toString());
  646. try
  647. {
  648. con.rollback();
  649. }
  650. catch (Exception e)
  651. {
  652. LOG.error("Error in addChildToPage rollback: " + e.toString());
  653. }
  654. }
  655. finally
  656. {
  657. if (con != null)
  658. {
  659. try
  660. {
  661. connector.close(con);
  662. }
  663. catch (Exception e)
  664. {
  665. LOG.error("Error in closing MySQL connection: " + e.toString());
  666. }
  667. }
  668. }
  669. LOG.info("addChildToPage for: " + parentId + " with " + childId+": "+updateOk);
  670. System.out.println("addChildToPage for: " + parentId + " with " + childId+": "+updateOk);
  671. return updateOk;
  672. }
  673. /**
  674. * Update publishing page based on page URI
  675. * @param con
  676. * @param pageId
  677. * @param status
  678. * @return
  679. */
  680. public static boolean updateReleasePageInfo (int pageId, String newStatus, String notes, String bugId)
  681. {
  682. String updatePageInfoSQL = "Update bp_release_pages set status = ?, notes = ?, bug_id = ? " +
  683. "where page_id = '" + pageId + "'";
  684. //LOG.info("updatePageInfoSQL: " + updatePageInfoSQL);
  685. Connection con = null;
  686. DBConnector connector = DBConnector.getInstance();
  687. boolean updateOk = false;
  688. try
  689. {
  690. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  691. con.setAutoCommit(false);
  692. PreparedStatement pstm = con.prepareStatement(updatePageInfoSQL);
  693. //long lastUpdate = DateTimeUtil.formatToOrderingTime(System.currentTimeMillis());
  694. pstm.setString(1, newStatus);
  695. pstm.setString(2, notes);
  696. pstm.setString(3, bugId);
  697. //pstm.setLong(4, lastUpdate);
  698. pstm.executeUpdate();
  699. con.commit();
  700. con.setAutoCommit(true);
  701. updateOk = true;
  702. }
  703. catch (SQLException sqle)
  704. {
  705. LOG.error("Error in updatePageInfo: " + sqle.toString());
  706. try
  707. {
  708. con.rollback();
  709. }
  710. catch (Exception e)
  711. {
  712. LOG.error("Error in updatePageInfo rollback: " + e.toString());
  713. }
  714. }
  715. finally
  716. {
  717. if (con != null)
  718. {
  719. try
  720. {
  721. connector.close(con);
  722. }
  723. catch (Exception e)
  724. {
  725. LOG.error("Error in closing MySQL connection: " + e.toString());
  726. }
  727. }
  728. }
  729. return updateOk;
  730. }
  731. /**
  732. * Insert a new release page and returns the page_id of new record inserted
  733. * @param con
  734. * @param pageDTO
  735. */
  736. public static int insertReleaseChildPage (ReleasePageDTO pageDTO)
  737. {
  738. String insertPageSQL = "Insert into bp_release_child_pages " +
  739. "(page_uri, mode, last_update) values (?, ?, ?)";
  740. int pageId = -1;
  741. Connection con = null;
  742. DBConnector connector = DBConnector.getInstance();
  743. try
  744. {
  745. //con = connector.getDBConnFactory(Environment.SQL);
  746. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  747. con.setAutoCommit(false);
  748. PreparedStatement pstm = con.prepareStatement(insertPageSQL);
  749. pstm.setString(1, pageDTO.getPageURI());
  750. pstm.setString(2, pageDTO.getMode());
  751. pstm.setLong(3, pageDTO.getLastUpdate());
  752. pstm.executeUpdate();
  753. con.commit();
  754. con.setAutoCommit(true);
  755. String getReleasePageSQL = "Select page_id from bp_release_child_pages where page_uri = '" + pageDTO.getPageURI() + "'";
  756. PreparedStatement getIdPstm = con.prepareStatement(getReleasePageSQL);
  757. ResultSet rs = getIdPstm.executeQuery();
  758. if (rs.next())
  759. {
  760. pageId = rs.getInt("page_id");
  761. }
  762. }
  763. catch (SQLException sqle)
  764. {
  765. LOG.error("Error in insertReleaseChildPage: " + sqle.toString());
  766. try
  767. {
  768. con.rollback();
  769. }
  770. catch (Exception e)
  771. {
  772. LOG.error("Error in insertReleaseChildPage rollback: " + e.toString());
  773. }
  774. }
  775. finally
  776. {
  777. if (con != null)
  778. {
  779. try
  780. {
  781. connector.close(con);
  782. }
  783. catch (Exception e)
  784. {
  785. LOG.error("Error in closing MySQL connection: " + e.toString());
  786. }
  787. }
  788. }
  789. return pageId;
  790. }
  791. /**
  792. * Insert a new release page and returns the page_id of new record inserted
  793. * @param con
  794. * @param pageDTO
  795. */
  796. public static int insertReleasePage (ReleasePageDTO pageDTO)
  797. {
  798. String insertPageSQL = "Insert into bp_release_pages " +
  799. "(page_uri, mode, status, bug_id, notes, last_update, self_edited) values (?, ?, ?, ?, ?, ?, ?)";
  800. int pageId = -1;
  801. Connection con = null;
  802. DBConnector connector = DBConnector.getInstance();
  803. try
  804. {
  805. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  806. //con = connector.getDBConnFactory(Environment.SQL);
  807. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  808. con.setAutoCommit(false);
  809. PreparedStatement pstm = con.prepareStatement(insertPageSQL);
  810. pstm.setString(1, pageDTO.getPageURI());
  811. pstm.setString(2, pageDTO.getMode());
  812. pstm.setString(3, pageDTO.getStatus());
  813. pstm.setString(4, pageDTO.getBugId());
  814. pstm.setString(5, pageDTO.getNotes());
  815. pstm.setLong(6, pageDTO.getLastUpdate());
  816. pstm.setString(7, pageDTO.getSelfEdited());
  817. pstm.executeUpdate();
  818. con.commit();
  819. con.setAutoCommit(true);
  820. String getReleasePageSQL = "Select page_id from bp_release_pages where page_uri = '" + pageDTO.getPageURI() + "'";
  821. PreparedStatement getIdPstm = con.prepareStatement(getReleasePageSQL);
  822. ResultSet rs = getIdPstm.executeQuery();
  823. if (rs.next())
  824. {
  825. pageId = rs.getInt("page_id");
  826. }
  827. }
  828. catch (SQLException sqle)
  829. {
  830. LOG.error("Error in insertReleasePage: " + sqle.toString());
  831. try
  832. {
  833. con.rollback();
  834. }
  835. catch (Exception e)
  836. {
  837. LOG.error("Error in insertReleasePage rollback: " + e.toString());
  838. }
  839. }
  840. finally
  841. {
  842. if (con != null)
  843. {
  844. try
  845. {
  846. connector.close(con);
  847. }
  848. catch (Exception e)
  849. {
  850. LOG.error("Error in closing MySQL connection: " + e.toString());
  851. }
  852. }
  853. }
  854. return pageId;
  855. }
  856. /**
  857. * Synchronize editing pages between CMS tables and publishing tables
  858. */
  859. public static void updatePageSystem (Vector cmsPageURIs)
  860. {
  861. Connection con = null;
  862. DBConnector connector = DBConnector.getInstance();
  863. try
  864. {
  865. // delete old records
  866. // Implement later
  867. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  868. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  869. for (int i = 0; i < cmsPageURIs.size(); i++)
  870. {
  871. // check if there is a file in the current release existed in bp_release_pages
  872. String pageURI = (String)cmsPageURIs.elementAt(i);
  873. insertPageToSystem(pageURI);
  874. }
  875. }
  876. catch (SQLException sqle)
  877. {
  878. LOG.error("Error in creating MySQL connection: " + sqle.toString());
  879. }
  880. finally
  881. {
  882. if (con != null)
  883. {
  884. try
  885. {
  886. connector.close(con);
  887. }
  888. catch (Exception e)
  889. {
  890. LOG.error("Error in closing MySQL connection: " + e.toString());
  891. }
  892. }
  893. }
  894. }
  895. /**
  896. * Insert a new release page
  897. * @param con
  898. * @param pageDTO
  899. */
  900. public static void insertPageToSystem (String pageURI)
  901. {
  902. String updatePageStatusSQL = "Insert into bp_page_system " +
  903. "(page_uri) values" +
  904. "('"
  905. + pageURI +
  906. "')";
  907. Connection con = null;
  908. DBConnector connector = DBConnector.getInstance();
  909. try
  910. {
  911. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  912. //con = connector.getDBConnFactory(Environment.SQL);
  913. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  914. con.setAutoCommit(false);
  915. PreparedStatement pstm = con.prepareStatement(updatePageStatusSQL);
  916. pstm.executeUpdate();
  917. con.commit();
  918. con.setAutoCommit(true);
  919. }
  920. catch (SQLException sqle)
  921. {
  922. LOG.error("Error in updatePageStatus: " + sqle.toString());
  923. try
  924. {
  925. con.rollback();
  926. }
  927. catch (Exception e)
  928. {
  929. LOG.error("Error in updatePageStatus rollback: " + e.toString());
  930. }
  931. }
  932. finally
  933. {
  934. if (con != null)
  935. {
  936. try
  937. {
  938. connector.close(con);
  939. }
  940. catch (Exception e)
  941. {
  942. LOG.error("Error in closing MySQL connection: " + e.toString());
  943. }
  944. }
  945. }
  946. }
  947. /**
  948. * This method delete the records in bp_release_pages table that is no longer valid for the publishing.
  949. * Eg, when a new page is created than deleted or a page marked as delete but then is unmarked by Author
  950. * @param pageURIs
  951. */
  952. public static void cleanReleasePages (Vector pageURIs)
  953. {
  954. if (pageURIs == null || pageURIs.size() == 0)
  955. {
  956. return;
  957. }
  958. // combine URI set
  959. StringBuffer pageSetBuf = new StringBuffer();
  960. pageSetBuf.append("(");
  961. for (int i = 0; i < pageURIs.size(); i++)
  962. {
  963. if (i == pageURIs.size() -1)
  964. {
  965. pageSetBuf.append("'").append(pageURIs.elementAt(i)).append("'");
  966. }
  967. else
  968. {
  969. pageSetBuf.append("'").append(pageURIs.elementAt(i)).append("',");
  970. }
  971. }
  972. pageSetBuf.append(")");
  973. String cleanQuery = "Delete from bp_release_pages where page_uri not in " + pageSetBuf.toString();
  974. Connection con = null;
  975. DBConnector connector = DBConnector.getInstance();
  976. try
  977. {
  978. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  979. //con = connector.getDBConnFactory(Environment.SQL);
  980. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  981. con.setAutoCommit(false);
  982. PreparedStatement pstm = con.prepareStatement(cleanQuery);
  983. pstm.executeUpdate();
  984. con.commit();
  985. con.setAutoCommit(true);
  986. }
  987. catch (SQLException sqle)
  988. {
  989. LOG.error("Error in cleanReleasePages: " + sqle.toString());
  990. try
  991. {
  992. con.rollback();
  993. }
  994. catch (Exception e)
  995. {
  996. LOG.error("Error in cleanReleasePages rollback: " + e.toString());
  997. }
  998. }
  999. finally
  1000. {
  1001. if (con != null)
  1002. {
  1003. try
  1004. {
  1005. connector.close(con);
  1006. }
  1007. catch (Exception e)
  1008. {
  1009. LOG.error("Error in closing MySQL connection: " + e.toString());
  1010. }
  1011. }
  1012. }
  1013. }
  1014. /**
  1015. * This method delete the records in bp_release_pages table that is no longer valid for the publishing.
  1016. * Eg, when a new page is created than deleted or a page marked as delete but then is unmarked by Author
  1017. * Dont use this method.
  1018. * @param pageIds
  1019. */
  1020. public static void cleanReleaseChildPages (Vector<ReleasePageDTO> pageDTOs, String prefix)
  1021. {
  1022. if (pageDTOs == null)
  1023. {
  1024. return;
  1025. }
  1026. // combine URI set
  1027. StringBuffer pageSetBuf = new StringBuffer();
  1028. pageSetBuf.append("(''");
  1029. for (int i = 0; i < pageDTOs.size(); i++)
  1030. {
  1031. ReleasePageDTO childPage = pageDTOs.elementAt(i);
  1032. pageSetBuf.append(",'").append(childPage.getPageId()).append("'");
  1033. }
  1034. pageSetBuf.append(")");
  1035. // clean child pages
  1036. String cleanChildQuery = "Delete from bp_release_child_pages where page_id not in " + pageSetBuf.toString() + " and page_uri like '" + prefix + "%'";
  1037. String cleanChildParentQuery = "Delete from bp_release_childparent where child_id in " +
  1038. "(select page_id from bp_release_child_pages where page_id not in "
  1039. + pageSetBuf.toString() + " and page_uri like '" + prefix + "%')";
  1040. LOG.info("Clean child pages: " + cleanChildQuery);
  1041. LOG.info("Clean child_parent links: " + cleanChildParentQuery);
  1042. Connection con = null;
  1043. DBConnector connector = DBConnector.getInstance();
  1044. try
  1045. {
  1046. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1047. //con = connector.getDBConnFactory(Environment.SQL);
  1048. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1049. con.setAutoCommit(false);
  1050. PreparedStatement pstm = con.prepareStatement(cleanChildParentQuery);
  1051. pstm.executeUpdate();
  1052. con.commit();
  1053. pstm = con.prepareStatement(cleanChildQuery);
  1054. pstm.executeUpdate();
  1055. con.commit();
  1056. con.setAutoCommit(true);
  1057. }
  1058. catch (SQLException sqle)
  1059. {
  1060. LOG.error("Error in cleanReleaseChildPages: " + sqle.toString());
  1061. try
  1062. {
  1063. con.rollback();
  1064. }
  1065. catch (Exception e)
  1066. {
  1067. LOG.error("Error in cleanReleaseChildPages rollback: " + e.toString());
  1068. }
  1069. }
  1070. finally
  1071. {
  1072. if (con != null)
  1073. {
  1074. try
  1075. {
  1076. connector.close(con);
  1077. }
  1078. catch (Exception e)
  1079. {
  1080. LOG.error("Error in closing MySQL connection: " + e.toString());
  1081. }
  1082. }
  1083. }
  1084. }
  1085. /**
  1086. * Record action made with page in publishing
  1087. * @param pageId
  1088. * @param userId
  1089. * @param actionType
  1090. * @param notes
  1091. * @param time Formated long value: YYYYmmddHHmmss
  1092. * @return
  1093. */
  1094. public static boolean insertReleaseAction (int pageId, String userId, String status,
  1095. String notes, long updateTime)
  1096. {
  1097. LOG.info("insertReleaseAction():BEGIN");
  1098. LOG.info(updateTime);
  1099. String insertReleaseActionSQL = "Insert into bp_release_actions " +
  1100. "(page_id, user_id, status, notes, action_time) values (?, ?, ?, ?, ?)";
  1101. boolean result = false;
  1102. Connection con = null;
  1103. DBConnector connector = DBConnector.getInstance();
  1104. try
  1105. {
  1106. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1107. //con = connector.getDBConnFactory(Environment.SQL);
  1108. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1109. con.setAutoCommit(false);
  1110. PreparedStatement pstm = con.prepareStatement(insertReleaseActionSQL);
  1111. pstm.setInt(1, pageId);
  1112. pstm.setString(2, userId);
  1113. pstm.setString(3, status);
  1114. pstm.setString(4, notes);
  1115. pstm.setLong(5, updateTime);
  1116. pstm.executeUpdate();
  1117. con.commit();
  1118. con.setAutoCommit(true);
  1119. result = true;
  1120. }
  1121. catch (SQLException sqle)
  1122. {
  1123. LOG.error("Error in insertReleaseAction: " + sqle.toString());
  1124. try
  1125. {
  1126. con.rollback();
  1127. }
  1128. catch (Exception e)
  1129. {
  1130. LOG.error("Error in insertReleaseAction rollback: " + e.toString());
  1131. }
  1132. }
  1133. finally
  1134. {
  1135. if (con != null)
  1136. {
  1137. try
  1138. {
  1139. connector.close(con);
  1140. }
  1141. catch (Exception e)
  1142. {
  1143. LOG.error("Error in closing MySQL connection: " + e.toString());
  1144. }
  1145. }
  1146. }
  1147. LOG.info("insertReleaseAction():END");
  1148. return result;
  1149. }
  1150. public static boolean insertOrphanReleaseAction (int pageId, String userId, String status,
  1151. String notes, long updateTime)
  1152. {
  1153. LOG.info("insertOrphanReleaseAction():BEGIN");
  1154. LOG.info(updateTime);
  1155. String insertReleaseActionSQL = "Insert into bp_release_actions " +
  1156. "(page_id, childpage_id, user_id, status, notes, action_time) values (-1, ?, ?, ?, ?, ?)";
  1157. boolean result = false;
  1158. Connection con = null;
  1159. DBConnector connector = DBConnector.getInstance();
  1160. try
  1161. {
  1162. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1163. //con = connector.getDBConnFactory(Environment.SQL);
  1164. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1165. con.setAutoCommit(false);
  1166. PreparedStatement pstm = con.prepareStatement(insertReleaseActionSQL);
  1167. pstm.setInt(1, pageId);
  1168. pstm.setString(2, userId);
  1169. pstm.setString(3, status);
  1170. pstm.setString(4, notes);
  1171. pstm.setLong(5, updateTime);
  1172. pstm.executeUpdate();
  1173. con.commit();
  1174. con.setAutoCommit(true);
  1175. result = true;
  1176. }
  1177. catch (SQLException sqle)
  1178. {
  1179. LOG.error("Error in insertOrphanReleaseAction: " + sqle.toString());
  1180. try
  1181. {
  1182. con.rollback();
  1183. }
  1184. catch (Exception e)
  1185. {
  1186. LOG.error("Error in insertOrphanReleaseAction rollback: " + e.toString());
  1187. }
  1188. }
  1189. finally
  1190. {
  1191. if (con != null)
  1192. {
  1193. try
  1194. {
  1195. connector.close(con);
  1196. }
  1197. catch (Exception e)
  1198. {
  1199. LOG.error("Error in closing MySQL connection: " + e.toString());
  1200. }
  1201. }
  1202. }
  1203. LOG.info("insertOrphanReleaseAction():END");
  1204. return result;
  1205. }
  1206. /**
  1207. * Build action histories of this page
  1208. * @param pageId
  1209. * @return
  1210. */
  1211. public static String buildActionHistories (int pageId)
  1212. {
  1213. String selectReleaseActionSQL = "Select notes from bp_release_actions where page_id = '"
  1214. + pageId + "' order by action_time desc";
  1215. StringBuffer actionHisBuf = new StringBuffer();
  1216. Connection con = null;
  1217. DBConnector connector = DBConnector.getInstance();
  1218. try
  1219. {
  1220. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1221. //con = connector.getDBConnFactory(Environment.SQL);
  1222. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1223. PreparedStatement pstm = con.prepareStatement(selectReleaseActionSQL);
  1224. ResultSet rs = pstm.executeQuery();
  1225. while (rs.next())
  1226. {
  1227. String notes = rs.getString("notes");
  1228. if (notes != null)
  1229. {
  1230. actionHisBuf.append(notes).append("\n\n");
  1231. }
  1232. }
  1233. if (actionHisBuf.length() >= 2)
  1234. {
  1235. actionHisBuf.delete(actionHisBuf.length() - 2, actionHisBuf.length());
  1236. }
  1237. }
  1238. catch (SQLException sqle)
  1239. {
  1240. LOG.error("Error in buildActionHistories: " + sqle.toString());
  1241. }
  1242. finally
  1243. {
  1244. if (con != null)
  1245. {
  1246. try
  1247. {
  1248. connector.close(con);
  1249. }
  1250. catch (Exception e)
  1251. {
  1252. LOG.error("Error in closing MySQL connection: " + e.toString());
  1253. }
  1254. }
  1255. }
  1256. return actionHisBuf.toString();
  1257. }
  1258. /**
  1259. * Build action histories for orphan documents
  1260. * @param pageId
  1261. * @return
  1262. */
  1263. public static String buildOrphanActionHistories (int pageId)
  1264. {
  1265. String selectReleaseActionSQL = "Select notes from bp_release_actions where childpage_id = '"
  1266. + pageId + "' order by action_time desc";
  1267. StringBuffer actionHisBuf = new StringBuffer();
  1268. Connection con = null;
  1269. DBConnector connector = DBConnector.getInstance();
  1270. try
  1271. {
  1272. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1273. //con = connector.getDBConnFactory(Environment.SQL);
  1274. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1275. PreparedStatement pstm = con.prepareStatement(selectReleaseActionSQL);
  1276. ResultSet rs = pstm.executeQuery();
  1277. while (rs.next())
  1278. {
  1279. String notes = rs.getString("notes");
  1280. if (notes != null)
  1281. {
  1282. actionHisBuf.append(notes).append("\n\n");
  1283. }
  1284. }
  1285. if (actionHisBuf.length() >= 2)
  1286. {
  1287. actionHisBuf.delete(actionHisBuf.length() - 2, actionHisBuf.length());
  1288. }
  1289. }
  1290. catch (SQLException sqle)
  1291. {
  1292. LOG.error("Error in buildActionHistories: " + sqle.toString());
  1293. }
  1294. finally
  1295. {
  1296. if (con != null)
  1297. {
  1298. try
  1299. {
  1300. connector.close(con);
  1301. }
  1302. catch (Exception e)
  1303. {
  1304. LOG.error("Error in closing MySQL connection: " + e.toString());
  1305. }
  1306. }
  1307. }
  1308. return actionHisBuf.toString();
  1309. }
  1310. /**
  1311. * Get the last publishing action userId right before the page change to status
  1312. * @param pageId
  1313. * @param status: Status that the page is changed by user
  1314. * @return
  1315. */
  1316. public static String getLastPublishingActionUserId (int pageId, String status)
  1317. {
  1318. String getMaxUpdateActionSQL = "Select max(action_time) as atMax from bp_release_actions where page_id = '"
  1319. + pageId + "' and status = '" + status + "'";
  1320. String getLastUserActionSQL = "Select user_id from bp_release_actions where page_id = '"
  1321. + pageId + "' and status = '" + status + "' and action_time = ?";
  1322. Connection con = null;
  1323. DBConnector connector = DBConnector.getInstance();
  1324. try
  1325. {
  1326. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1327. //con = connector.getDBConnFactory(Environment.SQL);
  1328. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1329. PreparedStatement pstmGetMax = con.prepareStatement(getMaxUpdateActionSQL);
  1330. ResultSet rsGetMax = pstmGetMax.executeQuery();
  1331. if (rsGetMax.next())
  1332. {
  1333. long maxActionTime = rsGetMax.getLong("atMax");
  1334. // Get user_id from max action time
  1335. PreparedStatement pstmLastUser = con.prepareStatement(getLastUserActionSQL);
  1336. pstmLastUser.setLong(1, maxActionTime);
  1337. ResultSet rsLastUser = pstmLastUser.executeQuery();
  1338. if (rsLastUser.next())
  1339. {
  1340. return rsLastUser.getString("user_id");
  1341. }
  1342. }
  1343. }
  1344. catch (SQLException sqle)
  1345. {
  1346. LOG.error("Error in getLastPublishingActionUserId: " + sqle.toString());
  1347. }
  1348. finally
  1349. {
  1350. if (con != null)
  1351. {
  1352. try
  1353. {
  1354. connector.close(con);
  1355. }
  1356. catch (Exception e)
  1357. {
  1358. LOG.error("Error in closing MySQL connection: " + e.toString());
  1359. }
  1360. }
  1361. }
  1362. return null;
  1363. }
  1364. /**
  1365. * Delete release page by pageId
  1366. * @return
  1367. */
  1368. public static boolean removeReleasePage (int pageId)
  1369. {
  1370. String deleteReleasePageSQL = "Delete from bp_release_pages where page_id = '" + pageId + "'";
  1371. boolean result = false;
  1372. Connection con = null;
  1373. DBConnector connector = DBConnector.getInstance();
  1374. try
  1375. {
  1376. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1377. //con = connector.getDBConnFactory(Environment.SQL);
  1378. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1379. con.setAutoCommit(false);
  1380. PreparedStatement pstm = con.prepareStatement(deleteReleasePageSQL);
  1381. pstm.executeUpdate();
  1382. con.commit();
  1383. con.setAutoCommit(true);
  1384. result = true;
  1385. }
  1386. catch (SQLException sqle)
  1387. {
  1388. LOG.error("Error in deleteReleasePage: " + sqle.toString());
  1389. try
  1390. {
  1391. con.rollback();
  1392. }
  1393. catch (Exception e)
  1394. {
  1395. LOG.error("Error in deleteReleasePage rollback: " + e.toString());
  1396. }
  1397. }
  1398. finally
  1399. {
  1400. if (con != null)
  1401. {
  1402. try
  1403. {
  1404. connector.close(con);
  1405. }
  1406. catch (Exception e)
  1407. {
  1408. LOG.error("Error in closing MySQL connection: " + e.toString());
  1409. }
  1410. }
  1411. }
  1412. return result;
  1413. }
  1414. /**
  1415. * Delete release child page by pageId
  1416. * @return
  1417. */
  1418. public static boolean removeReleaseChildPage (int childPageId)
  1419. {
  1420. String deleteReleaseChildPageSQL = "Delete from bp_release_child_pages where page_id = '" + childPageId + "'";
  1421. boolean result = false;
  1422. Connection con = null;
  1423. DBConnector connector = DBConnector.getInstance();
  1424. try
  1425. {
  1426. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1427. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1428. con.setAutoCommit(false);
  1429. PreparedStatement pstm = con.prepareStatement(deleteReleaseChildPageSQL);
  1430. pstm.executeUpdate();
  1431. con.commit();
  1432. con.setAutoCommit(true);
  1433. result = true;
  1434. }
  1435. catch (SQLException sqle)
  1436. {
  1437. LOG.error("Error in removeReleaseChildPage: " + sqle.toString());
  1438. try
  1439. {
  1440. con.rollback();
  1441. }
  1442. catch (Exception e)
  1443. {
  1444. LOG.error("Error in removeReleaseChildPage rollback: " + e.toString());
  1445. }
  1446. }
  1447. finally
  1448. {
  1449. if (con != null)
  1450. {
  1451. try
  1452. {
  1453. connector.close(con);
  1454. }
  1455. catch (Exception e)
  1456. {
  1457. LOG.error("Error in closing MySQL connection: " + e.toString());
  1458. }
  1459. }
  1460. }
  1461. return result;
  1462. }
  1463. /**
  1464. * Delete release actions by pageId
  1465. * @return
  1466. */
  1467. public static boolean removeReleaseActions (int pageId)
  1468. {
  1469. String deleteReleasePageSQL = "Delete from bp_release_actions where page_id = '" + pageId + "'";
  1470. boolean result = false;
  1471. Connection con = null;
  1472. DBConnector connector = DBConnector.getInstance();
  1473. try
  1474. {
  1475. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1476. //con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1477. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1478. con.setAutoCommit(false);
  1479. PreparedStatement pstm = con.prepareStatement(deleteReleasePageSQL);
  1480. pstm.executeUpdate();
  1481. con.commit();
  1482. con.setAutoCommit(true);
  1483. result = true;
  1484. }
  1485. catch (SQLException sqle)
  1486. {
  1487. LOG.error("Error in deleteReleaseActions: " + sqle.toString());
  1488. try
  1489. {
  1490. con.rollback();
  1491. }
  1492. catch (Exception e)
  1493. {
  1494. LOG.error("Error in deleteReleaseActions rollback: " + e.toString());
  1495. }
  1496. }
  1497. finally
  1498. {
  1499. if (con != null)
  1500. {
  1501. try
  1502. {
  1503. connector.close(con);
  1504. }
  1505. catch (Exception e)
  1506. {
  1507. LOG.error("Error in closing MySQL connection: " + e.toString());
  1508. }
  1509. }
  1510. }
  1511. return result;
  1512. }
  1513. /**
  1514. * Delete release child pages by parentId
  1515. * @return
  1516. */
  1517. public static boolean removeReleaseChildPagesByParent (int parentId)
  1518. {
  1519. String selectChildIdFromParentSQL = "Select child_id from bp_release_childparent " +
  1520. "where parent_id = '" + parentId + "'";
  1521. String deleteReleaseChildPageSQL = "Delete from bp_release_child_pages where page_id in ";
  1522. String deleteChildParentSQL = "Delete from bp_release_childparent where child_id in ";
  1523. boolean result = false;
  1524. Connection con = null;
  1525. DBConnector connector = DBConnector.getInstance();
  1526. try
  1527. {
  1528. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1529. //con = connector.getDBConnFactory(Environment.SQL);
  1530. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1531. // get child_id set from parent_id
  1532. PreparedStatement pstm = con.prepareStatement(selectChildIdFromParentSQL);
  1533. ResultSet rs = pstm.executeQuery();
  1534. StringBuffer inCondStrBuf = new StringBuffer("(''");
  1535. while (rs.next())
  1536. {
  1537. int child_id = rs.getInt("child_id");
  1538. inCondStrBuf.append(",'").append(child_id).append("'");
  1539. }
  1540. inCondStrBuf.append(")");
  1541. con.setAutoCommit(false);
  1542. LOG.info("deleteReleaseChildPageSQL: " + deleteReleaseChildPageSQL + inCondStrBuf.toString());
  1543. pstm = con.prepareStatement(deleteReleaseChildPageSQL + inCondStrBuf.toString());
  1544. pstm.executeUpdate();
  1545. // delete child-parent relationship
  1546. pstm = con.prepareStatement(deleteChildParentSQL + inCondStrBuf.toString());
  1547. pstm.executeUpdate();
  1548. con.commit();
  1549. con.setAutoCommit(true);
  1550. result = true;
  1551. }
  1552. catch (SQLException sqle)
  1553. {
  1554. LOG.error("Error in removeReleaseChildPagesByParent: " + sqle.toString());
  1555. try
  1556. {
  1557. con.rollback();
  1558. }
  1559. catch (Exception e)
  1560. {
  1561. LOG.error("Error in removeReleaseChildPagesByParent rollback: " + e.toString());
  1562. }
  1563. }
  1564. finally
  1565. {
  1566. if (con != null)
  1567. {
  1568. try
  1569. {
  1570. connector.close(con);
  1571. }
  1572. catch (Exception e)
  1573. {
  1574. LOG.error("Error in closing MySQL connection: " + e.toString());
  1575. }
  1576. }
  1577. }
  1578. return result;
  1579. }
  1580. /**
  1581. * Delete release child pages by parentId
  1582. * @return
  1583. */
  1584. public static boolean removeAllInvalidParentPages ()
  1585. {
  1586. String selectAllParentIdSQL = "Select parent_id from bp_release_childparent";
  1587. String deleteInvalidParentPageSQL = "Delete from bp_release_pages where mode = 'Impacted' and " +
  1588. "self_edited = 'N' and page_id not in ";
  1589. boolean result = false;
  1590. Connection con = null;
  1591. DBConnector connector = DBConnector.getInstance();
  1592. try
  1593. {
  1594. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1595. //con = connector.getDBConnFactory(Environment.SQL);
  1596. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1597. // get child_id set from parent_id
  1598. PreparedStatement pstm = con.prepareStatement(selectAllParentIdSQL);
  1599. ResultSet rs = pstm.executeQuery();
  1600. StringBuffer inCondStrBuf = new StringBuffer("(''");
  1601. while (rs.next())
  1602. {
  1603. int parent_id = rs.getInt("parent_id");
  1604. inCondStrBuf.append(",'").append(parent_id).append("'");
  1605. }
  1606. inCondStrBuf.append(")");
  1607. con.setAutoCommit(false);
  1608. LOG.info("deleteInvalidParentPageSQL: " + deleteInvalidParentPageSQL + inCondStrBuf.toString());
  1609. pstm = con.prepareStatement(deleteInvalidParentPageSQL + inCondStrBuf.toString());
  1610. pstm.executeUpdate();
  1611. con.commit();
  1612. con.setAutoCommit(true);
  1613. result = true;
  1614. }
  1615. catch (SQLException sqle)
  1616. {
  1617. LOG.error("Error in removeAllInvalidParentPages: " + sqle.toString());
  1618. try
  1619. {
  1620. con.rollback();
  1621. }
  1622. catch (Exception e)
  1623. {
  1624. LOG.error("Error in removeAllInvalidParentPages rollback: " + e.toString());
  1625. }
  1626. }
  1627. finally
  1628. {
  1629. if (con != null)
  1630. {
  1631. try
  1632. {
  1633. connector.close(con);
  1634. }
  1635. catch (Exception e)
  1636. {
  1637. LOG.error("Error in closing MySQL connection: " + e.toString());
  1638. }
  1639. }
  1640. }
  1641. return result;
  1642. }
  1643. /**
  1644. * Get all approved pages for deploy
  1645. * @return
  1646. */
  1647. public static Vector<ReleasePageDTO> getAllApprovedParentPages ()
  1648. {
  1649. String selectAllApprovedPagesSQL = "Select page_id, page_uri, mode, status, bug_id, notes, last_update " +
  1650. "from bp_release_pages where status = 'Approved'";
  1651. Vector<ReleasePageDTO> approvedPages = new Vector<ReleasePageDTO>();
  1652. Connection con = null;
  1653. DBConnector connector = DBConnector.getInstance();
  1654. try
  1655. {
  1656. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1657. //con = connector.getDBConnFactory(Environment.SQL);
  1658. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1659. PreparedStatement pstm = con.prepareStatement(selectAllApprovedPagesSQL);
  1660. ResultSet rs = pstm.executeQuery();
  1661. ReleasePageDTO pageDTO = null;
  1662. while (rs.next())
  1663. {
  1664. pageDTO = new ReleasePageDTO();
  1665. pageDTO.setPageId(rs.getInt("page_id"));
  1666. pageDTO.setParentId(-1);
  1667. pageDTO.setPageURI(rs.getString("page_uri"));
  1668. pageDTO.setMode(rs.getString("mode"));
  1669. pageDTO.setStatus(rs.getString("status"));
  1670. pageDTO.setBugId(rs.getString("bug_id"));
  1671. pageDTO.setNotes(rs.getString("notes"));
  1672. pageDTO.setLastUpdate(rs.getLong("last_update"));
  1673. pageDTO.setSelfEdited("Y");
  1674. approvedPages.add(pageDTO);
  1675. }
  1676. }
  1677. catch (SQLException sqle)
  1678. {
  1679. LOG.error("Error in getAllApprovedParentPages: " + sqle.toString());
  1680. }
  1681. finally
  1682. {
  1683. if (con != null)
  1684. {
  1685. try
  1686. {
  1687. connector.close(con);
  1688. }
  1689. catch (Exception e)
  1690. {
  1691. LOG.error("Error in closing MySQL connection: " + e.toString());
  1692. }
  1693. }
  1694. }
  1695. return approvedPages;
  1696. }
  1697. /**
  1698. * Check if a parent page is Ok to deploy:
  1699. * - It has no children that whose's parent are not approved
  1700. * - It has status of 'Approved'
  1701. * @return
  1702. */
  1703. public static boolean isParentPageReadyToDeploy (int parentId)
  1704. {
  1705. String checkAllChildren = "select count(*) as numC from bp_release_childparent cp where cp.parent_id = '" + parentId + "'";
  1706. String checkParentStatus = "select status from bp_release_pages where page_id = '" + parentId + "'";
  1707. String selectChildIdFromParentSQL = "Select child_id from bp_release_childparent " +
  1708. "where parent_id = '" + parentId + "'";
  1709. String checkAllParentApproved = "Select count(*) as num from bp_release_pages p inner join bp_release_childparent cp on (p.page_id = cp.parent_id) " +
  1710. "where p.status != 'Approved' and p.status != 'Deployed' and cp.child_id in (" +
  1711. selectChildIdFromParentSQL +")";
  1712. boolean result = false;
  1713. Connection con = null;
  1714. DBConnector connector = DBConnector.getInstance();
  1715. try
  1716. {
  1717. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1718. //con = connector.getDBConnFactory(Environment.SQL);
  1719. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1720. // get child_id set from parent_id
  1721. PreparedStatement pstm = con.prepareStatement(checkAllChildren);
  1722. ResultSet rs = pstm.executeQuery();
  1723. if (rs.next())
  1724. {
  1725. int numC = rs.getInt("numC");
  1726. rs.close();
  1727. pstm.close();
  1728. if (numC > 0)
  1729. {
  1730. // Check other parent of their children
  1731. pstm = con.prepareStatement(selectChildIdFromParentSQL);
  1732. rs = pstm.executeQuery();
  1733. //LOG.info("checkAllParentApproved: " + checkAllParentApproved);
  1734. pstm = con.prepareStatement(checkAllParentApproved);
  1735. rs = pstm.executeQuery();
  1736. if (rs.next())
  1737. {
  1738. int num = rs.getInt("num");
  1739. if (num == 0)
  1740. {
  1741. result = true;
  1742. }
  1743. }
  1744. }
  1745. else
  1746. {
  1747. pstm = con.prepareStatement(checkParentStatus);
  1748. rs = pstm.executeQuery();
  1749. if (rs.next())
  1750. {
  1751. String status = rs.getString("status");
  1752. if (status != null && (status.equals("Approved") || status.equals("Deployed")))
  1753. {
  1754. result = true;
  1755. }
  1756. }
  1757. }
  1758. }
  1759. }
  1760. catch (SQLException sqle)
  1761. {
  1762. LOG.error("Error in removeReleaseChildPagesByParent: " + sqle.toString());
  1763. }
  1764. finally
  1765. {
  1766. if (con != null)
  1767. {
  1768. try
  1769. {
  1770. connector.close(con);
  1771. }
  1772. catch (Exception e)
  1773. {
  1774. LOG.error("Error in closing MySQL connection: " + e.toString());
  1775. }
  1776. }
  1777. }
  1778. return result;
  1779. }
  1780. /**
  1781. * Check if a child page is Ok to deploy:
  1782. * - Has at least 1 parent
  1783. * - All parent are approved
  1784. * @return
  1785. */
  1786. public static boolean isChildPageReadyToDeploy (int childPageId)
  1787. {
  1788. String checkAllParentApproved = "Select count(*) as numAP from bp_release_pages p inner join bp_release_childparent cp on (p.page_id = cp.parent_id) " +
  1789. "where (p.status = 'Approved' or p.status = 'Deployed') and cp.child_id = '" + childPageId + "'";
  1790. String checkAllParent = "select count(*) as numP from bp_release_childparent cp where cp.child_id = '" + childPageId + "'";
  1791. boolean result = false;
  1792. Connection con = null;
  1793. DBConnector connector = DBConnector.getInstance();
  1794. try
  1795. {
  1796. int numParentApproved = 0;
  1797. int numAllParent = 0;
  1798. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1799. //con = connector.getDBConnFactory(Environment.SQL);
  1800. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1801. // get child_id set from parent_id
  1802. PreparedStatement pstm = con.prepareStatement(checkAllParentApproved);
  1803. ResultSet rs = pstm.executeQuery();
  1804. if (rs.next())
  1805. {
  1806. numParentApproved = rs.getInt("numAP");
  1807. }
  1808. pstm = con.prepareStatement(checkAllParent);
  1809. rs = pstm.executeQuery();
  1810. if (rs.next())
  1811. {
  1812. numAllParent = rs.getInt("numP");
  1813. }
  1814. if (numParentApproved > 0 && numParentApproved == numAllParent)
  1815. {
  1816. result = true;
  1817. }
  1818. }
  1819. catch (SQLException sqle)
  1820. {
  1821. LOG.error("Error in removeReleaseChildPagesByParent: " + sqle.toString());
  1822. }
  1823. finally
  1824. {
  1825. if (con != null)
  1826. {
  1827. try
  1828. {
  1829. connector.close(con);
  1830. }
  1831. catch (Exception e)
  1832. {
  1833. LOG.error("Error in closing MySQL connection: " + e.toString());
  1834. }
  1835. }
  1836. }
  1837. return result;
  1838. }
  1839. /**
  1840. * Check if a child page has been deployed:
  1841. * - Has at least 1 parent
  1842. * - All parent are approved
  1843. * @return
  1844. */
  1845. public static boolean isChildPageDeployed (int childPageId)
  1846. {
  1847. String checkAllParentDeployed = "Select count(*) as numDP from bp_release_pages p inner join bp_release_childparent cp on (p.page_id = cp.parent_id) " +
  1848. "where p.status = 'Deployed' and cp.child_id = '" + childPageId + "'";
  1849. String checkAllParent = "select count(*) as numP from bp_release_childparent cp where cp.child_id = '" + childPageId + "'";
  1850. boolean result = false;
  1851. Connection con = null;
  1852. DBConnector connector = DBConnector.getInstance();
  1853. try
  1854. {
  1855. int numParentApproved = 0;
  1856. int numAllParent = 0;
  1857. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1858. //con = connector.getDBConnFactory(Environment.SQL);
  1859. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1860. // get child_id set from parent_id
  1861. PreparedStatement pstm = con.prepareStatement(checkAllParentDeployed);
  1862. ResultSet rs = pstm.executeQuery();
  1863. if (rs.next())
  1864. {
  1865. numParentApproved = rs.getInt("numDP");
  1866. }
  1867. pstm = con.prepareStatement(checkAllParent);
  1868. rs = pstm.executeQuery();
  1869. if (rs.next())
  1870. {
  1871. numAllParent = rs.getInt("numP");
  1872. }
  1873. if (numParentApproved > 0 && numParentApproved == numAllParent)
  1874. {
  1875. result = true;
  1876. }
  1877. }
  1878. catch (SQLException sqle)
  1879. {
  1880. LOG.error("Error in removeReleaseChildPagesByParent: " + sqle.toString());
  1881. }
  1882. finally
  1883. {
  1884. if (con != null)
  1885. {
  1886. try
  1887. {
  1888. connector.close(con);
  1889. }
  1890. catch (Exception e)
  1891. {
  1892. LOG.error("Error in closing MySQL connection: " + e.toString());
  1893. }
  1894. }
  1895. }
  1896. return result;
  1897. }
  1898. /**
  1899. * Check if there is deployable pages in the system
  1900. * @return
  1901. */
  1902. public static boolean hasDeployablePages ()
  1903. {
  1904. String selectApprovedPageIdsSQL = "Select page_id " +
  1905. "from bp_release_pages where status = 'Approved'";
  1906. Connection con = null;
  1907. DBConnector connector = DBConnector.getInstance();
  1908. boolean result = false;
  1909. try
  1910. {
  1911. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1912. //con = connector.getDBConnFactory(Environment.SQL);
  1913. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1914. PreparedStatement pstm = con.prepareStatement(selectApprovedPageIdsSQL);
  1915. ResultSet rs = pstm.executeQuery();
  1916. while (rs.next())
  1917. {
  1918. int pageId = rs.getInt("page_id");
  1919. if (isParentPageReadyToDeploy(pageId))
  1920. {
  1921. result = true;
  1922. break;
  1923. }
  1924. }
  1925. Statement stat = con.createStatement();
  1926. ResultSet rst = stat.executeQuery("SELECT * FROM bp_release_child_pages where status='Approved'");
  1927. if (rst.next()) {
  1928. return true;
  1929. }
  1930. }
  1931. catch (SQLException sqle)
  1932. {
  1933. LOG.error("Error in hasDeployablePages: " + sqle.toString());
  1934. }
  1935. finally
  1936. {
  1937. if (con != null)
  1938. {
  1939. try
  1940. {
  1941. connector.close(con);
  1942. }
  1943. catch (Exception e)
  1944. {
  1945. LOG.error("Error in closing MySQL connection: " + e.toString());
  1946. }
  1947. }
  1948. }
  1949. return result;
  1950. }
  1951. /**
  1952. * Create a release package by inserting a new record to bp_releases table
  1953. * @param packageName
  1954. * @return Id of new package inserted
  1955. */
  1956. public static int createReleasePackage(String packageName, String notes)
  1957. {
  1958. if (packageName == null || packageName.trim().equals(""))
  1959. {
  1960. return -1;
  1961. }
  1962. String insertReleaseSQL = "Insert into bp_releases (released, package_name, notes) values (?, ?, ?)";
  1963. int releaseId = -1;
  1964. Connection con = null;
  1965. DBConnector connector = DBConnector.getInstance();
  1966. try
  1967. {
  1968. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  1969. //con = connector.getDBConnFactory(Environment.SQL);
  1970. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  1971. con.setAutoCommit(false);
  1972. PreparedStatement pstm = con.prepareStatement(insertReleaseSQL);
  1973. long released = DateTimeUtil.formatToOrderingTime(System.currentTimeMillis());
  1974. pstm.setLong(1, released);
  1975. pstm.setString(2, packageName);
  1976. pstm.setString(3, notes);
  1977. pstm.executeUpdate();
  1978. con.commit();
  1979. con.setAutoCommit(true);
  1980. String getReleasePageSQL = "Select release_id from bp_releases where package_name = '" + packageName + "'";
  1981. PreparedStatement getIdPstm = con.prepareStatement(getReleasePageSQL);
  1982. ResultSet rs = getIdPstm.executeQuery();
  1983. if (rs.next())
  1984. {
  1985. releaseId = rs.getInt("release_id");
  1986. }
  1987. }
  1988. catch (SQLException sqle)
  1989. {
  1990. LOG.error("Error in createReleasePackage: " + sqle.toString());
  1991. try
  1992. {
  1993. con.rollback();
  1994. }
  1995. catch (Exception e)
  1996. {
  1997. LOG.error("Error in createReleasePackage rollback: " + e.toString());
  1998. }
  1999. }
  2000. finally
  2001. {
  2002. if (con != null)
  2003. {
  2004. try
  2005. {
  2006. connector.close(con);
  2007. }
  2008. catch (Exception e)
  2009. {
  2010. LOG.error("Error in closing MySQL connection: " + e.toString());
  2011. }
  2012. }
  2013. }
  2014. return releaseId;
  2015. }
  2016. /**
  2017. * Create a release note by inserting a new record to bp_notes table
  2018. * @param packageName
  2019. * @param releasePageDTO
  2020. */
  2021. public static void createReleaseNote (int releaseId, ReleasePageDTO releasePageDTO, Vector<ReleasePageDTO> childPages)
  2022. {
  2023. LOG.info("createReleaseNote():BEGIN");
  2024. if (releaseId < 0 || releasePageDTO == null)
  2025. {
  2026. return;
  2027. }
  2028. String insertReleaseNoteSQL = "Insert into bp_release_notes " +
  2029. "(release_id, page_id, parent_id, page_uri, page_ext, mode, bug_id, is_embeded) " +
  2030. "values (?, ?, ?, ?, ?, ?, ?, ?)";
  2031. String updatePageSQL = "Update bp_release_pages set status = 'Deployed' where page_id = ?";
  2032. Connection con = null;
  2033. DBConnector connector = DBConnector.getInstance();
  2034. try
  2035. {
  2036. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2037. //con = connector.getDBConnFactory(Environment.SQL);
  2038. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2039. con.setAutoCommit(false);
  2040. // insert note for parentPage
  2041. PreparedStatement pstm = null;
  2042. if (releasePageDTO.getMode() != null && !releasePageDTO.getMode().equals("Impacted") &&
  2043. releasePageDTO.getSelfEdited() != null && releasePageDTO.getSelfEdited().equals("Y"))
  2044. {
  2045. pstm =con.prepareStatement(insertReleaseNoteSQL);
  2046. pstm.setInt(1, releaseId);
  2047. pstm.setInt(2, releasePageDTO.getPageId());
  2048. pstm.setInt(3, -1);
  2049. pstm.setString(4, releasePageDTO.getPageURI());
  2050. String pageURI = releasePageDTO.getPageURI();
  2051. String pageExt = "Unknown";
  2052. if (pageURI != null && pageURI.lastIndexOf('.') > -1)
  2053. {
  2054. pageExt = pageURI.substring(pageURI.lastIndexOf('.') + 1);
  2055. }
  2056. pstm.setString(5, pageExt);
  2057. pstm.setString(6, releasePageDTO.getMode());
  2058. pstm.setString(7, releasePageDTO.getBugId());
  2059. pstm.setString(8, "N");
  2060. pstm.executeUpdate();
  2061. }
  2062. int parentId = releasePageDTO.getPageId();
  2063. // update page status to 'Deployed' for both self_edited is true or false
  2064. pstm = con.prepareStatement(updatePageSQL);
  2065. pstm.setInt(1, releasePageDTO.getPageId());
  2066. pstm.executeUpdate();
  2067. // insert note for child pages. If parent page is not self_edited consider these children as
  2068. // orphan
  2069. if (childPages != null)
  2070. {
  2071. for (int i = 0; i < childPages.size(); i++)
  2072. {
  2073. ReleasePageDTO childPage = (ReleasePageDTO)childPages.elementAt(i);
  2074. if (childPage != null)
  2075. {
  2076. pstm = con.prepareStatement(insertReleaseNoteSQL);
  2077. pstm.setInt(1, releaseId);
  2078. pstm.setInt(2, childPage.getPageId());
  2079. pstm.setInt(3, parentId);
  2080. pstm.setString(4, childPage.getPageURI());
  2081. String childPageURI = childPage.getPageURI();
  2082. String childPageExt = "Unknown";
  2083. if (childPageURI != null && childPageURI.lastIndexOf('.') > -1)
  2084. {
  2085. childPageExt = childPageURI.substring(childPageURI.lastIndexOf('.') + 1);
  2086. }
  2087. pstm.setString(5, childPageExt);
  2088. // inherit from parent
  2089. pstm.setString(6, childPage.getMode());
  2090. pstm.setString(7, releasePageDTO.getBugId());
  2091. pstm.setString(8, "Y");
  2092. pstm.executeUpdate();
  2093. }
  2094. }
  2095. }
  2096. con.commit();
  2097. // Update page status to deployed
  2098. con.setAutoCommit(true);
  2099. LOG.info("createReleaseNote():END");
  2100. }
  2101. catch (SQLException sqle)
  2102. {
  2103. LOG.error("Error in createReleaseNote: " + sqle.toString());
  2104. try
  2105. {
  2106. con.rollback();
  2107. }
  2108. catch (Exception e)
  2109. {
  2110. LOG.error("Error in createReleaseNote rollback: " + e.toString());
  2111. }
  2112. }
  2113. finally
  2114. {
  2115. if (con != null)
  2116. {
  2117. try
  2118. {
  2119. connector.close(con);
  2120. }
  2121. catch (Exception e)
  2122. {
  2123. LOG.error("Error in closing MySQL connection: " + e.toString());
  2124. }
  2125. }
  2126. }
  2127. }
  2128. // /**
  2129. // * Delete all pages that are published
  2130. // * @param packageName
  2131. // * @param releasePageDTO
  2132. // */
  2133. // public static void cleanUpDeployedPages ()
  2134. // {
  2135. // String deleteDeployedChildPageSQL = "Delete from bp_release_child_pages where status = 'Deployed'";
  2136. //
  2137. // String deleteDeployedPageActionSQL = "Delete from bp_release_actions where page_id in " +
  2138. // "(select page_id from bp_release_pages where status = 'Deployed')";
  2139. // String deleteDeployedPageSQL = "Delete from bp_release_pages where status = 'Deployed'";
  2140. // String deleteDeployedChildPageSQL = "Delete from bp_release_child_pages where status = 'Deployed'";
  2141. //
  2142. // Connection con = null;
  2143. // DBConnector connector = DBConnector.getInstance();
  2144. // try
  2145. // {
  2146. // //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2147. // //con = connector.getDBConnFactory(Environment.SQL);
  2148. // con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2149. //
  2150. // con.setAutoCommit(false);
  2151. //
  2152. // PreparedStatement pstm = con.prepareStatement(deleteDeployedPageActionSQL);
  2153. // pstm.executeUpdate();
  2154. //
  2155. // pstm = con.prepareStatement(deleteDeployedPageSQL);
  2156. // pstm.executeUpdate();
  2157. //
  2158. // pstm = con.prepareStatement(deleteDeployedChildPageSQL);
  2159. // pstm.executeUpdate();
  2160. //
  2161. // con.commit();
  2162. // con.setAutoCommit(true);
  2163. // }
  2164. // catch (SQLException sqle)
  2165. // {
  2166. // LOG.error("Error in cleanUpPublishedPages: " + sqle.toString());
  2167. // try
  2168. // {
  2169. // con.rollback();
  2170. // }
  2171. // catch (Exception e)
  2172. // {
  2173. // LOG.error("Error in cleanUpPublishedPages rollback: " + e.toString());
  2174. // }
  2175. // }
  2176. // finally
  2177. // {
  2178. // if (con != null)
  2179. // {
  2180. // try
  2181. // {
  2182. // connector.close(con);
  2183. // }
  2184. // catch (Exception e)
  2185. // {
  2186. // LOG.error("Error in closing MySQL connection: " + e.toString());
  2187. // }
  2188. // }
  2189. // }
  2190. // }
  2191. /**
  2192. * Get all deployed pages for clean up
  2193. * @return
  2194. */
  2195. public static Vector<Integer> getAllDeployedParentPageIds ()
  2196. {
  2197. String selectAllApprovedPagesSQL = "Select page_id from bp_release_pages where status = 'Deployed'";
  2198. Vector<Integer> deployedPageIds = new Vector<Integer>();
  2199. Connection con = null;
  2200. DBConnector connector = DBConnector.getInstance();
  2201. try
  2202. {
  2203. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2204. //con = connector.getDBConnFactory(Environment.SQL);
  2205. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2206. PreparedStatement pstm = con.prepareStatement(selectAllApprovedPagesSQL);
  2207. ResultSet rs = pstm.executeQuery();
  2208. while (rs.next())
  2209. {
  2210. deployedPageIds.add(Integer.valueOf(rs.getInt("page_id")));
  2211. }
  2212. }
  2213. catch (SQLException sqle)
  2214. {
  2215. LOG.error("Error in getAllDeployedParentPageIds: " + sqle.toString());
  2216. }
  2217. finally
  2218. {
  2219. if (con != null)
  2220. {
  2221. try
  2222. {
  2223. connector.close(con);
  2224. }
  2225. catch (Exception e)
  2226. {
  2227. LOG.error("Error in closing MySQL connection: " + e.toString());
  2228. }
  2229. }
  2230. }
  2231. return deployedPageIds;
  2232. }
  2233. /**
  2234. * Get all deployed pages for clean up
  2235. * @return
  2236. */
  2237. public static ArrayList<String> getDeployedParentURIs ()
  2238. {
  2239. // only self_edited pages are exported
  2240. String selectUndeleteDeployedPagesSQL = "Select page_uri from bp_release_pages " +
  2241. "where status = 'Deployed' and mode != 'Impacted' and self_edited = 'Y'";
  2242. ArrayList<String> undeleteDeployedPages = new ArrayList<String>();
  2243. Connection con = null;
  2244. DBConnector connector = DBConnector.getInstance();
  2245. try
  2246. {
  2247. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2248. //con = connector.getDBConnFactory(Environment.SQL);
  2249. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2250. PreparedStatement pstm = con.prepareStatement(selectUndeleteDeployedPagesSQL);
  2251. ResultSet rs = pstm.executeQuery();
  2252. while (rs.next())
  2253. {
  2254. undeleteDeployedPages.add(rs.getString("page_uri"));
  2255. }
  2256. }
  2257. catch (SQLException sqle)
  2258. {
  2259. LOG.error("Error in getUndeltedDeployedPageURIs: " + sqle.toString());
  2260. }
  2261. finally
  2262. {
  2263. if (con != null)
  2264. {
  2265. try
  2266. {
  2267. connector.close(con);
  2268. }
  2269. catch (Exception e)
  2270. {
  2271. LOG.error("Error in closing MySQL connection: " + e.toString());
  2272. }
  2273. }
  2274. }
  2275. return undeleteDeployedPages;
  2276. }
  2277. /**
  2278. * Log the action of user to the publishing page. This will stay in the database permernantly
  2279. * @param eventTime
  2280. * @param pageURI
  2281. * @param userID
  2282. * @param status
  2283. * @param notes
  2284. */
  2285. public static void doAudit(long eventTime, String pageURI, String userID, String status, String notes)
  2286. {
  2287. if (pageURI == null && userID == null)
  2288. {
  2289. return;
  2290. }
  2291. String insertPageSQL = "Insert into bp_release_audit " +
  2292. "(event_time, page_uri, user_id, status, notes) values " +
  2293. "(?, ?, ?, ?, ?)";
  2294. Connection con = null;
  2295. DBConnector connector = DBConnector.getInstance();
  2296. try
  2297. {
  2298. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2299. //con = connector.getDBConnFactory(Environment.SQL);
  2300. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2301. con.setAutoCommit(false);
  2302. PreparedStatement pstm = con.prepareStatement(insertPageSQL);
  2303. pstm.setLong(1, eventTime);
  2304. pstm.setString(2, pageURI);
  2305. pstm.setString(3, userID);
  2306. pstm.setString(4, status);
  2307. pstm.setString(5, notes);
  2308. pstm.executeUpdate();
  2309. con.commit();
  2310. con.setAutoCommit(true);
  2311. }
  2312. catch (SQLException sqle)
  2313. {
  2314. LOG.error("Error in doAudit: " + sqle.toString());
  2315. try
  2316. {
  2317. con.rollback();
  2318. }
  2319. catch (Exception e)
  2320. {
  2321. LOG.error("Error in doAudit rollback: " + e.toString());
  2322. }
  2323. }
  2324. finally
  2325. {
  2326. if (con != null)
  2327. {
  2328. try
  2329. {
  2330. connector.close(con);
  2331. }
  2332. catch (Exception e)
  2333. {
  2334. LOG.error("Error in closing MySQL connection: " + e.toString());
  2335. }
  2336. }
  2337. }
  2338. }
  2339. /**
  2340. * Get all html publishing pages
  2341. * @return
  2342. */
  2343. public static Vector<ReleasePageDTO> getAllPublishingPages ()
  2344. {
  2345. String selectAllPublishingPagesSQL = "Select page_id, page_uri, mode, status, bug_id, notes, last_update, self_edited " +
  2346. "from bp_release_pages order by status desc, mode, page_uri";
  2347. Vector<ReleasePageDTO> publishingPages = new Vector<ReleasePageDTO>();
  2348. Connection con = null;
  2349. DBConnector connector = DBConnector.getInstance();
  2350. try
  2351. {
  2352. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2353. //con = connector.getDBConnFactory(Environment.SQL);
  2354. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2355. PreparedStatement pstm = con.prepareStatement(selectAllPublishingPagesSQL);
  2356. ResultSet rs = pstm.executeQuery();
  2357. ReleasePageDTO pageDTO = null;
  2358. while (rs.next())
  2359. {
  2360. pageDTO = new ReleasePageDTO();
  2361. pageDTO.setPageId(rs.getInt("page_id"));
  2362. pageDTO.setParentId(-1);
  2363. pageDTO.setPageURI(rs.getString("page_uri"));
  2364. pageDTO.setMode(rs.getString("mode"));
  2365. pageDTO.setStatus(rs.getString("status"));
  2366. pageDTO.setBugId(rs.getString("bug_id"));
  2367. pageDTO.setNotes(rs.getString("notes"));
  2368. pageDTO.setLastUpdate(rs.getLong("last_update"));
  2369. pageDTO.setSelfEdited(rs.getString("self_edited"));
  2370. publishingPages.add(pageDTO);
  2371. }
  2372. }
  2373. catch (SQLException sqle)
  2374. {
  2375. LOG.error("Error in getAllPublishingPages: " + sqle.toString());
  2376. }
  2377. finally
  2378. {
  2379. if (con != null)
  2380. {
  2381. try
  2382. {
  2383. connector.close(con);
  2384. }
  2385. catch (Exception e)
  2386. {
  2387. LOG.error("Error in closing MySQL connection: " + e.toString());
  2388. }
  2389. }
  2390. }
  2391. return publishingPages;
  2392. }
  2393. /**
  2394. * Get all html publishing child pages
  2395. * @return
  2396. */
  2397. public static Vector<ReleasePageDTO> getAllChildPages ()
  2398. {
  2399. String selectAllOrphanChildPagesSQL = "Select page_id, page_uri, mode, last_update from bp_release_child_pages";
  2400. Vector<ReleasePageDTO> childPages = new Vector<ReleasePageDTO>();
  2401. Connection con = null;
  2402. DBConnector connector = DBConnector.getInstance();
  2403. try
  2404. {
  2405. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2406. //con = connector.getDBConnFactory(Environment.SQL);
  2407. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2408. PreparedStatement pstm = con.prepareStatement(selectAllOrphanChildPagesSQL);
  2409. ResultSet rs = pstm.executeQuery();
  2410. ReleasePageDTO pageDTO = null;
  2411. while (rs.next())
  2412. {
  2413. pageDTO = new ReleasePageDTO();
  2414. pageDTO.setPageId(rs.getInt("page_id"));
  2415. pageDTO.setPageURI(rs.getString("page_uri"));
  2416. pageDTO.setMode(rs.getString("mode"));
  2417. pageDTO.setLastUpdate(rs.getLong("last_update"));
  2418. childPages.add(pageDTO);
  2419. }
  2420. }
  2421. catch (SQLException sqle)
  2422. {
  2423. LOG.error("Error in getAllChildPages: " + sqle.toString());
  2424. }
  2425. finally
  2426. {
  2427. if (con != null)
  2428. {
  2429. try
  2430. {
  2431. connector.close(con);
  2432. }
  2433. catch (Exception e)
  2434. {
  2435. LOG.error("Error in closing MySQL connection: " + e.toString());
  2436. }
  2437. }
  2438. }
  2439. return childPages;
  2440. }
  2441. /**
  2442. * Get all html deleting publishing pages
  2443. * @return
  2444. */
  2445. public static Vector getAllDeletingPages ()
  2446. {
  2447. String selectAllApprovedPagesSQL = "Select page_id, page_uri, status, bug_id, notes, last_update, self_edited " +
  2448. "from bp_release_pages where mode = 'Deleted' order by page_uri";
  2449. Vector<ReleasePageDTO> deletingPages = new Vector<ReleasePageDTO>();
  2450. Connection con = null;
  2451. DBConnector connector = DBConnector.getInstance();
  2452. try
  2453. {
  2454. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2455. //con = connector.getDBConnFactory(Environment.SQL);
  2456. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2457. PreparedStatement pstm = con.prepareStatement(selectAllApprovedPagesSQL);
  2458. ResultSet rs = pstm.executeQuery();
  2459. ReleasePageDTO pageDTO = null;
  2460. while (rs.next())
  2461. {
  2462. pageDTO = new ReleasePageDTO();
  2463. pageDTO.setPageId(rs.getInt("page_id"));
  2464. pageDTO.setParentId(-1);
  2465. pageDTO.setPageURI(rs.getString("page_uri"));
  2466. pageDTO.setMode("Deleted");
  2467. pageDTO.setStatus(rs.getString("status"));
  2468. pageDTO.setBugId(rs.getString("bug_id"));
  2469. pageDTO.setNotes(rs.getString("notes"));
  2470. pageDTO.setLastUpdate(rs.getLong("last_update"));
  2471. pageDTO.setSelfEdited(rs.getString("self_edited"));
  2472. deletingPages.add(pageDTO);
  2473. }
  2474. }
  2475. catch (SQLException sqle)
  2476. {
  2477. LOG.error("Error in getAllDeletingPages: " + sqle.toString());
  2478. }
  2479. finally
  2480. {
  2481. if (con != null)
  2482. {
  2483. try
  2484. {
  2485. connector.close(con);
  2486. }
  2487. catch (Exception e)
  2488. {
  2489. LOG.error("Error in closing MySQL connection: " + e.toString());
  2490. }
  2491. }
  2492. }
  2493. return deletingPages;
  2494. }
  2495. /**
  2496. * Get all releases happened in the system
  2497. * @return
  2498. */
  2499. public static Vector getAllReleases()
  2500. {
  2501. String getAllReleasesSQL = "Select release_id, released, package_name, notes from bp_releases order by released desc";
  2502. Vector<ReleasePackageDTO> releases = new Vector<ReleasePackageDTO>();
  2503. Connection con = null;
  2504. DBConnector connector = DBConnector.getInstance();
  2505. try
  2506. {
  2507. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2508. //con = connector.getDBConnFactory(Environment.SQL);
  2509. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2510. PreparedStatement pstm = con.prepareStatement(getAllReleasesSQL);
  2511. ResultSet rs = pstm.executeQuery();
  2512. ReleasePackageDTO releaseDTO = null;
  2513. while (rs.next())
  2514. {
  2515. releaseDTO = new ReleasePackageDTO();
  2516. releaseDTO.setReleaseId(rs.getInt("release_id"));
  2517. releaseDTO.setReleasedAt(rs.getLong("released"));
  2518. releaseDTO.setPackageName(rs.getString("package_name"));
  2519. releaseDTO.setNotes(rs.getString("notes"));
  2520. releases.add(releaseDTO);
  2521. }
  2522. }
  2523. catch (SQLException sqle)
  2524. {
  2525. LOG.error("Error in getAllReleases: " + sqle.toString());
  2526. }
  2527. finally
  2528. {
  2529. if (con != null)
  2530. {
  2531. try
  2532. {
  2533. connector.close(con);
  2534. }
  2535. catch (Exception e)
  2536. {
  2537. LOG.error("Error in closing MySQL connection: " + e.toString());
  2538. }
  2539. }
  2540. }
  2541. return releases;
  2542. }
  2543. /**
  2544. * Get all pages released in a released package
  2545. * @return
  2546. */
  2547. public static Vector getBugIdsInRelease(int releaseId)
  2548. {
  2549. String getAllBugIdsSQL = "Select distinct(bug_id) from bp_release_notes where release_id = '" + releaseId +
  2550. "' order by bug_id asc";
  2551. Vector<String> bugIds = new Vector<String>();
  2552. Connection con = null;
  2553. DBConnector connector = DBConnector.getInstance();
  2554. try
  2555. {
  2556. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2557. //con = connector.getDBConnFactory(Environment.SQL);
  2558. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2559. PreparedStatement pstm = con.prepareStatement(getAllBugIdsSQL);
  2560. ResultSet rs = pstm.executeQuery();
  2561. while (rs.next())
  2562. {
  2563. bugIds.add(rs.getString("bug_id"));
  2564. }
  2565. }
  2566. catch (SQLException sqle)
  2567. {
  2568. LOG.error("Error in getBugIdsInRelease: " + sqle.toString());
  2569. }
  2570. finally
  2571. {
  2572. if (con != null)
  2573. {
  2574. try
  2575. {
  2576. connector.close(con);
  2577. }
  2578. catch (Exception e)
  2579. {
  2580. LOG.error("Error in closing MySQL connection: " + e.toString());
  2581. }
  2582. }
  2583. }
  2584. return bugIds;
  2585. }
  2586. /**
  2587. * Get all pages released in a released package
  2588. * @return
  2589. */
  2590. public static Vector getReleaseDetailsByBugId (int releaseId, String bugId)
  2591. {
  2592. String getReleaseDetailsSQL = "Select page_id, parent_id, page_uri, page_ext, mode, is_embeded from bp_release_notes " +
  2593. "where release_id = '" + releaseId + "' and bug_Id = '" + bugId + "' " +
  2594. "and mode != 'Impacted' order by page_ext asc";
  2595. Vector<ReleasePageDTO> releaseDetails = new Vector<ReleasePageDTO>();
  2596. //LOG.info("getReleaseDetailsSQL: " + getReleaseDetailsSQL);
  2597. HashSet<String> releasedURIs = new HashSet<String>();
  2598. Connection con = null;
  2599. DBConnector connector = DBConnector.getInstance();
  2600. try
  2601. {
  2602. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2603. //con = connector.getDBConnFactory(Environment.SQL);
  2604. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2605. PreparedStatement pstm = con.prepareStatement(getReleaseDetailsSQL);
  2606. ResultSet rs = pstm.executeQuery();
  2607. ReleasePageDTO pageDTO = null;
  2608. while (rs.next())
  2609. {
  2610. String pageURI = rs.getString("page_uri");
  2611. if (!releasedURIs.contains(pageURI))
  2612. {
  2613. releasedURIs.add(pageURI);
  2614. pageDTO = new ReleasePageDTO();
  2615. pageDTO.setPageId(rs.getInt("page_id"));
  2616. pageDTO.setParentId(rs.getInt("parent_id"));
  2617. pageDTO.setPageURI(pageURI);
  2618. pageDTO.setMode(rs.getString("mode"));
  2619. pageDTO.setStatus("Deployed");
  2620. pageDTO.setBugId(bugId);
  2621. pageDTO.setNotes("Page has been deployed"); // no use
  2622. pageDTO.setSelfEdited("Y"); // no use
  2623. releaseDetails.add(pageDTO);
  2624. }
  2625. }
  2626. }
  2627. catch (SQLException sqle)
  2628. {
  2629. LOG.error("Error in getReleaseDetailsByBugId: " + sqle.toString());
  2630. }
  2631. finally
  2632. {
  2633. if (con != null)
  2634. {
  2635. try
  2636. {
  2637. connector.close(con);
  2638. }
  2639. catch (Exception e)
  2640. {
  2641. LOG.error("Error in closing MySQL connection: " + e.toString());
  2642. }
  2643. }
  2644. }
  2645. return releaseDetails;
  2646. }
  2647. /**
  2648. * This method delete the records in bp_release_pages table that is no longer valid for the publishing.
  2649. * Eg, when a new page is created than deleted or a page marked as delete but then is unmarked by Author
  2650. * @param validPageIds
  2651. */
  2652. public static void removeOphanPage (int parentId, Vector validPageIds)
  2653. {
  2654. String cleanQuery = null;
  2655. if (validPageIds == null || validPageIds.size() == 0)
  2656. {
  2657. cleanQuery = "Delete from bp_release_childparent where parent_id = '" + parentId + "'";
  2658. }
  2659. else
  2660. {
  2661. // combine URI set
  2662. StringBuffer pageSetBuf = new StringBuffer();
  2663. pageSetBuf.append("(");
  2664. for (int i = 0; i < validPageIds.size(); i++)
  2665. {
  2666. if (i == validPageIds.size() -1)
  2667. {
  2668. pageSetBuf.append("'").append(validPageIds.elementAt(i)).append("'");
  2669. }
  2670. else
  2671. {
  2672. pageSetBuf.append("'").append(validPageIds.elementAt(i)).append("',");
  2673. }
  2674. }
  2675. pageSetBuf.append(")");
  2676. // clean child pages
  2677. cleanQuery = "Delete from bp_release_childparent where parent_id = '" + parentId + "' " +
  2678. "and child_id not in " + pageSetBuf.toString();
  2679. }
  2680. Connection con = null;
  2681. DBConnector connector = DBConnector.getInstance();
  2682. try
  2683. {
  2684. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2685. //con = connector.getDBConnFactory(Environment.SQL);
  2686. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2687. con.setAutoCommit(false);
  2688. PreparedStatement pstm = con.prepareStatement(cleanQuery);
  2689. pstm.executeUpdate();
  2690. con.commit();
  2691. }
  2692. catch (SQLException sqle)
  2693. {
  2694. LOG.error("Error in removeOphanPage: " + sqle.toString());
  2695. try
  2696. {
  2697. con.rollback();
  2698. }
  2699. catch (Exception e)
  2700. {
  2701. LOG.error("Error in removeOphanPage rollback: " + e.toString());
  2702. }
  2703. }
  2704. finally
  2705. {
  2706. if (con != null)
  2707. {
  2708. try
  2709. {
  2710. connector.close(con);
  2711. }
  2712. catch (Exception e)
  2713. {
  2714. LOG.error("Error in closing MySQL connection: " + e.toString());
  2715. }
  2716. }
  2717. }
  2718. }
  2719. public static Vector<Integer> getParentPagesOfChild (int childPageId)
  2720. {
  2721. String getParentPagesOfChildSQL = "Select parent_id from bp_release_childparent " +
  2722. "where child_id = '" + childPageId + "'";
  2723. Vector<Integer> parentPageIds = new Vector<Integer>();
  2724. //LOG.info("getReleaseDetailsSQL: " + getReleaseDetailsSQL);
  2725. Connection con = null;
  2726. DBConnector connector = DBConnector.getInstance();
  2727. try
  2728. {
  2729. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2730. //con = connector.getDBConnFactory(Environment.SQL);
  2731. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2732. PreparedStatement pstm = con.prepareStatement(getParentPagesOfChildSQL);
  2733. ResultSet rs = pstm.executeQuery();
  2734. while (rs.next())
  2735. {
  2736. int parent_id = rs.getInt("parent_id");
  2737. parentPageIds.add(new Integer(parent_id));
  2738. }
  2739. }
  2740. catch (SQLException sqle)
  2741. {
  2742. LOG.error("Error in getParentPagesOfChild: " + sqle.toString());
  2743. }
  2744. finally
  2745. {
  2746. if (con != null)
  2747. {
  2748. try
  2749. {
  2750. connector.close(con);
  2751. }
  2752. catch (Exception e)
  2753. {
  2754. LOG.error("Error in closing MySQL connection: " + e.toString());
  2755. }
  2756. }
  2757. }
  2758. return parentPageIds;
  2759. }
  2760. /**
  2761. * Update all 'Paused' pages to 'Approved' pages
  2762. * @param con
  2763. * @param pageURI
  2764. * @return
  2765. */
  2766. public static boolean unpauseAllApprovedPages ()
  2767. {
  2768. String updatePageStatusSQL = "Update bp_release_pages set status = 'Approved' " +
  2769. "where status = 'Paused'";
  2770. boolean updateOk = false;
  2771. Connection con = null;
  2772. DBConnector connector = DBConnector.getInstance();
  2773. try
  2774. {
  2775. //con = connector.getDBConnFactory(Environment.SQL);
  2776. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2777. con.setAutoCommit(false);
  2778. PreparedStatement pstm = con.prepareStatement(updatePageStatusSQL);
  2779. pstm.executeUpdate();
  2780. con.commit();
  2781. con.setAutoCommit(true);
  2782. updateOk = true;
  2783. }
  2784. catch (SQLException sqle)
  2785. {
  2786. LOG.error("Error in unpauseAllApprovedPages: " + sqle.toString());
  2787. try
  2788. {
  2789. con.rollback();
  2790. }
  2791. catch (Exception e)
  2792. {
  2793. LOG.error("Error in unpauseAllApprovedPages rollback: " + e.toString());
  2794. }
  2795. }
  2796. finally
  2797. {
  2798. if (con != null)
  2799. {
  2800. try
  2801. {
  2802. connector.close(con);
  2803. }
  2804. catch (Exception e)
  2805. {
  2806. LOG.error("Error in closing MySQL connection: " + e.toString());
  2807. }
  2808. }
  2809. }
  2810. return updateOk;
  2811. }
  2812. /**
  2813. * Update child page's last_update
  2814. * @param con
  2815. * @param pageURI
  2816. * @return
  2817. */
  2818. public static boolean updateChildPageLastUpdate (int pageId, long lastUpdate, String mode, String status)
  2819. {
  2820. String updateChildPageLastUpdateSQL = "Update bp_release_child_pages set last_update = ?, mode = ?, status = ?" +
  2821. "where page_id = '" + pageId + "' ";
  2822. boolean updateOk = false;
  2823. Connection con = null;
  2824. DBConnector connector = DBConnector.getInstance();
  2825. try
  2826. {
  2827. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2828. con.setAutoCommit(false);
  2829. PreparedStatement pstm = con.prepareStatement(updateChildPageLastUpdateSQL);
  2830. pstm.setLong(1, lastUpdate);
  2831. pstm.setString(2, mode);
  2832. pstm.setString(3, status);
  2833. pstm.executeUpdate();
  2834. con.commit();
  2835. con.setAutoCommit(true);
  2836. updateOk = true;
  2837. }
  2838. catch (SQLException sqle)
  2839. {
  2840. LOG.error("Error in updateChildPageLastUpdate: " + sqle.toString());
  2841. try
  2842. {
  2843. con.rollback();
  2844. }
  2845. catch (Exception e)
  2846. {
  2847. LOG.error("Error in updateChildPageLastUpdate rollback: " + e.toString());
  2848. }
  2849. }
  2850. finally
  2851. {
  2852. if (con != null)
  2853. {
  2854. try
  2855. {
  2856. connector.close(con);
  2857. }
  2858. catch (Exception e)
  2859. {
  2860. LOG.error("Error in closing MySQL connection: " + e.toString());
  2861. }
  2862. }
  2863. }
  2864. return updateOk;
  2865. }
  2866. public static void debugPageDTO (ReleasePageDTO pageDTO)
  2867. {
  2868. if (pageDTO != null)
  2869. {
  2870. LOG.info("Page Id: " + pageDTO.getPageId());
  2871. LOG.info("Page URI: " + pageDTO.getPageURI());
  2872. LOG.info("Page Mode: " + pageDTO.getMode());
  2873. LOG.info("Page Status: " + pageDTO.getStatus());
  2874. LOG.info("Page BugId: " + pageDTO.getBugId());
  2875. LOG.info("Page LastModified: " + pageDTO.getLastUpdate());
  2876. }
  2877. }
  2878. //These methods are used to process changed documents which do not belong to any pages (orphan)
  2879. /**
  2880. * Get all changed documents which do not have parent
  2881. * @return
  2882. */
  2883. public static Vector<ReleasePageDTO> getAllChangedChildPages(String userId) {
  2884. String selectSQL = "Select page_id, page_uri, mode, last_update, status, bug_id" +
  2885. " from bp_release_child_pages where page_id not in (SELECT child_id FROM bp_release_childparent) " +
  2886. " order by page_uri";
  2887. String lastUserEditedSQL = "Select user_id from bp_release_actions where childpage_id=? " +
  2888. "and status='Edited' and action_time=(Select max(action_time) as atMax from bp_release_actions where childpage_id=? " +
  2889. "and status='Edited')";
  2890. String lastUserCheckedSQL = "Select user_id from bp_release_actions where childpage_id=? " +
  2891. "and status='Checked' and action_time=(Select max(action_time) as atMax from bp_release_actions where childpage_id=? " +
  2892. "and status='Checked')";
  2893. System.out.println(lastUserEditedSQL);
  2894. System.out.println(lastUserCheckedSQL);
  2895. Vector<ReleasePageDTO> changedChildPages = new Vector<ReleasePageDTO>();
  2896. Connection con = null;
  2897. DBConnector connector = DBConnector.getInstance();
  2898. try {
  2899. LOG.info("SQL: "+selectSQL);
  2900. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2901. //con = connector.getDBConnFactory(Environment.SQL);
  2902. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2903. PreparedStatement pstm = con.prepareStatement(selectSQL);
  2904. ResultSet rs = pstm.executeQuery();
  2905. ReleasePageDTO pageDTO = null;
  2906. while (rs.next()) {
  2907. int id = rs.getInt("page_id");
  2908. pageDTO = new ReleasePageDTO();
  2909. pageDTO.setPageId(id);
  2910. pageDTO.setParentId(-1);
  2911. pageDTO.setPageURI(rs.getString("page_uri"));
  2912. pageDTO.setMode(rs.getString("mode"));
  2913. pageDTO.setLastUpdate(rs.getLong("last_update"));
  2914. pageDTO.setStatus(rs.getString("status"));
  2915. pageDTO.setBugId(rs.getString("bug_id"));
  2916. pageDTO.setOrphan(true);
  2917. /**
  2918. * Check last user update
  2919. */
  2920. PreparedStatement eps = con.prepareStatement(lastUserEditedSQL);
  2921. eps.setInt(1, id);
  2922. eps.setInt(2, id);
  2923. ResultSet eRs = eps.executeQuery();
  2924. if(eRs.next()) {
  2925. System.out.println(eRs.getString("user_id")+"***"+userId);
  2926. if (!userId.equals(eRs.getString("user_id"))) {
  2927. pageDTO.setAbleSend4Review(true);
  2928. }
  2929. }
  2930. PreparedStatement cps = con.prepareStatement(lastUserCheckedSQL);
  2931. cps.setInt(1, id);
  2932. cps.setInt(2, id);
  2933. ResultSet cRs = cps.executeQuery();
  2934. if(cRs.next()) {
  2935. System.out.println(cRs.getString("user_id")+"***"+userId);
  2936. if (!userId.equals(cRs.getString("user_id"))) {
  2937. pageDTO.setAblePassChecking(true);
  2938. }
  2939. }
  2940. eps.close();
  2941. cps.close();
  2942. changedChildPages.add(pageDTO);
  2943. }
  2944. }
  2945. catch (SQLException sqle) {
  2946. LOG.error("Error in getAllChangedChildPages: " + sqle.toString());
  2947. }
  2948. finally {
  2949. if (con != null) {
  2950. try {
  2951. connector.close(con);
  2952. } catch (Exception e) {
  2953. LOG.error("Error in closing MySQL connection: " + e.toString());
  2954. }
  2955. }
  2956. }
  2957. LOG.info("Number of child pages which do not have parent: " + changedChildPages.size());
  2958. System.out.println("Number of child pages which do not have parent: " + changedChildPages.size());
  2959. return changedChildPages;
  2960. }
  2961. public static String getOrphanDocumentMode(int pageId) {
  2962. String selectSQL = "SELECT mode FROM bp_release_child_pages";
  2963. String mode = "";
  2964. //LOG.info("updatePageInfoSQL: " + updatePageInfoSQL);
  2965. Connection con = null;
  2966. DBConnector connector = DBConnector.getInstance();
  2967. try {
  2968. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  2969. //con = connector.getDBConnFactory(Environment.SQL);
  2970. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  2971. PreparedStatement pstm = con.prepareStatement(selectSQL);
  2972. ResultSet rs = pstm.executeQuery();
  2973. if (rs.next()) {
  2974. mode = rs.getString("mode");
  2975. }
  2976. pstm.close();
  2977. } catch (SQLException sqle) {
  2978. LOG.error("Error in getReleasePageByURI: " + sqle.toString());
  2979. } finally {
  2980. if (con != null) {
  2981. try {
  2982. connector.close(con);
  2983. } catch (Exception e) {
  2984. LOG.error("Error in closing MySQL connection: " + e.toString());
  2985. }
  2986. }
  2987. }
  2988. return mode;
  2989. }
  2990. /**
  2991. * Update publishing page based on page URI
  2992. * @param con
  2993. * @param pageId
  2994. * @param status
  2995. * @return
  2996. */
  2997. public static boolean updateOrphanPageInfo (int pageId, String newStatus, String ptbBugId) {
  2998. String updatePageInfoSQL = "Update bp_release_child_pages set status = ?, bug_id = ? " +
  2999. "where page_id = '" + pageId + "'";
  3000. //LOG.info("updatePageInfoSQL: " + updatePageInfoSQL);
  3001. Connection con = null;
  3002. DBConnector connector = DBConnector.getInstance();
  3003. boolean updateOk = false;
  3004. try {
  3005. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  3006. con.setAutoCommit(false);
  3007. PreparedStatement pstm = con.prepareStatement(updatePageInfoSQL);
  3008. //long lastUpdate = DateTimeUtil.formatToOrderingTime(System.currentTimeMillis());
  3009. pstm.setString(1, newStatus);
  3010. pstm.setString(2, ptbBugId);
  3011. //pstm.setLong(4, lastUpdate);
  3012. pstm.executeUpdate();
  3013. con.commit();
  3014. con.setAutoCommit(true);
  3015. updateOk = true;
  3016. } catch (SQLException sqle) {
  3017. LOG.error("Error in updatePageInfo: " + sqle.toString());
  3018. try {
  3019. con.rollback();
  3020. } catch (Exception e) {
  3021. LOG.error("Error in updatePageInfo rollback: " + e.toString());
  3022. }
  3023. } finally {
  3024. if (con != null) {
  3025. try {
  3026. connector.close(con);
  3027. } catch (Exception e) {
  3028. LOG.error("Error in closing MySQL connection: " + e.toString());
  3029. }
  3030. }
  3031. }
  3032. return updateOk;
  3033. }
  3034. /**
  3035. * Delete release page by pageId
  3036. * @return
  3037. */
  3038. public static boolean removeOrphanReleasePage (int pageId) {
  3039. String deleteReleasePageSQL = "Delete from bp_release_child_pages where page_id = '" + pageId + "'";
  3040. boolean result = false;
  3041. Connection con = null;
  3042. DBConnector connector = DBConnector.getInstance();
  3043. try {
  3044. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  3045. //con = connector.getDBConnFactory(Environment.SQL);
  3046. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  3047. con.setAutoCommit(false);
  3048. PreparedStatement pstm = con.prepareStatement(deleteReleasePageSQL);
  3049. pstm.executeUpdate();
  3050. con.commit();
  3051. con.setAutoCommit(true);
  3052. result = true;
  3053. } catch (SQLException sqle) {
  3054. LOG.error("Error in deleteReleasePage: " + sqle.toString());
  3055. try {
  3056. con.rollback();
  3057. } catch (Exception e) {
  3058. LOG.error("Error in deleteReleasePage rollback: " + e.toString());
  3059. }
  3060. } finally {
  3061. if (con != null) {
  3062. try {
  3063. connector.close(con);
  3064. }
  3065. catch (Exception e) {
  3066. LOG.error("Error in closing MySQL connection: " + e.toString());
  3067. }
  3068. }
  3069. }
  3070. return result;
  3071. }
  3072. /**
  3073. * Delete release page by uri
  3074. * @return
  3075. */
  3076. public static boolean removeOrphanReleasePages (ArrayList<String> uris) {
  3077. String deleteReleasePageSQL = "Delete from bp_release_child_pages where page_uri in (' '";
  3078. for (int i=0; i<uris.size(); i++) {
  3079. deleteReleasePageSQL += ",'"+uris.get(i)+"'";
  3080. }
  3081. deleteReleasePageSQL += ")";
  3082. LOG.info("SQL: "+deleteReleasePageSQL);
  3083. boolean result = false;
  3084. Connection con = null;
  3085. DBConnector connector = DBConnector.getInstance();
  3086. try {
  3087. //int caseWorkNo = CaseWorkSQLHandler.getMaxCaseNo() + 1;
  3088. //con = connector.getDBConnFactory(Environment.SQL);
  3089. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  3090. con.setAutoCommit(false);
  3091. PreparedStatement pstm = con.prepareStatement(deleteReleasePageSQL);
  3092. pstm.executeUpdate();
  3093. con.commit();
  3094. con.setAutoCommit(true);
  3095. result = true;
  3096. } catch (SQLException sqle) {
  3097. LOG.error("Error in deleteReleasePage: " + sqle.toString());
  3098. try {
  3099. con.rollback();
  3100. } catch (Exception e) {
  3101. LOG.error("Error in deleteReleasePage rollback: " + e.toString());
  3102. }
  3103. } finally {
  3104. if (con != null) {
  3105. try {
  3106. connector.close(con);
  3107. }
  3108. catch (Exception e) {
  3109. LOG.error("Error in closing MySQL connection: " + e.toString());
  3110. }
  3111. }
  3112. }
  3113. return result;
  3114. }
  3115. public static Vector<ReleasePageDTO> getAllApprovedOrphans() {
  3116. Vector<ReleasePageDTO> uris = new Vector<ReleasePageDTO>();
  3117. String selectSQL = "Select page_id,page_uri,mode,bug_id from bp_release_child_pages where status = 'Approved'";
  3118. Connection con = null;
  3119. DBConnector connector = DBConnector.getInstance();
  3120. try {
  3121. con = connector.getDBConnFactory(Environment.PENSIONLINE);
  3122. con.setAutoCommit(false);
  3123. PreparedStatement pstm = con.prepareStatement(selectSQL);
  3124. ResultSet rs = pstm.executeQuery();
  3125. while (rs.next()) {
  3126. ReleasePageDTO obj = new ReleasePageDTO();
  3127. obj.setBugId(rs.getString("bug_id"));
  3128. obj.setMode(rs.getString("mode"));
  3129. obj.setPageId(rs.getInt("page_id"));
  3130. obj.setPageURI(rs.getString("page_uri"));
  3131. uris.add(obj);
  3132. }
  3133. con.commit();
  3134. con.setAutoCommit(true);
  3135. } catch (SQLException sqle) {
  3136. LOG.error("Error in getAllApprovedOrphans: " + sqle.toString());
  3137. try {
  3138. con.rollback();
  3139. } catch (Exception e) {
  3140. LOG.error("Error in getAllApprovedOrphans rollback: " + e.toString());
  3141. }
  3142. } finally {
  3143. if (con != null) {
  3144. try {
  3145. connector.close(con);
  3146. }
  3147. catch (Exception e) {
  3148. LOG.error("Error in closing MySQL connection: " + e.toString());
  3149. }
  3150. }
  3151. }
  3152. LOG.info("There are "+uris.size()+" orphan documents ready to publish");
  3153. return uris;
  3154. }
  3155. }