-
Notifications
You must be signed in to change notification settings - Fork 4
Conversation
public DelegatingResourceDescription getRepresentationDescription(Representation rep) { | ||
if (rep instanceof DefaultRepresentation) { | ||
final DelegatingResourceDescription description = new DelegatingResourceDescription(); | ||
description.addProperty("id"); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 .
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same typo as above
omod/src/main/java/org/openmrs/module/messages/resources/ActorResponseRestResource.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Override | ||
protected void delete(ActorResponse delegate, String textQuestion, RequestContext textResponse ) throws ResponseException { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved thanks
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
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?
omod/src/main/java/org/openmrs/module/messages/resources/ActorResponseRestResource.java
Outdated
Show resolved
Hide resolved
omod/src/main/java/org/openmrs/module/messages/resources/ActorResponseRestResource.java
Outdated
Show resolved
Hide resolved
@@ -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"); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)
It's going to be included in the next release. |
…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
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