From 8a474ca8939099c8df8919cbbaf2e2be0c4b0ab5 Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Mon, 13 Aug 2012 01:31:40 -0500
Subject: [PATCH] Fixed REST common class dependency.

The ConfigurationResponse previously had a method that used a class
that exists on the server only, creating a dependency issue since
the ConfigurationResponse will be used by the client as well. The
method now has been moved into a separate factory class.

Ticket #215
---
 .../certsrv/system/ConfigurationResponse.java      | 17 --------
 .../cms/servlet/csadmin/SystemCertDataFactory.java | 47 ++++++++++++++++++++++
 .../cms/servlet/csadmin/SystemConfigService.java   |  4 +-
 3 files changed, 49 insertions(+), 19 deletions(-)
 create mode 100644 base/common/src/com/netscape/cms/servlet/csadmin/SystemCertDataFactory.java

diff --git a/base/common/src/com/netscape/certsrv/system/ConfigurationResponse.java b/base/common/src/com/netscape/certsrv/system/ConfigurationResponse.java
index 489970c9cb8611d08c68ad3113a10710f0dca8ff..6d3275a518af9d6510667b612131a74bfce9e574 100644
--- a/base/common/src/com/netscape/certsrv/system/ConfigurationResponse.java
+++ b/base/common/src/com/netscape/certsrv/system/ConfigurationResponse.java
@@ -20,8 +20,6 @@ package com.netscape.certsrv.system;
 import java.security.cert.CertificateEncodingException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Vector;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -32,7 +30,6 @@ import javax.xml.bind.annotation.XmlRootElement;
 import netscape.security.x509.X509CertImpl;
 
 import com.netscape.certsrv.apps.CMS;
-import com.netscape.cms.servlet.csadmin.Cert;
 
 /**
  * @author alee
@@ -56,20 +53,6 @@ public class ConfigurationResponse {
         adminCert = new SystemCertData();
     }
 
-    public void setSystemCerts(Vector<Cert> certs) {
-        systemCerts.clear();
-        Enumeration<Cert> e = certs.elements();
-        while (e.hasMoreElements()) {
-            Cert cert = e.nextElement();
-            SystemCertData cdata = new SystemCertData();
-            cdata.setCert(cert.getCert());
-            cdata.setRequest(cert.getRequest());
-            cdata.setTag(cert.getCertTag());
-            cdata.setCertChain(cert.getCertChain());
-            systemCerts.add(cdata);
-        }
-    }
-
     /**
      * @return the systemCerts
      */
diff --git a/base/common/src/com/netscape/cms/servlet/csadmin/SystemCertDataFactory.java b/base/common/src/com/netscape/cms/servlet/csadmin/SystemCertDataFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..bd23c8f16bf6662d0567b50b1e42a812709a786b
--- /dev/null
+++ b/base/common/src/com/netscape/cms/servlet/csadmin/SystemCertDataFactory.java
@@ -0,0 +1,47 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cms.servlet.csadmin;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import com.netscape.certsrv.system.SystemCertData;
+
+/**
+ * @author edewata
+ */
+public class SystemCertDataFactory {
+
+    public static SystemCertData create(Cert cert) {
+        SystemCertData data = new SystemCertData();
+        data.setCert(cert.getCert());
+        data.setRequest(cert.getRequest());
+        data.setTag(cert.getCertTag());
+        data.setCertChain(cert.getCertChain());
+        return data;
+    }
+
+    public static Collection<SystemCertData> create(Collection<Cert> certs) {
+        Collection<SystemCertData> result = new ArrayList<SystemCertData>();
+        for (Cert cert : certs) {
+            result.add(create(cert));
+        }
+        return result;
+    }
+}
diff --git a/base/common/src/com/netscape/cms/servlet/csadmin/SystemConfigService.java b/base/common/src/com/netscape/cms/servlet/csadmin/SystemConfigService.java
index c7560fbc4d38783ef554ebc7e599cd45145594c1..53b004846b0b631a451553804d0046be805e61f2 100644
--- a/base/common/src/com/netscape/cms/servlet/csadmin/SystemConfigService.java
+++ b/base/common/src/com/netscape/cms/servlet/csadmin/SystemConfigService.java
@@ -545,7 +545,7 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
 
         // submitting to external ca
         if ((data.getIssuingCA()!= null) && data.getIssuingCA().equals("External CA") && (!hasSigningCert)) {
-            response.setSystemCerts(certs);
+            response.setSystemCerts(SystemCertDataFactory.create(certs));
             return response;
         }
 
@@ -564,7 +564,7 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
                 throw new PKIException("Error in confguring system certificates");
             }
         }
-        response.setSystemCerts(certs);
+        response.setSystemCerts(SystemCertDataFactory.create(certs));
 
         // BackupKeyCertPanel/SavePKCS12Panel
         if (data.getBackupKeys().equals("true")) {
-- 
1.7.11.2

