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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Removed the ProgramWorkFlowServiceTest from the PR
Isabirye1515 committed Jan 19, 2025
commit 82f820f208bb63d7a448236505ab3635b023acb7
2 changes: 1 addition & 1 deletion api/src/main/java/org/openmrs/BaseOpenmrsMetadata.java
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@
public abstract class BaseOpenmrsMetadata extends BaseOpenmrsObject implements OpenmrsMetadata {

//***** Properties *****
@Column(name = "name", length = 255)
@Column(name = "name", nullable = false, length = 255)
@Field
private String name;

107 changes: 98 additions & 9 deletions api/src/main/java/org/openmrs/ProgramWorkflow.java
Original file line number Diff line number Diff line change
@@ -11,12 +11,12 @@

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;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -29,8 +29,6 @@
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.envers.Audited;
import org.openmrs.util.NaturalStrings;

@@ -40,7 +38,7 @@
@Entity
@Table(name = "program_workflow")
@Audited
public class ProgramWorkflow extends BaseChangeableOpenmrsMetadata {
public class ProgramWorkflow extends BaseOpenmrsObject {

private static final long serialVersionUID = 1L;

@@ -52,19 +50,46 @@ public class ProgramWorkflow extends BaseChangeableOpenmrsMetadata {
@Column(name = "program_workflow_id")
private Integer programWorkflowId;

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

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

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

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


// ******************
// Constructors
@@ -318,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
*
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ public void setProgramWorkflowDAO(ProgramWorkflowDAO dao) {
* @see org.openmrs.api.ProgramWorkflowService#saveProgram(org.openmrs.Program)
*/
@Override
@Transactional
public Program saveProgram(Program program) throws APIException {
// Program
if (program.getConcept() == null) {
5 changes: 2 additions & 3 deletions api/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
@@ -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/ProgramWorkflowState.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Cohort.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/CohortMembership.hbm.xml"/>
@@ -109,7 +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.ProgramWorkflow"/>
<mapping class="org.openmrs.ObsReferenceRange"/>
<mapping class="org.openmrs.ConceptReferenceRange"/>
</session-factory>
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
@@ -387,7 +387,6 @@ public void savePatientProgram_shouldSetEndDateOfAllRecentStatesOnTransitionToTe
*
* @see ProgramWorkflowService#saveProgram(Program)
*/
@SuppressWarnings("null")
@Test
public void saveProgram_shouldCreateProgramWorkflows() {
int numBefore = Context.getProgramWorkflowService().getAllPrograms().size();
@@ -399,19 +398,16 @@ public void saveProgram_shouldCreateProgramWorkflows() {

ProgramWorkflow workflow = new ProgramWorkflow();
workflow.setConcept(cs.getConcept(4));
workflow.setName("CIVIL STATUS"); // Set a valid name
program.addWorkflow(workflow);

ProgramWorkflowState state1 = new ProgramWorkflowState();
state1.setConcept(cs.getConcept(5));
state1.setName("SINGLE"); // Set a valid name
state1.setInitial(true);
state1.setTerminal(false);
workflow.addState(state1);

ProgramWorkflowState state2 = new ProgramWorkflowState();
state2.setConcept(cs.getConcept(6));
state2.setName("MARRIED"); // Set a valid name
state2.setInitial(false);
state2.setTerminal(true);
workflow.addState(state2);
@@ -425,7 +421,7 @@ public void saveProgram_shouldCreateProgramWorkflows() {
assertEquals(1, p.getWorkflows().size(), "Wrong number of workflows");

ProgramWorkflow wf = p.getWorkflowByName("CIVIL STATUS");
assertNotNull(wf, "Workflow 'CIVIL STATUS' not found");
assertNotNull(wf);

List<String> names = new ArrayList<>();
for (ProgramWorkflowState s : wf.getStates()) {
@@ -434,7 +430,6 @@ public void saveProgram_shouldCreateProgramWorkflows() {
TestUtil.assertCollectionContentsEquals(Arrays.asList("SINGLE", "MARRIED"), names);
}


/**
* @see ProgramWorkflowService#getConceptStateConversionByUuid(String)
*/
@@ -589,6 +584,7 @@ public void getWorkflowByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() {
public void getSortedStates_shouldSortNamesContainingNumbersIntelligently() {

ProgramWorkflow program = new ProgramWorkflow();

ConceptName state1ConceptName = new ConceptName("Group 10", Context.getLocale());
Concept state1Concept = new Concept();
state1Concept.addName(state1ConceptName);
@@ -1117,4 +1113,4 @@ public void triggerStateConversion_shouldTestTransitionToState(){
// return props;
// }

}
}