diff --git a/ModelCatalogueCorePlugin/grails-app/controllers/org/modelcatalogue/core/DataImportController.groovy b/ModelCatalogueCorePlugin/grails-app/controllers/org/modelcatalogue/core/DataImportController.groovy index a190f85f6a..a4a7dcbb86 100644 --- a/ModelCatalogueCorePlugin/grails-app/controllers/org/modelcatalogue/core/DataImportController.groovy +++ b/ModelCatalogueCorePlugin/grails-app/controllers/org/modelcatalogue/core/DataImportController.groovy @@ -227,6 +227,7 @@ class DataImportController { } protected logError(Long id,Exception e){ + BuildProgressMonitor.get(id)?.onError(e) log.error "Error importing Asset[$id]", e Asset updated = Asset.get(id) updated.refresh() diff --git a/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/CatalogueBuilderContext.groovy b/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/CatalogueBuilderContext.groovy index 2f3e4a5429..26b905d4f6 100644 --- a/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/CatalogueBuilderContext.groovy +++ b/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/CatalogueBuilderContext.groovy @@ -42,8 +42,8 @@ class CatalogueBuilderContext { * @param contextElementType * @param closure */ - public WithOptionalOrClause withContextElement(Class contextElementType, @DelegatesTo(CatalogueBuilder) @ClosureParams(value=FromString, options = ['org.modelcatalogue.core.util.builder.CatalogueElementProxy', 'org.modelcatalogue.core.util.builder.CatalogueElementProxy,Closure']) Closure closure) { - ContextItem contextElement = getContextElement(contextElementType) as ContextItem + public WithOptionalOrClause withContextElement(Class contextElementType, boolean anyDepth = false, @DelegatesTo(CatalogueBuilder) @ClosureParams(value=FromString, options = ['org.modelcatalogue.core.util.builder.CatalogueElementProxy', 'org.modelcatalogue.core.util.builder.CatalogueElementProxy,Closure']) Closure closure) { + ContextItem contextElement = getContextElement(contextElementType, 0, anyDepth) as ContextItem if (contextElement) { closure.resolveStrategy = Closure.DELEGATE_FIRST closure.delegate = builder @@ -92,7 +92,7 @@ class CatalogueBuilderContext { contextElement } - private ContextItem getContextElement(Class contextElementType = CatalogueElement, int skip = 0) { + private ContextItem getContextElement(Class contextElementType = CatalogueElement, int skip = 0, boolean anyDepth = false) { int skipped = 0 for (Map context in contexts.reverse()) { if (skipped++ < skip) { @@ -102,6 +102,9 @@ class CatalogueBuilderContext { if (result) { return result } + if (!anyDepth) { + return null + } } return null } diff --git a/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/DefaultCatalogueBuilder.groovy b/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/DefaultCatalogueBuilder.groovy index 52816a9f0c..5eff55e13d 100644 --- a/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/DefaultCatalogueBuilder.groovy +++ b/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/DefaultCatalogueBuilder.groovy @@ -523,7 +523,7 @@ import org.modelcatalogue.core.api.CatalogueElement as ApiCatalogueElement return } - context.withContextElement(DataModel) { + context.withContextElement(DataModel, true) { element.setParameter('dataModel', it) } } @@ -656,7 +656,7 @@ import org.modelcatalogue.core.api.CatalogueElement as ApiCatalogueElement return true } boolean ret = true - context.withContextElement(DataModel) { + context.withContextElement(DataModel, true) { ret = it.name == (parameters.dataModel ?: parameters.classification)?.toString() } return ret diff --git a/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/DefaultRelationshipBuilder.groovy b/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/DefaultRelationshipBuilder.groovy index b7a5c42651..687fff957a 100644 --- a/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/DefaultRelationshipBuilder.groovy +++ b/ModelCatalogueCorePlugin/src/groovy/org/modelcatalogue/core/util/builder/DefaultRelationshipBuilder.groovy @@ -75,7 +75,7 @@ class DefaultRelationshipBuilder implements RelationshipBuilder { * @param extensions closure defining the metadata */ void to(String name, @DelegatesTo(RelationshipConfiguration) Closure extensions = {}) { - context.withContextElement(DataModel) { + context.withContextElement(DataModel, true) { to repository.createProxy(getDestinationHintOrClass(), [classification: it.name, name: name]), extensions } or { to repository.createProxy(getDestinationHintOrClass(), [name: name]), extensions @@ -164,7 +164,7 @@ class DefaultRelationshipBuilder implements RelationshipBuilder { } void from(String name, @DelegatesTo(RelationshipConfiguration) Closure extensions = {}) { - context.withContextElement(DataModel) { + context.withContextElement(DataModel, true) { from repository.createProxy(getSourceHintOrClass(), [classification: it.name, name: name]), extensions } or { from repository.createProxy(getSourceHintOrClass(), [name: name]), extensions diff --git a/ModelCatalogueCorePlugin/test/integration/org/modelcatalogue/core/util/CatalogueBuilderIntegrationSpec.groovy b/ModelCatalogueCorePlugin/test/integration/org/modelcatalogue/core/util/CatalogueBuilderIntegrationSpec.groovy index 259831fccc..bf053ce6f5 100644 --- a/ModelCatalogueCorePlugin/test/integration/org/modelcatalogue/core/util/CatalogueBuilderIntegrationSpec.groovy +++ b/ModelCatalogueCorePlugin/test/integration/org/modelcatalogue/core/util/CatalogueBuilderIntegrationSpec.groovy @@ -14,6 +14,11 @@ import static org.modelcatalogue.core.util.HibernateHelper.* class CatalogueBuilderIntegrationSpec extends AbstractIntegrationSpec { + public static final String DATA_MODEL_NO_HIERARCHY = "test no hierarchy" + public static final String DATA_MODEL_NO_HIERARCHY_DATA_CLASS = "no parent" + public static final String DATA_MODEL_NO_HIERARCHY_DATA_ELEMENT = "reference type element test" + public static final String DATA_MODEL_NO_HIERARCHY_DATA_TYPE = "reference type test" + public static final String DATA_MODEL_NO_HIERARCHY_REFERENCE = "reference no class" def dataModelService def elementService @@ -1203,9 +1208,27 @@ class CatalogueBuilderIntegrationSpec extends AbstractIntegrationSpec { child.dataModel == dataModel grandChild grandChild.dataModel == dataModel + } - - - + def "when creating refrence data type don't create hierarchy"() { + given: + build { + dataModel(name: DATA_MODEL_NO_HIERARCHY) { + dataClass(name: DATA_MODEL_NO_HIERARCHY_DATA_CLASS) { + dataElement(name: DATA_MODEL_NO_HIERARCHY_DATA_ELEMENT) { + dataType(name: DATA_MODEL_NO_HIERARCHY_DATA_TYPE) { + dataClass(name: DATA_MODEL_NO_HIERARCHY_REFERENCE) + } } } } } + when: + DataClass noParent = DataClass.findByName(DATA_MODEL_NO_HIERARCHY_DATA_CLASS) + DataType reference = DataType.findByName(DATA_MODEL_NO_HIERARCHY_DATA_TYPE) + DataClass noChild = DataClass.findByName(DATA_MODEL_NO_HIERARCHY_REFERENCE) + then: + noParent + reference + noChild + noParent.countParentOf() == 0 + reference.instanceOf(ReferenceType) + noChild.countChildOf() == 0 } } diff --git a/ModelCatalogueCorePluginTestApp/grails-app/conf/Config.groovy b/ModelCatalogueCorePluginTestApp/grails-app/conf/Config.groovy index ab8d2bf0a9..02b5375a75 100644 --- a/ModelCatalogueCorePluginTestApp/grails-app/conf/Config.groovy +++ b/ModelCatalogueCorePluginTestApp/grails-app/conf/Config.groovy @@ -334,10 +334,11 @@ grails.assets.babel.enabled = true grails.plugin.springsecurity.useBasicAuth = true grails.plugin.springsecurity.basic.realmName = "Model Catalogue" grails.plugin.springsecurity.filterChain.chainMap = [ - '/catalogue/upload': 'JOINED_FILTERS,-exceptionTranslationFilter', - '/catalogue/*/*/export': 'JOINED_FILTERS,-exceptionTranslationFilter', - '/user/current': 'JOINED_FILTERS,-exceptionTranslationFilter', - '/**': 'JOINED_FILTERS,-basicAuthenticationFilter,-basicExceptionTranslationFilter' + '/catalogue/upload': 'JOINED_FILTERS,-exceptionTranslationFilter', + '/catalogue/*/*/export': 'JOINED_FILTERS,-exceptionTranslationFilter', + '/user/current': 'JOINED_FILTERS,-exceptionTranslationFilter', + '/api/modelCatalogue/core/feedback/**': 'JOINED_FILTERS,-exceptionTranslationFilter', + '/**': 'JOINED_FILTERS,-basicAuthenticationFilter,-basicExceptionTranslationFilter' ] grails.plugin.springsecurity.logout.handlerNames = [ 'rememberMeServices',