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

RESTWS-701 Added REST Implementation for Server logs #329

Merged
merged 1 commit into from
May 29, 2018

Conversation

suthagar23
Copy link
Member

@suthagar23 suthagar23 commented Mar 3, 2018

It will be helped to expose the Server logs through the REST Webservices. There are some minor logics included using the Wrapper classes to increase the usage of the log lines.

  • ServerLogResource1_8 - REST Implementation for Server Logs
  • ServerLogResource1_8Test - Test cases for the Server Logs REST Implementations
  • ServerLogActionWrapper - Minor Pattern Matching logic included
  • MockServerLogActionWrapper - Used for mocking while executing the test cases.

The user needs the "Get Server Logs" privilege to access this endpoint.

Issue: RESTWS-701

@suthagar23
Copy link
Member Author

@dkayiwa Could you please take a look at here?

@djazayeri
Copy link
Member

I think it's important that we add a privilege check here. (Or, maybe openmrs-core already enforces that?)

@suthagar23
Copy link
Member Author

Yes, we need to add privilege check here. Let me add it here. Thanks @djazayeri

@suthagar23
Copy link
Member Author

@djazayeri I have added the privilege check here, can you please take a look at here?

@dkayiwa
Copy link
Member

dkayiwa commented Mar 13, 2018

Did you take a look at the above travis failure?

@suthagar23
Copy link
Member Author

@dkayiwa

Yah, I have noticed that one. But the error does not relate to this change. Every PR for this repo has the Travis failure due to this issue.
Non-resolvable parent POM for org.openmrs.module:webservices.rest-omod-2.2:[unknown-version]: Could not find artifact org.openmrs.module:webservices.rest:pom:2.22.0-SNAPSHOT in sonatype-snapshots

@suthagar23
Copy link
Member Author

Thanks, @sumangala028 for pointing out the new changes in the POM file to resolve the issue mentioned above.

@dkayiwa Can you please take a look at here for the test errors.

@dkayiwa
Copy link
Member

dkayiwa commented Mar 18, 2018

Do the pass locally?

@suthagar23 suthagar23 force-pushed the RESTWS-701 branch 2 times, most recently from 62fc4e6 to 94805ff Compare March 18, 2018 12:52
@coveralls
Copy link

coveralls commented Mar 18, 2018

Coverage Status

Coverage decreased (-0.09%) to 41.562% when pulling 616d242 on suthagar23:RESTWS-701 into d76b294 on openmrs:master.

@suthagar23
Copy link
Member Author

@dkayiwa, I have fixed the issues. Can you please take a look again

@dkayiwa
Copy link
Member

dkayiwa commented Mar 19, 2018

Does this appear in the online swagger docs?

@suthagar23
Copy link
Member Author

Sorry, I didn't get you properly. What do you mean by "online swagger docs"?

@dkayiwa
Copy link
Member

dkayiwa commented Mar 19, 2018

@gayanW do you have a minute to respond to the above? 😊

@suthagar23
Copy link
Member Author

I think I need to add getGETModel() to get this into Online Swagger docs.
Am I correct @dkayiwa and @gayanW ?

@gayanW
Copy link
Member

gayanW commented Mar 21, 2018

I think I need to add getGETModel() to get this into Online Swagger docs.
Am I correct @dkayiwa and @gayanW ?

Yeah you'd need implement getGETModel(). Once done you check if it correctly appears in the swagger documentation in: http://localhost:8080/openmrs/module/webservices/rest/apiDocs.htm

However your resource class does not seem extend any of the base resource classes.

FYI: methods such as getGETModel, getCreatableProperties comes from the DelegatingResourceHandler interface.

You can find more information here:
https://wiki.openmrs.org/display/docs/Documenting+REST+Resources

@suthagar23
Copy link
Member Author

I have implemented this class from Listable Interface, not with DelegatingResourceHandler Interface. Listable Interface doesn't have any methods like getGETModel, getCreatableProperties for the swagger access. So how can I override those methods here?

@gayanW
Copy link
Member

gayanW commented Mar 21, 2018

To my understanding most resources extends one of the base resource classes which inherit DelegatingResourceHandler.

DelegatingResourceHandler is the one that is currently being used to describe resource representations.

@dkayiwa will have an idea on what to do in this case :)

@suthagar23 suthagar23 force-pushed the RESTWS-701 branch 3 times, most recently from f3135bc to a67ee55 Compare March 23, 2018 19:48
@suthagar23
Copy link
Member Author

@dkayiwa Finally I have modified the code to get this in the online swagger docs 😄
I have attached the screenshot from the swagger docs here,

image


and Thanks for the comments @gayanW

@suthagar23
Copy link
Member Author

suthagar23 commented Apr 9, 2018

@dkayiwa If you have time, Could you please review it and help me to complete this work to release the SysAdmin 1.1 OWA :-)

/**
* Constants used for the Server Log REST Service privilege checking
*/
public static final String GET_SERVER_LOGS = "Get Server Logs";
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you prefix this with PRIV_ to make it clearer from the name?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have updated the variable name. Thanks @dkayiwa

