summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitri Dolguikh <dmitri@appliedlogic.ca>2009-12-01 13:43:16 -0400
committerDmitri Dolguikh <dmitri@appliedlogic.ca>2009-12-01 13:43:16 -0400
commitc363dfb884beb99b7fd84b26ac4499936b4024dd (patch)
treec4e67dced78a9b36e5aaf25d7854a7d336282a0d
parentb047f3a1cab5ba97f6c1711e0463cae898610227 (diff)
parent449f14c6a0eae1253c5987edd16429def8e3d1f2 (diff)
downloadcandlepin-c363dfb884beb99b7fd84b26ac4499936b4024dd.tar.gz
candlepin-c363dfb884beb99b7fd84b26ac4499936b4024dd.tar.xz
candlepin-c363dfb884beb99b7fd84b26ac4499936b4024dd.zip
Merge branch 'master' of ssh://git.fedorahosted.org/git/candlepin
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java70
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java13
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/Owner.java4
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.java79
-rw-r--r--proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java19
5 files changed, 151 insertions, 34 deletions
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java b/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java
index 446e78d..f6c50db 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/Entitlement.java
@@ -17,6 +17,18 @@ package org.fedoraproject.candlepin.model;
import java.util.Date;
import java.util.List;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
@@ -40,51 +52,62 @@ import javax.xml.bind.annotation.XmlTransient;
*/
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
-public class Entitlement extends BaseModel {
+@Entity
+@Table(name="cp_entitlement")
+public class Entitlement {
+ @Id
+ @GeneratedValue(strategy=GenerationType.AUTO)
+ private Long id;
+
+ @ManyToOne
+ @JoinColumn(nullable=false)
private Owner owner;
- private EntitlementPool pool;
- private List<Entitlement> childEntitlements;
+ @ManyToOne
+ @JoinColumn(nullable=false)
+ private EntitlementPool pool;
+
private Date startDate;
- /**
- * default ctor
- */
public Entitlement() {
- super(null);
}
/**
- * @return the org
+ * @return the id
*/
- @XmlTransient
- public Owner getOwner() {
- return owner;
+ public Long getId() {
+ return id;
}
/**
- * @param ownerIn the owner to set
+ * @param id the id to set
*/
- public void setOwner(Owner ownerIn) {
- this.owner = ownerIn;
+ public void setId(Long id) {
+ this.id = id;
}
+ public Entitlement(EntitlementPool poolIn, Owner ownerIn, Date startDateIn) {
+ pool = poolIn;
+ owner = ownerIn;
+ startDate = startDateIn;
+ }
+
/**
- * @return the childEntitlements
+ * @return the owner
*/
- public List<Entitlement> getChildEntitlements() {
- return childEntitlements;
+ @XmlTransient
+ public Owner getOwner() {
+ return owner;
}
/**
- * @param childEntitlements the childEntitlements to set
+ * @param ownerIn the owner to set
*/
- public void setChildEntitlements(List<Entitlement> childEntitlements) {
- this.childEntitlements = childEntitlements;
+ public void setOwner(Owner ownerIn) {
+ this.owner = ownerIn;
}
-
/**
* @return Returns the product.
*/
@@ -92,7 +115,6 @@ public class Entitlement extends BaseModel {
return this.pool.getProduct();
}
-
/**
* @return Returns the pool.
*/
@@ -100,7 +122,6 @@ public class Entitlement extends BaseModel {
return pool;
}
-
/**
* @param poolIn The pool to set.
*/
@@ -108,7 +129,6 @@ public class Entitlement extends BaseModel {
pool = poolIn;
}
-
/**
* @return Returns the startDate.
*/
@@ -116,13 +136,11 @@ public class Entitlement extends BaseModel {
return startDate;
}
-
/**
* @param startDateIn The startDate to set.
*/
public void setStartDate(Date startDateIn) {
startDate = startDateIn;
}
-
}
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java
index 7ffa155..7829048 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/EntitlementPool.java
@@ -16,10 +16,12 @@ package org.fedoraproject.candlepin.model;
import java.util.Date;
+import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
+import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
@@ -42,17 +44,23 @@ public class EntitlementPool {
private Long id;
@ManyToOne
+ @JoinColumn(nullable=false)
private Owner owner;
@ManyToOne
+ @JoinColumn(nullable=false)
private Product product;
+ @Column(nullable=false)
private Long maxMembers;
-
+
+ @Column(nullable=false)
private Long currentMembers;
+ @Column(nullable=false)
private Date startDate;
+ @Column(nullable=false)
private Date endDate;
public EntitlementPool() {
@@ -65,6 +73,9 @@ public class EntitlementPool {
this.maxMembers = maxMembersIn;
this.startDate = startDateIn;
this.endDate = endDateIn;
+
+ // Always assume no current members if creating a new pool.
+ this.currentMembers = new Long(0);
}
/**
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java b/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java
index eace64c..46f8999 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/Owner.java
@@ -22,6 +22,7 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
+import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlAccessType;
@@ -52,7 +53,8 @@ public class Owner {
@Transient
private List<Consumer> consumers;
- @Transient
+ // EntitlementPool is the owning side of this relationship.
+ @OneToMany(mappedBy="owner", targetEntity=EntitlementPool.class)
private List<EntitlementPool> entitlementPools;
@Transient
diff --git a/proxy/code/src/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.java b/proxy/code/src/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.java
new file mode 100644
index 0000000..2517d3b
--- /dev/null
+++ b/proxy/code/src/org/fedoraproject/candlepin/model/test/EntitlementPoolTest.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright (c) 2009 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.test;
+
+import java.sql.Date;
+
+import java.util.Calendar;
+
+import org.fedoraproject.candlepin.model.EntitlementPool;
+import org.fedoraproject.candlepin.model.Owner;
+import org.fedoraproject.candlepin.model.Product;
+
+import org.fedoraproject.candlepin.test.DatabaseTestFixture;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+
+public class EntitlementPoolTest extends DatabaseTestFixture {
+
+ private EntitlementPool pool;
+ private Product prod;
+ private Owner owner;
+
+ @Before
+ public void createObjects() {
+ beginTransaction();
+ String ownerName = "Example Corporation";
+ owner = new Owner(ownerName);
+ em.persist(owner);
+ prod = new Product("cptest-label", "My Product");
+ em.persist(prod);
+ commitTransaction();
+ beginTransaction();
+ pool = new EntitlementPool(owner, prod, new Long(1000),
+ createDate(2009, 11, 30), createDate(2015, 11, 30));
+ em.persist(pool);
+ commitTransaction();
+ }
+
+ private Date createDate(int year, int month, int day) {
+ Calendar cal = Calendar.getInstance();
+
+ cal.set(Calendar.YEAR, year);
+ cal.set(Calendar.MONTH, month);
+ cal.set(Calendar.DATE, day);
+
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ cal.set(Calendar.MINUTE, 0);
+ cal.set(Calendar.SECOND, 0);
+ cal.set(Calendar.MILLISECOND, 0);
+
+ Date jsqlD = new Date(cal.getTime().getTime());
+ return jsqlD;
+ }
+
+ @Test
+ public void testCreate() {
+ EntitlementPool lookedUp = (EntitlementPool)em.find(EntitlementPool.class, pool.getId());
+ assertNotNull(lookedUp);
+ assertEquals(owner.getId(), lookedUp.getOwner().getId());
+ assertEquals(prod.getId(), lookedUp.getProduct().getId());
+
+ }
+
+}
diff --git a/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java b/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java
index 485b982..286e07b 100644
--- a/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java
+++ b/proxy/code/src/org/fedoraproject/candlepin/test/DatabaseTestFixture.java
@@ -8,6 +8,7 @@ import javax.persistence.EntityTransaction;
import org.fedoraproject.candlepin.model.Consumer;
import org.fedoraproject.candlepin.model.ConsumerInfo;
import org.fedoraproject.candlepin.model.ConsumerType;
+import org.fedoraproject.candlepin.model.Entitlement;
import org.fedoraproject.candlepin.model.EntitlementPool;
import org.fedoraproject.candlepin.model.Owner;
import org.fedoraproject.candlepin.model.Product;
@@ -46,6 +47,18 @@ public class DatabaseTestFixture {
beginTransaction();
}
+ List<Entitlement> ents = em.createQuery("from Entitlement e").
+ getResultList();
+ for (Entitlement e : ents) {
+ em.remove(e);
+ }
+
+ List<EntitlementPool> pools = em.createQuery("from EntitlementPool p").
+ getResultList();
+ for (EntitlementPool p : pools) {
+ em.remove(p);
+ }
+
// TODO: Would rather be doing this, but such a bulk delete does not seem to respect
// the cascade to child products and thus fails.
// em.createQuery("delete from Product").executeUpdate();
@@ -77,12 +90,6 @@ public class DatabaseTestFixture {
em.remove(c);
}
- List<EntitlementPool> pools = em.createQuery("from EntitlementPool p").
- getResultList();
- for (EntitlementPool p : pools) {
- em.remove(p);
- }
-
commitTransaction();
em.close();
}