From 5f9abd7e81040d54d9a4096574bfa106c3782706 Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Tue, 28 Feb 2012 18:20:59 -0600
Subject: [PATCH] Removed hard-coded REST paths.

The KeyDAO and KeyRequestDAO have been changed to remove hard-coded
paths and use annotation reflection to get the paths from the REST
interface definitions.

Ticket #95
---
 .../com/netscape/cms/servlet/key/model/KeyDAO.java |   12 ++++++++----
 .../cms/servlet/request/model/KeyRequestDAO.java   |   11 +++++++++--
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java b/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java
index f5a1e496ab9b5be2bc3f7d1db112612ffc8b4169..9922456d3e2d17b238ba155fbdd640650da61e36 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/key/model/KeyDAO.java
@@ -23,6 +23,7 @@ import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.List;
 
+import javax.ws.rs.Path;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 import com.netscape.certsrv.apps.CMS;
@@ -34,6 +35,7 @@ import com.netscape.certsrv.request.IRequest;
 import com.netscape.certsrv.request.IRequestQueue;
 import com.netscape.certsrv.request.RequestId;
 import com.netscape.certsrv.request.RequestStatus;
+import com.netscape.cms.servlet.key.KeyResource;
 import com.netscape.cms.servlet.request.model.RecoveryRequestData;
 
 /**
@@ -185,12 +187,14 @@ public class KeyDAO {
     
     public KeyDataInfo createKeyDataInfo(IKeyRecord rec, UriInfo uriInfo) throws EBaseException {
         KeyDataInfo ret = new KeyDataInfo();
-        String serial = null;
-        serial = (rec.getSerialNumber()).toString();
-         
+
+        Path keyPath = KeyResource.class.getAnnotation(Path.class);
+        BigInteger serial = rec.getSerialNumber();
+
         UriBuilder keyBuilder = uriInfo.getBaseUriBuilder();
-        keyBuilder.path("/key/" + serial);
+        keyBuilder.path(keyPath.value() + "/" + serial);
         ret.setKeyURL(keyBuilder.build().toString());
+
         return ret;
     }
     
diff --git a/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java b/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java
index 7f60a01114d2096f3af4667784ed4681b73da069..f5dd363f706113202e2963a8b407e0660f896d55 100644
--- a/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java
+++ b/pki/base/common/src/com/netscape/cms/servlet/request/model/KeyRequestDAO.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
 
+import javax.ws.rs.Path;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
@@ -37,9 +38,11 @@ import com.netscape.certsrv.request.IRequestVirtualList;
 import com.netscape.certsrv.request.RequestId;
 import com.netscape.certsrv.request.RequestStatus;
 import com.netscape.cms.servlet.base.model.Link;
+import com.netscape.cms.servlet.key.KeyResource;
 import com.netscape.cms.servlet.key.model.KeyDAO;
 import com.netscape.cms.servlet.key.model.KeyDataInfos;
 import com.netscape.certsrv.profile.IEnrollProfile;
+import com.netscape.cms.servlet.request.KeyRequestResource;
 
 /**
  * @author alee
@@ -273,14 +276,18 @@ public class KeyRequestDAO {
         ret.setRequestType(request.getRequestType());
         ret.setRequestStatus(request.getRequestStatus().toString());
         
+        Path keyRequestPath = KeyRequestResource.class.getAnnotation(Path.class);
         String rid = request.getRequestId().toString();
+
         UriBuilder reqBuilder = uriInfo.getBaseUriBuilder();
-        reqBuilder.path("/keyrequest/" + rid);
+        reqBuilder.path(keyRequestPath.value() + "/" + rid);
         ret.setRequestURL(reqBuilder.build().toString());
         
+        Path keyPath = KeyResource.class.getAnnotation(Path.class);
         String kid = request.getExtDataInString("keyrecord");
+
         UriBuilder keyBuilder = uriInfo.getBaseUriBuilder();
-        keyBuilder.path("/key/" + kid);
+        keyBuilder.path(keyPath.value() + "/" + kid);
         ret.setKeyURL(keyBuilder.build().toString());
         
         return ret;
-- 
1.7.7.1.msysgit.0

