-
Notifications
You must be signed in to change notification settings - Fork 521
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
RESTWS-920: Endpoint for OrderAttribute and OrderAttributeType. #587
base: master
Are you sure you want to change the base?
Conversation
* We should not need to apply this fix in versions where TRUNK-5022 is fixed. | ||
*/ | ||
@OpenmrsProfile(openmrsPlatformVersion = "2.5.* - 9.*") | ||
public class InitPathMatcher2_5 implements ServletContextAware { |
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 this in any way related to the changes required for your ticket?
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; | ||
import org.xml.sax.InputSource; | ||
|
||
public class RestControllerTestUtils extends BaseModuleWebContextSensitiveTest { |
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 is this for?
/** | ||
* Facilitates testing controllers. | ||
*/ | ||
public abstract class MainResourceControllerTest extends RestControllerTestUtils { |
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 is this for?
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; | ||
import org.xml.sax.InputSource; | ||
|
||
public class RestControllerTestUtils extends BaseModuleWebContextSensitiveTest { |
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 is this for?
return "Dispensing Location: " + new SimpleDateFormat("yyyy-MM-dd").parse("2011-04-25"); | ||
} | ||
catch (ParseException ex) { | ||
ex.printStackTrace(); |
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.
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.
@dkayiwa done responding to all comments raised
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.
Can you also add an OrderAttributeController2_5Test?
And an OrderAttributeTypeController2_5Test?
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> |
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.
Remove this dependency
omod-2.5/pom.xml
Outdated
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-1.8</artifactId> |
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.
Remove this dependency
omod-2.5/pom.xml
Outdated
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-1.9</artifactId> |
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.
Remove this dependency
omod-2.5/pom.xml
Outdated
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-1.9</artifactId> |
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.
Remove this dependency
@slubwama for the ClassNotFoundException, in your pom.xml file, remove the webservices.rest 1.8-omod and 1.9-omod dependencies. |
@slubwama because you extended |
@slubwama did you abandon this? |
…s.rest into RESTWS-920
…s.rest into RESTWS-920
…e-9f4f-5396a31e68fb
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.
Few minor things, but this mostly LGTM
* @param <P> The parent/owning type for the type T | ||
* @param <PR> The Resource for the parent/owning type P | ||
*/ | ||
public abstract class BaseAttributeCrudResource2_5<T extends Attribute<?, ?>, P, PR> extends DelegatingSubResource<T, P, DelegatingCrudResource<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.
Why doesn't this just extend BaseAttributeCrudResource1_9
?
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.
It's also not entirely clear to me what this is adding to that class...
* | ||
* @param <T> | ||
*/ | ||
public abstract class BaseAttributeTypeCrudResource2_5<T extends AttributeType<?>> extends MetadataDelegatingCrudResource<T> { |
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.
It seems like this should extend BaseAttributeTypeCrudResource1_9
.
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'm equally unsure that we even need this class at all.
for (OrderAttribute orderAttribute : delegate.getOrder().getActiveAttributes()) { | ||
if (orderAttribute.equals(delegate)) { | ||
needToAdd = false; | ||
break; | ||
} | ||
} |
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.
for (OrderAttribute orderAttribute : delegate.getOrder().getActiveAttributes()) { | |
if (orderAttribute.equals(delegate)) { | |
needToAdd = false; | |
break; | |
} | |
} | |
if (delegate.getOrder().getActiveAttributes().contains(delegate)) { | |
delegate.getOrder().addAttribute(delegate); | |
} |
.../openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/OrderAttributeResource2_5.java
Show resolved
Hide resolved
*/ | ||
@Override | ||
protected void delete(OrderAttribute delegate, String reason, RequestContext context) throws ResponseException { | ||
throw new UnsupportedOperationException("Cannot purge OrderAttribute"); |
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 not?
List<OrderAttributeType> allAttrs = service().getAllOrderAttributeTypes(); | ||
List<OrderAttributeType> queryResult = new ArrayList<OrderAttributeType>(); | ||
for (OrderAttributeType locAttr : allAttrs) { | ||
if (Pattern.compile(Pattern.quote(context.getParameter("q")), Pattern.CASE_INSENSITIVE) |
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.
- We don't really need a regex here. You can just using
locAttr.getName().toLowerCase().contains(context.getParameter("q").toLowerCase())
- If we do use a Regex here, do not call
Pattern.compile()
in a loop; lift it to outside the loop context.
/** | ||
* Tests functionality of {@link OrderAttributeController}. | ||
*/ | ||
public class OrderAttributeController2_5Test extends MainResourceControllerTest { |
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.
This is really a test for the OrderResource
, so it should be OrderController2_5Test
, no?
@dkayiwa need review on this again |
@slubwama add this to your test class: https://pastebin.com/SRcYACN2 |
…s.rest into RESTWS-920
…s.rest into RESTWS-920 # Conflicts: # omod-2.5/pom.xml
for (OrderAttributeType locAttr : allAttrs) { | ||
if (locAttr.getName().toLowerCase().contains(context.getParameter("q").toLowerCase())) { | ||
queryResult.add(locAttr); | ||
} | ||
} |
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.
It would be ideal, I think, if we could extend the order server to handle this search for use. Anything where we're loading all database entries into memory is going to perform slowly.
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.
We probably want the ability (and to default!) to not returning any retired order attributes without the user explicitly requesting it.
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.
Finally, if possible, it might be nice to order the results so that prefix matches come before "containing" matches. (This shouldn't block the PR)
public String getResourceVersion() { | ||
return RestConstants2_5.RESOURCE_VERSION; | ||
} | ||
} |
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.
} | |
} | |
* @param attrs | ||
*/ | ||
@PropertySetter("attributes") | ||
public static void setAttributes(Order instance, List<OrderAttribute> attrs) { |
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'm a little nervous about this. Shouldn't we try to ensure that we update any attributes that might've been updated? Or do we just delete everything (somewhere) and add everything on request?
@slubwama looking forward to this so that we can explore using it to store lab orders sample data |
https://issues.openmrs.org/browse/RESTWS-920
Description of what I changed
Issue I worked on
see https://issues.openmrs.org/browse/RESTWS-
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 andadded 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