Skip to content

Commit

Permalink
Merge pull request #874 from MetadataConsulting/MET-1326-reference-in…
Browse files Browse the repository at this point in the history
…staead-of-hierarchy

MET-1326 fixed problem with reference types creating hierarchy as well
  • Loading branch information
musketyr authored Nov 3, 2016
2 parents 9fd79b6 + 3a53ab4 commit 994a3b1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class CatalogueBuilderContext {
* @param contextElementType
* @param closure
*/
public <T extends CatalogueElement> WithOptionalOrClause withContextElement(Class<T> contextElementType, @DelegatesTo(CatalogueBuilder) @ClosureParams(value=FromString, options = ['org.modelcatalogue.core.util.builder.CatalogueElementProxy<T>', 'org.modelcatalogue.core.util.builder.CatalogueElementProxy<T>,Closure']) Closure closure) {
ContextItem<T> contextElement = getContextElement(contextElementType) as ContextItem<T>
public <T extends CatalogueElement> WithOptionalOrClause withContextElement(Class<T> contextElementType, boolean anyDepth = false, @DelegatesTo(CatalogueBuilder) @ClosureParams(value=FromString, options = ['org.modelcatalogue.core.util.builder.CatalogueElementProxy<T>', 'org.modelcatalogue.core.util.builder.CatalogueElementProxy<T>,Closure']) Closure closure) {
ContextItem<T> contextElement = getContextElement(contextElementType, 0, anyDepth) as ContextItem<T>
if (contextElement) {
closure.resolveStrategy = Closure.DELEGATE_FIRST
closure.delegate = builder
Expand Down Expand Up @@ -92,7 +92,7 @@ class CatalogueBuilderContext {
contextElement
}

private <T extends CatalogueElement> ContextItem<T> getContextElement(Class<T> contextElementType = CatalogueElement, int skip = 0) {
private <T extends CatalogueElement> ContextItem<T> getContextElement(Class<T> contextElementType = CatalogueElement, int skip = 0, boolean anyDepth = false) {
int skipped = 0
for (Map<Class, ContextItem> context in contexts.reverse()) {
if (skipped++ < skip) {
Expand All @@ -102,6 +102,9 @@ class CatalogueBuilderContext {
if (result) {
return result
}
if (!anyDepth) {
return null
}
}
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ import org.modelcatalogue.core.api.CatalogueElement as ApiCatalogueElement
return
}

context.withContextElement(DataModel) {
context.withContextElement(DataModel, true) {
element.setParameter('dataModel', it)
}
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
}
9 changes: 5 additions & 4 deletions ModelCatalogueCorePluginTestApp/grails-app/conf/Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 994a3b1

Please sign in to comment.