From 410769c12c2f4c56e520661d5c5ecfc4355b923c Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Fri, 14 Feb 2014 21:30:38 -0500
Subject: [PATCH] Updated REST interface for TPS profile mappings.

The REST interface for TPS profile mappings has been modified to return
Response objects to allow better handling of server responses.

Ticket #554
---
 .../certsrv/tps/profile/ProfileMappingClient.java  |  9 +++++---
 .../tps/profile/ProfileMappingResource.java        |  9 +++++---
 .../server/tps/profile/ProfileMappingService.java  | 25 +++++++++-------------
 3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingClient.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingClient.java
index dcb35132edd7779a17168fa33bb8a763d54397c0..409d8d7182c16c720222fd2b6e1fbc697de7c582 100644
--- a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingClient.java
@@ -41,11 +41,13 @@ public class ProfileMappingClient extends Client {
     }
 
     public ProfileMappingCollection findProfileMappings(Integer start, Integer size) {
-        return resource.findProfileMappings(start, size);
+        Response response = resource.findProfileMappings(start, size);
+        return client.getEntity(response, ProfileMappingCollection.class);
     }
 
     public ProfileMappingData getProfileMapping(String profileMappingID) {
-        return resource.getProfileMapping(profileMappingID);
+        Response response = resource.getProfileMapping(profileMappingID);
+        return client.getEntity(response, ProfileMappingData.class);
     }
 
     public ProfileMappingData addProfileMapping(ProfileMappingData profileMappingData) {
@@ -64,6 +66,7 @@ public class ProfileMappingClient extends Client {
     }
 
     public void removeProfileMapping(String profileMappingID) {
-        resource.removeProfileMapping(profileMappingID);
+        Response response = resource.removeProfileMapping(profileMappingID);
+        client.getEntity(response, Void.class);
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java
index 698a1b13b3b46222bd09bb8a5ba8ad5f985e5f49..19d62bce0c6f6e32b7792f8f0c38014a2d562e3b 100644
--- a/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileMappingResource.java
@@ -44,15 +44,17 @@ import com.netscape.certsrv.authentication.AuthMethodMapping;
 public interface ProfileMappingResource {
 
     @GET
+    @ClientResponseType(entityType=ProfileMappingCollection.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public ProfileMappingCollection findProfileMappings(
+    public Response findProfileMappings(
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
     @GET
     @Path("{profileMappingID}")
+    @ClientResponseType(entityType=ProfileMappingData.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public ProfileMappingData getProfileMapping(@PathParam("profileMappingID") String profileMappingID);
+    public Response getProfileMapping(@PathParam("profileMappingID") String profileMappingID);
 
     @POST
     @ACLMapping("profile-mappings.add")
@@ -83,7 +85,8 @@ public interface ProfileMappingResource {
 
     @DELETE
     @Path("{profileMappingID}")
+    @ClientResponseType(entityType=Void.class)
     @ACLMapping("profile-mappings.remove")
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public void removeProfileMapping(@PathParam("profileMappingID") String profileMappingID);
+    public Response removeProfileMapping(@PathParam("profileMappingID") String profileMappingID);
 }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileMappingService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileMappingService.java
index cd43bb9c39b155d562cfa4f3a398a939e4ee6ae6..bcb169578958e96525cf7f8f386e929e644d9af4 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileMappingService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileMappingService.java
@@ -93,7 +93,7 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
     }
 
     @Override
-    public ProfileMappingCollection findProfileMappings(Integer start, Integer size) {
+    public Response findProfileMappings(Integer start, Integer size) {
 
         CMS.debug("ProfileMappingService.findProfileMappings()");
 
@@ -131,7 +131,7 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
                 response.addLink(new Link("next", uri));
             }
 
-            return response;
+            return createOKResponse(response);
 
         } catch (PKIException e) {
             throw e;
@@ -143,7 +143,7 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
     }
 
     @Override
-    public ProfileMappingData getProfileMapping(String profileMappingID) {
+    public Response getProfileMapping(String profileMappingID) {
 
         CMS.debug("ProfileMappingService.getProfileMapping(\"" + profileMappingID + "\")");
 
@@ -151,7 +151,7 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ProfileMappingDatabase database = subsystem.getProfileMappingDatabase();
 
-            return createProfileMappingData(database.getRecord(profileMappingID));
+            return createOKResponse(createProfileMappingData(database.getRecord(profileMappingID)));
 
         } catch (PKIException e) {
             throw e;
@@ -174,10 +174,7 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
             database.addRecord(profileMappingData.getID(), createProfileMappingRecord(profileMappingData));
             profileMappingData = createProfileMappingData(database.getRecord(profileMappingData.getID()));
 
-            return Response
-                    .created(profileMappingData.getLink().getHref())
-                    .entity(profileMappingData)
-                    .build();
+            return createCreatedResponse(profileMappingData, profileMappingData.getLink().getHref());
 
         } catch (PKIException e) {
             throw e;
@@ -220,9 +217,7 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
 
             profileMappingData = createProfileMappingData(database.getRecord(profileMappingID));
 
-            return Response
-                    .ok(profileMappingData)
-                    .build();
+            return createOKResponse(profileMappingData);
 
         } catch (PKIException e) {
             throw e;
@@ -280,9 +275,7 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
 
             ProfileMappingData profileMappingData = createProfileMappingData(database.getRecord(profileMappingID));
 
-            return Response
-                    .ok(profileMappingData)
-                    .build();
+            return createOKResponse(profileMappingData);
 
         } catch (PKIException e) {
             throw e;
@@ -294,7 +287,7 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
     }
 
     @Override
-    public void removeProfileMapping(String profileMappingID) {
+    public Response removeProfileMapping(String profileMappingID) {
 
         CMS.debug("ProfileMappingService.removeProfileMapping(\"" + profileMappingID + "\")");
 
@@ -311,6 +304,8 @@ public class ProfileMappingService extends PKIService implements ProfileMappingR
 
             database.removeRecord(profileMappingID);
 
+            return createNoContentResponse();
+
         } catch (PKIException e) {
             throw e;
 
-- 
1.8.4.2

