summaryrefslogtreecommitdiffstats
path: root/proxy/code/src/org
diff options
context:
space:
mode:
authorjesus m. rodriguez <jesusr@redhat.com>2009-11-12 15:25:33 -0500
committerjesus m. rodriguez <jesusr@redhat.com>2009-11-12 15:25:33 -0500
commitf4feea49201468152cb19cc1a5013b6d2d7f7f8a (patch)
tree98467f17ee49c886f1e8a444e7a7e362dc40d9d1 /proxy/code/src/org
parent5f2c420567b94d6fc8949833d6d441c2bd1a291e (diff)
downloadcandlepin-f4feea49201468152cb19cc1a5013b6d2d7f7f8a.tar.gz
candlepin-f4feea49201468152cb19cc1a5013b6d2d7f7f8a.tar.xz
candlepin-f4feea49201468152cb19cc1a5013b6d2d7f7f8a.zip
allow upload of cert and return list of available ent pools
Diffstat (limited to 'proxy/code/src/org')
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java3
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/Pinsetter.java62
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java86
3 files changed, 147 insertions, 4 deletions
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java
index e6604e7..d4cf900 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java
@@ -22,7 +22,8 @@ import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
- * Represents a collection of entitlements for a given order.
+ * Represents a pool of products eligible to be consumed (entitled).
+ * For every Product there will be a corresponding Pool.
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Pinsetter.java b/proxy/code/src/org/fedoraproject/candlepin/model/Pinsetter.java
new file mode 100644
index 0000000..f95b1cc
--- /dev/null
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/Pinsetter.java
@@ -0,0 +1,62 @@
+/**
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+
+/**
+ * Pinsetter
+ * @version $Rev$
+ */
+public class Pinsetter {
+ public static Pinsetter instance = new Pinsetter();
+ private static List<EntitlementPool> pools = new ArrayList<EntitlementPool>();
+
+ private Pinsetter() {
+ // do nothing
+ }
+
+ public static Pinsetter get() {
+ return instance;
+ }
+
+ /**
+ * Add a new product to entitle.
+ * @param owner Owner of the product/entitlement.
+ * @param pname Product name
+ * @param maxmem Maximum members available.
+ * @param start start date of the product entitlement
+ * @param end end date of the product entitlement.
+ */
+ public void addProduct(Owner owner, String pname, long maxmem,
+ Date start, Date end) {
+
+ Product p = new Product(pname, pname);
+
+ EntitlementPool ep = new EntitlementPool();
+ ep.setOwner(owner);
+ ep.setProduct(p);
+ ep.setMaxMembers(maxmem);
+ ep.setStartDate(start);
+ ep.setEndDate(end);
+ ep.setName(pname);
+
+ pools.add(ep);
+ ObjectFactory.get().store(ep);
+ }
+}
diff --git a/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java b/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java
index 7eae390..b0ae0c7 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/resource/CertificateResource.java
@@ -14,21 +14,29 @@
*/
package org.fedoraproject.candlepin.resource;
+import org.fedoraproject.candlepin.model.ObjectFactory;
+import org.fedoraproject.candlepin.model.Owner;
+import org.fedoraproject.candlepin.model.Pinsetter;
import org.fedoraproject.candlepin.model.User;
import com.redhat.rhn.common.cert.Certificate;
import com.redhat.rhn.common.cert.CertificateFactory;
+import com.redhat.rhn.common.cert.ChannelFamilyDescriptor;
import com.sun.jersey.core.util.Base64;
import org.jdom.JDOMException;
import java.io.IOException;
+import java.text.ParseException;
+import java.util.Date;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
/**
@@ -54,14 +62,18 @@ public class CertificateResource extends BaseResource {
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- public String create(String base64cert) {
+ public String upload(String base64cert) {
try {
- System.out.println("cert: [" + base64cert + "]");
+ if (base64cert == null || "".equals(base64cert)) {
+ throw new WebApplicationException(Response.Status.BAD_REQUEST);
+ }
+
String decoded = Base64.base64Decode(base64cert);
System.out.println(decoded);
cert = CertificateFactory.read(decoded);
- System.out.println(cert.getExpires());
+
+ addProducts(cert);
}
catch (JDOMException e) {
// TODO Auto-generated catch block
@@ -71,6 +83,10 @@ public class CertificateResource extends BaseResource {
// TODO Auto-generated catch block
e.printStackTrace();
}
+ catch (ParseException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
return "uuid";
}
@@ -83,4 +99,68 @@ public class CertificateResource extends BaseResource {
public static Certificate get() {
return cert;
}
+
+ private void addProducts(Certificate cert) throws ParseException {
+ // look up the owner by the same name, if none found, create a new one.
+ Owner owner = (Owner) ObjectFactory.get().lookupByFieldName(
+ Owner.class, "name", cert.getOwner());
+
+ if (owner == null) {
+ owner = new Owner();
+ owner.setName(cert.getOwner());
+ owner = (Owner) ObjectFactory.get().store(owner);
+ System.out.println(owner.getUuid());
+ }
+
+ // get the product the cert is for (and the channel families
+ // which have the other products you can have)
+ Date issued = cert.getIssuedDate();
+ Date expires = cert.getExpiresDate();
+
+ Pinsetter.get().addProduct(owner, cert.getProduct(),
+ new Long(cert.getSlots()).longValue(),
+ issued, expires);
+
+ // create products for the channel families
+ for (ChannelFamilyDescriptor cfd : cert.getChannelFamilies()) {
+ Pinsetter.get().addProduct(owner, cfd.getFamily(),
+ new Long(cfd.getQuantity()).longValue(),
+ issued, expires);
+ }
+
+ // create products for each of the add-on entitlements.
+ if (!isEmpty(cert.getMonitoringSlots())) {
+ Pinsetter.get().addProduct(owner, "monitoring",
+ new Long(cert.getMonitoringSlots()).longValue(),
+ issued, expires);
+ }
+
+ if (!isEmpty(cert.getNonlinuxSlots())) {
+ Pinsetter.get().addProduct(owner, "nonlinux",
+ new Long(cert.getNonlinuxSlots()).longValue(),
+ issued, expires);
+ }
+
+ if (!isEmpty(cert.getProvisioningSlots())) {
+ Pinsetter.get().addProduct(owner, "provisioning",
+ new Long(cert.getProvisioningSlots()).longValue(),
+ issued, expires);
+ }
+
+ if (!isEmpty(cert.getVirtualizationSlots())) {
+ Pinsetter.get().addProduct(owner, "virtualization_host",
+ new Long(cert.getVirtualizationSlots()).longValue(),
+ issued, expires);
+ }
+
+ if (!isEmpty(cert.getVirtualizationPlatformSlots())) {
+ Pinsetter.get().addProduct(owner, "virtualization_host_platform",
+ new Long(cert.getVirtualizationPlatformSlots()).longValue(),
+ issued, expires);
+ }
+ }
+
+ private boolean isEmpty(String str) {
+ return str == null || "".equals(str);
+ }
}