From d9f9aaac6d8982dceacacd8adbe781e51fdcf603 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Sat, 14 Dec 2013 19:44:47 -0500
Subject: [PATCH] Added dialog for adding TPS groups.

A new dialog box has been added for adding TPS groups. A separate
group ID attribute has been added to the REST service as required
by Backbone.

Ticket #654
---
 .../src/com/netscape/certsrv/group/GroupData.java  | 23 ++++++++++++++++++++++
 .../com/netscape/cmstools/group/GroupAddCLI.java   |  2 +-
 .../netscape/cms/servlet/admin/GroupService.java   | 13 +++++++-----
 base/tps-tomcat/shared/webapps/tps/groups.html     | 20 +++++++++++++++----
 base/tps-tomcat/shared/webapps/tps/js/group.js     |  7 ++++++-
 5 files changed, 54 insertions(+), 11 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/group/GroupData.java b/base/common/src/com/netscape/certsrv/group/GroupData.java
index a21ad7f01ca34e4ef05f58947fd670a6a95d3836..33f66a4e38433474649b0b2a1e14c9428c20ea58 100644
--- a/base/common/src/com/netscape/certsrv/group/GroupData.java
+++ b/base/common/src/com/netscape/certsrv/group/GroupData.java
@@ -34,6 +34,8 @@ import com.netscape.certsrv.common.Constants;
 public class GroupData {
 
     String id;
+    String groupID;
+
     String description;
 
     Link link;
@@ -47,6 +49,15 @@ public class GroupData {
         this.id = id;
     }
 
+    @XmlElement(name="GroupID")
+    public String getGroupID() {
+        return groupID;
+    }
+
+    public void setGroupID(String groupID) {
+        this.groupID = groupID;
+    }
+
     @FormParam(Constants.PR_GROUP_DESC)
     @XmlElement(name="Description")
     public String getDescription() {
@@ -71,7 +82,9 @@ public class GroupData {
         final int prime = 31;
         int result = 1;
         result = prime * result + ((description == null) ? 0 : description.hashCode());
+        result = prime * result + ((groupID == null) ? 0 : groupID.hashCode());
         result = prime * result + ((id == null) ? 0 : id.hashCode());
+        result = prime * result + ((link == null) ? 0 : link.hashCode());
         return result;
     }
 
@@ -89,11 +102,21 @@ public class GroupData {
                 return false;
         } else if (!description.equals(other.description))
             return false;
+        if (groupID == null) {
+            if (other.groupID != null)
+                return false;
+        } else if (!groupID.equals(other.groupID))
+            return false;
         if (id == null) {
             if (other.id != null)
                 return false;
         } else if (!id.equals(other.id))
             return false;
+        if (link == null) {
+            if (other.link != null)
+                return false;
+        } else if (!link.equals(other.link))
+            return false;
         return true;
     }
 }
diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupAddCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupAddCLI.java
index a29ce62ef048750c79f7768ed89e62dfc7d198ff..47153cd3f9183f28cfe0d7c4c9f29488fc142959 100644
--- a/base/java-tools/src/com/netscape/cmstools/group/GroupAddCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/group/GroupAddCLI.java
@@ -69,7 +69,7 @@ public class GroupAddCLI extends CLI {
         String groupID = cmdArgs[0];
 
         GroupData groupData = new GroupData();
-        groupData.setID(groupID);
+        groupData.setGroupID(groupID);
         groupData.setDescription(cmd.getOptionValue("description"));
 
         groupData = groupCLI.groupClient.addGroup(groupData);
diff --git a/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java b/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java
index a20b548adc9cad126fbf9ad1991f21b4e0bb8a15..722979d7966ca76425ee53aca006cddc6d75c89c 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/admin/GroupService.java
@@ -79,14 +79,17 @@ public class GroupService extends PKIService implements GroupResource {
 
         GroupData groupData = new GroupData();
 
-        String id = group.getGroupID();
-        if (!StringUtils.isEmpty(id)) groupData.setID(id);
+        String groupID = group.getGroupID();
+        if (!StringUtils.isEmpty(groupID)) {
+            groupData.setID(groupID);
+            groupData.setGroupID(groupID);
+        }
 
         String description = group.getDescription();
         if (!StringUtils.isEmpty(description)) groupData.setDescription(description);
 
-        String groupID = URLEncoder.encode(groupData.getID(), "UTF-8");
-        URI uri = uriInfo.getBaseUriBuilder().path(GroupResource.class).path("{groupID}").build(groupID);
+        String encodedGroupID = URLEncoder.encode(groupData.getID(), "UTF-8");
+        URI uri = uriInfo.getBaseUriBuilder().path(GroupResource.class).path("{groupID}").build(encodedGroupID);
         groupData.setLink(new Link("self", uri));
 
         return groupData;
@@ -190,7 +193,7 @@ public class GroupService extends PKIService implements GroupResource {
 
         if (groupData == null) throw new BadRequestException("Group data is null.");
 
-        String groupID = groupData.getID();
+        String groupID = groupData.getGroupID();
 
         // ensure that any low-level exceptions are reported
         // to the signed audit log and stored as failures
diff --git a/base/tps-tomcat/shared/webapps/tps/groups.html b/base/tps-tomcat/shared/webapps/tps/groups.html
index ade0b7745b769592eb221376d653d5a2877686ba..58381b724e1d6d0eb7fb70f12100fefabc3e778d 100644
--- a/base/tps-tomcat/shared/webapps/tps/groups.html
+++ b/base/tps-tomcat/shared/webapps/tps/groups.html
@@ -25,15 +25,22 @@
     <script src="/tps/js/group.js"></script>
     <script>
 $(function() {
+    var addDialog = new Dialog({
+        el: $("#group-dialog"),
+        title: "Add Group",
+        actions: ["cancel", "add"]
+    });
     var editDialog = new Dialog({
         el: $("#group-dialog"),
         title: "Edit Group",
-        readonly: ["id"]
+        readonly: ["groupID"],
+        actions: ["cancel", "save"]
     });
 
     new TableView({
         el: $("table[name='groups']"),
         collection: new GroupCollection({ size: 3 }),
+        addDialog: addDialog,
         editDialog: editDialog
     });
 });
@@ -48,7 +55,10 @@ $(function() {
     <tr>
          <th class="rcue-table-actions" colspan="2">
              <span><input type="text" placeholder="Search..."></span>
-             <span><button>Add</button><button>Remove</button></span>
+             <span>
+                 <button name="add">Add</button>
+                 <button name="remove">Remove</button>
+             </span>
          </th>
     </tr>
     <tr>
@@ -58,7 +68,7 @@ $(function() {
 </thead>
 <tbody>
     <tr>
-        <td name="id">&nbsp;</td>
+        <td name="groupID">&nbsp;</td>
         <td name="description">&nbsp;</td>
     </tr>
 </tbody>
@@ -81,11 +91,13 @@ $(function() {
             <a class="rcue-button-close" href="#"></a>
         </header>
         <fieldset>
-            <label>Group ID</label><input name="id" type="text"><br>
+            <label>Group ID</label><input name="groupID" type="text"><br>
             <label>Description</label><input name="description" type="text"><br>
         </fieldset>
         <footer>
+            <button name="add" class="primary">Add</button>
             <button name="save" class="primary">Save</button>
+            <button name="remove" class="primary">Remove</button>
             <button name="cancel">Cancel</button>
         </footer>
     </div>
diff --git a/base/tps-tomcat/shared/webapps/tps/js/group.js b/base/tps-tomcat/shared/webapps/tps/js/group.js
index 4030712b004ce2d5eaa6797136b113582df6a8c4..0396bf35464bd2ba3e813862656a579ce8112a4a 100644
--- a/base/tps-tomcat/shared/webapps/tps/js/group.js
+++ b/base/tps-tomcat/shared/webapps/tps/js/group.js
@@ -22,15 +22,18 @@
 var GroupModel = Model.extend({
     urlRoot: "/tps/rest/admin/groups",
     parseResponse: function(response) {
+        if (!response || !response.Group) return {};
         return {
             id: response.Group["@id"],
+            groupID: response.Group.GroupID,
             description: response.Group.Description
         };
     },
     createRequest: function(attributes) {
         return {
            Group: {
-               "@id": attributes.id,
+               "@id": this.id,
+                GroupID: attributes.groupID,
                 Description: attributes.description
            }
         };
@@ -38,6 +41,7 @@ var GroupModel = Model.extend({
 });
 
 var GroupCollection = Collection.extend({
+    model: GroupModel,
     urlRoot: "/tps/rest/admin/groups",
     getEntries: function(response) {
         return response.Groups.Group;
@@ -48,6 +52,7 @@ var GroupCollection = Collection.extend({
     parseEntry: function(entry) {
         return new GroupModel({
             id: entry["@id"],
+            groupID: entry.GroupID,
             description: entry.Description
         });
     }
-- 
1.8.4.2

