diff --git a/ModelCatalogueCorePlugin/grails-app/domain/org/modelcatalogue/core/dataarchitect/ImportRow.groovy b/ModelCatalogueCorePlugin/grails-app/domain/org/modelcatalogue/core/dataarchitect/ImportRow.groovy index c388591609..4095f047e4 100644 --- a/ModelCatalogueCorePlugin/grails-app/domain/org/modelcatalogue/core/dataarchitect/ImportRow.groovy +++ b/ModelCatalogueCorePlugin/grails-app/domain/org/modelcatalogue/core/dataarchitect/ImportRow.groovy @@ -18,6 +18,7 @@ class ImportRow { String measurementSymbol Map metadata Boolean imported = false + Set rowActions = [] static hasMany = [rowActions: RowAction] diff --git a/ModelCatalogueCorePlugin/grails-app/services/org/modelcatalogue/core/PublishedElementService.groovy b/ModelCatalogueCorePlugin/grails-app/services/org/modelcatalogue/core/PublishedElementService.groovy index 41709ef56d..910e0ab25f 100644 --- a/ModelCatalogueCorePlugin/grails-app/services/org/modelcatalogue/core/PublishedElementService.groovy +++ b/ModelCatalogueCorePlugin/grails-app/services/org/modelcatalogue/core/PublishedElementService.groovy @@ -61,13 +61,13 @@ class PublishedElementService { if(element instanceof DataElement) { if (element.containedIn.size() > 0) { element.containedIn.each { Model model -> - if (model.status != PublishedElementStatus.PENDING && model.status != PublishedElementStatus.UPDATED) { + if (model.status != PublishedElementStatus.DRAFT && model.status != PublishedElementStatus.UPDATED) { Model archivedModel = archiveAndIncreaseVersion(model) archivedModel.removeFromContains(element) archivedModel.addToContains(archived) } - if (model.status == PublishedElementStatus.PENDING) {element.status = PublishedElementStatus.PENDING} + if (model.status == PublishedElementStatus.DRAFT) {element.status = PublishedElementStatus.DRAFT} } element.save() diff --git a/ModelCatalogueCorePlugin/grails-app/services/org/modelcatalogue/core/dataarchitect/DataImportService.groovy b/ModelCatalogueCorePlugin/grails-app/services/org/modelcatalogue/core/dataarchitect/DataImportService.groovy index 9988b273cc..b9f4eb9776 100644 --- a/ModelCatalogueCorePlugin/grails-app/services/org/modelcatalogue/core/dataarchitect/DataImportService.groovy +++ b/ModelCatalogueCorePlugin/grails-app/services/org/modelcatalogue/core/dataarchitect/DataImportService.groovy @@ -217,7 +217,7 @@ class DataImportService { protected Model addModelToImport(DataImport importer, Model model) { if (!importer.models.find{it.id == model.id}) { - if(model.status != PublishedElementStatus.UPDATED){model.status = PublishedElementStatus.PENDING} + if(model.status != PublishedElementStatus.UPDATED){model.status = PublishedElementStatus.DRAFT} model.save() importer.models.add(model) } @@ -351,8 +351,8 @@ class DataImportService { dataElement.status = PublishedElementStatus.UPDATED dataElement.save() dataElement = updateMetadata(metadata, dataElement) - if(model.status!=PublishedElementStatus.UPDATED && model.status!=PublishedElementStatus.PENDING){ - model.status = PublishedElementStatus.PENDING + if(model.status!=PublishedElementStatus.UPDATED && model.status!=PublishedElementStatus.DRAFT){ + model.status = PublishedElementStatus.DRAFT model.save() } } @@ -389,8 +389,8 @@ class DataImportService { } - if(model.status!=PublishedElementStatus.UPDATED && model.status!=PublishedElementStatus.PENDING){ - model.status = PublishedElementStatus.PENDING + if(model.status!=PublishedElementStatus.UPDATED && model.status!=PublishedElementStatus.DRAFT){ + model.status = PublishedElementStatus.DRAFT model.save() } } diff --git a/ModelCatalogueCorePlugin/test/integration/org/modelcatalogue/core/dataarchitect/DataImportServiceSpec.groovy b/ModelCatalogueCorePlugin/test/integration/org/modelcatalogue/core/dataarchitect/DataImportServiceSpec.groovy index 083e950c15..bf2738ca0f 100644 --- a/ModelCatalogueCorePlugin/test/integration/org/modelcatalogue/core/dataarchitect/DataImportServiceSpec.groovy +++ b/ModelCatalogueCorePlugin/test/integration/org/modelcatalogue/core/dataarchitect/DataImportServiceSpec.groovy @@ -1,16 +1,25 @@ package org.modelcatalogue.core.dataarchitect import org.modelcatalogue.core.AbstractIntegrationSpec +import org.modelcatalogue.core.DataElement +import org.modelcatalogue.core.Model import spock.lang.Shared class DataImportServiceSpec extends AbstractIntegrationSpec { - - @Shared dataImportService @Shared - ImportRow validImportRow, validImportRow2, modelOnlyImportRow, invalidImportRow, modelOnlyImportRow2 + def dataImportService + @Shared + ImportRow validImportRow, validImportRow2, modelOnlyImportRow,modelOnlyImportRow2, invalidImportRow + @Shared + def fileName, fileName2, fileName3 + + def setupSpec() { + fileName= "test/integration/resources/DataTemplate.xls" + fileName2= "test/integration/resources/DataTemplateChangeDataItemName.xls" + fileName3= "test/integration/resources/DataTemplateChangeDataItems.xls" dataImportService = new DataImport() loadFixtures() validImportRow = new ImportRow() @@ -72,185 +81,174 @@ class DataImportServiceSpec extends AbstractIntegrationSpec { validImportRow2.conceptualDomainDescription = " the domain of formula one" } + void "Test load spreadsheet twice"() + { + when:"loading the dataElements" + def inputStream = new FileInputStream(fileName) + ExcelLoader parser = new ExcelLoader(inputStream) + def (headers, rows) = parser.parse() + HeadersMap headersMap = new HeadersMap() + headersMap.dataElementCodeRow = "Data Item Unique Code" + headersMap.dataElementNameRow = "Data Item Name" + headersMap.dataElementDescriptionRow = "Data Item Description" + headersMap.dataTypeRow = "Data type" + headersMap.parentModelNameRow = "Parent Model" + headersMap.parentModelCodeRow = "Parent Model Unique Code" + headersMap.containingModelNameRow = "Model" + headersMap.containingModelCodeRow = "Model Unique Code" + headersMap.measurementUnitNameRow = "Measurement Unit" + headersMap.metadataRow = "Metadata" + def importer = dataImportService.importData(headers, rows, "NHIC : TRA", "NHIC : TRA", "NHIC TRA conceptual domain for renal transplantation", headersMap) + dataImportService.resolveAll(importer) + dataImportService.ingestImportQueue(importer) + DataElement de1 = DataElement.findByModelCatalogueId("MC_037e6162-3b6f-4ae2-a171-2470b64dff10_1") + DataElement de2 = DataElement.findByModelCatalogueId("MC_065e6162-3b6f-4ae2-a171-2470b64dff10_1") + DataElement de3 = DataElement.findByModelCatalogueId("MC_067e6162-3b4f-4ae2-a171-2470b64dff10_1") + DataElement de4 = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b64dff10_1") + DataElement de5 = DataElement.findByModelCatalogueId("MC_067e6162-1b6f-4ae2-a171-2470b64dff10_1") + DataElement de6 = DataElement.findByModelCatalogueId("MC_067e6189-3b6f-4ae2-a171-2470b64dff10_1") + DataElement de7 = DataElement.findByModelCatalogueId("MC_067e6232-3b6f-4ae2-a171-2470b64dff10_1") + DataElement de8 = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-4ae7-a171-2470b64dff10_1") + DataElement de9 = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-4ae9-a171-2470b64dff10_1") + DataElement de10 = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-2ae2-a171-2470b64dff10_1") + DataElement de11 = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-9ae2-a181-2470b64dff10_1") + Model admissions = Model.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b63dff00_1") + Model unit = Model.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b64dff19_1") + Model demographics = Model.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b63dff01_1") + then:"the dataElement should have name" + de1 + de2 + de3 + de4 + de5 + de6 + de7 + de8 + de9 + de10 + de11 + admissions + demographics + unit + admissions.parentOf.contains(demographics) + admissions.parentOf.contains(unit) + demographics.contains.contains(de1) + demographics.contains.contains(de1) + demographics.contains.contains(de2) + demographics.contains.contains(de3) + demographics.contains.contains(de4) + demographics.contains.contains(de5) + unit.contains.contains(de6) + unit.contains.contains(de7) + unit.contains.contains(de8) + unit.contains.contains(de9) + unit.contains.contains(de10) + unit.contains.contains(de11) + when: "I load the spreadsheet in again with changes to the first data element name" -// def fileName= "test/integration/resources/DataTemplate.xls" -// def fileName2= "test/integration/resources/DataTemplateChangeDataItemName.xls" -// def fileName3= "test/integration/resources/DataTemplateChangeDataItems.xls" -// def dataImportService, initCatalogueService -// -// def setup(){ -// initCatalogueService.initDefaultRelationshipTypes() -// initCatalogueService.initDefaultMeasurementUnits() -// initCatalogueService.initDefaultDataTypes() -// } + def inputStream2 = new FileInputStream(fileName2) + ExcelLoader parser2 = new ExcelLoader(inputStream2) + (headers, rows) = parser2.parse() + def importer2 = dataImportService.importData(headers, rows, "NHIC : TRA", "NHIC : TRA", "NHIC TRA conceptual domain for renal transplantation", headersMap) + dataImportService.resolveAll(importer2) + dataImportService.ingestImportQueue(importer2) + def de1Old = DataElement.findByModelCatalogueId("MC_037e6162-3b6f-4ae2-a171-2470b64dff10_1") + def demographicsOld = Model.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b63dff01_1") -// void "Test load spreadsheet twice"() -// { -// when:"loading the dataElements" -// def inputStream = new FileInputStream(fileName) -// ExcelLoader parser = new ExcelLoader(inputStream) -// def (headers, rows) = parser.parse() -// -// HeadersMap headersMap = new HeadersMap() -// headersMap.dataElementCodeRow = "Data Item Unique Code" -// headersMap.dataElementNameRow = "Data Item Name" -// headersMap.dataElementDescriptionRow = "Data Item Description" -// headersMap.dataTypeRow = "Data type" -// headersMap.parentModelNameRow = "Parent Model" -// headersMap.parentModelCodeRow = "Parent Model Unique Code" -// headersMap.containingModelNameRow = "Model" -// headersMap.containingModelCodeRow = "Model Unique Code" -// headersMap.measurementUnitNameRow = "Measurement Unit" -// headersMap.metadataRow = "Metadata" -// -// dataImportService.importData(headers, rows, "NHIC : TRA", "NHIC TRA conceptual domain for renal transplantation", ["NHIC Datasets", "TRA", "TRA_OUH", "Round 1"], headersMap) -// DataElement de1 = DataElement.findByModelCatalogueId("MC_037e6162-3b6f-4ae2-a171-2470b64dff10_1") -// DataElement de2 = DataElement.findByModelCatalogueId("MC_065e6162-3b6f-4ae2-a171-2470b64dff10_1") -// DataElement de3 = DataElement.findByModelCatalogueId("MC_067e6162-3b4f-4ae2-a171-2470b64dff10_1") -// DataElement de4 = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b64dff10_1") -// DataElement de5 = DataElement.findByModelCatalogueId("MC_067e6162-1b6f-4ae2-a171-2470b64dff10_1") -// DataElement de6 = DataElement.findByModelCatalogueId("MC_067e6189-3b6f-4ae2-a171-2470b64dff10_1") -// DataElement de7 = DataElement.findByModelCatalogueId("MC_067e6232-3b6f-4ae2-a171-2470b64dff10_1") -// DataElement de8 = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-4ae7-a171-2470b64dff10_1") -// DataElement de9 = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-4ae9-a171-2470b64dff10_1") -// DataElement de10 = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-2ae2-a171-2470b64dff10_1") -// DataElement de11 = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-9ae2-a181-2470b64dff10_1") -// Model admissions = Model.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b63dff00_1") -// Model unit = Model.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b64dff19_1") -// Model demographics = Model.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b63dff01_1") -// -// -// then:"the dataElement should have name" -// de1 -// de2 -// de3 -// de4 -// de5 -// de6 -// de7 -// de8 -// de9 -// de10 -// de11 -// admissions -// demographics -// unit -// admissions.parentOf.contains(demographics) -// admissions.parentOf.contains(unit) -// demographics.contains.contains(de1) -// demographics.contains.contains(de1) -// demographics.contains.contains(de2) -// demographics.contains.contains(de3) -// demographics.contains.contains(de4) -// demographics.contains.contains(de5) -// unit.contains.contains(de6) -// unit.contains.contains(de7) -// unit.contains.contains(de8) -// unit.contains.contains(de9) -// unit.contains.contains(de10) -// unit.contains.contains(de11) -// -// when: "I load the spreadsheet in again with changes to the first data element name" -// -// def inputStream2 = new FileInputStream(fileName2) -// ExcelLoader parser2 = new ExcelLoader(inputStream2) -// (headers, rows) = parser2.parse() -// dataImportService.importData(headers, rows, "NHIC : TRA", "NHIC TRA conceptual domain for renal transplantation", ["NHIC Datasets", "TRA", "TRA_OUH", "Round 1"], headersMap) -// def de1Old = DataElement.findByModelCatalogueId("MC_037e6162-3b6f-4ae2-a171-2470b64dff10_1") -// def demographicsOld = Model.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b63dff01_1") -// -// then: "the data element and corresponding model have been updated" -// -// de1.refresh() -// demographics.refresh() -// de1.modelCatalogueId=="MC_037e6162-3b6f-4ae2-a171-2470b64dff10_2" -// de1.supersedes.contains(de1Old) -// de2 -// de3 -// de4 -// de5 -// de6 -// de7 -// de8 -// de9 -// de10 -// de11 -// admissions -// demographics -// unit -// admissions.parentOf.contains(demographics) -// admissions.parentOf.contains(unit) -// demographics.contains.contains(de1) -// demographics.contains.contains(de1) -// demographics.contains.contains(de2) -// demographics.contains.contains(de3) -// demographics.contains.contains(de4) -// demographics.contains.contains(de5) -// demographics.supersedes.contains(demographicsOld) -// !demographicsOld.contains.contains(de1) -// demographicsOld.contains.contains(de1Old) -// !unit.supersedes -// unit.contains.contains(de6) -// unit.contains.contains(de7) -// unit.contains.contains(de8) -// unit.contains.contains(de9) -// unit.contains.contains(de10) -// unit.contains.contains(de11) -// -// -// when: "I load the spreadsheet in again with changes to the first data element name" -// -// def inputStream3 = new FileInputStream(fileName3) -// ExcelLoader parser3 = new ExcelLoader(inputStream3) -// (headers, rows) = parser3.parse() -// dataImportService.importData(headers, rows, "NHIC : TRA", "NHIC TRA conceptual domain for renal transplantation", ["NHIC Datasets", "TRA", "TRA_OUH", "Round 1"], headersMap) -// de1Old = DataElement.findByModelCatalogueId("MC_037e6162-3b6f-4ae2-a171-2470b64dff10_2") -// demographicsOld = Model.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b63dff01_2") -// def deTimeOld = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-4ae7-a171-2470b64dff10_1") -// def deTime = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-4ae7-a171-2470b64dff10_2") -// -// then: "the data element and corresponding model have been updated" -// -// de1.refresh() -// demographics.refresh() -// de1.modelCatalogueId=="MC_037e6162-3b6f-4ae2-a171-2470b64dff10_3" -// de1.supersedes.contains(de1Old) -// de2 -// de3 -// de4 -// de5 -// de6 -// de7 -// de8 -// de9 -// de10 -// de11 -// deTime -// deTimeOld -// admissions -// demographics -// unit -// admissions.parentOf.contains(demographics) -// admissions.parentOf.contains(unit) -// demographics.contains.contains(de1) -// demographics.contains.contains(de1) -// demographics.contains.contains(de2) -// demographics.contains.contains(de3) -// demographics.contains.contains(de4) -// demographics.contains.contains(de5) -// demographics.supersedes.contains(demographicsOld) -// unit.contains.contains(de6) -// unit.contains.contains(de7) -// unit.contains.contains(de8) -// unit.contains.contains(de9) -// unit.contains.contains(de10) -// unit.contains.contains(de11) + then: "the data element and corresponding model have been updated" -// } + de1.refresh() + demographics.refresh() + de1.modelCatalogueId=="MC_037e6162-3b6f-4ae2-a171-2470b64dff10_2" + de1.supersedes.contains(de1Old) + de2 + de3 + de4 + de5 + de6 + de7 + de8 + de9 + de10 + de11 + admissions + demographics + unit + admissions.parentOf.contains(demographics) + admissions.parentOf.contains(unit) + demographics.contains.contains(de1) + demographics.contains.contains(de1) + demographics.contains.contains(de2) + demographics.contains.contains(de3) + demographics.contains.contains(de4) + demographics.contains.contains(de5) + demographics.supersedes.contains(demographicsOld) + !demographicsOld.contains.contains(de1) + demographicsOld.contains.contains(de1Old) + !unit.supersedes + unit.contains.contains(de6) + unit.contains.contains(de7) + unit.contains.contains(de8) + unit.contains.contains(de9) + unit.contains.contains(de10) + unit.contains.contains(de11) + + + when: "I load the spreadsheet in again with changes to the first data element name" + + def inputStream3 = new FileInputStream(fileName3) + ExcelLoader parser3 = new ExcelLoader(inputStream3) + (headers, rows) = parser3.parse() + def importer3 = dataImportService.importData(headers, rows, "NHIC : TRA", "NHIC : TRA", "NHIC TRA conceptual domain for renal transplantation", headersMap) + dataImportService.resolveAll(importer3) + dataImportService.ingestImportQueue(importer3) + de1Old = DataElement.findByModelCatalogueId("MC_037e6162-3b6f-4ae2-a171-2470b64dff10_2") + demographicsOld = Model.findByModelCatalogueId("MC_067e6162-3b6f-4ae2-a171-2470b63dff01_2") + def deTimeOld = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-4ae7-a171-2470b64dff10_1") + def deTime = DataElement.findByModelCatalogueId("MC_067e6162-3b6f-4ae7-a171-2470b64dff10_2") + + then: "the data element and corresponding model have been updated" + + de1.refresh() + demographics.refresh() + de1.modelCatalogueId=="MC_037e6162-3b6f-4ae2-a171-2470b64dff10_3" + de1.supersedes.contains(de1Old) + de2 + de3 + de4 + de5 + de6 + de7 + de8 + de9 + de10 + de11 + deTime + deTimeOld + admissions + demographics + unit + admissions.parentOf.contains(demographics) + admissions.parentOf.contains(unit) + demographics.contains.contains(de1) + demographics.contains.contains(de1) + demographics.contains.contains(de2) + demographics.contains.contains(de3) + demographics.contains.contains(de4) + demographics.contains.contains(de5) + demographics.supersedes.contains(demographicsOld) + unit.contains.contains(de6) + unit.contains.contains(de7) + unit.contains.contains(de8) + unit.contains.contains(de9) + unit.contains.contains(de10) + unit.contains.contains(de11) + + } // void "Test loading NHIC spreadsheet"(){ diff --git a/ModelCatalogueCorePlugin/test/integration/resources/DataTemplate.xls b/ModelCatalogueCorePlugin/test/integration/resources/DataTemplate.xls index 633ad40264..076614a8ca 100644 Binary files a/ModelCatalogueCorePlugin/test/integration/resources/DataTemplate.xls and b/ModelCatalogueCorePlugin/test/integration/resources/DataTemplate.xls differ