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

Prov 103 [issue](https://issues.openmrs.org/browse/PROV-103) #45

Merged
merged 32 commits into from
Nov 8, 2023
Merged

Prov 103 [issue](https://issues.openmrs.org/browse/PROV-103) #45

merged 32 commits into from
Nov 8, 2023

Conversation

josephbate
Copy link
Contributor

@josephbate josephbate commented Nov 15, 2022

Issue in Question

(link:https://issues.openmrs.org/browse/PROV-103?src=confmacro)

getting Errors in deploying the module

i made changes in the omod config.xml however i didnt see the changes when i deployed my omod file in the server, i keted on getting the same error
so used print statements to check if the omad file was picked up but that didn't reflect in my logs

i release there was a worning of my server configuration not existing when i selected the providerSearch option
WARN - OpenmrsUtil.getDirectoryInApplicationDataDirectory(1155) |2022-11-14 18:17:07,548| 'C:\Users\toshiba\openmrs\server2\configuration' doesn't exist. Creating directories now.

i assume in some way the omod file is not detected by the server or there is something i missed
@dkayiwa @mozzy11 @ibacher @gitcliff

@josephbate
Copy link
Contributor Author

josephbate commented Nov 18, 2022

#37
everyone
i managed to get the sdk working fine however using conditional resourcing didn't really solve the ticket so i decided to follow @dkayiwa suggestion on talk of using java reflection to load the class
i been trying to find a way to use the this method but could not get how to call the loaded class constructor in the model.addAttribute()

been trying out mostof the methods to see if i can use the object togetInstance()constructor into the model.AddAttribute() but i get method undefined in the type class error

heres the ticket in question PROV-103

please let me know if there's something am missing or any other step i can make to solve this ticket
@mozzy11 @dkayiwa @gitcliff @ibacher

@dkayiwa
Copy link
Member

dkayiwa commented Nov 22, 2022

@josephbate can you include a link to the JIRA ticket as advised at? https://wiki.openmrs.org/display/docs/Pull+Request+Tips

@josephbate
Copy link
Contributor Author

@josephbate can you include a link to the JIRA ticket as advised at? https://wiki.openmrs.org/display/docs/Pull+Request+Tips

okay let me do that quickly

@josephbate
Copy link
Contributor Author

sorry for the delay i had power issues but i have edited the post @dkayiwa

@josephbate josephbate closed this Nov 28, 2022
@josephbate josephbate reopened this Nov 28, 2022
@josephbate
Copy link
Contributor Author

here are my changes so far PROV-103
@dkayiwa @mozzy11

@josephbate
Copy link
Contributor Author

heres the ticket in question PROV-103
i had edited the first comment and included the link

please let me know if you see it

@gitcliff
Copy link

gitcliff commented Dec 1, 2022

heres the ticket in question PROV-103 i had edited the first comment and included the link

please let me know if you see it

@josephbate could you add it above in the description like here

@mozzy11
Copy link
Member

mozzy11 commented Jan 30, 2023

Thanks @josephbate .
have you tested your changes locally ??
you also need to provide a more meaningful commit message to reflect what you have done

@josephbate josephbate changed the title Prov 103 Prov 103:https://issues.openmrs.org/browse/PROV-103 Jan 30, 2023
@josephbate josephbate changed the title Prov 103:https://issues.openmrs.org/browse/PROV-103 Prov 103: https://issues.openmrs.org/browse/PROV-103 Jan 30, 2023
@josephbate josephbate changed the title Prov 103: https://issues.openmrs.org/browse/PROV-103 Prov 103 #https://issues.openmrs.org/browse/PROV-103 Jan 30, 2023
@josephbate
Copy link
Contributor Author

josephbate commented Jan 31, 2023

hello everyone
@mozzy11;
yes i tested it and i kept on geting them same errors and veiw exception
there are two method in the NameSupport class that's getInstance() and
getDefaultLayoutFormat()

**My finding currently working on #37 **

  1. now i understand i must somehow replicate the NameSupport.getInstance().getDefaultLayoutTemplate() syntax with the class i loaded via reflection but in my effort at the moment its close to impossible, i keep on getting illegalLanguage Exceptions and syntax errors
  2. invoking the methods via reflection stills does no good
  3. there is one approach i also tried out, of using the java new instance method to achieve the above call, below the are code snippets

`try {
Class<?> cls = Class.forName("org.openmrs.layout.name.NameSupport");

		Object obj = cls.newInstance();

                    NameSupport ns;
                    if (obj instanceof NameSupport){
                              ns = (NameSupport)obj;
                    } else {
                              return
                    }

		System.out.println(
				"8###################******************does this work******************######################## "
						+ ns.getInstance().getDefaultLayoutTemplate());

		model.addAttribute("layoutTemplate", ns.getInstance().getDefaultLayoutTemplate());
	} catch (Throwable e) {
		e.printStackTrace();
	}
	
}`

the problem with this approach without using the imported NameSuport class it cannot work, so that means the new version of that class when loaded cannot override the imported because casting the class in the new stance object makes it override it hence giving the same exception

so with that i am asking for assistance on this @dkayiwa @mozzy11
please let me know if there is something i missed or maybe i didn't understance because i am running out of ideas

@ibacher
Copy link
Member

ibacher commented Jan 31, 2023

It would probably be better to do this with MethodHandles, but (without any error handling):

Class<?> cls = Class.forName("org.openmrs.layout.name.NameSupport");
Method getInstance = cls.getMethod("getInstance");
Object instance = getInstance.invoke(null);
Method getDefaultLayoutTemplate = cls.getDeclaredMethod("getDefaultLayoutTemplate");
Object layoutTemplate = getDefaultLayoutTemplate.invoke(instance);

@josephbate josephbate changed the title Prov 103 #https://issues.openmrs.org/browse/PROV-103 Prov 103 [issue](https://issues.openmrs.org/browse/PROV-103) Jan 31, 2023
@josephbate
Copy link
Contributor Author

It would probably be better to do this with MethodHandles, but (without any error handling):

Class<?> cls = Class.forName("org.openmrs.layout.name.NameSupport");
Method getInstance = cls.getMethod("getInstance");
Object instance = getInstance.invoke(null);
Method getDefaultLayoutTemplate = cls.getDeclaredMethod("getDefaultLayoutTemplate");
Object layoutTemplate = getDefaultLayoutTemplate.invoke(instance);

thank you @ibacher
oooh, it being a static method it invokes no arguments
i really didnt think of that plus i didnt know that "getDefaultLayoutTemplate" could be called by the same class object
"Its an inherited method", my word!
this is an eye opener
let me try it out

@josephbate
Copy link
Contributor Author

hello everyone
i finally solved the bug,

My finding as of #37

  1. the code snippet @ibacher suggected was an eye opener, however using it made get noSuchMethod exception whilst trying to invoke getDefaultLayoutTemplate()
  2. to solve it i also loaded the org.openmrs.layout.LayoutSupport so as to access and when i ran the sdk and test the module the error disapeared

thank you so much guys @dkayiwa @gitcliff @mozzy11 @ibacher

my issue is ready for review


public void controller(FragmentModel model) throws ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {

Class<?> cls1 = Class.forName("org.openmrs.layout.LayoutSupport");
Copy link
Member

@mozzy11 mozzy11 Feb 6, 2023

Choose a reason for hiding this comment

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

Thanks @josephbate .
can you make this backward compatible , this should only run conditionally in the higher OpenMRS version where we have this change in the class location ,or else we should directly import the class in the older versions of OpenMRS

@@ -14,13 +14,35 @@

package org.openmrs.module.providermanagement.fragment.controller;

import org.openmrs.layout.web.name.NameSupport;
import java.lang.reflect.*;
Copy link
Member

Choose a reason for hiding this comment

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

@mozzy11
Copy link
Member

mozzy11 commented Feb 6, 2023

@mozzy11
Copy link
Member

mozzy11 commented Feb 8, 2023

@josephbate , you can use this constant to check the running Openmrs version
an example of where its used .

@ezef
Copy link

ezef commented Oct 13, 2023

Hi Everyone, there is something that is holding this PR to be merged?

@gracepotma gracepotma requested review from ibacher and dkayiwa October 13, 2023 17:49
}


/**
Copy link
Member

Choose a reason for hiding this comment

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

If we're going to include Javadocs, they should actually provide some information.

* @throws IllegalAccessException
*/

public void controller(FragmentModel model) throws ClassNotFoundException, NoSuchMethodException, SecurityException,
Copy link
Member

Choose a reason for hiding this comment

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

I think at this point, its just easier to say throws Exception, no?

Copy link
Member

Choose a reason for hiding this comment

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

Also, is there nothing we can do here to recover from these exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you have any suggestions @ibacher

/*
* backward compatibility
*/
Class<?> nameSurpport;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Class<?> nameSurpport;
Class<?> nameSupport;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hello @ibacher thank you for pointing them out let me try to solve them

@josephbate
Copy link
Contributor Author

Hello @ibacher i think i i have resolved some of the problems you pointed out

api/pom.xml Outdated
@@ -4,7 +4,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>providermanagement</artifactId>
<version>2.14.0-SNAPSHOT</version>
<version>2.15.0-SNAPSHOT</version>
Copy link
Member

Choose a reason for hiding this comment

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

I would not expect version changes to be part of this pull request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would not expect version changes to be part of this pull request.

it think the verion i forked is base on 2.15.0- snapshot

Copy link
Member

Choose a reason for hiding this comment

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

Check what the current upstream version is.


/*
* backward compatibility
* dynamic class loading and reflection to interact with classes that provide layout templates for perso names in the system, allowing for flexibility and extensibility in managing name layouts.
Copy link
Member

Choose a reason for hiding this comment

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

I do not see value added by this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hello @dkayiwa i have made some changes please find them in the commit below

@dkayiwa
Copy link
Member

dkayiwa commented Nov 2, 2023

@josephbate did you address my comment about the version change?

@josephbate
Copy link
Contributor Author

@josephbate did you address my comment about the version change?

done! @dkayiwa

@dkayiwa
Copy link
Member

dkayiwa commented Nov 2, 2023

Can you fix the build errors?

pom.xml Outdated
@@ -4,7 +4,7 @@

<groupId>org.openmrs.module</groupId>
<artifactId>providermanagement</artifactId>
<version>2.14.0-SNAPSHOT</version>
<version>2.15.0-SNAPSHOT</version>
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 version change for?

omod/pom.xml Outdated
@@ -4,7 +4,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>providermanagement</artifactId>
<version>2.14.0-SNAPSHOT</version>
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 version change for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#45 (comment)

i was reacting to this comment, and was restoring the prevoius version before my commits
intially i had som build failures thats why i made switch

@josephbate
Copy link
Contributor Author

i think everything works fine!
@dkayiwa

@dkayiwa
Copy link
Member

dkayiwa commented Nov 2, 2023

Can you look at these build failures?

@dkayiwa
Copy link
Member

dkayiwa commented Nov 2, 2023

And also fix the build failures.

@dkayiwa dkayiwa merged commit 8ee4396 into openmrs:master Nov 8, 2023
1 check passed
dkayiwa added a commit that referenced this pull request Nov 8, 2023
dkayiwa added a commit that referenced this pull request Nov 8, 2023
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.

7 participants