From ea4336ad7ea7680d88371e4f0dc8e1ac0009cad0 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Mon, 23 Jun 2014 14:51:46 -0400
Subject: [PATCH] Fixed missing TPS activity attributes.

The ActivityService has been fixed to return the missing TPS activity
attributes including IP, operation, result, and message. The TPS CLI
and UI has been fixed to display the activity date in UTC format.

Ticket #1050
---
 .../com/netscape/certsrv/logging/ActivityData.java | 53 ++++++++++++++++++++--
 .../com/netscape/cmstools/logging/ActivityCLI.java |  9 +++-
 .../netscape/cmstools/logging/ActivityFindCLI.java |  2 +-
 .../netscape/cmstools/logging/ActivityShowCLI.java |  2 +-
 base/server/share/webapps/pki/css/pki-ui.css       |  4 ++
 base/server/share/webapps/pki/js/pki-ui.js         |  5 +-
 base/tps-tomcat/shared/webapps/tps/js/activity.js  |  9 ++--
 .../tps-tomcat/shared/webapps/tps/ui/activity.html |  4 +-
 .../dogtagpki/server/tps/dbs/ActivityDatabase.java |  2 +-
 .../dogtagpki/server/tps/dbs/ActivityRecord.java   |  4 +-
 .../dogtagpki/server/tps/rest/ActivityService.java |  8 ++++
 11 files changed, 88 insertions(+), 14 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/logging/ActivityData.java b/base/common/src/com/netscape/certsrv/logging/ActivityData.java
