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

O3-310: allow Put operations on an application-writable config.json file to openmrs/data/frontends/config.json #57

Closed
wants to merge 4 commits into from

Conversation

jnsereko
Copy link

@jnsereko jnsereko commented Feb 28, 2023

There should be a config.json file that the application is allowed to manage, which lives in the application data directory.

module-spa should have a REST endpoint PUT /ws/frontend/config that sets the value of this file.

The file is served the usual way along with everything else in the frontend/ directory.

The Implementer Tools should have a button that updates that file with the temporary config.

cc @dkayiwa @hadijahkyampeire

Issue Link: https://issues.openmrs.org/browse/O3-310

Screenshots

Uploading screen recording.mov…

config.video.mov

@jnsereko jnsereko marked this pull request as ready for review March 1, 2023 08:51
Copy link
Author

@jnsereko jnsereko left a comment

Choose a reason for hiding this comment

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

By default, every request to spa/ transformed with an a retrieve the index.html file.
Ideally, i think, this is the reason the controllers i registered with 70e0cdd were actually not being called (silent).

I tried to call them manually but things just got messed up the more, leaving me with implementing the logic in the doGet and doPut.

I also didn't want to reimplement the existing logic of rendering the index.html logic

cc @dkayiwa @ibacher @hadijahkyampeire @vasharma05 @brandones @denniskigen

Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

@jnsereko Thanks for the PR! I think there are some decent ideas here, but some things that need to be addressed before this can be merged in.

I think there are some design questions here that need to be handled as well, specifically around how this is supposed to interact with the implementer tools. What should happen when, having created a configuration, I go back into the implementer tools to configure a different component? What if I decide my configuration is broken and I want to get rid of it?

