Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated with added course manager sample for chapter 6
- Loading branch information
Showing
137 changed files
with
5,016 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
...nced-web-mvc/coursemanager/src/main/java/org/rooinaction/coursemanager/model/Address.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.rooinaction.coursemanager.model; | ||
|
||
import javax.persistence.Embeddable; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
import org.springframework.roo.addon.javabean.RooJavaBean; | ||
import org.springframework.roo.addon.serializable.RooSerializable; | ||
|
||
@Embeddable | ||
@RooSerializable | ||
@RooJavaBean | ||
public class Address { | ||
|
||
@NotNull | ||
@Size(min = 1, max = 60) | ||
private String addressLine1; | ||
|
||
@Size(min = 1, max = 60) | ||
private String addressLine2; | ||
|
||
@NotNull | ||
@Size(min = 1, max = 40) | ||
private String city; | ||
|
||
@NotNull | ||
@Size(min = 2, max = 2) | ||
private String stateCode; | ||
|
||
@NotNull | ||
@Size(min = 1, max = 10) | ||
private String postalCode; | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
...anced-web-mvc/coursemanager/src/main/java/org/rooinaction/coursemanager/model/Course.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.rooinaction.coursemanager.model; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToMany; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.OneToMany; | ||
import javax.validation.constraints.DecimalMax; | ||
import javax.validation.constraints.DecimalMin; | ||
import javax.validation.constraints.Digits; | ||
import javax.validation.constraints.Max; | ||
import javax.validation.constraints.Min; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
import org.springframework.roo.addon.javabean.RooJavaBean; | ||
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord; | ||
import org.springframework.roo.addon.tostring.RooToString; | ||
|
||
@RooJavaBean | ||
@RooToString | ||
@RooJpaActiveRecord(finders = { "findCoursesByNameLike" }) | ||
public class Course { | ||
|
||
@NotNull | ||
@Size(min = 1, max = 60) | ||
private String name; | ||
|
||
@NotNull | ||
@Size(max = 1000) | ||
private String description; | ||
|
||
@NotNull | ||
@DecimalMin("0.0") | ||
@DecimalMax("99999.00") | ||
@Digits(integer = 7, fraction = 2) | ||
private BigDecimal listPrice; | ||
|
||
@NotNull | ||
@Column(name = "max_capacity") | ||
@Min(1L) | ||
@Max(9999L) | ||
private Integer maxiumumCapacity; | ||
|
||
@NotNull | ||
@Enumerated(EnumType.STRING) | ||
@Column(name = "course_type") | ||
private CourseTypeEnum courseType; | ||
|
||
@ManyToOne(fetch = FetchType.EAGER) | ||
@JoinColumn(name = "training_program") | ||
private TrainingProgram trainingProgram; | ||
|
||
@ManyToMany(cascade = CascadeType.ALL, mappedBy = "courses") | ||
@Column(name = "tag_id") | ||
private Set<Tag> tags = new HashSet<Tag>(); | ||
|
||
@OneToMany(mappedBy = "course", cascade = CascadeType.ALL) | ||
private Set<Offering> offerings = new HashSet<Offering>(); | ||
|
||
public void addTag(Tag tag) { | ||
tag.addCourse(this); | ||
} | ||
|
||
public void addOffering(Offering offering) { | ||
offering.setCourse(this); | ||
this.offerings.add(offering); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getName(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...b-mvc/coursemanager/src/main/java/org/rooinaction/coursemanager/model/CourseTypeEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.rooinaction.coursemanager.model; | ||
|
||
|
||
public enum CourseTypeEnum { | ||
|
||
SEMINAR, CREDIT, CONTINUING_EDUCATION | ||
} |
6 changes: 6 additions & 0 deletions
6
...eb-mvc/coursemanager/src/main/java/org/rooinaction/coursemanager/model/FrequencyType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.rooinaction.coursemanager.model; | ||
|
||
public enum FrequencyType { | ||
|
||
WEEKLY, MONTHLY, BIWEEKLY | ||
} |
23 changes: 23 additions & 0 deletions
23
...d-web-mvc/coursemanager/src/main/java/org/rooinaction/coursemanager/model/Instructor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.rooinaction.coursemanager.model; | ||
|
||
import javax.persistence.Column; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
|
||
import org.springframework.roo.addon.javabean.RooJavaBean; | ||
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord; | ||
import org.springframework.roo.addon.tostring.RooToString; | ||
|
||
@RooJavaBean | ||
@RooToString | ||
@RooJpaActiveRecord | ||
public class Instructor extends Person { | ||
|
||
@NotNull | ||
@Size(min = 9, max = 9) | ||
@Column(name = "tax_number") | ||
private String taxNumber; | ||
|
||
@NotNull | ||
private boolean active; | ||
} |
71 changes: 71 additions & 0 deletions
71
...ced-web-mvc/coursemanager/src/main/java/org/rooinaction/coursemanager/model/Offering.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.rooinaction.coursemanager.model; | ||
|
||
import java.util.Date; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Temporal; | ||
import javax.persistence.TemporalType; | ||
import javax.persistence.TypedQuery; | ||
import javax.validation.constraints.AssertTrue; | ||
|
||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.roo.addon.javabean.RooJavaBean; | ||
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord; | ||
import org.springframework.roo.addon.serializable.RooSerializable; | ||
import org.springframework.roo.addon.tostring.RooToString; | ||
|
||
@RooJavaBean | ||
@RooToString | ||
@RooSerializable | ||
@RooJpaActiveRecord | ||
public class Offering { | ||
|
||
@Temporal(TemporalType.TIMESTAMP) | ||
@DateTimeFormat(style = "S-") | ||
@Column(name = "run_date") | ||
private Date runDate; | ||
|
||
@ManyToOne(cascade = CascadeType.ALL) | ||
private Course course; | ||
|
||
@OneToMany(mappedBy = "offering", cascade = CascadeType.ALL) | ||
private Set<Registration> registrations = new HashSet<Registration>(); | ||
|
||
@ManyToOne(cascade = CascadeType.ALL) | ||
private Instructor instructor; | ||
|
||
@AssertTrue(message="course.full.exception") | ||
public boolean isValid() { | ||
int maxCapacity = course.getMaxiumumCapacity(); | ||
return registrations.size() <= maxCapacity; | ||
} | ||
|
||
public void addRegistration(Registration registration) { | ||
registration.setOffering(this); | ||
registrations.add(registration); | ||
} | ||
|
||
public long countStudentsRegisteredInOffering() { | ||
return entityManager().createQuery("select count(r) from Registration r " + | ||
"where r.offering = :offering", | ||
Long.class).setParameter("offering", this).getSingleResult(); | ||
} | ||
|
||
public static TypedQuery<Offering> findOfferingsByCourseId(Long courseId) { | ||
if (courseId == null) throw new IllegalArgumentException("The courseID argument is required"); | ||
EntityManager em = entityManager(); | ||
TypedQuery<Offering> q = em.createQuery("SELECT Offering FROM Offering AS offering WHERE offering.course.id = :courseId", Offering.class); | ||
q.setParameter("courseId", courseId); | ||
return q; | ||
} | ||
|
||
public String toString() { | ||
return getRunDate().toString(); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
...anced-web-mvc/coursemanager/src/main/java/org/rooinaction/coursemanager/model/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package org.rooinaction.coursemanager.model; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Transient; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
|
||
import org.springframework.roo.addon.javabean.RooJavaBean; | ||
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord; | ||
import org.springframework.roo.addon.serializable.RooSerializable; | ||
import org.springframework.roo.addon.tostring.RooToString; | ||
|
||
@RooJavaBean | ||
@RooToString | ||
@RooSerializable | ||
@RooJpaActiveRecord(inheritanceType = "TABLE_PER_CLASS") | ||
public abstract class Person { | ||
|
||
@Size(min = 1, max = 30) | ||
@Column(name = "first_name") | ||
private String firstName; | ||
|
||
@Size(min = 1, max = 30) | ||
@Column(name = "middle_name_or_initial") | ||
private String middleNameOrInitial; | ||
|
||
@NotNull | ||
@Size(min = 1, max = 30) | ||
@Column(name = "last_name") | ||
private String lastName; | ||
|
||
@NotNull | ||
@Size(min = 1, max = 60) | ||
@Column(name = "address_line1") | ||
private String addressLine1; | ||
|
||
@Size(min = 1, max = 60) | ||
@Column(name = "address_line2") | ||
private String addressLine2; | ||
|
||
@NotNull | ||
@Size(min = 1, max = 40) | ||
private String city; | ||
|
||
@NotNull | ||
@Size(min = 2, max = 2) | ||
@Column(name = "state_code") | ||
private String stateCode; | ||
|
||
@NotNull | ||
@Size(min = 1, max = 10) | ||
@Column(name = "postal_code") | ||
private String postalCode; | ||
|
||
public Long getId() { | ||
return this.id; | ||
} | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.TABLE) | ||
@Column(name = "id") | ||
private Long id; | ||
|
||
@NotNull | ||
@Size(max = 80) | ||
@Column(name = "email_address") | ||
private java.lang.String emailAddress; | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
@Transient | ||
public String getFullName() { | ||
StringBuffer sbName = | ||
new StringBuffer(); | ||
sbName.append(lastName); | ||
if (firstName != null && firstName.length() > 0) { | ||
sbName.append(", "); | ||
sbName.append(firstName); | ||
} | ||
if (middleNameOrInitial != null && middleNameOrInitial.length() > 0) { | ||
if (firstName == null || firstName.length() > 0) sbName.append(","); | ||
sbName.append(" "); | ||
sbName.append(middleNameOrInitial); | ||
} | ||
return sbName.toString(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...web-mvc/coursemanager/src/main/java/org/rooinaction/coursemanager/model/Registration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.rooinaction.coursemanager.model; | ||
|
||
import java.util.Date; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.TypedQuery; | ||
|
||
import org.springframework.roo.addon.javabean.RooJavaBean; | ||
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord; | ||
import org.springframework.roo.addon.serializable.RooSerializable; | ||
import org.springframework.roo.addon.tostring.RooToString; | ||
|
||
@RooJavaBean | ||
@RooToString | ||
@RooSerializable | ||
@RooJpaActiveRecord(finders = { "findRegistrationsByStudentAndOffering", "findRegistrationsByStudentAndOfferingNot" }) | ||
public class Registration { | ||
|
||
public Registration(Student student, Offering offering) { | ||
this.student = student; | ||
this.offering = offering; | ||
paymentMade = false; | ||
attended = false; | ||
} | ||
|
||
public Registration() { | ||
super(); | ||
} | ||
|
||
@ManyToOne | ||
private Student student; | ||
|
||
@ManyToOne | ||
private Offering offering; | ||
|
||
@Column(name = "payment_made") | ||
private boolean paymentMade; | ||
|
||
private boolean attended; | ||
|
||
public static TypedQuery<Registration> findRegistrationsByStudent(Long studentId, Date startDate, Date endDate) { | ||
if (studentId == null) throw new IllegalArgumentException("The student id argument is required"); | ||
EntityManager em = Registration.entityManager(); | ||
TypedQuery<Registration> q = em.createQuery("SELECT DISTINCT r " + "FROM Registration AS r " + "WHERE r.student.id = :studentId " + "AND r.offering IN (SELECT o from Offering o " + " WHERE o.runDate between :start and :end)", Registration.class); | ||
q.setParameter("studentId", studentId); | ||
q.setParameter("start", startDate); | ||
q.setParameter("end", endDate); | ||
return q; | ||
} | ||
} |
Oops, something went wrong.