From 96bd5d47fc458dfc1e9850e92595294e549d23a2 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Fri, 14 Feb 2014 19:15:03 -0500
Subject: [PATCH] Updated REST interface for TPS profiles.

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

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

diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileClient.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileClient.java
index bf06f1566cbb56368fca90972ad7969d4d2f1305..9ca571d19d091ad907b735c00099bec348be20b8 100644
--- a/base/common/src/com/netscape/certsrv/tps/profile/ProfileClient.java
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileClient.java
@@ -45,11 +45,13 @@ public class ProfileClient extends Client {
     }
 
     public ProfileCollection findProfiles(Integer start, Integer size) {
-        return resource.findProfiles(start, size);
+        Response response = resource.findProfiles(start, size);
+        return client.getEntity(response, ProfileCollection.class);
     }
 
     public ProfileData getProfile(String profileID) {
-        return resource.getProfile(profileID);
+        Response response = resource.getProfile(profileID);
+        return client.getEntity(response, ProfileData.class);
     }
 
     public ProfileData addProfile(ProfileData profileData) {
@@ -68,6 +70,7 @@ public class ProfileClient extends Client {
     }
 
     public void removeProfile(String profileID) {
-        resource.removeProfile(profileID);
+        Response response = resource.removeProfile(profileID);
+        client.getEntity(response, Void.class);
     }
 }
diff --git a/base/common/src/com/netscape/certsrv/tps/profile/ProfileResource.java b/base/common/src/com/netscape/certsrv/tps/profile/ProfileResource.java
index e8a33c18b75c72674e03ed5382627e7e586f5237..45e0520c495f588a2be429a3d8b082de04c2572e 100644
--- a/base/common/src/com/netscape/certsrv/tps/profile/ProfileResource.java
+++ b/base/common/src/com/netscape/certsrv/tps/profile/ProfileResource.java
@@ -44,15 +44,17 @@ import com.netscape.certsrv.authentication.AuthMethodMapping;
 public interface ProfileResource {
 
     @GET
+    @ClientResponseType(entityType=ProfileCollection.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public ProfileCollection findProfiles(
+    public Response findProfiles(
             @QueryParam("start") Integer start,
             @QueryParam("size") Integer size);
 
     @GET
     @Path("{profileID}")
+    @ClientResponseType(entityType=ProfileData.class)
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public ProfileData getProfile(@PathParam("profileID") String profileID);
+    public Response getProfile(@PathParam("profileID") String profileID);
 
     @POST
     @ACLMapping("profiles.add")
@@ -83,7 +85,8 @@ public interface ProfileResource {
 
     @DELETE
     @Path("{profileID}")
+    @ClientResponseType(entityType=Void.class)
     @ACLMapping("profiles.remove")
     @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
-    public void removeProfile(@PathParam("profileID") String profileID);
+    public Response removeProfile(@PathParam("profileID") String profileID);
 }
diff --git a/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileService.java b/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileService.java
index 543efb400b63ee1c39a1968b0ca6e04faba84761..edc7df1cdeb282c257aad036492ba18a536527f2 100644
--- a/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileService.java
+++ b/base/tps-tomcat/src/org/dogtagpki/server/tps/profile/ProfileService.java
@@ -93,7 +93,7 @@ public class ProfileService extends PKIService implements ProfileResource {
     }
 
     @Override
-    public ProfileCollection findProfiles(Integer start, Integer size) {
+    public Response findProfiles(Integer start, Integer size) {
 
         CMS.debug("ProfileService.findProfiles()");
 
@@ -131,7 +131,7 @@ public class ProfileService extends PKIService implements ProfileResource {
                 response.addLink(new Link("next", uri));
             }
 
-            return response;
+            return createOKResponse(response);
 
         } catch (PKIException e) {
             throw e;
@@ -143,7 +143,7 @@ public class ProfileService extends PKIService implements ProfileResource {
     }
 
     @Override
-    public ProfileData getProfile(String profileID) {
+    public Response getProfile(String profileID) {
 
         if (profileID == null) throw new BadRequestException("Profile ID is null.");
 
@@ -153,7 +153,7 @@ public class ProfileService extends PKIService implements ProfileResource {
             TPSSubsystem subsystem = (TPSSubsystem)CMS.getSubsystem(TPSSubsystem.ID);
             ProfileDatabase database = subsystem.getProfileDatabase();
 
-            return createProfileData(database.getRecord(profileID));
+            return createOKResponse(createProfileData(database.getRecord(profileID)));
 
         } catch (PKIException e) {
             throw e;
@@ -179,10 +179,7 @@ public class ProfileService extends PKIService implements ProfileResource {
 
             profileData = createProfileData(database.getRecord(profileData.getID()));
 
-            return Response
-                    .created(profileData.getLink().getHref())
-                    .entity(profileData)
-                    .build();
+            return createCreatedResponse(profileData, profileData.getLink().getHref());
 
         } catch (PKIException e) {
             throw e;
@@ -228,9 +225,7 @@ public class ProfileService extends PKIService implements ProfileResource {
 
             profileData = createProfileData(database.getRecord(profileID));
 
-            return Response
-                    .ok(profileData)
-                    .build();
+            return createOKResponse(profileData);
 
         } catch (PKIException e) {
             throw e;
@@ -288,9 +283,7 @@ public class ProfileService extends PKIService implements ProfileResource {
 
             ProfileData profileData = createProfileData(database.getRecord(profileID));
 
-            return Response
-                    .ok(profileData)
-                    .build();
+            return createOKResponse(profileData);
 
         } catch (PKIException e) {
             throw e;
@@ -302,7 +295,7 @@ public class ProfileService extends PKIService implements ProfileResource {
     }
 
     @Override
-    public void removeProfile(String profileID) {
+    public Response removeProfile(String profileID) {
 
         if (profileID == null) throw new BadRequestException("Profile ID is null.");
 
@@ -321,6 +314,8 @@ public class ProfileService extends PKIService implements ProfileResource {
 
             database.removeRecord(profileID);
 
+            return createNoContentResponse();
+
         } catch (PKIException e) {
             throw e;
 
-- 
1.8.4.2