Finally, why is this defaulting to /openmrs/spa/frontend/config instead of, e.g., /openmrs/spa/config.json`?

@ibacher
Copy link
Member

ibacher commented Mar 1, 2023

PS The requests for /openmrs/spa get sent to a filter (which will run before any controllers) which forward the request to the servlet, which is why your controllers weren't getting called.

@jnsereko
Copy link
Author

jnsereko commented Mar 7, 2023

@ibacher @dkayiwa, i think we have to change the endpoint simply to config.json than the earlier frontend/config.json so as to simplify this requirement
By default the spa module tries to get the url as a file under the frontend directory. So a request like /openmrs/spa/config.json will be resolved as /openmrs/data/frontend/config.json while a request like /openmrs/spa/frontend/config.json will be transformed to /openmrs/data/frontend/frontend/config.json

I have also removed creation of the config directory because it seams useless

@jnsereko jnsereko requested review from ibacher and removed request for dkayiwa March 7, 2023 00:46
@jnsereko jnsereko changed the title O3-310: allow Put operations on an application-writable config.json file to spa/frontends/config O3-310: allow Put operations on an application-writable config.json file to openmrs/data/frontends/config.json Mar 7, 2023
@jnsereko
Copy link
Author

jnsereko commented Mar 8, 2023

@dkayiwa @ibacher kindly review

@jnsereko jnsereko requested review from dkayiwa and removed request for ibacher March 9, 2023 12:06
@jnsereko
Copy link
Author

jnsereko commented Mar 9, 2023

hey @ibacher @dkayiwa, is this fit for merge?

omod/pom.xml Outdated Show resolved Hide resolved
@dkayiwa
Copy link
Member

dkayiwa commented Mar 26, 2023

@jnsereko are you still working on this?

@jnsereko jnsereko requested a review from dkayiwa March 27, 2023 12:03
@jnsereko
Copy link
Author

@dkayiwa @ibacher I have cleaned the code

@ibacher
Copy link
Member

ibacher commented May 29, 2023

Is it that 3.x has finally migrated away form using the this module?

The Docker images have never used module-spa.

@jnsereko
Copy link
Author

jnsereko commented May 29, 2023 via email

@ibacher
Copy link
Member

ibacher commented May 29, 2023

When you were testing this previously, I'm pretty sure you were using the SDK. We haven't changed anything about how the routing works. If you're using the Docker containers, requests to /openmrs/spa will never hit the backend... and that's been the case since we put the Docker containers together. (This is, in fact, what allows us to provide the "single-page" experience; any request to /openmrs/spa is forwarded to the frontend container and any request for a URL in the frontend container that does not otherwise resolve to something serves the single-page content).

@jnsereko
Copy link
Author

jnsereko commented May 29, 2023 via email

@jnsereko
Copy link
Author

jnsereko commented Jun 1, 2023

When you were testing this previously, I'm pretty sure you were using the SDK. We haven't changed anything about how the routing works. If you're using the Docker containers, requests to /openmrs/spa will never hit the backend... and that's been the case since we put the Docker containers together. (This is, in fact, what allows us to provide the "single-page" experience; any request to /openmrs/spa is forwarded to the frontend container and any request for a URL in the frontend container that does not otherwise resolve to something serves the single-page content).

i have created a thread for how to move forward because we cant limit this feature to working only in the openmrs-sdk environment.

config.json file name shouldn't be dynamic

dynamically serve 'frontend/config.json' endpoint

remove unrequited change
@jnsereko
Copy link
Author

jnsereko commented Jun 12, 2023

thanks to @dkayiwa, i dynamically defined a servlet to expose an end-point openmrs/ws/frontend/config.json rather than using openmrs/spa/config.json where the request does not reach the backend in the docker environment.

This works fine in both openmrs-sdk and openmrs-docker environment

@jnsereko
Copy link
Author

jnsereko commented Jun 26, 2023

@dkayiwa @ibacher the frontend implementation has been approved see openmrs/openmrs-esm-core#629 (review)

public void setServletContext(ServletContext servletContext) {

try {
ServletRegistration openmrsServletReg = servletContext.getServletRegistration("openmrs");
Copy link
Member

Choose a reason for hiding this comment

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

What is this mapping used for?

Copy link
Author

Choose a reason for hiding this comment

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

I thought we need to ensure that any mapping is supposed to be on top of the OpenMRS servlet. just to eliminate circumstances like https:localhost:port/ws/frontend/config.json

Copy link
Member

Choose a reason for hiding this comment

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

What happens when you remove line 32?

Copy link
Author

@jnsereko jnsereko Jun 26, 2023

Choose a reason for hiding this comment

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

If servletContext.getServletRegistration("openmrs"); isn't necessary @dkayiwa, how can i add mappings to the Openmrs Servlet then?

Copy link
Member

Choose a reason for hiding this comment

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

What happens when you remove line 32?

Copy link
Author

Choose a reason for hiding this comment

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

works fine.

@jnsereko jnsereko requested a review from dkayiwa June 28, 2023 04:54
String basicAuth = request.getHeader("Authorization");
if (basicAuth != null) {
// check that header is in format "Basic ${base64encode(username + ":" + password)}"
if (isValidAuthFormat(response, basicAuth)) return;
Copy link
Member

Choose a reason for hiding this comment

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

ServletRegistration servletReg = servletContext.addServlet("spaServlet", new SpaServlet());
servletReg.addMapping("/ws/frontend/config.json");

Dynamic filter = servletContext.addFilter("spaFilter", new SpaFilter());
Copy link
Member

Choose a reason for hiding this comment

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

Is the SpaFilter part of this ticket?

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String requestURI = request.getRequestURI();
if (requestURI.endsWith("/config.json")) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you reduce the deep nesting of these if statements?

@brandones
Copy link
Contributor

@jnsereko Do you still have bandwidth to work on this? Could you please work with @dkayiwa to get it across the finish line? It's soooooo close!!

@dkayiwa
Copy link
Member

dkayiwa commented Dec 28, 2023

I completely agree! 👍

@jnsereko
Copy link
Author

jnsereko commented Dec 28, 2023

updating it now

@dkayiwa
Copy link
Member

dkayiwa commented Dec 28, 2023

Is this functionality going to be only for those who are not using the docker setup of O3 (Because it does not load the spa module)

@jnsereko
Copy link
Author

Is this functionality going to be only for those who are not using the docker setup of O3 (Because it does not load the spa module)

We can add the module to distro if we choose to. I can do that with your permission

@dkayiwa
Copy link
Member

dkayiwa commented Dec 28, 2023

I do not think that would be the best option. One other option is adding this to the rest webservices module. This calls for some sort of discussion on talk.

@jnsereko
Copy link
Author

I do not think that would be the best option. One other option is adding this to the rest webservices module. This calls for some sort of discussion on talk.

I have created a thread: https://talk.openmrs.org/t/adding-openmrs-spa-module-to-dev3-vs-migrating-some-of-its-logic-to-rest-webservices/41250

@jnsereko
Copy link
Author

jnsereko commented Jan 3, 2024

@dkayiwa PR created in Rest web services repo openmrs/openmrs-module-webservices.rest#595

@dkayiwa dkayiwa closed this Jan 3, 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
Development

Successfully merging this pull request may close these issues.

4 participants