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

Switching from Hibernate Mappings to Annotations - PersonAttributeType #4284

Merged
merged 1 commit into from
Mar 24, 2023

Conversation

mherman22
Copy link
Contributor

@mherman22 mherman22 commented Mar 23, 2023

Description of what I changed

I changed the PersonAttributeType domain's reliance on xml mappings to use the more understandable JPA annotations. I used annotations like https://github.com/column, https://github.com/entity https://github.com/table @OneToMany and many others as can be seen in the changes in this pull request.

I tested the changes against a local setup using sdk by creating a person attribute type using this endpoint http:https://localhost:8091/openmrs/ws/rest/v1/personattributetype using the payload below;-

{
    "name": "Edit User Privileges",
    "description": "Able to manage the user privileges",
    "format": "org.openmrs.Concept",
    "foreignKey": 1054,
    "searchable": false,
    "editPrivilege": "24635eec-dd5a-11e6-9d9c-0242ac150002"
}

And the resulting payload is as shown below;-

{
    "uuid": "f8e16d41-a8b5-4a78-b696-7358bd90e7ac",
    "display": "Edit User Privileges",
    "name": "Edit User Privileges",
    "description": "Able to manage the user privileges",
    "format": "org.openmrs.Concept",
    "foreignKey": 1054,
    "sortWeight": 17.0,
    "searchable": false,
    "editPrivilege": null,
    "retired": false,
    "links": [{
        "rel": "self",
        "uri": "http:https://localhost:8091/openmrs/ws/rest/v1/personattributetype/f8e16d41-a8b5-4a78-b696-7358bd90e7ac",
        "resourceAlias": "personattributetype"
    }, {
        "rel": "full",
        "uri": "http:https://localhost:8091/openmrs/ws/rest/v1/personattributetype/f8e16d41-a8b5-4a78-b696-7358bd90e7ac?v=full",
        "resourceAlias": "personattributetype"
    }],
    "resourceVersion": "1.8"
}

Issue I worked on

see https://issues.openmrs.org/browse/TRUNK-5945

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • I have added tests to cover my changes. (If you refactored
    existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.

    No? -> execute above command

  • All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

public class PersonAttributeType extends BaseChangeableOpenmrsMetadata implements java.io.Serializable, Comparable<PersonAttributeType> {

public static final long serialVersionUID = 2112313431211L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "person_attribute_type_id")
Copy link
Member

Choose a reason for hiding this comment

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

How are we capturing this? unsaved-value="0"

Copy link
Contributor Author

@mherman22 mherman22 Mar 24, 2023

Choose a reason for hiding this comment

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

So my thinking was that in the JPA annotation mapping, we don't need to explicitly set unsaved-value="0", as this behavior is already handled by the GenerationType.IDENTITY strategy. But let me add the nullable=false

/cc: @dkayiwa

@@ -35,7 +35,7 @@ public class PersonAttributeType extends BaseChangeableOpenmrsMetadata implement

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "person_attribute_type_id")
@Column(name = "person_attribute_type_id", nullable = false)
Copy link
Member

Choose a reason for hiding this comment

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

do we need nullable = false on an id? Isn't it automatically implied?

Copy link
Contributor Author

@mherman22 mherman22 Mar 24, 2023

Choose a reason for hiding this comment

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

@dkayiwa i have gotten rid of it

@dkayiwa dkayiwa merged commit a0cea59 into openmrs:master Mar 24, 2023
Wandji69 pushed a commit to Wandji69/openmrs-core that referenced this pull request Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants