1 64 65 70 package com.jcorporate.expresso.services.controller; 71 72 import com.jcorporate.expresso.core.controller.Block; 73 import com.jcorporate.expresso.core.controller.ControllerException; 74 import com.jcorporate.expresso.core.controller.ControllerRequest; 75 import com.jcorporate.expresso.core.controller.ControllerResponse; 76 import com.jcorporate.expresso.core.controller.DBController; 77 import com.jcorporate.expresso.core.controller.Output; 78 import com.jcorporate.expresso.core.controller.State; 79 import com.jcorporate.expresso.core.controller.Transition; 80 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 81 import com.jcorporate.expresso.core.logging.LogException; 82 import com.jcorporate.expresso.core.logging.LogHandler; 83 import com.jcorporate.expresso.services.dbobj.LogEntry; 84 85 import java.util.Iterator ; 86 87 88 94 public class Log 95 extends DBController { 96 private int maxLines = 100; 97 98 101 public Log() { 102 super(); 103 104 State show = new State("show", "Show Text Log"); 105 addState(show); 106 setInitialState("show"); 107 108 State showdb = new State("showDb", "Show Database Log"); 109 addState(showdb); 110 111 State clear = new State("clear", "Clear Text Log"); 112 addState(clear); 113 setInitialState("clear"); 114 115 State cleardb = new State("clearDb", "Clear Database Log"); 116 addState(cleardb); 117 setInitialState("clearDb"); 118 this.setSchema(com.jcorporate.expresso.core.ExpressoSchema.class); 119 } 120 121 122 129 public void runShowDbState(ControllerRequest request, 130 ControllerResponse response) 131 throws ControllerException { 132 try { 133 LogHandler.flush(); 134 } catch (LogException le) { 135 throw new ControllerException(le); 136 } 137 138 Block logTable = new Block(); 139 response.addBlock(logTable); 140 logTable.setAttribute("table", "Y"); 141 logTable.setDescription("Current Log"); 142 logTable.setAttribute("header-row", "Time|Message|Object|UserId|Job"); 143 144 try { 145 LogEntry logEntryList = new LogEntry(SecuredDBObject.SYSTEM_ACCOUNT); 146 logEntryList.setDataContext(request.getDataContext()); 147 logEntryList.setMaxRecords(maxLines + 1); 148 149 LogEntry oneEntry = null; 150 Iterator e = logEntryList.searchAndRetrieveList("LogTime DESC").iterator(); 151 int lineCount = 0; 152 Block oneRow = null; 153 Output oneCell = null; 154 155 while (e.hasNext()) { 156 oneEntry = (LogEntry) e.next(); 157 oneRow = new Block("log row"); 158 oneRow.setAttribute("row", "Y"); 159 logTable.add(oneRow); 160 oneCell = new Output(oneEntry.getField("LogTime")); 161 oneRow.add(oneCell); 162 oneCell = new Output(oneEntry.getField("MessageText")); 163 oneRow.add(oneCell); 164 oneCell = new Output(oneEntry.getField("ObjectName")); 165 oneRow.add(oneCell); 166 oneCell = new Output(oneEntry.getField("ExpUid")); 167 oneRow.add(oneCell); 168 oneCell = new Output(oneEntry.getField("JobNumber")); 169 oneRow.add(oneCell); 170 lineCount++; 171 172 if (lineCount >= maxLines) { 173 break; 174 } 175 } 176 177 if (lineCount == 0) { 178 Output none = new Output("none", "No entries in the log"); 179 response.add(none); 180 } 181 if (lineCount >= maxLines) { 183 Output disp = new Output("disp", 184 "Display stopped at " + maxLines + 185 " lines."); 186 response.add(disp); 187 } 188 } catch (Exception ioe) { 189 throw new ControllerException(ioe); 190 } 191 192 response.addTransition(new Transition("clearDb", this)); 193 response.addTransition(new Transition("show", this)); 194 response.addTransition(new Transition("clear", this)); 195 } 196 197 198 201 public String getTitle() { 202 return ("Manage System Logs"); 203 } 204 205 } 206 | Popular Tags |