index 0624cc73bc8a240577c3d29036977c0349b06900..d918357ad16309ebf72b849de8cd9f4ee5dd7f98 100644
--- a/base/common/src/com/netscape/certsrv/logging/ActivityData.java
+++ b/base/common/src/com/netscape/certsrv/logging/ActivityData.java
@@ -56,6 +56,7 @@ public class ActivityData {
     String ip;
     String operation;
     String result;
+    String message;
     Date date;
 
     Link link;
@@ -88,11 +89,11 @@ public class ActivityData {
     }
 
     @XmlElement(name="IP")
-    public String getIp() {
+    public String getIP() {
         return ip;
     }
 
-    public void setIp(String ip) {
+    public void setIP(String ip) {
         this.ip = ip;
     }
 
@@ -114,6 +115,15 @@ public class ActivityData {
         this.result = result;
     }
 
+    @XmlElement(name="Message")
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
     @XmlElement(name="Date")
     public Date getDate() {
         return date;
@@ -136,8 +146,14 @@ public class ActivityData {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
+        result = prime * result + ((date == null) ? 0 : date.hashCode());
         result = prime * result + ((id == null) ? 0 : id.hashCode());
+        result = prime * result + ((ip == null) ? 0 : ip.hashCode());
         result = prime * result + ((link == null) ? 0 : link.hashCode());
+        result = prime * result + ((message == null) ? 0 : message.hashCode());
+        result = prime * result + ((operation == null) ? 0 : operation.hashCode());
+        result = prime * result + ((this.result == null) ? 0 : this.result.hashCode());
+        result = prime * result + ((tokenID == null) ? 0 : tokenID.hashCode());
         result = prime * result + ((userID == null) ? 0 : userID.hashCode());
         return result;
     }
@@ -151,16 +167,46 @@ public class ActivityData {
         if (getClass() != obj.getClass())
             return false;
         ActivityData other = (ActivityData) obj;
+        if (date == null) {
+            if (other.date != null)
+                return false;
+        } else if (!date.equals(other.date))
+            return false;
         if (id == null) {
             if (other.id != null)
                 return false;
         } else if (!id.equals(other.id))
             return false;
+        if (ip == null) {
+            if (other.ip != null)
+                return false;
+        } else if (!ip.equals(other.ip))
+            return false;
         if (link == null) {
             if (other.link != null)
                 return false;
         } else if (!link.equals(other.link))
             return false;
+        if (message == null) {
+            if (other.message != null)
+                return false;
+        } else if (!message.equals(other.message))
+            return false;
+        if (operation == null) {
+            if (other.operation != null)
+                return false;
+        } else if (!operation.equals(other.operation))
+            return false;
+        if (result == null) {
+            if (other.result != null)
+                return false;
+        } else if (!result.equals(other.result))
+            return false;
+        if (tokenID == null) {
+            if (other.tokenID != null)
+                return false;
+        } else if (!tokenID.equals(other.tokenID))
+            return false;
         if (userID == null) {
             if (other.userID != null)
                 return false;
@@ -194,9 +240,10 @@ public class ActivityData {
         before.setID("activity1");
         before.setTokenID("TOKEN1234");
         before.setUserID("user1");
-        before.setIp("192.168.1.1");
+        before.setIP("192.168.1.1");
         before.setOperation("enroll");
         before.setResult("success");
+        before.setMessage("test");
         before.setDate(new Date());
 
         String string = before.toString();
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java
index df012e8e8763ca8ee0fa9267476ff55ac7827527..f53e687001f80ce6976ba537abcd6b00572e55c2 100644
--- a/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java
@@ -46,12 +46,19 @@ public class ActivityCLI extends CLI {
         super.execute(args);
     }
 
-    public static void printActivity(ActivityData activity) {
+    public static void printActivity(ActivityData activity, boolean showAll) {
         System.out.println("  Activity ID: " + activity.getID());
         if (activity.getTokenID() != null) System.out.println("  Token ID: " + activity.getTokenID());
         if (activity.getUserID() != null) System.out.println("  User ID: " + activity.getUserID());
+        if (activity.getIP() != null) System.out.println("  IP: " + activity.getIP());
+        if (activity.getOperation() != null) System.out.println("  Operation: " + activity.getOperation());
+        if (activity.getResult() != null) System.out.println("  Result: " + activity.getResult());
         if (activity.getDate() != null) System.out.println("  Date: " + activity.getDate());
 
+        if (showAll) {
+            if (activity.getMessage() != null)  System.out.println("  Message: " + activity.getMessage());
+        }
+
         Link link = activity.getLink();
         if (verbose && link != null) {
             System.out.println("  Link: " + link.getHref());
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
index 8020b8464fe17970690eaf5c4358d441dddccd60..413eae10155c9298c9c510ed186b451cb8843239 100644
--- a/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
@@ -101,7 +101,7 @@ public class ActivityFindCLI extends CLI {
                 System.out.println();
             }
 
-            ActivityCLI.printActivity(activityData);
+            ActivityCLI.printActivity(activityData, false);
         }
 
         MainCLI.printMessage("Number of entries returned " + activities.size());
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
index ea0d69fecf768a511e71ff1e2d78b2e997f60b27..b68d6adb547f891061d1de2731a0400dff859302 100644
--- a/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
@@ -75,6 +75,6 @@ public class ActivityShowCLI extends CLI {
 
         MainCLI.printMessage("Activity \"" + activityID + "\"");
 
-        ActivityCLI.printActivity(activityData);
+        ActivityCLI.printActivity(activityData, true);
     }
 }
diff --git a/base/server/share/webapps/pki/css/pki-ui.css b/base/server/share/webapps/pki/css/pki-ui.css
index d5c74445fd1dc81a18fddeabafabe3e7a6204ad1..c0202887654dfade26bec31a1e70194119927d34 100644
--- a/base/server/share/webapps/pki/css/pki-ui.css
+++ b/base/server/share/webapps/pki/css/pki-ui.css
@@ -56,6 +56,10 @@ fieldset label {
   line-height: 30px;
 }
 
+fieldset input {
+  min-width: 250px;
+}
+
 input[readonly="readonly"] {
   background-image: none;
   border: 1px solid #FFFFFF;
diff --git a/base/server/share/webapps/pki/js/pki-ui.js b/base/server/share/webapps/pki/js/pki-ui.js
index d4e2706011df748a22d824fa1b45d4b2fd087263..bf04d0121f9aeb8bace68e00f954a64ab38aaf25 100644
--- a/base/server/share/webapps/pki/js/pki-ui.js
+++ b/base/server/share/webapps/pki/js/pki-ui.js
@@ -447,9 +447,11 @@ var TableItem = Backbone.View.extend({
 
             var name = RegExp.$1;
             var value = self.get(name);
+            if (value === undefined) value = "";
+            if (value instanceof Date) value = value.toUTCString();
 
             // replace pattern occurance with attribute value
-            newContent += content.substring(0, index) + (value === undefined ? "" : value);
+            newContent += content.substring(0, index) + value;
 
             // process the remaining content
             content = content.substring(index + name.length + 3);
@@ -1024,6 +1026,7 @@ var EntryPage = Page.extend({
         var name = input.attr("name");
         var value = self.entry[name];
         if (value === undefined) value = "";
+        if (value instanceof Date) value = value.toUTCString();
         input.val(value);
     },
     close: function() {
diff --git a/base/tps-tomcat/shared/webapps/tps/js/activity.js b/base/tps-tomcat/shared/webapps/tps/js/activity.js
index 1d029c86e6c96b9371cabdec2c1983ef4e98b0fc..cbc724e2337f9c49b20c1e9cb1d0b6aaed3a6c4d 100644
--- a/base/tps-tomcat/shared/webapps/tps/js/activity.js
+++ b/base/tps-tomcat/shared/webapps/tps/js/activity.js
@@ -29,7 +29,8 @@ var ActivityModel = Model.extend({
             ip: response.IP,
             operation: response.Operation,
             result: response.Result,
-            date: response.Date
+            message: response.Message,
+            date: new Date(response.Date)
         };
     },
     createRequest: function(attributes) {
@@ -40,7 +41,8 @@ var ActivityModel = Model.extend({
             IP: attributes.ip,
             Operation: attributes.operation,
             Result: attributes.result,
-            Date: attributes.date
+            Message: attributes.message,
+            Date: attributes.date.getTime()/1000 + 'Z'
         };
     }
 });
@@ -61,7 +63,8 @@ var ActivityCollection = Collection.extend({
             ip: entry.IP,
             operation: entry.Operation,
             result: entry.Result,
-            date: entry.Date
+            message: entry.Message,
+            date: new Date(entry.Date)
         });
     }
 });
diff --git a/base/tps-tomcat/shared/webapps/tps/ui/activity.html b/base/tps-tomcat/shared/webapps/tps/ui/activity.html
index 262e00c0829a6a09c56c7eb257849668a6588578..5ba96a4e19f033c4f85a448a51e13d056d059684 100644
--- a/base/tps-tomcat/shared/webapps/tps/ui/activity.html
+++ b/base/tps-tomcat/shared/webapps/tps/ui/activity.html
@@ -18,7 +18,7 @@
 <div class="pki-header">
 <ol class="breadcrumb">
     <li><a href="#">Home</a></li>
-    <li><a href="#activities">Activity</a></li>
+    <li><a href="#activities">Activities</a></li>
     <li class="active"><strong><span name="title">Activity ${id}</span></strong></li>
 </ol>
 
@@ -41,5 +41,7 @@
     <input name="result" readonly="readonly"><br>
     <label>Date</label>
     <input name="date" readonly="readonly"><br>
+    <label>Message</label>
+    <input name="message" readonly="readonly"><br>
 </fieldset>
 </div>
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityDatabase.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityDatabase.java
index 72e3102578f989727f7098456fe45af2495aabb7..313c961ac2eae09415e56cb34df53da73a272c09 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityDatabase.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityDatabase.java
@@ -62,7 +62,7 @@ public class ActivityDatabase extends LDAPDatabase<ActivityRecord> {
 
         ActivityRecord activityRecord = new ActivityRecord();
         activityRecord.setId(id);
-        activityRecord.setIp(ip);
+        activityRecord.setIP(ip);
         activityRecord.setTokenID(tokenID);
         activityRecord.setOperation(operation);
         activityRecord.setResult(result);
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityRecord.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityRecord.java
index 815d5ee08134c9c123c5e2df6f1dacabd65861c4..fe5b1f91c8e3d5767d00b4c8f38b0b67ab812357 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityRecord.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/dbs/ActivityRecord.java
@@ -71,11 +71,11 @@ public class ActivityRecord extends DBRecord {
     }
 
     @DBAttribute("tokenIP")
-    public String getIp() {
+    public String getIP() {
         return ip;
     }
 
-    public void setIp(String ip) {
+    public void setIP(String ip) {
         this.ip = ip;
     }
 
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ActivityService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ActivityService.java
index ca499e7ca932728502f288cfc2aefc207001a67f..6002e7a94de2052613c6b2e89442a3bf02c4f5bf 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ActivityService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/rest/ActivityService.java
@@ -70,6 +70,10 @@ public class ActivityService extends PKIService implements ActivityResource {
         activityData.setID(activityRecord.getId());
         activityData.setTokenID(activityRecord.getTokenID());
         activityData.setUserID(activityRecord.getUserID());
+        activityData.setIP(activityRecord.getIP());
+        activityData.setOperation(activityRecord.getOperation());
+        activityData.setResult(activityRecord.getResult());
+        activityData.setMessage(activityRecord.getMessage());
         activityData.setDate(activityRecord.getDate());
 
         String activityID = activityRecord.getId();
@@ -92,6 +96,10 @@ public class ActivityService extends PKIService implements ActivityResource {
         activityRecord.setId(activityData.getID());
         activityRecord.setTokenID(activityData.getTokenID());
         activityRecord.setUserID(activityData.getUserID());
+        activityRecord.setIP(activityData.getIP());
+        activityRecord.setOperation(activityData.getOperation());
+        activityRecord.setResult(activityData.getResult());
+        activityRecord.setMessage(activityData.getMessage());
         activityRecord.setDate(activityData.getDate());
 
         return activityRecord;
-- 
1.8.4.2

