Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Add Rest Resource For ActorResponse #1

Closed
wants to merge 4 commits into from

Conversation

sherrif10
Copy link

Conversations are on talk https://talk.openmrs.org/t/get-api-responses-onto-dashboard-from-actorresponsetable/37656/5
Add Rest Endpoint for ActorResponse table. This feature is needed in one our CFL distribution.
Kindly help me review
cc @pwargulak @aagrawa4

public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
if (rep instanceof DefaultRepresentation) {
final DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("id");
Copy link
Collaborator

Choose a reason for hiding this comment

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

please extract all these hard-coded values into consts. You're using several times the same values like "id", "patient", "actor", "person" etc. etc. Please go through whole file and extract to consts where possible

Copy link
Author

Choose a reason for hiding this comment

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

Hello @druchniewicz . Sorry, i was supposed to use UUID instead of Id.
Let me resolve this quickly.


@Override
public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
if (rep instanceof DefaultRepresentation) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

in each 'if' block you create 'DelegatingResourceDescription description' variable
Please create this variable at the beginning of the method and assign null 'DelegatingResourceDescription description = null;' and then in each if block you can create proper object and assign it to this value. Then instead of return statement in each if block you return 'description' value once at the end of file. (and you won't have to return null value separately)

Copy link
Author

Choose a reason for hiding this comment

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

Hello @druchniewicz . Kindly am i didnot get your comment above well .

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean that we can extract 'description' variable at the beginning of the method and assign 'null' value initially. DelegatingResourceDescription description = null;
and then in 'if-else' block, create a object and assign it to 'description' variable.
if (rep instanceof DefaultRepresentation) {
description = new DelegatingResourceDescription();
[...]
else if (rep instanceof FullRepresentation) {
description = new DelegatingResourceDescription();
[...]
else if (rep instanceof RefRepresentation) {
description = new DelegatingResourceDescription();

Thanks to this you have only one 'return' statement at the end of method, instead of in each if-else block. And also you don't have to return null at the end separately.
return description

.property("patient", new ArrayProperty(new RefProperty("#/definitions/PatientCreate")))
.property("person", new ArrayProperty(new RefProperty("#/definitions/PersonCreate")))
.property("id", new IntegerProperty())
.property("answereTime", new DateProperty())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess there was supposed to be "answeredTime" -> this is the one of the biggest benefit storing repeated multiple times values in consts - small chance to make a typo. But even if make a typo, we only correct it in one place and that's it

.property("sourceId", new StringProperty())
.property("textResponse", new StringProperty())
.property("id", new IntegerProperty())
.property("answereTime", new StringProperty())
Copy link
Collaborator

Choose a reason for hiding this comment

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

same typo as above

}

@Override
protected void delete(ActorResponse delegate, String textQuestion, RequestContext textResponse ) throws ResponseException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why textQuestion and textResponse params are here? They are not used

Copy link
Author

Choose a reason for hiding this comment

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

Resolved thanks

Copy link
Collaborator

Choose a reason for hiding this comment

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

You changed only param names. You still have two unsed params - they are required because you override delete method from interface, right?
Second remark - you have condition "if response != null" then "do nothing". It does it make sense. In this case you always delete null entity

}

@Override
public void purge(ActorResponse delegate, RequestContext context ) throws ResponseException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

context param is not used

"2.3.*", "2.4.*", "2.5.*", "2.6.*" })
public class ActorResponseRestResource extends DelegatingCrudResource<ActorResponse> {

protected static final String REASON = "REST web service";
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it used somewhere?

@@ -0,0 +1,243 @@
package org.openmrs.module.messages.resources;
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use google-java-format plugin (https://github.com/google/google-java-format) to reformat code, because there are a lot of ugly indents, missing spaces etc. You can install such plugin directly in your IDE

@@ -0,0 +1,243 @@
package org.openmrs.module.messages.resources;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@sherrif10 I guess you tested this whole code and it works fine, right?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you so much @druchniewicz , i will address to the above comments.

private final ActorResponseRestResource actorResponseRestResource = new ActorResponseRestResource();

@Mock
private org.openmrs.module.messages.api.service.ActorResponseService ActorResponseService;
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't use whole package path if you don't need.
and change ActorResponseService field name to actorResponseService


@Override
public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
if (rep instanceof DefaultRepresentation) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean that we can extract 'description' variable at the beginning of the method and assign 'null' value initially. DelegatingResourceDescription description = null;
and then in 'if-else' block, create a object and assign it to 'description' variable.
if (rep instanceof DefaultRepresentation) {
description = new DelegatingResourceDescription();
[...]
else if (rep instanceof FullRepresentation) {
description = new DelegatingResourceDescription();
[...]
else if (rep instanceof RefRepresentation) {
description = new DelegatingResourceDescription();

Thanks to this you have only one 'return' statement at the end of method, instead of in each if-else block. And also you don't have to return null at the end separately.
return description

.property("preferredTextQuestion", new RefProperty("#/definitions/TextQuestionGetRef"))
.property("preferredActor", new RefProperty("#/definitions/ActorGetRef"))
.property("preferreQuestion", new RefProperty("#/definitions/QuestionGetRef"));
.property("Response", new RefProperty("#/definitions/ResponseGetRef"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why you changed these properties names and first character to upper case?
Should not these names be a class fields names or can by any names?

@@ -209,7 +219,7 @@ public Model getUPDATEModel(Representation representation) {
*/
@Override
public List<String> getPropertiesToExposeAsSubResources() {
return Arrays.asList("actorResponseType", "question", "attributes");
return Arrays.asList("actorResponseType", "concept", "patient","p");
Copy link
Collaborator

Choose a reason for hiding this comment

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

what does this change mean? Why suddenly other fields and one more field?

}

@Override
protected void delete(ActorResponse delegate, String textQuestion, RequestContext textResponse ) throws ResponseException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You changed only param names. You still have two unsed params - they are required because you override delete method from interface, right?
Second remark - you have condition "if response != null" then "do nothing". It does it make sense. In this case you always delete null entity

}

@Override
public ActorResponse getByUniqueId(String uuid) {
return Context.getService(ActorResponseService.class).getByUuid(uuid);
public ActorResponse getByUniqueId(String uniqueid) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think 'uuid' was a good name, but if you want to use 'uniqueid' name then please change it to 'uniqueId' (camel-case convention)

@pwargulak
Copy link
Collaborator

It's going to be included in the next release.

@pwargulak pwargulak closed this Dec 15, 2023
druchniewicz pushed a commit that referenced this pull request Mar 22, 2024
…act time

Merge in ITX-BPV/openmrs-module-messages from feature/AGRE-2167 to development

* commit 'b8b5dd2f2549731d93a95918afaae2d799e52993':
  AGRE-2167: Fixed receiving calls after the best contact time
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants