Hi family, The add-on manager OWA which is a refresh of the Open Web App Management Module is almost done. We have so far implemented features to upload, search, list and delete Open Web Apps and looking forward to more improvements to the OWA as my team’s stay at OpenMRS elapses. However, we added a new feature to search for OWAs online via the openmrs add-on index and install them. The online search feature has been successfully implemented but the installation feature after an OWA is retrieved from the add-on index is what is yet to be completed. The reason for the delay in the install feature completion is due to CORS blocker that we have. The feature works in a way that a user searches for the module and directly installs it if it is not available. The installation process includes retrieving the OWA from whatever site it is being hosted at e.g bintray. We welcome any suggestions and approaches towards the problem at hand or yet better ways to install OWAs after a successful online search. cc: @suthagar23 @dkayiwa @kingisaac95 @jeiddiah @millicent
@suthagar23 do you wanna share how you approached this when doing the system admin app?
@dkayiwa Sure, I will share that after look at this code base
Here I also faced same CORS situation while working with SysAdmin OWA. I contacted Bintary support team for this problem, they informed me that they will work on this browser based CORS problem at the end of the year.
Another solution for this problem is, Using JSONP instead of JSON calls. Anyway this also did not work for at that time for the Bintary.
For the immediate solution, Do not call the Bintary REST end point from the broswer(using JS - React or Angular). Just do the Bintary side REST request from the server(Inside the OpenMRS server). Then you can successfully download the package from the bintary without any issues
Cc : @dkayiwa
@suthagar23 I successfully download the package but this was after I got a chrome extension to curb the CORS issue ( not scaleable) but on upload of the package the response I get from the server is that the App is not a zip archive. Although I used promises to get the zip and send it as part of the body for a POST request to install the app. Would you please shed more light on this: [quote=“suthagar23, post:4, topic:13616”] Just do the Bintary side REST request from the server(Inside the OpenMRS server). Then you can successfully download the package from the bintary without any issues [/quote]
First, you can’t depend on the Chrome Extension for the CORS issue . That’s only for the developers, not for the users. How can you ensure that the user alreadty installed this extension to avoid the CORS in their browser level? They may use some other browsers, then they can’t download the module from the browser level. So best way is, avoid the chrome extension and implement this function in the server level.
For the module upload, you should create a FormData including that Zip as file type. Please find the
uploadModule method from here,
@suthagar23 Okay. I will be reaching out soon enough.
I just prepared a workflow for this access. You need to accesss Bintary API from the Server Side.
This is some resource for your help,
Please find the UpdateModule method to get more information (You need to add some extra functions to achieve this task, please find the methods inside the Module Directory) , https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/module/ModuleFactory.java
// URL : download file URL InputStream inputStream = ModuleUtil.getURLStream(url); String filename = url.getPath().substring(url.getPath().lastIndexOf("/")); File moduleFile = ModuleUtil.insertModuleFile(inputStream, filename);
insertModuleFile()from this ModuleUtil file, https://github.com/openmrs/openmrs-core/blob/master/api/src/main/java/org/openmrs/module/ModuleUtil.java
Follow this Module Code base to get some related function to achieve this task, https://github.com/openmrs/openmrs-core/tree/master/api/src/main/java/org/openmrs/module