GSoC 2018 - OAuth Module Enhancements And SMART Apps Support Project

gsoc2018
Tags: #<Tag:0x00007f88c943ab30>

(Prabodh Kotasthane) #21

I have also seen that here also we are autowiring. But this throws no exception. Why?


(Prabodh Kotasthane) #22

And even I have tried autowiring other DAOs in multiple files and use them. That also results in no Exception. :confused:


(Sanatt Abrol) #23

I think this has to do with the classes being in different packages. Try moving the smart classes to the previous package.


(Prabodh Kotasthane) #24

I tried with autowiring the DAOs in other packages too like UserCredentialsDAO. Still no NullPointerException


(Sanatt Abrol) #25

UserCredentialsDAO is in org.openmrs.module.oauth2.api.* and Smart classes in org.openmrs.module.smart.*


(Prabodh Kotasthane) #26

Yeah UserCredentialsDAO is in same package as the ClientsDAO. So if it has something with different packages then this was all in all a same case. :confused:


(Sanatt Abrol) #27

Let me pull your code and see


(Prabodh Kotasthane) #28

Sure. You think this fix is fine? I mean everything seems to work fine after this fix. :slight_smile:


(Sanatt Abrol) #29

In your code SmartClasses are under “oauth2.api” and not “smart” https://github.com/PKatGITHUB/openmrs-module-oauth2/tree/gsoc-18/api/src/main/java/org/openmrs/module

Where is the code giving you the error?


(Sanatt Abrol) #30

@pkatopenmrs I saw your code, what you didn’t specify earlier was that NullPointerException was thrown on Hibernate saveOrUpdate() methods. I thought you were talking about bean errors


(Prabodh Kotasthane) #31

They are under oauth2.api.smart right?


(Prabodh Kotasthane) #32

Yeah… the hibernate methods. :confused:


(Sanatt Abrol) #33

You should have mentioned that earlier. ClientDAO autowiring works well. What’s giving the NullPointerException is session.getCurrentSession()


(Prabodh Kotasthane) #34

Is this because these methods are getting null parameters? If yes then isn’t it the same problem of null beans?


(Sanatt Abrol) #35

No. Look at https://github.com/PKatGITHUB/openmrs-module-oauth2/blob/07627d8f4b270b23016b4652a2b28e149ef40683/api/src/main/resources/moduleApplicationContext.xml#L24.

“sessionFactory” under property target of Transaction manager is referring to HibernateOAuth2DAO

and you are using the same sessionFactory here(https://github.com/PKatGITHUB/openmrs-module-oauth2/blob/07627d8f4b270b23016b4652a2b28e149ef40683/api/src/main/java/org/openmrs/module/oauth2/api/smart/db/hibernate/HibernateSmartDAO.java#L34).

That’s why sessionFactory.getCurrentSession() is not working in HibernateOAuth2DAO


(Sanatt Abrol) #36

So when you explicitly override the default configuration of “target” in transactionManager, that solves the error as it keeps from nulling the session.


(Sanatt Abrol) #37

It was always a problem of ill-defined HibernateConfiguration and nothing concerning to Autowiring


(Prabodh Kotasthane) #38

Yep i got you. But still

this sessionFactory is explicitly defined for the DAO object “dao” used in Oauth2ServiceImpl. All the other sessionFactory are autowired.

As you see here :

the sessionFactory is autowired. So this : https://github.com/PKatGITHUB/openmrs-module-oauth2/blob/07627d8f4b270b23016b4652a2b28e149ef40683/api/src/main/java/org/openmrs/module/oauth2/api/smart/db/hibernate/HibernateSmartDAO.java#L34 sessionFactory is different from this : https://github.com/PKatGITHUB/openmrs-module-oauth2/blob/07627d8f4b270b23016b4652a2b28e149ef40683/api/src/main/java/org/openmrs/module/oauth2/api/db/hibernate/HibernateOauth2DAO.java#L33 one right??


(Sanatt Abrol) #39

Exactly what I am saying. sessionFactory works that way. See this (https://github.com/PKatGITHUB/openmrs-module-oauth2/blob/07627d8f4b270b23016b4652a2b28e149ef40683/api/src/main/resources/moduleApplicationContext.xml#L10). This is Context.getService() definitions.

Now, if you change this to “dao” instead of "clientDAO"you’ll get the same error as before. This was the error all along as Context.getService() definition were being ambiguous with @Autowire of sessionFactory that we use throughout


(Sanatt Abrol) #40

You can’t understand what I am saying? Remove these lines from the configuration XML. Now, you’ll see that clientRegistrationService tests run fine and smartManagementService tests fail giving NullPointerException