| 1 package smile.stored; 2 3 import java.util.*; 4 import java.sql.*; 5 6 16 public class s_insertArticle2 extends StoredProcedure implements ProcedureInterface { 17 18 String pubName; 19 20 String section; 21 22 String pubDate; 23 24 String fileName; 25 26 String approved; 27 28 String headline; 29 30 String headline2; 31 32 String lead; 33 34 String byline; 35 36 String bycredit; 37 38 String dateline; 39 40 String body; 41 42 String leadIn; 43 44 String webHeadline; 45 46 String keywords; 47 48 String webLead; 49 50 String pubRank; 51 52 String pubData; 53 54 String disableIndex; 55 56 String disableArticle; 57 58 String rank; 59 60 String articleType; 61 62 String noVersioning; 63 64 String customURL; 65 66 String verNum; 67 68 String itemID; 69 70 String doesExists; 71 72 String mappingCode; 73 74 String startDate; 75 76 String endDate; 77 78 String lifeCycle; 79 80 String oldSection; 81 82 String toValidOrPublish; 83 84 String oldState; 85 86 public s_insertArticle2() { 87 } 88 89 public void init(HashMap initData, Connection con) { 90 super.init(initData, con); 92 pubName = utils.getString(data, "PUBNAME", ""); 94 section = utils.getString(data, "SECTION", ""); 95 pubDate = utils.getString(data, "PUBDATE", ""); 96 fileName = utils.getString(data, "FILENAME", ""); 97 approved = utils.getString(data, "APPROVED", ""); 98 headline = utils.getString(data, "HEADLINE", ""); 99 headline2 = utils.getString(data, "HEADLINE2", ""); 100 lead = utils.getString(data, "LEAD", ""); 101 byline = utils.getString(data, "BYLINE", ""); 102 bycredit = utils.getString(data, "BYCREDIT", ""); 103 dateline = utils.getString(data, "DATELINE", ""); 104 body = utils.getString(data, "BODY", ""); 105 leadIn = utils.getString(data, "LEADIN", ""); 106 webHeadline = utils.getString(data, "WEBHEADLINE", ""); 107 keywords = utils.getString(data, "KEYWORDS", ""); 108 webLead = utils.getString(data, "WEBLEAD", ""); 109 pubRank = utils.getString(data, "PUBRANK", ""); 110 disableIndex = utils.getString(data, "DISABLEINDEX", ""); 111 disableArticle = utils.getString(data, "DISABLEARTICLE", ""); 112 rank = utils.getString(data, "RANK", "999"); 113 articleType = utils.getString(data, "ARTICLETYPE", ""); 114 customURL = utils.getString(data, "CUSTOMURL", ""); 115 startDate = utils.getString(data, "STARTDATE", ""); 116 endDate = utils.getString(data, "ENDDATE", ""); 117 lifeCycle = utils.getString(data, "LIFECYCLE", ""); 118 oldSection = utils.getString(data, "OLDSECTION", section); 119 toValidOrPublish = utils.getString(data, "TOVALIDORPUBLISH", "0"); 120 oldState = utils.getString(data, "OLDSTATE", "0"); 121 } 122 123 public void checkParams() throws SQLException { 124 if (section.equals("")) 125 throw new SQLException("ERROR: required field 'section' was not sent."); 126 if (pubName.equals("")) 127 throw new SQLException("ERROR: required field 'pubName' was not sent."); 128 if (fileName.equals("")) 129 throw new SQLException("ERROR: required field 'fileName' was not sent."); 130 if (pubDate.equals("")) 131 throw new SQLException("ERROR: required field 'pubDate' was not sent."); 132 } 133 134 public void checkAction() throws SQLException { 135 } 136 137 public void executeAction() throws SQLException { 138 139 StringBuffer v_useDate = new StringBuffer (); 141 v_useDate.append("SELECT defaultSectionWithDate "); 142 v_useDate.append(" FROM tblpublications ").append(" WHERE pubName = '" + pubName + "'"); 143 String useDate = execStatementToValue(v_useDate.toString()); 144 145 StringBuffer v_sb = new StringBuffer (); 146 v_sb.append("SELECT COALESCE(max(versionNum), 0)+1 "); 147 v_sb.append(" FROM tblarticles ").append(" WHERE section = '" + oldSection + "'"); 148 if (useDate == "1") 149 v_sb.append(" AND pubDate = '" + pubDate + "'"); 150 v_sb.append(" AND pubName = '" + pubName + "'").append(" AND fileName = '" + fileName + "'"); 151 152 String verNum = execStatementToValue(v_sb.toString()); 153 154 String articleTypeID = "0"; 155 if ((articleType != null) && (!articleType.equals(""))) { 156 StringBuffer v_sbSelect = new StringBuffer (); 157 v_sbSelect.append("SELECT COALESCE(articleTypeID, 0 ) "); 158 v_sbSelect.append("FROM tblarticletypes ").append("WHERE pubName = '" + pubName + "' ").append("AND articleType = '" + articleType + "'"); 159 160 articleTypeID = execStatementToValue(v_sbSelect.toString()); 161 if (articleTypeID.equals("")) { 162 articleTypeID = "0"; 163 } 164 } 165 166 StringBuffer v_sbInsert = new StringBuffer (); 167 v_sbInsert 168 .append("INSERT INTO tblarticles ") 169 .append( 170 "(pubName, headline, headline2, webHeadline, lead, dateline, keywords, webLead, pubRank, pubData, byline, bycredit, pubDate, section, ") 171 .append( 172 " body, leadIn, updateDate, docType, versionNum, approved, fileName, disableIndex, disableArticle, articleTypeID, customURL, workflow_state) ") 173 .append("VALUES ( '" + pubName + "', '" + headline + "', '" + headline2 + "' , '" + webHeadline + "', ").append( 174 " '" + lead + "', '" + dateline + "' , '" + keywords + "' , '" + webLead + "' , '" + pubRank + "' , ").append( 175 " '" + pubData + "' , '" + byline + "' , '" + bycredit + "' , '" + pubDate + "' , '" + section + "' , ").append( 176 " '" + body + "' , '" + leadIn + "' , now() , 1, " + verNum + " , '" + approved + "' , '" + fileName + "', ").append( 177 " '" + disableIndex + "' , '" + disableArticle + "' , '" + articleTypeID + "' , '" + customURL + "'," + toValidOrPublish + ")"); 178 179 StringBuffer v_sbItemID = new StringBuffer (); 180 if ((Integer.parseInt(verNum) == 1) || ((oldState.equals("2")) && (toValidOrPublish.equals("0"))) 181 || ((oldState.equals("2")) && (toValidOrPublish.equals("1")))) { 182 v_sbItemID.append("SELECT max(itemID) + 1 ").append("from tblarticles"); 183 } else if (Integer.parseInt(verNum) > 1) { 184 v_sbItemID.append("SELECT itemID ").append("FROM tblarticles ").append("WHERE section = '" + oldSection + "' "); 185 if (useDate == "1") 186 v_sbItemID.append("AND pubDate = '" + pubDate + "' "); 187 v_sbItemID.append("AND pubName = '" + pubName + "' ").append("AND fileName = '" + fileName + "' ").append("AND versionNum < " + verNum + " ") 188 .append("AND workflow_state= " + oldState); 189 } 190 191 synchronized (this) { 192 execStatement(v_sbInsert.toString()); 193 itemID = execStatementToValue(v_sbItemID.toString()); 194 } 195 196 StringBuffer v_sbUpdate = new StringBuffer (); 197 v_sbUpdate.append("UPDATE tblarticles ").append("SET itemID = '" + itemID + "' ").append("WHERE section = '" + section + "' ").append( 198 "AND pubDate = '" + pubDate + "' ").append("AND pubName = '" + pubName + "' ").append("AND fileName = '" + fileName + "' ").append( 199 "AND versionNum = " + verNum + " ").append("AND workflow_state=" + toValidOrPublish); 200 execStatement(v_sbUpdate.toString()); 201 202 if (lifeCycle.equals("on")) { 204 StringBuffer v_sbUpdate1 = new StringBuffer (); 205 v_sbUpdate1.append("UPDATE tblarticles ").append("SET pubStart = '" + startDate + "', ").append("pubEnd = '" + endDate + "', ").append( 206 "lifeCycle=1 ").append("WHERE itemID = '" + itemID + "' "); 207 execStatement(v_sbUpdate1.toString()); 208 } else { 209 StringBuffer v_sbUpdate1 = new StringBuffer (); 210 v_sbUpdate1.append("UPDATE tblarticles ").append("SET pubStart = null, ") .append("pubEnd = null, ") .append("lifeCycle=0 ").append("WHERE itemID = '" + itemID + "' "); 220 execStatement(v_sbUpdate1.toString()); 221 } 222 223 StringBuffer v_sbInsert2 = new StringBuffer (); 226 v_sbInsert2.append("INSERT INTO tblarticleversions ").append("SELECT * FROM tblarticles ").append("WHERE section = '" + oldSection + "' "); 227 if (useDate == "1") 228 v_sbInsert2.append("AND pubDate = '" + pubDate + "' "); 229 v_sbInsert2.append("AND pubName = '" + pubName + "' ").append("AND fileName = '" + fileName + "' ").append("AND versionNum < " + verNum + " ").append( 230 "AND workflow_state<=" + toValidOrPublish + " "); 231 execStatement(v_sbInsert2.toString()); 232 233 StringBuffer v_sbDelete = new StringBuffer (); 235 v_sbDelete.append("DELETE from tblarticles ").append("WHERE section = '" + oldSection + "' "); 236 if (useDate == "1") 237 v_sbDelete.append("AND pubDate = '" + pubDate + "' "); 238 v_sbDelete.append("AND pubName = '" + pubName + "' ").append("AND fileName = '" + fileName + "' ").append("AND itemID <> '" + itemID + "' ").append( 239 "AND versionNum <= " + verNum + " ").append("AND workflow_state<=" + toValidOrPublish + " "); 240 execStatement(v_sbDelete.toString()); 241 242 StringBuffer v_sbDelete2 = new StringBuffer (); 243 v_sbDelete2.append("DELETE from tblarticles ").append("WHERE section = '" + oldSection + "' "); 244 if (useDate == "1") 245 v_sbDelete2.append("AND pubDate = '" + pubDate + "' "); 246 v_sbDelete2.append("AND pubName = '" + pubName + "' ").append("AND fileName = '" + fileName + "' ").append("AND versionNum < " + verNum + " ").append( 247 "AND workflow_state<=" + toValidOrPublish + " "); 248 execStatement(v_sbDelete2.toString()); 249 250 StringBuffer v_sbExists = new StringBuffer (); 252 v_sbExists.append("SELECT count(0) ").append(" FROM tblarticleorder o, tblsections s ").append(" WHERE o.mappingCode = s.mappingCode ").append( 253 "AND o.itemID = '" + itemID + "' ").append("AND s.section = '" + section + "'"); 254 255 doesExists = execStatementToValue(v_sbExists.toString()); 256 257 if (Integer.parseInt(doesExists) < 1) { 258 StringBuffer v_sbMappingCode = new StringBuffer (); 259 v_sbMappingCode.append("SELECT mappingCode from tblsections ").append("WHERE section = '" + section + "' ").append( 260 "AND pubName = '" + pubName + "'"); 261 262 mappingCode = execStatementToValue(v_sbMappingCode.toString()); 263 264 if (mappingCode != null && mappingCode != "") { 265 StringBuffer v_sbInsert3 = new StringBuffer (); 266 v_sbInsert3.append("INSERT INTO tblarticleorder ").append("(itemID, rank, mappingCode, timeStart, ").append( 267 "timeEnd, mappingUpdateDate, pubName, section, pubDate) ").append("VALUES ").append("('" + itemID + "', ").append("'" + rank + "', ") 268 .append("'" + mappingCode + "', ").append("'" + sdf.format(new java.util.Date ()) + "', ").append( 269 "'" + sdf.format(new java.util.Date ()) + "', ").append("'" + sdf.format(new java.util.Date ()) + "', ").append( 270 "'" + pubName + "', ").append("'" + section + "', ").append("'" + pubDate + "')"); 271 272 execStatement(v_sbInsert3.toString()); 273 } 274 } 275 s_updateArticlePreload sp_uaa = new s_updateArticlePreload(); 276 sp_uaa.init(data, psConnection); 277 sp_uaa.setItemID(itemID); 278 sp_uaa.setTargetDataStore(targetDataStore); 279 sp_uaa.executeAction(); 280 281 execStatementToRS("SELECT " + itemID + " as itemID"); 282 283 } 284 285 } 286 | Popular Tags |