001: /* Copyright 2002 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.services.stats;
007:
008: import org.jasig.portal.ChannelDefinition;
009: import org.jasig.portal.UserProfile;
010: import org.jasig.portal.layout.node.IUserLayoutChannelDescription;
011: import org.jasig.portal.layout.node.IUserLayoutFolderDescription;
012: import org.jasig.portal.security.IPerson;
013:
014: /**
015: * Formulates stats messages which can be logged, printed, etc.
016: * Subclasses need to override <code>outputMessage(String message)</code>.
017: * @author Ken Weiner, kweiner@unicon.net
018: * @version $Revision: 36546 $
019: *
020: * @deprecated IStatsRecorder implementation is replaced with a much more flexible system based on the Spring ApplicationEventPublisher
021: * and Event Listeners. For more information see:
022: * http://www.ja-sig.org/wiki/display/UPC/Proposal+to+Deprecate+IStatsRecorder
023: */
024: public abstract class MessageStatsRecorder implements IStatsRecorder {
025:
026: public void recordLogin(IPerson person) {
027: String msg = getDisplayName(person)
028: + " logged in successfully at " + new java.util.Date();
029: outputMessage(fixMsg(msg));
030: }
031:
032: public void recordLogout(IPerson person) {
033: String msg = getDisplayName(person) + " logged out at "
034: + new java.util.Date();
035: outputMessage(fixMsg(msg));
036: }
037:
038: public void recordSessionCreated(IPerson person) {
039: String msg = "Session created for " + getDisplayName(person)
040: + " " + "at " + new java.util.Date();
041: outputMessage(fixMsg(msg));
042: }
043:
044: public void recordSessionDestroyed(IPerson person) {
045: String msg = "Session destroyed for " + getDisplayName(person)
046: + " " + "at " + new java.util.Date();
047: outputMessage(fixMsg(msg));
048: }
049:
050: public void recordChannelDefinitionPublished(IPerson person,
051: ChannelDefinition channelDef) {
052: String msg = "Channel '" + channelDef.getName() + "' "
053: + "was published by " + getDisplayName(person) + " "
054: + "at " + new java.util.Date();
055: outputMessage(fixMsg(msg));
056: }
057:
058: public void recordChannelDefinitionModified(IPerson person,
059: ChannelDefinition channelDef) {
060: String msg = "Channel '" + channelDef.getName() + "' "
061: + "was modified by " + getDisplayName(person) + " "
062: + "at " + new java.util.Date();
063: outputMessage(fixMsg(msg));
064: }
065:
066: public void recordChannelDefinitionRemoved(IPerson person,
067: ChannelDefinition channelDef) {
068: String msg = "Channel '" + channelDef.getName() + "' "
069: + "was removed by " + getDisplayName(person) + " "
070: + "at " + new java.util.Date();
071: outputMessage(fixMsg(msg));
072: }
073:
074: public void recordChannelAddedToLayout(IPerson person,
075: UserProfile profile,
076: IUserLayoutChannelDescription channelDesc) {
077: String msg = "Channel [" + channelDesc.getName() + ", "
078: + channelDesc.getChannelPublishId() + ", "
079: + channelDesc.getChannelSubscribeId() + "] "
080: + "was added to layout " + profile.getLayoutId() + " "
081: + "by " + getDisplayName(person) + " " + "at "
082: + new java.util.Date();
083: outputMessage(fixMsg(msg));
084: }
085:
086: public void recordChannelUpdatedInLayout(IPerson person,
087: UserProfile profile,
088: IUserLayoutChannelDescription channelDesc) {
089: String msg = "Channel [" + channelDesc.getName() + ", "
090: + channelDesc.getChannelPublishId() + ", "
091: + channelDesc.getChannelSubscribeId() + "] "
092: + "was updated in layout " + profile.getLayoutId()
093: + " " + "by " + getDisplayName(person) + " " + "at "
094: + new java.util.Date();
095: outputMessage(fixMsg(msg));
096: }
097:
098: public void recordChannelMovedInLayout(IPerson person,
099: UserProfile profile,
100: IUserLayoutChannelDescription channelDesc) {
101: String msg = "Channel [" + channelDesc.getName() + ", "
102: + channelDesc.getChannelPublishId() + ", "
103: + channelDesc.getChannelSubscribeId() + "] "
104: + "was moved in layout " + profile.getLayoutId() + " "
105: + "by " + getDisplayName(person) + " " + "at "
106: + new java.util.Date();
107: outputMessage(fixMsg(msg));
108: }
109:
110: public void recordChannelRemovedFromLayout(IPerson person,
111: UserProfile profile,
112: IUserLayoutChannelDescription channelDesc) {
113: String msg = "Channel [" + channelDesc.getName() + ", "
114: + channelDesc.getChannelPublishId() + ", "
115: + channelDesc.getChannelSubscribeId() + "] "
116: + "was removed from layout " + profile.getLayoutId()
117: + " " + "by " + getDisplayName(person) + " " + "at "
118: + new java.util.Date();
119: outputMessage(fixMsg(msg));
120: }
121:
122: public void recordFolderAddedToLayout(IPerson person,
123: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
124: String msg = "Folder [" + folderDesc.getName() + ", "
125: + folderDesc.getId() + "] " + "was added to layout "
126: + profile.getLayoutId() + " " + "by "
127: + getDisplayName(person) + " " + "at "
128: + new java.util.Date();
129: outputMessage(fixMsg(msg));
130: }
131:
132: public void recordFolderUpdatedInLayout(IPerson person,
133: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
134: String msg = "Folder [" + folderDesc.getName() + ", "
135: + folderDesc.getId() + "] " + "was updated in layout "
136: + profile.getLayoutId() + " " + "by "
137: + getDisplayName(person) + " " + "at "
138: + new java.util.Date();
139: outputMessage(fixMsg(msg));
140: }
141:
142: public void recordFolderMovedInLayout(IPerson person,
143: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
144: String msg = "Folder [" + folderDesc.getName() + ", "
145: + folderDesc.getId() + "] " + "was moved in layout "
146: + profile.getLayoutId() + " " + "by "
147: + getDisplayName(person) + " " + "at "
148: + new java.util.Date();
149: outputMessage(fixMsg(msg));
150: }
151:
152: public void recordFolderRemovedFromLayout(IPerson person,
153: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
154: String msg = "Folder [" + folderDesc.getName() + ", "
155: + folderDesc.getId() + "] "
156: + "was removed from layout " + profile.getLayoutId()
157: + " " + "by " + getDisplayName(person) + " " + "at "
158: + new java.util.Date();
159: outputMessage(fixMsg(msg));
160: }
161:
162: public void recordChannelInstantiated(IPerson person,
163: UserProfile profile,
164: IUserLayoutChannelDescription channelDesc) {
165: String msg = "Channel [" + channelDesc.getName() + ", "
166: + channelDesc.getChannelPublishId() + ", "
167: + channelDesc.getChannelSubscribeId() + "] "
168: + "was instantiated in layout " + profile.getLayoutId()
169: + " " + "by " + getDisplayName(person) + " " + "at "
170: + new java.util.Date();
171: outputMessage(fixMsg(msg));
172: }
173:
174: public void recordChannelRendered(IPerson person,
175: UserProfile profile,
176: IUserLayoutChannelDescription channelDesc) {
177: String msg = "Channel [" + channelDesc.getName() + ", "
178: + channelDesc.getChannelPublishId() + ", "
179: + channelDesc.getChannelSubscribeId() + "] "
180: + "was rendered in layout " + profile.getLayoutId()
181: + " " + "by " + getDisplayName(person) + " " + "at "
182: + new java.util.Date();
183: outputMessage(fixMsg(msg));
184: }
185:
186: public void recordChannelTargeted(IPerson person,
187: UserProfile profile,
188: IUserLayoutChannelDescription channelDesc) {
189: String msg = "Channel [" + channelDesc.getName() + ", "
190: + channelDesc.getChannelPublishId() + ", "
191: + channelDesc.getChannelSubscribeId() + "] "
192: + "was targeted in layout " + profile.getLayoutId()
193: + " " + "by " + getDisplayName(person) + " " + "at "
194: + new java.util.Date();
195: outputMessage(fixMsg(msg));
196: }
197:
198: /**
199: * Outputs the message formulated according
200: * to the stat being recorded. Subclasses
201: * have the responsibility of implementing
202: * this method.
203: * @param message, the message to output
204: */
205: protected abstract void outputMessage(String message);
206:
207: /**
208: * Creates a name suitable for displaying in a
209: * stats message. Indicates if user is a "guest" user.
210: * @param person, the person
211: * @return name, the display name for the user
212: */
213: private String getDisplayName(IPerson person) {
214: String name = null;
215: if (person != null) {
216: String userName = (String) person
217: .getAttribute(IPerson.USERNAME);
218: if (person.isGuest()) {
219: name = "GUEST_USER (" + fixNull(userName) + ")";
220: } else {
221: String firstName = (String) person
222: .getAttribute("givenName");
223: String lastName = (String) person.getAttribute("sn");
224: name = fixNull(firstName) + " " + fixNull(lastName)
225: + " (" + fixNull(userName) + ")";
226: }
227: } else {
228: name = "NULL_PERSON";
229: }
230: return name;
231: }
232:
233: /**
234: * Replaces null String with an empty String
235: * @param s, the string to fix
236: * @return s, the fixed string
237: */
238: private String fixNull(String s) {
239: return s == null ? "" : s;
240: }
241:
242: /**
243: * Prepends a string to each message to make it
244: * clear that it came from the LoggingStatsRecorder
245: * @param msg, the message to log
246: * @return msg, the message prepended with a string that
247: * identifies the message as having come from a stats recorder
248: */
249: private String fixMsg(String msg) {
250: return "STATS-RECORDER: " + msg;
251: }
252: }
|