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-5830: Migrate FieldType from Hibernate Mapping XML to JPA annotations #4804

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 31 additions & 2 deletions api/src/main/java/org/openmrs/FieldType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,49 @@
*/
package org.openmrs;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.envers.Audited;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
* FieldType
*/
@Entity
@Table(name = "field_type")
@Audited
@AttributeOverrides(value = {
@AttributeOverride(name = "name", column = @Column(name = "name", length = 50, nullable = false)),
@AttributeOverride(name = "retired", column = @Column(name = "retired", columnDefinition = "boolean default false"))
Copy link
Member

Choose a reason for hiding this comment

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

Why use "boolean default false" here?'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should set the retired column default value as false ?

Copy link
Member

Choose a reason for hiding this comment

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

In BaseOpenmrsMetadata default value for retired is set to false.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

without including columnDefinition = "boolean default false", HL7Service, OrderEntryIntergationTest, and MedicationDispenseServiceTest tests are getting failed.

Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: NULL not allowed for column "RETIRED"; SQL statement: insert into FIELD_TYPE (FIELD_TYPE_ID, NAME, IS_SET, CREATOR, DATE_CREATED, UUID) values (?, ?, ?, ?, ?, ?) [23502-200] at org.h2.message.DbException.getJdbcSQLException(DbException.java:459)

Copy link
Member

Choose a reason for hiding this comment

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

@dkayiwa, @ibacher what are your thoughts on this?

Copy link
Member

Choose a reason for hiding this comment

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

I do not like the column definition value of boolean default false
Can we think of an alternative?

})
public class FieldType extends BaseChangeableOpenmrsMetadata {


/**
* The constant serialVersionUID.
*/
public static final long serialVersionUID = 35467L;

// Fields


@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "field_type_id_seq")
@GenericGenerator(
name = "field_type_id_seq",
strategy = "native",
parameters = @Parameter(name = "sequence", value = "field_type_id_field_type_id_seq")
)
@Column(name = "field_type_id", nullable = false)
private Integer fieldTypeId;

@Column(name = "is_set", length = 1, nullable = false)
private Boolean isSet = false;

// Constructors
Expand Down
1 change: 0 additions & 1 deletion api/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<mapping resource="org/openmrs/api/db/hibernate/Drug.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/DrugReferenceMap.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Field.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/FieldType.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/Form.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/FormField.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/FormResource.hbm.xml" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,131 @@
referencedTableName="obs"
referencedColumnNames="obs_id"/>
</changeSet>

<changeSet id="TRUNK-5830-2024-10-28-1" author="manojll">
<preConditions onFail="MARK_RAN">
<tableExists tableName="field_type"/>
<and>
<not>
<columnExists tableName="field_type" columnName="date_changed"/>
</not>
</and>
</preConditions>
<comment>adding date change column</comment>
<addColumn tableName="field_type">
<column name="date_changed" type="datetime" />
</addColumn>
</changeSet>

<changeSet id="TRUNK-5830-2024-10-28-2" author="manojll">
<preConditions onFail="MARK_RAN">
<tableExists tableName="field_type"/>
<and>
<not>
<columnExists tableName="field_type" columnName="date_retired"/>
</not>
</and>
</preConditions>
<comment>adding retired_by column</comment>
<addColumn tableName="field_type">
<column name="date_retired" type="datetime" />
</addColumn>
</changeSet>

<changeSet id="TRUNK-5830-2024-10-28-3" author="manojll">
<preConditions onFail="MARK_RAN">
<tableExists tableName="field_type"/>
<and>
<not>
<columnExists tableName="field_type" columnName="retired_by"/>
</not>
</and>
</preConditions>
<comment>adding retired_by column</comment>
<addColumn tableName="field_type">
<column name="retired_by" type="int" />
</addColumn>
</changeSet>

<changeSet id="TRUNK-5830-2024-10-28-4" author="manojll">
<preConditions onFail="MARK_RAN">
<tableExists tableName="field_type"/>
<and>
<not>
<columnExists tableName="field_type" columnName="retire_reason"/>
</not>
</and>
</preConditions>
<comment>adding retire_reason column</comment>
<addColumn tableName="field_type">
<column name="retire_reason" type="varchar(255)" />
</addColumn>
</changeSet>

<changeSet id="TRUNK-5830-2024-10-28-5" author="manojll">
<preConditions onFail="MARK_RAN">
<tableExists tableName="field_type"/>
<and>
<not>
<columnExists tableName="field_type" columnName="creator"/>
</not>
</and>
</preConditions>
<comment>adding creator column</comment>
<addColumn tableName="field_type">
<column name="creator" type="int">
<constraints nullable="false" />
</column>
</addColumn>
</changeSet>

<changeSet id="TRUNK-5830-2024-10-28-6" author="manojll">
<preConditions onFail="MARK_RAN">
<tableExists tableName="field_type"/>
<and>
<not>
<columnExists tableName="field_type" columnName="date_created"/>
</not>
</and>
</preConditions>
<comment>adding date_created column</comment>
<addColumn tableName="field_type">
<column name="date_created" type="datetime">
<constraints nullable="false" />
</column>
</addColumn>
</changeSet>

<changeSet id="TRUNK-5830-2024-10-28-7" author="manojll">
<preConditions onFail="MARK_RAN">
<tableExists tableName="field_type"/>
<and>
<not>
<columnExists tableName="field_type" columnName="changed_by"/>
</not>
</and>
</preConditions>
<comment>adding changed_by column</comment>
<addColumn tableName="field_type">
<column name="changed_by" type="int" />
</addColumn>
</changeSet>

<changeSet id="TRUNK-5830-2024-10-28-8" author="manojll">
<preConditions onFail="MARK_RAN">
<tableExists tableName="field_type"/>
<and>
<not>
<columnExists tableName="field_type" columnName="retired"/>
</not>
</and>
</preConditions>
<comment>adding retired column</comment>
<addColumn tableName="field_type">
<column name="retired" type="boolean" defaultValueBoolean="false">
<constraints nullable="false" />
</column>
</addColumn>
</changeSet>

</databaseChangeLog>
2 changes: 2 additions & 0 deletions api/src/test/java/org/openmrs/api/OrderServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.openmrs.DrugIngredient;
import org.openmrs.DrugOrder;
import org.openmrs.Encounter;
import org.openmrs.FieldType;
import org.openmrs.FreeTextDosingInstructions;
import org.openmrs.GlobalProperty;
import org.openmrs.Location;
Expand Down Expand Up @@ -2737,6 +2738,7 @@ public void saveOrder_shouldFailIfTheJavaTypeOfThePreviousOrderDoesNotMatch() th
.addAnnotatedClass(DrugIngredient.class)
.addAnnotatedClass(AlertRecipient.class)
.addAnnotatedClass(PatientIdentifierType.class)
.addAnnotatedClass(FieldType.class)
.addAnnotatedClass(ProgramAttributeType.class)
.addAnnotatedClass(HL7InError.class)
.addAnnotatedClass(OrderType.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DatabaseUpdaterDatabaseIT extends DatabaseIT {
* This constant needs to be updated when adding new Liquibase update files to openmrs-core.
*/

private static final int CHANGE_SET_COUNT_FOR_GREATER_THAN_2_1_X = 899;
private static final int CHANGE_SET_COUNT_FOR_GREATER_THAN_2_1_X = 907;

private static final int CHANGE_SET_COUNT_FOR_2_1_X = 870;

Expand Down
Loading