-
Notifications
You must be signed in to change notification settings - Fork 3.9k
TRUNK-5837: Migrate Cohort Domain from Hibernate Mapping XML to JPA annotations. #4892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 9 commits
2ac6eab
7e782ca
a382fb6
f984bdd
28e3962
797cb9f
4b477fd
5209a9f
f0acb37
bd0d5ce
3182742
8e4412c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,18 @@ | |
package org.openmrs; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.hibernate.annotations.GenericGenerator; | ||
import org.hibernate.annotations.Parameter; | ||
import org.hibernate.envers.Audited; | ||
|
||
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.OneToMany; | ||
import javax.persistence.Table; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Date; | ||
|
@@ -22,17 +32,30 @@ | |
/** | ||
* This class represents a list of patientIds. | ||
*/ | ||
@Entity | ||
@Table(name = "cohort") | ||
@Audited | ||
public class Cohort extends BaseChangeableOpenmrsData { | ||
|
||
public static final long serialVersionUID = 0L; | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "cohort_id_seq") | ||
@GenericGenerator( | ||
name = "cohort_id_seq", | ||
strategy = "native", | ||
parameters = @Parameter(name = "sequence", value = "cohort_cohort_id_seq") | ||
) | ||
@Column(name = "cohort_id", nullable = false) | ||
private Integer cohortId; | ||
|
||
@Column(name = "name", nullable = false) | ||
private String name; | ||
|
||
@Column(name = "description", nullable = false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about the length? |
||
private String description; | ||
|
||
@OneToMany(mappedBy = "cohort", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private Collection<CohortMembership> memberships; | ||
|
||
public Cohort() { | ||
|
@@ -349,7 +372,7 @@ public void setMemberIds(Set<Integer> memberIds) { | |
} | ||
|
||
public void setMemberships(Collection<CohortMembership> members) { | ||
this.memberships = members; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something minor. Do we need the space here :) ? |
||
this.memberships = members; | ||
} | ||
|
||
/** | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ public void constructorWithCommaSeparatedIntegers_shouldAddMembersToCohort() { | |
@Test | ||
public void getCommaSeparatedPatientIds_shouldReturnCommaSeparatedListOfPatients() { | ||
|
||
List<Patient> patients = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this change required as part of the ticket? |
||
Set<Patient> patients = new HashSet<>(); | ||
Arrays.stream(ids).forEach(id -> patients.add(new Patient(id))); | ||
|
||
Cohort cohort = new Cohort("name", "description", patients); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you just forget to specify the length as was in the xml mapping file?