summaryrefslogtreecommitdiffstats
path: root/proxy/code/src
diff options
context:
space:
mode:
authorMike McCune <mmccune@gibson.pdx.redhat.com>2009-07-31 10:17:19 -0700
committerMike McCune <mmccune@gibson.pdx.redhat.com>2009-07-31 10:17:19 -0700
commitd4b45fbfc873979f162f0ba1e3444a181eb3a693 (patch)
treedaf575ad7b16f73ece8f3b24df5b80ffce602941 /proxy/code/src
parent89e2f558f73f8934b2d0d357d307a7ae7f134263 (diff)
downloadcandlepin-d4b45fbfc873979f162f0ba1e3444a181eb3a693.tar.gz
candlepin-d4b45fbfc873979f162f0ba1e3444a181eb3a693.tar.xz
candlepin-d4b45fbfc873979f162f0ba1e3444a181eb3a693.zip
fixing entitlementAPI
Diffstat (limited to 'proxy/code/src')
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/api/EntitlementApi.java27
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/api/test/EntitlementApiTest.java7
2 files changed, 25 insertions, 9 deletions
diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/EntitlementApi.java b/proxy/code/src/org/fedoraproject/candlepin/api/EntitlementApi.java
index d00712e..513bc9b 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/api/EntitlementApi.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/api/EntitlementApi.java
@@ -33,6 +33,7 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@@ -66,6 +67,17 @@ public class EntitlementApi extends BaseApi {
}
return o;
}
+
+ private Object validateObjectInput(String uuid, Class clazz) {
+ log.debug("UUID: " + uuid);
+ Object o = ObjectFactory.get().lookupByUUID(clazz, uuid);
+ if (o == null) {
+ throw new RuntimeException(clazz.getName() + " with UUID: [" +
+ uuid + "] not found");
+ }
+ return o;
+ }
+
@POST
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED})
@@ -117,9 +129,11 @@ public class EntitlementApi extends BaseApi {
*/
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- public boolean hasEntitlement(Form form) {
- Consumer c = (Consumer) validateObjectInput(form, "consumer_uuid", Consumer.class);
- Product p = (Product) validateObjectInput(form, "product_uuid", Product.class);
+ @Path("/has")
+ public boolean hasEntitlement(@PathParam("consumer_uuid") String consumer_uuid,
+ @PathParam("product_uuid") String product_uuid) {
+ Consumer c = (Consumer) validateObjectInput(consumer_uuid, Consumer.class);
+ Product p = (Product) validateObjectInput(product_uuid, Product.class);
for (Entitlement e : c.getEntitlements()) {
if (e.getProduct().equals(p)) {
return true;
@@ -134,8 +148,11 @@ public class EntitlementApi extends BaseApi {
* @param form containing consumer_uuid
* @return List<Entitlement> of applicable
*/
- public List<EntitlementPool> listAvailableEntitlements(Form form) {
- Consumer c = (Consumer) validateObjectInput(form, "consumer_uuid", Consumer.class);
+ @GET
+ @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ @Path("/listavailable")
+ public List<EntitlementPool> listAvailableEntitlements(@PathParam("uuid") String uuid) {
+ Consumer c = (Consumer) validateObjectInput(uuid, Consumer.class);
List<EntitlementPool> entitlementPools = new EntitlementPoolApi().list();
List<EntitlementPool> retval = new ArrayList<EntitlementPool>();
EntitlementMatcher matcher = new EntitlementMatcher();
diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/test/EntitlementApiTest.java b/proxy/code/src/org/fedoraproject/candlepin/api/test/EntitlementApiTest.java
index f04dae4..47e805f 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/api/test/EntitlementApiTest.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/api/test/EntitlementApiTest.java
@@ -113,16 +113,15 @@ public class EntitlementApiTest extends TestCase {
f.add("product_uuid", p.getUuid());
eapi.entitle(f);
- assertTrue(eapi.hasEntitlement(f));
+ assertTrue(eapi.hasEntitlement(c.getUuid(), p.getUuid()));
}
public void testListAvailableEntitlements() {
EntitlementApi eapi = new EntitlementApi();
Form f = new Form();
f.add("consumer_uuid", c.getUuid());
- f.add("product_uuid", p.getUuid());
-
- List avail = eapi.listAvailableEntitlements(f);
+
+ List avail = eapi.listAvailableEntitlements(c.getUuid());
assertNotNull(avail);
assertTrue(avail.size() > 0);