diff options
author | Mike McCune <mmccune@gibson.pdx.redhat.com> | 2009-07-28 13:47:58 -0700 |
---|---|---|
committer | Mike McCune <mmccune@gibson.pdx.redhat.com> | 2009-07-28 13:47:58 -0700 |
commit | d93301ef170d11dd321f7990327544b8697cac26 (patch) | |
tree | 1637c1012e3bf359ed6fed5eb9fbea30dc4bcea0 | |
parent | f52656f61de8e72409714420fac1f590a0161f28 (diff) | |
download | candlepin-d93301ef170d11dd321f7990327544b8697cac26.tar.gz candlepin-d93301ef170d11dd321f7990327544b8697cac26.tar.xz candlepin-d93301ef170d11dd321f7990327544b8697cac26.zip |
adding json list methods
8 files changed, 114 insertions, 71 deletions
diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/BaseApi.java b/proxy/code/src/org/fedoraproject/candlepin/api/BaseApi.java index 15ca1d9..7b5411f 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/api/BaseApi.java +++ b/proxy/code/src/org/fedoraproject/candlepin/api/BaseApi.java @@ -21,6 +21,7 @@ import org.fedoraproject.candlepin.model.BaseModel; import org.fedoraproject.candlepin.model.ObjectFactory; import org.fedoraproject.candlepin.util.MethodUtil; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -47,19 +48,6 @@ public abstract class BaseApi { return o; } - @GET @Path("/list") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public String list() { - StringBuffer retval = new StringBuffer(); - List objects = ObjectFactory.get().listObjectsByClass(getApiClass()); - //return objects; - for (int i = 0; i < objects.size(); i++) { - retval.append(objects.get(i).toString()); - retval.append("\n"); - } - return retval.toString(); - } - @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED}) @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/ConsumerApi.java b/proxy/code/src/org/fedoraproject/candlepin/api/ConsumerApi.java index 4afd1b1..013ea19 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/api/ConsumerApi.java +++ b/proxy/code/src/org/fedoraproject/candlepin/api/ConsumerApi.java @@ -15,8 +15,15 @@ package org.fedoraproject.candlepin.api; import org.fedoraproject.candlepin.model.Consumer; +import org.fedoraproject.candlepin.model.ObjectFactory; +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; @Path("/consumer") public class ConsumerApi extends BaseApi { @@ -26,5 +33,16 @@ public class ConsumerApi extends BaseApi { return Consumer.class; } + + @GET + @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public List<Consumer> list() { + List<Object> u = ObjectFactory.get().listObjectsByClass(getApiClass()); + List<Consumer> consumers = new ArrayList<Consumer>(); + for (Object o : u) { + consumers.add((Consumer) o); + } + return consumers; + } } diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/EntitlementApi.java b/proxy/code/src/org/fedoraproject/candlepin/api/EntitlementApi.java index a0aa047..c8cef2b 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/api/EntitlementApi.java +++ b/proxy/code/src/org/fedoraproject/candlepin/api/EntitlementApi.java @@ -25,10 +25,12 @@ import org.fedoraproject.candlepin.model.EntitlementPool; import org.fedoraproject.candlepin.model.ObjectFactory; import org.fedoraproject.candlepin.model.Product; +import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.ws.rs.Consumes; +import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; @@ -60,7 +62,6 @@ public class EntitlementApi extends BaseApi { @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Path("/entitle") public Object entitle(Form form) { - String retval = null; String consumerUuid = form.getFirst("consumer_uuid"); String productUuid = form.getFirst("product_uuid"); log.debug("UUID: " + consumerUuid); @@ -108,13 +109,18 @@ public class EntitlementApi extends BaseApi { return CertGenerator.getCertString(); } } - - - - - - return null; } + @GET + @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public List<Entitlement> list() { + List<Object> u = ObjectFactory.get().listObjectsByClass(getApiClass()); + List<Entitlement> entitlements = new ArrayList<Entitlement>(); + for (Object o : u) { + entitlements.add((Entitlement) o); + } + return entitlements; + } + } diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/EntitlementPoolApi.java b/proxy/code/src/org/fedoraproject/candlepin/api/EntitlementPoolApi.java new file mode 100644 index 0000000..10d2f00 --- /dev/null +++ b/proxy/code/src/org/fedoraproject/candlepin/api/EntitlementPoolApi.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2008 Red Hat, Inc. + * + * This software is licensed to you under the GNU General Public License, + * version 2 (GPLv2). There is NO WARRANTY for this software, express or + * implied, including the implied warranties of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 + * along with this software; if not, see + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + * Red Hat trademarks are not licensed under GPLv2. No permission is + * granted to use or replicate Red Hat trademarks that are incorporated + * in this software or its documentation. + */ +package org.fedoraproject.candlepin.api; + +import org.fedoraproject.candlepin.model.EntitlementPool; +import org.fedoraproject.candlepin.model.ObjectFactory; + +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/entitlementpool") +public class EntitlementPoolApi extends BaseApi { + + @Override + protected Class getApiClass() { + return EntitlementPool.class; + } + + + @GET + @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public List<EntitlementPool> list() { + List<Object> u = ObjectFactory.get().listObjectsByClass(getApiClass()); + List<EntitlementPool> pools = new ArrayList<EntitlementPool>(); + for (Object o : u) { + pools.add((EntitlementPool) o); + } + return pools; + } + +} diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/OwnerApi.java b/proxy/code/src/org/fedoraproject/candlepin/api/OwnerApi.java index 737702c..d6eeb20 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/api/OwnerApi.java +++ b/proxy/code/src/org/fedoraproject/candlepin/api/OwnerApi.java @@ -14,9 +14,16 @@ */ package org.fedoraproject.candlepin.api; +import org.fedoraproject.candlepin.model.ObjectFactory; import org.fedoraproject.candlepin.model.Owner; +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.GET; import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; @Path("/owner") public class OwnerApi extends BaseApi { @@ -25,6 +32,16 @@ public class OwnerApi extends BaseApi { protected Class getApiClass() { return Owner.class; } - - + + @GET + @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public List<Owner> list() { + List<Object> u = ObjectFactory.get().listObjectsByClass(getApiClass()); + List<Owner> owners = new ArrayList<Owner>(); + for (Object o : u) { + owners.add((Owner) o); + } + return owners; + } + } diff --git a/proxy/code/src/org/fedoraproject/candlepin/api/UserApi.java b/proxy/code/src/org/fedoraproject/candlepin/api/UserApi.java index 34949c0..f95b514 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/api/UserApi.java +++ b/proxy/code/src/org/fedoraproject/candlepin/api/UserApi.java @@ -14,10 +14,8 @@ */ package org.fedoraproject.candlepin.api; -import org.fedoraproject.candlepin.model.BaseModel; import org.fedoraproject.candlepin.model.ObjectFactory; import org.fedoraproject.candlepin.model.User; -import org.fedoraproject.candlepin.model.Users; import java.util.ArrayList; import java.util.List; @@ -48,58 +46,15 @@ public class UserApi extends BaseApi { return User.class; } - /* - * this works great but requires create a new class for each - * model type - */ - @GET @Path("/listusers") + @GET @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public Users listUsers() { - List<Object> objects = ObjectFactory.get().listObjectsByClass(getApiClass()); - Users users = new Users(); - users.userList = new ArrayList<User>(); - for (Object o : objects) { - users.userList.add((User)o); - } - return users; - } - - /* - * this works the best only requires that each api method - * have its own list method - */ - @GET @Path("/uselist") - @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public List<User> listUsers1() { + public List<User> list() { List<Object> u = ObjectFactory.get().listObjectsByClass(getApiClass()); List<User> users = new ArrayList<User>(); for (Object o : u) { - users.add((User)o); - } - return users; - } - - @GET @Path("/listobjects") - @Produces(MediaType.APPLICATION_JSON) - /* - * does not work shown here for example - */ - public List<Object> listObjects() { - return ObjectFactory.get().listObjectsByClass(getApiClass()); - } - - /* - * This produces the output of a BaseModel but not - * that of the real object i.e. User. - */ - @GET @Path("/listbasemodel") - @Produces(MediaType.APPLICATION_JSON) - public List<BaseModel> listUsers2() { - List<Object> u = ObjectFactory.get().listObjectsByClass(getApiClass()); - List<BaseModel> users = new ArrayList<BaseModel>(); - for (Object o : u) { - users.add((BaseModel)o); + users.add((User) o); } return users; } + } diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java b/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java index 5d582c6..be39196 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/ConsumerInfo.java @@ -17,6 +17,8 @@ package org.fedoraproject.candlepin.model; import java.util.HashMap; import java.util.Map; +import javax.xml.bind.annotation.XmlTransient; + public class ConsumerInfo { @@ -27,6 +29,7 @@ public class ConsumerInfo { /** * @return Returns the parent. */ + @XmlTransient public Consumer getParent() { return parent; } diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java index 410423c..49c7919 100644 --- a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java +++ b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java @@ -16,6 +16,13 @@ package org.fedoraproject.candlepin.model; import java.util.Date; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlTransient; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.PROPERTY) public class EntitlementPool extends BaseModel { private Owner owner; @@ -120,6 +127,7 @@ public class EntitlementPool extends BaseModel { /** * @param owner the owner to set */ + @XmlTransient public void setOwner(Owner owner) { this.owner = owner; } |