Skip to content
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

TRUNK-5842-ProgramWorkflow-Domain-Switching-from-Hibernate-Mappings to annotations #4888

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 121 additions & 6 deletions api/src/main/java/org/openmrs/ProgramWorkflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,85 @@

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;

Isabirye1515 marked this conversation as resolved.
Show resolved Hide resolved
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import org.hibernate.envers.Audited;
import org.openmrs.util.NaturalStrings;

/**
* ProgramWorkflow
*/
@Entity
@Table(name = "program_workflow")
@Audited
public class ProgramWorkflow extends BaseChangeableOpenmrsMetadata {
public class ProgramWorkflow extends BaseOpenmrsObject {

private static final long serialVersionUID = 1L;

// ******************
// Properties
// ******************

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "program_workflow_program_workflow_id_seq")
@Column(name = "program_workflow_id")
Isabirye1515 marked this conversation as resolved.
Show resolved Hide resolved
private Integer programWorkflowId;

private Program program;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "program_id", nullable = false)
private Program program;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "concept_id", nullable = false)
private Concept concept;

@OneToMany(mappedBy = "programWorkflow", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
@OrderBy("dateCreated ASC")
private Set<ProgramWorkflowState> states = new HashSet<>();

@ManyToOne(optional = false)
@JoinColumn(name = "creator")
private User creator;

@Column(name = "date_created", nullable = false)
private Date dateCreated;

@ManyToOne
@JoinColumn(name = "changed_by")
private User changedBy;

@Column(name = "date_changed")
private Date dateChanged;

@Column(name = "retired", nullable = false)
@org.hibernate.search.annotations.Field
private Boolean retired = Boolean.FALSE;

@Column(name = "date_retired")
private Date dateRetired;

@ManyToOne
@JoinColumn(name = "retired_by")
private User retiredBy;

private Concept concept;
@Column(name = "retire_reason", length = 255)
private String retireReason;

private Set<ProgramWorkflowState> states = new HashSet<>();

// ******************
// Constructors
Expand Down Expand Up @@ -292,6 +343,70 @@ public void setId(Integer id) {

}

public User getCreator() {
return creator;
}

public void setCreator(User creator) {
this.creator = creator;
}

public Date getDateCreated() {
return dateCreated;
}

public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}

public User getChangedBy() {
return changedBy;
}

public void setChangedBy(User changedBy) {
this.changedBy = changedBy;
}

public Date getDateChanged() {
return dateChanged;
}

public void setDateChanged(Date dateChanged) {
this.dateChanged = dateChanged;
}

public Boolean getRetired() {
return retired;
}

public void setRetired(Boolean retired) {
this.retired = retired;
}

public Date getDateRetired() {
return dateRetired;
}

public void setDateRetired(Date dateRetired) {
this.dateRetired = dateRetired;
}

public User getRetiredBy() {
return retiredBy;
}

public void setRetiredBy(User retiredBy) {
this.retiredBy = retiredBy;
}

public String getRetireReason() {
return retireReason;
}

public void setRetireReason(String retireReason) {
this.retireReason = retireReason;
}

/**
* Gets the number of states which are not retired
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void setProgramWorkflowDAO(ProgramWorkflowDAO dao) {
* @see org.openmrs.api.ProgramWorkflowService#saveProgram(org.openmrs.Program)
*/
@Override
@Transactional
Isabirye1515 marked this conversation as resolved.
Show resolved Hide resolved
public Program saveProgram(Program program) throws APIException {
// Program
if (program.getConcept() == null) {
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@
<mapping resource="org/openmrs/api/db/hibernate/LocationTag.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/LocationAttribute.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/EncounterType.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/EncounterProvider.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/EncounterProvider.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/EncounterRole.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Program.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ProgramWorkflow.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ProgramWorkflowState.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Cohort.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/CohortMembership.hbm.xml"/>
Expand Down Expand Up @@ -109,6 +108,7 @@
<mapping resource="org/openmrs/api/db/hibernate/ClobDatatypeStorage.hbm.xml" />

<!-- These mappings are required because of rerefences in Obs & Concept -->
<mapping class="org.openmrs.ProgramWorkflow"/>
<mapping class="org.openmrs.ObsReferenceRange"/>
<mapping class="org.openmrs.ConceptReferenceRange"/>
</session-factory>
Expand Down

This file was deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove this change from the PR?

Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ public void savePatientProgram_shouldSetEndDateOfAllRecentStatesOnTransitionToTe
*/
@Test
public void saveProgram_shouldCreateProgramWorkflows() {

int numBefore = Context.getProgramWorkflowService().getAllPrograms().size();

Program program = new Program();
Expand Down Expand Up @@ -1114,4 +1113,4 @@ public void triggerStateConversion_shouldTestTransitionToState(){
// return props;
// }

}
}