Metadata Sharing Module
  1. Metadata Sharing Module
  2. META-227

Starting in OpenMRS 1.9 you are not allowed to modify ConceptDatatypes, so we need to stop exporting/importing them

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Must Must
    • Resolution: Fixed
    • Affects Version/s: 1.0.7
    • Fix Version/s: 1.0.8
    • Component/s: None
    • Labels:
      None
    • Complexity:
      Medium

      Description

      Starting in OpenMRS 1.9 we no longer allow saveConceptDatatype, which leads to this exception when you try to import a MDS package containing one:

      ...
      Caused by: org.openmrs.api.db.DAOException: Error saving org.openmrs.ConceptDatatype_$$_javassist_65 [8d4a4488-c2cc-11de-8d13-0010c6dffd0f]
      	at org.openmrs.module.metadatasharing.handler.impl.OpenmrsObjectHandler.saveItem(OpenmrsObjectHandler.java:110)
      	at org.openmrs.module.metadatasharing.handler.impl.OpenmrsObjectHandler.saveItem(OpenmrsObjectHandler.java:33)
      	at org.openmrs.module.metadatasharing.handler.Handler.saveItem(Handler.java:38)
      	at org.openmrs.module.metadatasharing.task.impl.ImportPackageTask.saveItem(ImportPackageTask.java:317)
      	at org.openmrs.module.metadatasharing.task.impl.ImportPackageTask.saveItem(ImportPackageTask.java:312)
      	at org.openmrs.module.metadatasharing.task.impl.ImportPackageTask.saveItem(ImportPackageTask.java:312)
      	at org.openmrs.module.metadatasharing.task.impl.ImportPackageTask.importItems(ImportPackageTask.java:238)
      	at org.openmrs.module.metadatasharing.task.impl.ImportPackageTask.execute(ImportPackageTask.java:88)
      	... 46 more
      Caused by: org.openmrs.api.APIException: Cannot save org.openmrs.ConceptDatatype[8d4a4488-c2cc-11de-8d13-0010c6dffd0f]. Failed with the following exception:
      
      java.lang.reflect.InvocationTargetException
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.openmrs.module.metadatasharing.reflection.OpenmrsClassScanner.invokeServiceSaveItem(OpenmrsClassScanner.java:254)
      	at org.openmrs.module.metadatasharing.reflection.OpenmrsClassScanner.serviceSaveItem(OpenmrsClassScanner.java:174)
      	at org.openmrs.module.metadatasharing.handler.impl.OpenmrsObjectHandler.saveItem(OpenmrsObjectHandler.java:107)
      	at org.openmrs.module.metadatasharing.handler.impl.OpenmrsObjectHandler.saveItem(OpenmrsObjectHandler.java:33)
      	at org.openmrs.module.metadatasharing.handler.Handler.saveItem(Handler.java:38)
      	at org.openmrs.module.metadatasharing.task.impl.ImportPackageTask.saveItem(ImportPackageTask.java:317)
      	at org.openmrs.module.metadatasharing.task.impl.ImportPackageTask.saveItem(ImportPackageTask.java:312)
      	at org.openmrs.module.metadatasharing.task.impl.ImportPackageTask.saveItem(ImportPackageTask.java:312)
      	at org.openmrs.module.metadatasharing.task.impl.ImportPackageTask.importItems(ImportPackageTask.java:238)
      	at org.openmrs.module.metadatasharing.task.impl.ImportPackageTask.execute(ImportPackageTask.java:88)
      	at org.openmrs.module.metadatasharing.api.impl.MetadataSharingServiceImpl$1.task(MetadataSharingServiceImpl.java:203)
      	at org.openmrs.module.metadatasharing.api.db.hibernate.CustomSessionFlushTask.executeInManualFlushMode(CustomSessionFlushTask.java:59)
      	at org.openmrs.module.metadatasharing.api.impl.MetadataSharingServiceImpl.executeTask(MetadataSharingServiceImpl.java:199)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      	at $Proxy171.executeTask(Unknown Source)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:122)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      	at $Proxy172.executeTask(Unknown Source)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      	at $Proxy172.executeTask(Unknown Source)
      	at org.openmrs.module.metadatasharing.task.TaskEngine$RunnableTask.run(TaskEngine.java:124)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      	at java.lang.Thread.run(Thread.java:680)
      Caused by: org.apache.commons.lang.NotImplementedException: Code is not implemented
      	at org.openmrs.api.impl.ConceptServiceImpl.saveConceptDatatype(ConceptServiceImpl.java:807)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      	at $Proxy128.saveConceptDatatype(Unknown Source)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:122)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      	at $Proxy129.saveConceptDatatype(Unknown Source)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      	at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:50)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      	at $Proxy129.saveConceptDatatype(Unknown Source)
      	... 60 more
      
      	at org.openmrs.module.metadatasharing.reflection.OpenmrsClassScanner.invokeServiceSaveItem(OpenmrsClassScanner.java:265)
      	at org.openmrs.module.metadatasharing.reflection.OpenmrsClassScanner.serviceSaveItem(OpenmrsClassScanner.java:174)
      	at org.openmrs.module.metadatasharing.handler.impl.OpenmrsObjectHandler.saveItem(OpenmrsObjectHandler.java:107)
      	... 53 more
      

      We definitely need to avoid calling this method.

      We should probably also avoid exporting ConceptDatatype in packages.

      And we should probably prevent the user from choosing to include them in a package in the UI.

      @Rafal, waiting for your suggestion about the best way to handle this.

        Gliffy Diagrams

          Activity

          Hide
          Darius Jazayeri added a comment -

          This is a temporary workaround:

          diff --git a/api/src/main/java/org/openmrs/module/metadatasharing/reflection/OpenmrsClassScanner.java b/api/src/main/java/org/openmrs/module/metadatasharing/reflection/OpenmrsClassScanner.java
          index b7790b1..44127a8 100644
          --- a/api/src/main/java/org/openmrs/module/metadatasharing/reflection/OpenmrsClassScanner.java
          +++ b/api/src/main/java/org/openmrs/module/metadatasharing/reflection/OpenmrsClassScanner.java
          @@ -26,6 +26,7 @@
           import org.apache.commons.lang.exception.ExceptionUtils;
           import org.apache.commons.logging.Log;
           import org.apache.commons.logging.LogFactory;
          +import org.openmrs.ConceptDatatype;
           import org.openmrs.OpenmrsMetadata;
           import org.openmrs.PersonAttributeType;
           import org.openmrs.RelationshipType;
          @@ -35,6 +36,7 @@
           import org.openmrs.api.context.Context;
           import org.openmrs.module.metadatasharing.MetadataSharingConsts;
           import org.openmrs.util.OpenmrsClassLoader;
          +import org.openmrs.util.OpenmrsConstants;
           import org.springframework.core.io.Resource;
           import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
           import org.springframework.core.io.support.ResourcePatternResolver;
          @@ -220,6 +222,13 @@
           	}
           	
           	protected <T> T invokeServiceSaveItem(T item) throws APIException {
          +		// Starting in OpenMRS 1.9 we are not allowed to modify ConceptDatatype
          +		if ((OpenmrsConstants.OPENMRS_VERSION_SHORT.startsWith("1.9.") ||
          +				OpenmrsConstants.OPENMRS_VERSION_SHORT.startsWith("1.10.")) &&
          +				item instanceof ConceptDatatype) {
          +			return item;
          +		}
          +		
           		ClassMethod<OpenmrsService> classMethod = serviceSaveMethodsCache.get(item.getClass());
           		if (classMethod == null) {
           			classMethod = serviceSaveMethodsCache.get(item.getClass().getSuperclass());
          
          Show
          Darius Jazayeri added a comment - This is a temporary workaround: diff --git a/api/src/main/java/org/openmrs/module/metadatasharing/reflection/OpenmrsClassScanner.java b/api/src/main/java/org/openmrs/module/metadatasharing/reflection/OpenmrsClassScanner.java index b7790b1..44127a8 100644 --- a/api/src/main/java/org/openmrs/module/metadatasharing/reflection/OpenmrsClassScanner.java +++ b/api/src/main/java/org/openmrs/module/metadatasharing/reflection/OpenmrsClassScanner.java @@ -26,6 +26,7 @@ import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.openmrs.ConceptDatatype; import org.openmrs.OpenmrsMetadata; import org.openmrs.PersonAttributeType; import org.openmrs.RelationshipType; @@ -35,6 +36,7 @@ import org.openmrs.api.context.Context; import org.openmrs.module.metadatasharing.MetadataSharingConsts; import org.openmrs.util.OpenmrsClassLoader; + import org.openmrs.util.OpenmrsConstants; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; @@ -220,6 +222,13 @@ } protected <T> T invokeServiceSaveItem(T item) throws APIException { + // Starting in OpenMRS 1.9 we are not allowed to modify ConceptDatatype + if ((OpenmrsConstants.OPENMRS_VERSION_SHORT.startsWith( "1.9." ) || + OpenmrsConstants.OPENMRS_VERSION_SHORT.startsWith( "1.10." )) && + item instanceof ConceptDatatype) { + return item; + } + ClassMethod<OpenmrsService> classMethod = serviceSaveMethodsCache.get(item.getClass()); if (classMethod == null ) { classMethod = serviceSaveMethodsCache.get(item.getClass().getSuperclass());
          Hide
          Rafal Korytkowski added a comment - - edited

          We need to modify OpenmrsClassScanner to filter out classes based on the OpenMRS version. It should both hide them from export and import. The filter needs to be applied in initServiceSaveMethodsCache and getOpenmrsMetadataClasses.

          Show
          Rafal Korytkowski added a comment - - edited We need to modify OpenmrsClassScanner to filter out classes based on the OpenMRS version. It should both hide them from export and import. The filter needs to be applied in initServiceSaveMethodsCache and getOpenmrsMetadataClasses.
          Hide
          Darius Jazayeri added a comment -
          Show
          Darius Jazayeri added a comment - Pull request at https://github.com/OpenMRS/openmrs-module-metadatasharing/pull/3

            People

            • Assignee:
              Darius Jazayeri
              Reporter:
              Darius Jazayeri
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development