1 22 package org.cofax.cms; 23 24 import org.cofax.*; 25 import java.util.*; 26 import java.io.*; 27 import java.text.*; 28 29 38 39 public class CofaxToolsLifeCycle { 40 41 int count_articles_disabled; 42 43 int count_articles_enabled; 44 45 public String logFile = ""; 46 47 public void setLogFile(String logFile) { 48 this.logFile = logFile; 49 } 50 51 public boolean updateAllPublications(DataStore db) { 52 db.setKillTime(1000 * 30000); 53 StringBuffer v_publications = new StringBuffer (); 54 v_publications.append("SELECT pubName from tblpublications"); 55 String returnMessage = ""; 56 try { 57 HashMap ht = new HashMap(); 58 List pubs = (ArrayList) db.getPackageData(ht, "", v_publications.toString(), false); 59 HashMap hashinfo; 60 while (pubs.size() > 0) { 61 hashinfo = (HashMap) pubs.get(0); 62 String pubName = (String ) hashinfo.get("PUBNAME"); 63 returnMessage = updatePublication(db, pubName); 64 pubs.remove(0); 65 } 66 } catch (Exception e) { 67 log("CofaxToolsLifeCycle : Exception " + e, logFile); 68 } 69 return true; 70 } 71 72 public String updatePublication(DataStore db, String pubName) { 73 try { 74 StringBuffer v_articles = new StringBuffer (); 75 v_articles.append("select A.itemID, A.pubStart, A.pubEnd ").append("from tblarticles AS A ").append("where A.pubname= '" + pubName + "' ").append( 76 "and A.lifeCycle = 1"); 77 78 count_articles_disabled = 0; 79 count_articles_enabled = 0; 80 81 ArrayList articles = new ArrayList(); 82 HashMap ht = new HashMap(); 83 articles = (ArrayList) db.getPackageData(ht, "", v_articles.toString(), false); 84 while (articles.size() > 0) { 85 HashMap hashinfo = (HashMap) articles.get(0); 86 String itemID = (String ) hashinfo.get("ITEMID"); 87 String pubStart = (String ) hashinfo.get("PUBSTART"); 88 String pubEnd = (String ) hashinfo.get("PUBEND"); 89 articles.remove(0); 90 int startDateInt = Integer.parseInt(pubStart.substring(0, 4) + pubStart.substring(5, 7) + pubStart.substring(8, 10)); 92 int endDateInt = Integer.parseInt(pubEnd.substring(0, 4) + pubEnd.substring(5, 7) + pubEnd.substring(8, 10)); 93 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 94 String todayString = "" + (String ) sdf.format(new java.util.Date ()).toString(); 95 int todayDateInt = Integer.parseInt(todayString.substring(0, 4) + todayString.substring(5, 7) + todayString.substring(8, 10)); 96 if ((startDateInt > todayDateInt) || (endDateInt < todayDateInt)) { 97 String published = null; 99 StringBuffer v_published = new StringBuffer (); 100 v_published.append("SELECT itemID from tblarticlepreload where itemID='" + itemID + "'"); 101 try { 102 HashMap htTemp = new HashMap(); 103 HashMap ht2 = CofaxToolsDbUtils.getNameValuePackageHash(db, htTemp, v_published.toString()); 104 published = (String ) ht2.get("ITEMID"); 105 } catch (Exception e) { 106 published = null; 107 } 108 if ((published != null)) { 109 count_articles_disabled++; 111 HashMap ht3 = new HashMap(); 112 ht3.put("ITEMID", itemID); 113 String tag = "exec s_updateArticlePreload 'req:ITEMID' "; HashMap hto = CofaxToolsDbUtils.getNameValuePackageHash(db, ht3, tag); 116 } 117 } else { 118 String published = "0"; 120 StringBuffer v_published = new StringBuffer (); 121 v_published.append("SELECT itemID from tblarticlepreload where itemID='" + itemID + "'"); 122 try { 123 HashMap htTemp = new HashMap(); 124 HashMap ht2 = CofaxToolsDbUtils.getNameValuePackageHash(db, htTemp, v_published.toString()); 125 published = (String ) ht2.get("ITEMID"); 126 } catch (Exception e) { 127 published = "0"; 128 } 129 if (((published == null) || published.equals("0"))) { 130 count_articles_enabled++; 132 HashMap ht3 = new HashMap(); 133 ht3.put("ITEMID", itemID); 134 String tag = "exec s_updateArticlePreload 'req:ITEMID' "; HashMap hto = CofaxToolsDbUtils.getNameValuePackageHash(db, ht3, tag); 137 } 138 } 139 140 } 141 142 } catch (Exception e) { 143 log("CofaxToolsLifeCycle : Exception : " + e, logFile); 144 } 145 log("CofaxToolsLifeCycle : " + new java.util.Date () + " : Publication '" + pubName + "' : " + count_articles_disabled + " articles disabled and " 146 + count_articles_enabled + " articles enabled.", logFile); 147 return ("Done Update Publication. "); 148 } 149 150 159 public static void log(String input, String outputFile) { 160 try { 161 if (!(outputFile.equals(""))) { 162 PrintWriter fileOutputStream = new PrintWriter(new FileWriter(outputFile, true)); 163 fileOutputStream.println(input); 164 fileOutputStream.close(); 165 } else { 166 System.out.println("CofaxToolsLifeCycle.log : " + input); 167 } 168 } catch (IOException e) { 169 System.out.println("CofaxToolsLifeCycle.log : error : " + e.toString()); 170 } 171 } 172 173 } 174 | Popular Tags |