Skip to content

Commit

Permalink
Merge branch 'feature/find-synonym-relationships' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
amilward committed May 29, 2014
2 parents 041784e + d8ebb1f commit adc03c7
Show file tree
Hide file tree
Showing 17 changed files with 285 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.modelcatalogue.core.util.marshalling.xlsx.XLSXListRenderer

class ModelCatalogueCorePluginGrailsPlugin {
// the plugin version
def version = "0.3"
def version = "0.3.1"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.3.7 > *"
// resources that are excluded from plugin packaging
Expand Down
2 changes: 1 addition & 1 deletion ModelCatalogueCorePlugin/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
app.grails.version=2.3.7
app.name=ModelCatalogueCorePlugin
app.servlet.version=2.5
app.version=0.3
app.version=0.3.1
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ angular.module("mc.core.modelCatalogueDataArchitect", ['mc.util.rest', 'mc.util.
params = angular.extend({key: query}, additionalParams)
enhance rest method: 'GET', url: "#{modelCatalogueApiRoot}/dataArchitect/metadataKeyCheck", params: params

modelCatalogueDataArchitect.findRelationsByMetadataKeys = (query, query2, additionalParams = {}) ->
params = angular.extend({keyOne: query}, {keyTwo: query2}, additionalParams)
enhance rest method: 'GET', url: "#{modelCatalogueApiRoot}/dataArchitect/findRelationsByMetadataKeys", params: params

modelCatalogueDataArchitect
]
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ angular.module('mc.core.ui.catalogueElementView', ['mc.core.catalogueElementEnha
tabDefinition.active = true
activeTabSet = true
if element.elementTypeName == 'Model'
$scope.reports = [{name: "exportAll COSD", url: modelCatalogueApiRoot + "/dataArchitect/getSubModelElements/" + element.id + "?format=xlsx&report=COSD"}, {name: "exportAll XML", url: modelCatalogueApiRoot + "/dataArchitect/getSubModelElements/" + element.id + "?format=xlsx&report=NHIC"},{name: "exportAll NHIC", url: modelCatalogueApiRoot + "/dataArchitect/getSubModelElements/" + element.id + "?format=xml"}]
$scope.reports = [{name: "exportAll COSD", url: modelCatalogueApiRoot + "/dataArchitect/getSubModelElements/" + element.id + "?format=xlsx&report=COSD"}, {name: "exportAll NHIC", url: modelCatalogueApiRoot + "/dataArchitect/getSubModelElements/" + element.id + "?format=xlsx&report=NHIC"},{name: "exportAll XML", url: modelCatalogueApiRoot + "/dataArchitect/getSubModelElements/" + element.id + "?format=xml"}]

tabs.unshift tabDefinition

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ angular.module('mc.core.ui.states.defaultStates', ['ui.router'])
$scope.contained.elements = contained
$scope.selectedElement = element
$scope.contained.elements = element._containedElements_ ? listEnhancer.createEmptyList('org.modelcatalogue.core.DataElement')
])

else if $scope.resource == 'newRelationships'
$scope.columns = [
{header: "source", value: 'source.name', class: 'col-md-6' }
{header: "destination", value: 'destination.name', class: 'col-md-6' }
]

])
.config(['$stateProvider', ($stateProvider) ->

DEFAULT_ITEMS_PER_PAGE = 10
Expand Down Expand Up @@ -108,6 +115,7 @@ angular.module('mc.core.ui.states.defaultStates', ['ui.router'])
controller: 'mc.core.ui.states.ListCtrl'
}


$stateProvider.state 'mc.dataArchitect.metadataKey', {
url: "/metadataKeyCheck",
templateUrl: 'modelcatalogue/core/ui/state/parent.html'
Expand Down Expand Up @@ -150,6 +158,50 @@ angular.module('mc.core.ui.states.defaultStates', ['ui.router'])
controller: 'mc.core.ui.states.ListCtrl'
}

$stateProvider.state 'mc.dataArchitect.findRelationsByMetadataKeys', {
url: "/findRelationsByMetadataKeys",
templateUrl: 'modelcatalogue/core/ui/state/parent.html',
controller: ['$scope','$state','$modal',($scope, $state, $modal)->
dialog = $modal.open {
windowClass: 'messages-modal-prompt'
template: '''
<div class="modal-header">
<h4>please enter metadata key</h4>
</div>
<div class="modal-body">
<form role="form">
<div class="form-group">
<label for="keyOne">metadata key one</label>
<input type="text" id="keyOne" ng-model="result.keyOne" class="form-control">
<label for="keyTwo">metadata key two</label>
<input type="text" id="keyTwo" ng-model="result.keyTwo" class="form-control">
</form>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="$close(result)">OK</button>
<button class="btn btn-warning" ng-click="$dismiss()">Cancel</button>
</div>
'''
}

dialog.result.then (result) ->
$state.go('mc.dataArchitect.showMetadataRelations', {'keyOne':result.keyOne, 'keyTwo':result.keyTwo})
]
}

$stateProvider.state 'mc.dataArchitect.showMetadataRelations', {
url: "/showMetadataRelations/{keyOne}/{keyTwo}",
templateUrl: 'modelcatalogue/core/ui/state/list.html'
resolve:
list: ['$stateParams', 'modelCatalogueDataArchitect', ($stateParams, modelCatalogueDataArchitect) ->
$stateParams.resource = "newRelationships"
# it's safe to call top level for each controller, only model controller will respond on it
return modelCatalogueDataArchitect.findRelationsByMetadataKeys($stateParams.keyOne, $stateParams.keyTwo)
]

controller: 'mc.core.ui.states.ListCtrl'
}

])
.run(['$rootScope', '$state', '$stateParams', ($rootScope, $state, $stateParams) ->
# It's very handy to add references to $state and $stateParams to the $rootScope
Expand Down Expand Up @@ -178,7 +230,7 @@ angular.module('mc.core.ui.states.defaultStates', ['ui.router'])
</div>
</span>
<h2>{{title}} List</h2>
<decorated-list list="list"></decorated-list>
<decorated-list list="list" columns="columns"></decorated-list>
</div>
<div ng-if="resource == 'model'">
<div class="row">
Expand Down
5 changes: 3 additions & 2 deletions ModelCatalogueCorePlugin/grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ grails.project.dependency.resolution = {
export = false
}

compile ":coffee-asset-pipeline:1.5.0"
compile ":less-asset-pipeline:1.5.0"
compile ":asset-pipeline:1.8.8"
compile ":coffee-asset-pipeline:1.8.0"
compile ":less-asset-pipeline:1.7.0"
compile ":hibernate:3.6.10.8"

compile ":excel-export:0.2.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ grails.doc.copyright = ''// The copyright message to display
grails.doc.footer = ''// The footer to use


grails.assets.minifyJs = false

//configured data types, measurement units, relationship types

Expand Down Expand Up @@ -135,7 +136,7 @@ modelcatalogue.defaults.relationshiptypes = [
[name: "inclusion", sourceToDestination: "includes", destinationToSource: "included in", sourceClass: ConceptualDomain, destinationClass: ValueDomain],
[name: "instantiation", sourceToDestination: "instantiated by", destinationToSource: "instantiates", sourceClass: DataElement, destinationClass: ValueDomain],
[name: "supersession", sourceToDestination: "superseded by", destinationToSource: "supersedes", sourceClass: PublishedElement, destinationClass: PublishedElement, rule: "source.class == destination.class", system: true],
[name: "relatedTo", sourceToDestination: "related to", destinationToSource: "related to", sourceClass: CatalogueElement, destinationClass: CatalogueElement]
[name: "relatedTo", sourceToDestination: "related to", destinationToSource: "related to", sourceClass: DataElement, destinationClass: DataElement]
]

// Uncomment and edit the following lines to start using Grails encoding & escaping improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class ModelCatalogueCorePluginUrlMappings {
"/getSubModelElements/$modelId?" (controller:"dataArchitect"){
action = [GET: "getSubModelElements"]
}
"/findRelationsByMetadataKeys/$key?" (controller:"dataArchitect"){
action = [GET: "findRelationsByMetadataKeys"]
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,66 @@ class DataArchitectController {
respond elements
}

def findRelationsByMetadataKeys(Integer max){
setSafeMax(max)
def results
def keyOne = params.keyOne
def keyTwo = params.keyTwo
if(keyOne && keyTwo) {
try {
results = dataArchitectService.findRelationsByMetadataKeys(keyOne, keyTwo, params)
} catch (Exception e) {
println(e)
return
}

//FIXME we need new method to do this and integrate it with the ui
try {
dataArchitectService.actionRelationshipList(results.list)
} catch (Exception e) {
println(e)
return
}

def baseLink = "/dataArchitect/findRelationsByMetadataKeys"
def links = ListWrapper.nextAndPreviousLinks(params, baseLink, results.count)

Elements elements = new Elements(
base: baseLink,
total: results.count,
items: results.list,
itemType: Relationship,
previous: links.previous,
next: links.next,
offset: params.int('offset') ?: 0,
page: params.int('max') ?: 10,
sort: params.sort,
order: params.order
)

respond elements

}else{
respond "please enter keys"
}

}


// def actionRelationships(){
//
// def relations = params.relatedElements
//
// try {
// def errors = dataArchitectService.createRelationshipByType(relations, "relatedTo")
// }
// catch (Exception ex) {
// //log.error("Exception in handling excel file: "+ ex.message)
// log.error("Exception in handling excel file")
// flash.message = "Error while creating relationships`.";
// }
//
// }

protected setSafeMax(Integer max) {
withFormat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EnumeratedType extends DataType {
static transients = ['enumerations']

static constraints = {
enumAsString nullable: false, unique:true, maxSize: 10000, validator: { encodedVal, obj ->
enumAsString nullable: false, /*unique:true,*/ maxSize: 10000, validator: { encodedVal, obj ->
Map<String, String> val = stringToMap(encodedVal)
if (!val) return true
if (val.size() < 1) return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.modelcatalogue.core.util.ListAndCount
@Transactional
class DataArchitectService {

def modelCatalogueSearchService, publishedElementService
def modelCatalogueSearchService, publishedElementService, relationshipService

def uninstantiatedDataElements(Map params){
ListAndCount results = new ListAndCount()
Expand Down Expand Up @@ -58,29 +58,69 @@ class DataArchitectService {
ListAndCount results = new ListAndCount()
def searchParams = getParams(params)

totalCount = DataElement.executeQuery("SELECT DISTINCT COUNT(a) FROM DataElement a " +
"WHERE a.extensions IS EMPTY " +
"OR a NOT IN " +
"(SELECT a2 from DataElement a2 " +
"JOIN a2.extensions e2 " +
"WHERE e2.name = ?)", [searchParams.key], [cache:true]
)
totalCount = DataElement.executeQuery("SELECT DISTINCT COUNT(a) FROM DataElement a " +
"WHERE a.extensions IS EMPTY " +
"OR a NOT IN " +
"(SELECT a2 from DataElement a2 " +
"JOIN a2.extensions e2 " +
"WHERE e2.name = ?)", [searchParams.key], [cache:true]
)

missingMetadataKey = DataElement.executeQuery("SELECT DISTINCT a FROM DataElement a " +
"WHERE a.extensions IS EMPTY " +
"OR a NOT IN " +
"(SELECT a2 from DataElement a2 " +
"JOIN a2.extensions e2 " +
"WHERE e2.name = ?)", [searchParams.key], [max: searchParams.max, offset: searchParams.offset]
)

missingMetadataKey = DataElement.executeQuery("SELECT DISTINCT a FROM DataElement a " +
"WHERE a.extensions IS EMPTY " +
"OR a NOT IN " +
"(SELECT a2 from DataElement a2 " +
"JOIN a2.extensions e2 " +
"WHERE e2.name = ?)", [searchParams.key], [max: searchParams.max, offset: searchParams.offset]
)
results.count = (totalCount.get(0))?totalCount.get(0):0
results.list = missingMetadataKey

results.count = (totalCount.get(0))?totalCount.get(0):0
results.list = missingMetadataKey

return results
}

def findRelationsByMetadataKeys(String keyOne, String keyTwo, Map params){

ListAndCount results = new ListAndCount()
def searchParams = getParams(params)
def synonymDataElements = []
//FIXME the relationship type should be configurable
def relType = RelationshipType.findByName("relatedTo")

def key1Elements = DataElement.executeQuery("SELECT DISTINCT a FROM DataElement a " +
"inner join a.extensions e " +
"WHERE e.name = ?)", [keyOne])//, [max: searchParams.max, offset: searchParams.offset])

key1Elements.eachWithIndex { DataElement dataElement, int dataElementIndex ->
def extensionName = dataElement.extensions[dataElement.extensions.findIndexOf {
it.name == keyOne
}].extensionValue
def key2Elements = DataElement.executeQuery("SELECT DISTINCT a FROM DataElement a " +
"inner join a.extensions e " +
"WHERE e.name = ? and e.extensionValue = ?) ", [keyTwo, extensionName], [max: searchParams.max, offset: searchParams.offset])

// Create a Map
key2Elements.each {
//FIXME the relationship type needs to be configurable
def relationship = new Relationship(source: dataElement, destination: it, relationshipType: relType)
synonymDataElements << relationship
}
}

results.list = synonymDataElements
results.count = synonymDataElements.size()
return results
}

def actionRelationshipList(ArrayList<Relationship> list){
def errorMessages = []
list.each { relationship ->
relationship.save()
}
}

def indexAll(){
modelCatalogueSearchService.index(ConceptualDomain.list())
modelCatalogueSearchService.index(DataType.list())
Expand All @@ -106,6 +146,8 @@ class DataArchitectService {
private static Map getParams(Map params){
def searchParams = [:]
if(params.key){searchParams.put("key" , params.key)}
if(params.keyOne){searchParams.put("keyOne" , params.keyOne)}
if(params.keyTwo){searchParams.put("keyTwo" , params.keyTwo)}
if(params.max){searchParams.put("max" , params.max.toInteger())}else{searchParams.put("max" , 10)}
// if(params.sort){searchParams.put("sort" , "$params.sort")}else{searchParams.put("sort" , "name")}
// if(params.order){searchParams.put("order" , params.order.toLowerCase())}else{searchParams.put("order" , "asc")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.modelcatalogue.core.ValueDomain

class DataImportService {

static transactional = false
static transactional = true

private static final QUOTED_CHARS = ["\\": "&#92;", ":" : "&#58;", "|" : "&#124;", "%" : "&#37;"]
//the import script accepts and array of headers these should include the following:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ abstract class ListWrapper<T> {
if (params.key) {
link += "&key=${params.key}"
}
if (params.keyOne) {
link += "&keyOne=${params.keyOne}"
}
if (params.keyTwo) {
link += "&keyTwo=${params.keyTwo}"
}
if (params.toplevel) {
link += "&toplevel=${params.toplevel}"
}
Expand Down
Loading

0 comments on commit adc03c7

Please sign in to comment.