1 package smile.stored; 2 3 import java.util.*; 4 import java.sql.*; 5 6 17 public class s_updateArticlePreload extends StoredProcedure implements ProcedureInterface { 18 19 String itemID; 20 21 24 public s_updateArticlePreload() { 25 } 26 27 35 public void init(HashMap initData, Connection con) { 36 super.init(initData, con); 38 } 39 40 46 public void setItemID(String pItemID) { 47 itemID = pItemID; 48 } 49 50 56 public void checkParams() throws SQLException { 57 itemID = utils.getString(data, "ITEMID", ""); 58 } 59 60 66 public void checkAction() throws SQLException { 67 } 68 69 75 public void executeAction() throws SQLException { 76 77 boolean toExecute = true; 80 81 String useDate; 83 StringBuffer v_useDate = new StringBuffer (); 84 v_useDate.append("SELECT tblpublications.defaultSectionWithDate ").append("from tblarticles, tblpublications ").append( 85 "where tblpublications.pubName = tblarticles.pubName ").append("and tblarticles.itemID='" + itemID + "'"); 86 87 try { 88 useDate = execStatementToValue(v_useDate.toString()); 89 } catch (SQLException e) { 90 useDate = "1"; 91 } 92 93 String virtualFolder = ""; 95 String pubSectionDesc = ""; 96 String fullLink = ""; 97 String lifeCycle = ""; 98 String startDate = ""; 99 String endDate = ""; 100 String workflow_state = ""; 101 StringBuffer v_sb1 = new StringBuffer (); 102 v_sb1.append("SELECT "); 103 if (useDate == "1") { 104 v_sb1.append("CONCAT(a.pubName, '/', s.sectionName) as virtualFolder, "); 105 v_sb1.append("s.sectionDesc as pubSectionDesc, "); 106 v_sb1.append("a.customURL as fullLink, "); 107 } else { 108 v_sb1.append("CONCAT(a.pubName, '/', s.sectionName) as virtualFolder, "); 109 v_sb1.append("s.sectionDesc as pubSectionDesc, "); 110 v_sb1.append("a.customURL as fullLink, "); 111 } 112 v_sb1.append("a.lifeCycle, "); 113 v_sb1.append("a.PubStart, "); 114 v_sb1.append("a.PubEnd, "); 115 v_sb1.append("a.workflow_state "); 116 v_sb1.append(" FROM ").append(" tblarticles as a, tblpublications as p, tblsections as s ").append(" WHERE a.pubName = p.pubName ").append( 117 " and a.pubName=s.pubName ").append(" and a.section=s.section ").append(" and a.itemID=" + itemID); 118 119 execStatementToRS(v_sb1.toString()); 120 if (psResult.next()) { 121 virtualFolder = psResult.getString(1); 122 pubSectionDesc = psResult.getString(2); 123 124 if (pubSectionDesc != null) { 126 pubSectionDesc = utils.replaceString(pubSectionDesc, "'", "''"); 127 pubSectionDesc = utils.replaceString(pubSectionDesc, "\\", "\\\\"); 128 } 129 130 fullLink = psResult.getString(3); 131 lifeCycle = psResult.getString(4); 132 startDate = psResult.getString(5); 133 endDate = psResult.getString(6); 134 workflow_state = psResult.getString(7); 135 } 136 psResult.close(); 137 138 if (!(workflow_state.equals("2"))) 140 toExecute = false; 141 142 if (lifeCycle.equals("1")) { 144 int startDateInt = Integer.parseInt(startDate.substring(0, 4) + startDate.substring(5, 7) + startDate.substring(8, 10)); 145 int endDateInt = Integer.parseInt(endDate.substring(0, 4) + endDate.substring(5, 7) + endDate.substring(8, 10)); 146 147 String todayString = "" + (String ) sdf.format(new java.util.Date ()).toString(); 148 int todayDateInt = Integer.parseInt(todayString.substring(0, 4) + todayString.substring(5, 7) + todayString.substring(8, 10)); 149 if ((startDateInt > todayDateInt) || (endDateInt < todayDateInt)) { 150 toExecute = false; 152 System.out.println("s_updateArticlePreload : the article " + itemID + " is unpublished because of life cycle"); 153 } 154 155 } 156 157 execStatement("DELETE from tblarticlepreload WHERE itemID='" + itemID + "'"); 159 160 if (toExecute) { 162 163 StringBuffer v_listImage = new StringBuffer (); 164 StringBuffer v_listImageCaption = new StringBuffer (); 165 StringBuffer v_articleImage = new StringBuffer (); 166 StringBuffer v_articleImageCaption = new StringBuffer (); 167 v_listImage.append("SELECT COALESCE(itemName, '') from tblmultimedia where itemID = '" + itemID + "' AND type='sectionImage'"); 168 v_listImageCaption.append("SELECT COALESCE(caption, '') from tblmultimedia where itemID = '" + itemID + "' AND type='sectionImage'"); 169 v_articleImage.append("SELECT COALESCE(itemName, '') from tblmultimedia where itemID = '" + itemID + "' AND type='articleImage'"); 170 v_articleImageCaption.append("SELECT COALESCE(caption, '') from tblmultimedia where itemID = '" + itemID + "' AND type='articleImage'"); 171 String listImage; 172 String listImageCaption; 173 String articleImage; 174 String articleImageCaption; 175 try { 176 listImage = utils.replaceString(execStatementToValue(v_listImage.toString()), "'", "''"); 177 } catch (SQLException e) { 178 listImage = ""; 179 } 180 181 try { 182 listImageCaption = utils.replaceString(execStatementToValue(v_listImageCaption.toString()), "'", "''"); 183 } catch (SQLException e) { 184 listImageCaption = ""; 185 } 186 187 try { 188 articleImage = utils.replaceString(execStatementToValue(v_articleImage.toString()), "'", "''"); 189 } catch (SQLException e) { 190 articleImage = ""; 191 } 192 193 try { 194 articleImageCaption = utils.replaceString(execStatementToValue(v_articleImageCaption.toString()), "'", "''"); 195 } catch (SQLException e) { 196 articleImageCaption = ""; 197 } 198 199 StringBuffer v_Update1 = new StringBuffer (); 201 v_Update1.append("INSERT INTO tblarticlepreload (itemID, mappingCode, ").append(" shortTime, dayOfWeek, virtualFolder, pubSectionDesc, pubYear, ") 202 .append(" pubMonth, pubDay, dateFolder, pubDateLong, fullLink, articleLeadIn, ").append( 203 " sigImage, sigImageCaption, sectionName, sectionDesc, sigDir, ").append(" sectionImage, sectionType, orderingRank, hostname, ") 204 .append(" listImage, listImageCaption, articleImage, articleImageCaption, relatedLinksCount, pubDesc) ").append("SELECT ").append( 205 " a.itemId, o.mappingCode, ").append(" DATE_FORMAT(a.pubDate, '%h:%i %p'),").append(" DATE_FORMAT(a.pubDate, '%W'), ").append( 206 " '" + virtualFolder + "', ").append(" '" + pubSectionDesc + "', ").append(" DATE_FORMAT(a.pubDate, '%Y'), ").append( 207 " DATE_FORMAT(a.pubDate, '%m'), ").append(" DATE_FORMAT(a.pubDate, '%d'), ").append(" DATE_FORMAT(a.pubDate, '%Y/%m/%d'), ") 208 .append(" DATE_FORMAT(a.pubDate, '%W, %M %e, %Y'), "); 209 210 String _contextPath = org.cofax.cms.CofaxToolsServlet.contextUrl; 211 212 if (fullLink == null || fullLink.equals("")) 213 v_Update1.append(" CONCAT(p.hostName,'"+_contextPath+"/',a.pubName,'/',s.sectionName,'/',fileName,'.htm'), "); 214 else 215 v_Update1.append(" '" + fullLink + "', "); 216 v_Update1.append(" at.articleTypeLeadIn, ").append(" at.articleTypeImage, ").append(" at.articleTypeName, ").append(" s.sectionName, ").append( 217 " s.sectionDesc, ").append(" s.sigDir, ").append(" s.Image, ").append(" s.sectionType, ").append(" o.rank, ").append(" p.hostname, ") 218 .append(" '" + listImage + "' as listImage, ").append(" '" + listImageCaption + "' as listImageCaption, ").append( 219 " '" + articleImage + "' as articleImage, ").append(" '" + articleImageCaption + "' as articleImageCaption, ").append( 220 " 0 as relatedLinksCount, ").append(" p.pubDesc as pubDesc ").append("FROM ").append( 221 " tblarticleorder as o, tblarticles as a LEFT JOIN tblarticletypes as at ON a.articleTypeID=at.articleTypeID, ").append( 222 "tblpublications as p, tblsections as s ").append("WHERE a.pubName = p.pubName ").append("AND a.disableArticle = 0 ").append( 223 "AND (at.disableArticleType = 0 or at.disableArticleType is null) ").append("AND a.pubName = s.pubName ").append( 224 "AND o.mappingCode = s.mappingCode ").append("AND o.itemID = a.itemID ").append("AND a.itemID = '" + itemID + "'"); 225 226 execStatement(v_Update1.toString()); 227 } 228 execStatementToRS(queryResultOk); 229 230 } 231 232 } 233 | Popular Tags |