MauroDataMapper-Plugins / mdm-plugin-database-sqlserver

Apache License 2.0
2 stars 1 forks source link

Enumeration detection fails without maximum enumerations value set #16

Closed joe-crawford closed 1 year ago

joe-crawford commented 2 years ago

Using develop of mdm-application-build with 8.1.0-SNAPSHOT of mdm-plugin-database-sqlserver, when an import is submitted using the SQL Server importer, and the 'Detect Enumerations' option is ticked, but the 'Maximum Enumerations' value is left blank, the import fails with the following error message:

Server Error

We're sorry, but the server responded with an error message.

Details

{
  "headers": {
    "normalizedNames": {},
    "lazyUpdate": null
  },
  "status": 500,
  "statusText": "OK",
  "url": "http://localhost:8080/api/dataModels/import/uk.ac.ox.softeng.maurodatamapper.plugins.database.sqlserver/SqlServerDatabaseDataModelImporterProviderService/8.1.0-SNAPSHOT",
  "ok": false,
  "name": "HttpErrorResponse",
  "message": "Http failure response for http://localhost:8080/api/dataModels/import/uk.ac.ox.softeng.maurodatamapper.plugins.database.sqlserver/SqlServerDatabaseDataModelImporterProviderService/8.1.0-SNAPSHOT: 500 OK",
  "error": {
    "status": 500,
    "reason": "Internal Server Error",
    "errorCode": "UEX--",
    "message": "Cannot execute null+1",
    "path": "/api/dataModels/import/uk.ac.ox.softeng.maurodatamapper.plugins.database.sqlserver/SqlServerDatabaseDataModelImporterProviderService/8.1.0-SNAPSHOT",
    "environment": "DEVELOPMENT",
    "version": "5.2.0-SNAPSHOT",
    "exception": {
      "type": "NullPointerException",
      "message": "Cannot execute null+1",
      "stacktrace": [
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.sqlserver.query.SqlServerQueryStringProvider.distinctColumnValuesQueryString(SqlServerQueryStringProvider.groovy:118)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.AbstractDatabaseDataModelImporterProviderService.getDistinctColumnValues(AbstractDatabaseDataModelImporterProviderService.groovy:661)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.AbstractDatabaseDataModelImporterProviderService.detectEnumerationsForDataElement(AbstractDatabaseDataModelImporterProviderService.groovy:367)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.AbstractDatabaseDataModelImporterProviderService$_calculateEnumerationsAndSummaryMetadata_closure4.doCall(AbstractDatabaseDataModelImporterProviderService.groovy:335)",
        "jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)",
        "jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.AbstractDatabaseDataModelImporterProviderService.calculateEnumerationsAndSummaryMetadata(AbstractDatabaseDataModelImporterProviderService.groovy:329)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.AbstractDatabaseDataModelImporterProviderService$_updateDataModelWithEnumerationsAndSummaryMetadata_closure3$_closure29.doCall(AbstractDatabaseDataModelImporterProviderService.groovy:296)",
        "jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)",
        "jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.AbstractDatabaseDataModelImporterProviderService$_updateDataModelWithEnumerationsAndSummaryMetadata_closure3.doCall(AbstractDatabaseDataModelImporterProviderService.groovy:286)",
        "jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)",
        "jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.AbstractDatabaseDataModelImporterProviderService.updateDataModelWithEnumerationsAndSummaryMetadata(AbstractDatabaseDataModelImporterProviderService.groovy:285)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.AbstractDatabaseDataModelImporterProviderService.importAndUpdateDataModelsFromResults(AbstractDatabaseDataModelImporterProviderService.groovy:229)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.sqlserver.SqlServerDatabaseDataModelImporterProviderService.importAndUpdateDataModelsFromResults(SqlServerDatabaseDataModelImporterProviderService.groovy:120)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.AbstractDatabaseDataModelImporterProviderService.importDataModelsFromParameters(AbstractDatabaseDataModelImporterProviderService.groovy:212)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.AbstractDatabaseDataModelImporterProviderService$_importModels_closure1.doCall(AbstractDatabaseDataModelImporterProviderService.groovy:138)",
        "jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)",
        "jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
        "uk.ac.ox.softeng.maurodatamapper.plugins.database.AbstractDatabaseDataModelImporterProviderService.importModels(AbstractDatabaseDataModelImporterProviderService.groovy:137)",
        "uk.ac.ox.softeng.maurodatamapper.core.provider.importer.ModelImporterProviderService.importDomains(ModelImporterProviderService.groovy:53)",
        "uk.ac.ox.softeng.maurodatamapper.core.importer.ImporterService.importDomains(ImporterService.groovy:66)",
        "uk.ac.ox.softeng.maurodatamapper.core.controller.ModelController.$tt__importModels(ModelController.groovy:715)",
        "jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)",
        "jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
        "jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)",
        "jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
        "grails.gorm.transactions.GrailsTransactionTemplate$2.doInTransaction(GrailsTransactionTemplate.groovy:94)",
        "org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)",
        "grails.gorm.transactions.GrailsTransactionTemplate.execute(GrailsTransactionTemplate.groovy:91)",
        "jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)",
        "jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
        "org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:211)",
        "org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:188)",
        "org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)",
        "org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)",
        "org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)",
        "org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)",
        "org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)",
        "org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)",
        "org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)",
        "org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)",
        "java.lang.Thread.run(Thread.java:833)"
      ]
    }
  }
}

The import succeeds when a maximum enumerations value is set.

Expected behaviour

The detect enumerations option should use a default maximum enumerations value if none is set. Also the default should be displayed via the UI in the description field.

Other details

Import tested against the metadata_simple database created with the test script in this repository, and a SQL server container created with

docker run --rm -d \
 -e 'ACCEPT_EULA=Y' \
 -e 'SA_PASSWORD=yourStrong(!)Password' \
 -p 1433:1433 \
 --name sqlserver2019 \
 mcr.microsoft.com/mssql/server:2019-latest