1 4 package com.openedit.archive.history; 5 6 import java.text.SimpleDateFormat ; 7 import java.util.Calendar ; 8 import java.util.Date ; 9 import java.util.GregorianCalendar ; 10 import java.util.Iterator ; 11 12 import com.openedit.OpenEditException; 13 import com.openedit.WebPageRequest; 14 import com.openedit.archive.Archive; 15 import com.openedit.archive.collection.Collection; 16 import com.openedit.archive.collection.CollectionItem; 17 import com.openedit.modules.BaseModule; 18 import com.openedit.modules.archive.ArchiveModule; 19 import com.openedit.store.Product; 20 import com.openedit.store.StoreException; 21 22 public class HistoryModule extends BaseModule 23 { 24 public Archive getArchive( WebPageRequest inReq ) throws OpenEditException 25 { 26 Archive archive = (Archive) inReq.getPageValue( Archive.ARCHIVE_PARAM ); 27 if( archive == null) 28 { 29 ArchiveModule mod = (ArchiveModule)getModule("ArchiveModule"); 30 archive = mod.getArchive(inReq); 31 } 32 return archive; 33 } 34 35 public HistoryArchive getHistoryArchive(WebPageRequest inReq) throws OpenEditException 36 { 37 String name = inReq.getPage().get("HistoryArchiveName"); 38 if( name == null) 39 { 40 name = "historyArchive"; 41 } 42 HistoryArchive history = (HistoryArchive)getBeanFactory().getBean(name); 43 return history; 44 } 45 46 public UsageHistory getUsageHistory( WebPageRequest inReq) throws Exception 47 { 48 String produid = inReq.getRequestParameter("productid"); 49 if (produid == null) 50 { 51 Product product = (Product)inReq.getPageValue("product"); 52 produid = product.getId(); 53 } 54 Archive archive = getArchive(inReq); 55 UsageHistory history = getHistoryArchive(inReq).getUsageHistory(archive, produid); 56 inReq.putPageValue("usagehistory", history); 57 return history; 58 } 59 60 public void saveUsageHistoryForCollection(WebPageRequest inReq) throws Exception 61 { 62 63 String isfpos = inReq.getRequestParameter("isfpo"); 65 String username = inReq.getRequestParameter("username"); 66 String use = inReq.getRequestParameter("use"); 68 String use2 = inReq.getRequestParameter("use2"); 69 String formID = inReq.getRequestParameter("formID"); 72 String comments = inReq.getRequestParameter("comments"); 73 String restrictdays = inReq.getRequestParameter("rdays"); 75 77 boolean isfpo = Boolean.parseBoolean(isfpos); 78 79 saveRecord(inReq, username, use, use2, formID, comments, restrictdays, isfpo); 80 81 inReq.putPageValue("isfpo", String.valueOf(isfpo)); 82 83 87 223 } 224 225 protected void saveRecord(WebPageRequest inReq, String username, String use, String use2, 226 String formID, String comments, String restrictdays, boolean isfpo) 227 throws OpenEditException, StoreException 228 { 229 SimpleDateFormat format = new SimpleDateFormat ("dd/MM/yyyy"); 230 Date nowDate = new Date (); 231 232 String nowString = format.format(nowDate); 235 Calendar releaseCalendar = new GregorianCalendar (); 236 releaseCalendar.add(Calendar.DAY_OF_YEAR, Integer.parseInt(restrictdays)); 237 String releaseString = format.format(releaseCalendar.getTime()); 238 239 Archive archive = getArchive(inReq); 240 241 Collection col = archive.getUserCollections().getSelectedCollection(); 242 243 for (Iterator iter = col.getCollectionItems().iterator(); iter.hasNext();) 244 { 245 CollectionItem item = (CollectionItem) iter.next(); 246 Product product = item.getProduct(); 247 248 UsageHistory history = getHistoryArchive(inReq).getUsageHistory(archive, product.getId()); 249 HistoryRecord record = history.createNewRecord(); 250 record.putData("date", nowString); 252 record.putData("description", comments); 253 record.putData("audience", use); 254 record.putData("typeofuse", use2); 255 record.putData("username", username); 256 record.putData("formnum", formID); 257 record.putData("isfpo", String.valueOf(isfpo)); 258 history.addRecord(record); 259 getHistoryArchive(inReq).save(archive, history); 260 261 262 product.putAttribute("Restricted", "true"); 263 product.putAttribute("Restriction Release Date", releaseString); 264 265 StringBuffer recordlog = new StringBuffer (); 266 for (Iterator iterator = history.getRecordData(); iterator.hasNext();) { 267 HistoryRecord tolog = (HistoryRecord) iterator.next(); 268 recordlog.append(nowString); 269 recordlog.append("\t"); 270 recordlog.append(comments); 271 recordlog.append("\t"); 272 recordlog.append(use); 273 recordlog.append("\t"); 274 recordlog.append(use2); 275 recordlog.append("\t"); 276 recordlog.append(username); 277 recordlog.append("\t"); 278 recordlog.append(formID); 279 recordlog.append("\t"); 280 recordlog.append(String.valueOf(isfpo)); 281 recordlog.append("\r\n"); 282 283 } 284 product.putAttribute("Version History", recordlog.toString()); 285 getArchive(inReq).getStore().saveProduct(product); 286 287 } 288 } 289 } 290 | Popular Tags |