return logElements;
}
catch (PatternSyntaxException e) {
// In case of Exception, It will return empty array
Copy link
Member

Choose a reason for hiding this comment

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

Then how will the client differentiate between finding no match and errors occurred?

@dkayiwa
Copy link
Member

dkayiwa commented Apr 12, 2018

@suthagar23 did you compile, install, and test to see if your resource shows up in the online swagger docs?

@suthagar23
Copy link
Member Author

Yes @dkayiwa, I can see those resources in the online swagger docs. You can see it below,

image

@dkayiwa
Copy link
Member

dkayiwa commented Apr 14, 2018

Do your resources show up in the online swagger docs when running on the latest snapshot version of openmrs-core?

@suthagar23
Copy link
Member Author

I have just checked the latest snapshot version of openmrs-core (openmrs-2.2.0-SNAPSHOT). But I couldn't see the swagger docs 😞 .
But I can see it in the openmrs-2.0.6-SNAPSHOT version.
What is the issue here? Could you please help me?

@dkayiwa
Copy link
Member

dkayiwa commented Apr 16, 2018

Can you raise it on talk?

@suthagar23
Copy link
Member Author

Sure @dkayiwa I will post it to talk.

@Override
public SimpleObject getAll(RequestContext context) throws ResponseException {
SimpleObject rest = new SimpleObject();
rest.put("serverLog", serverLogActionWrapper.getServerLogs());
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to put the logs in single field? I'd Imagine that you just need to a return a list of server logs

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought to get that list of logs from "serverlog" field. Anyway, returning that list directly to the resource also a good point. Thanks @wluyima

Copy link
Member Author

Choose a reason for hiding this comment

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

Since the server logs will return nearly 100 lines, I kept those inside a single key to reduce the complexity for now. We can add some other keys based later as well.

@Override
public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("serverLog", "serverLog");
Copy link
Member

Choose a reason for hiding this comment

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

The properties should be the individual fields on the ServerLogWrapper class

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added this property to the ServerLogActionWrapper class here - https://github.com/openmrs/openmrs-module-webservices.rest/pull/329/files#diff-410f1f6f7c035020e68aa6abe419b84bR28

Do we need another ServerLogWrapper Class also?

}

@Override
public String getUri(Object instance) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to override this?

import java.util.ArrayList;
import java.util.List;

/***
Copy link
Member

Choose a reason for hiding this comment

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

Did you format your code?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for the mistake, I will make it better

@dkayiwa
Copy link
Member

dkayiwa commented Apr 20, 2018

@suthagar23 did you eventually figure this out?
cc @gayanW

@suthagar23
Copy link
Member Author

Not yet @dkayiwa. I am working on this to figure out the actual problem and looking for the changes in the new release which is blocking this resource in the swagger documentation.

@gayanW
Copy link
Member

gayanW commented Apr 22, 2018

Swagger doc loads fine in the qa-refapp. I didn't have chance to test it locally.

@dkayiwa
Copy link
Member

dkayiwa commented Apr 30, 2018

@suthagar23 are you doing any more changes on this?

@suthagar23
Copy link
Member Author

@dkayiwa Let me check again the issue here.

@dkayiwa
Copy link
Member

dkayiwa commented May 10, 2018

@suthagar23 did you address Wyclif's comments?

@dkayiwa
Copy link
Member

dkayiwa commented May 21, 2018

@suthagar23 did you see the above?

@dkayiwa
Copy link
Member

dkayiwa commented May 27, 2018

@suthagar23 can you finish this up?

@suthagar23 suthagar23 force-pushed the RESTWS-701 branch 2 times, most recently from 00f888a to 6db0cb8 Compare May 28, 2018 13:25
@suthagar23
Copy link
Member Author

@dkayiwa I have updated the PR now. Extremely sorry for the delay since I forgot this work for a long time 😢

@suthagar23 suthagar23 force-pushed the RESTWS-701 branch 4 times, most recently from 6be7252 to 6783a01 Compare May 29, 2018 06:45
…d point.

Added REST Implementation with Privilege check for the Server logs end point.

Added REST Implementation with Privilege check for the Server logs end point.

Added REST Implementation with Privilege check for the Server logs end point.

Added REST Implementation with Privilege check for the Server logs end point.

Added REST Implementation with Privilege check for the Server logs end point.

Added REST Implementation with Privilege check for the Server logs end point.

Added REST Implementation with Privilege check for Server Logs end point.

Added REST Implementation for Server logs

Privilege check added for the REST end point

updated the privilege check

Comments updated

Changed support class for the resource

Minor fix in REST Constants

Added more improvements to get it in the Swagger Docs

Added some testcases to serverLogController

Added some unit tests to increase the coverage

Added some unit tests

Fix some minor issues

Fixed minor formatting issues

Fixed minor issues

Added some tests

Added some tests

Added some tests

Added some tests for serverLog resource

Added some tests for serverLog resource

Added some tests for serverLog resource
@dkayiwa dkayiwa merged commit c5f1730 into openmrs:master May 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants