@@ -2805,6 +2805,21 @@ var D2RQMappingCtrl = function($scope, $http, $q, flash, ServerErrorResponse, Ac
28052805 } ) ;
28062806 } ;
28072807
2808+ $scope . actualizeMappingGroup = function ( id ) {
2809+ $http ( {
2810+ url : d2rqServiceUrl + "/mappings/groups/" + id + "/actualize" ,
2811+ method : "POST" ,
2812+ data : { user : AccountService . getUsername ( ) } ,
2813+ dataType : "json" ,
2814+ headers : { "Content-Type" :"application/json; charset=utf-8" }
2815+ } ) . then ( function ( response ) {
2816+ $scope . refreshMappingGroups ( ) ;
2817+ } , function ( response ) {
2818+ flash . error = ServerErrorResponse . getMessage ( response . status ) ;
2819+ $scope . refreshMappingGroups ( ) ;
2820+ } ) ;
2821+ } ;
2822+
28082823 //mappings
28092824
28102825 $scope . modaltitle = "" ;
@@ -2817,11 +2832,36 @@ var D2RQMappingCtrl = function($scope, $http, $q, flash, ServerErrorResponse, Ac
28172832 { value :'patternColumns' , label :'Pattern Columns' } ,
28182833 ] ;
28192834
2835+ $scope . joinConditionTypes = [
2836+ { value :'fk' , label :'Foreign Key' } ,
2837+ { value :'linkingTable' , label :'Linking Table' } ,
2838+ ] ;
2839+
2840+ var table2columns = { } ; //property - table name, value - columns list
2841+
28202842 $scope . tables = [ ] ;
28212843
28222844 $scope . tableColumns = [ ] ; // array of string
28232845
2846+ var updatePropertiesColumns = function ( ) {
2847+ for ( var ind in $scope . mapping . dataProperties ) {
2848+ var dp = $scope . mapping . dataProperties [ ind ] ;
2849+ if ( $scope . tableColumns . indexOf ( dp . column ) == - 1 ) dp . column = null ;
2850+ }
2851+ for ( var ind in $scope . mapping . objectProperties ) {
2852+ var op = $scope . mapping . objectProperties [ ind ] ;
2853+ if ( $scope . tableColumns . indexOf ( op . column ) == - 1 ) op . column = null ;
2854+ op . join . table1 = $scope . mapping . table ;
2855+ if ( $scope . tableColumns . indexOf ( op . join . table1column ) == - 1 ) op . join . table1column = null ;
2856+ }
2857+ } ;
2858+
28242859 $scope . updateColumns = function ( ) {
2860+ if ( $scope . tableColumns [ $scope . mapping . table ] != undefined ) {
2861+ $scope . tableColumns = $scope . tableColumns [ $scope . mapping . table ] ;
2862+ updatePropertiesColumns ( ) ;
2863+ return ;
2864+ }
28252865 $http ( {
28262866 url : d2rqServiceUrl + "/database/columns/get" ,
28272867 method : "GET" ,
@@ -2830,26 +2870,41 @@ var D2RQMappingCtrl = function($scope, $http, $q, flash, ServerErrorResponse, Ac
28302870 headers : { "Content-Type" :"application/json; charset=utf-8" }
28312871 } ) . then ( function ( response ) {
28322872 var result = response . data ;
2833- $scope . tableColumns = [ ] ;
2873+ var columns = [ ]
28342874 for ( var ind in result ) {
2835- $scope . tableColumns . push ( result [ ind ] . column ) ;
2875+ columns . push ( result [ ind ] . column ) ;
28362876 }
2837- //refresh properties
2838- for ( var ind in $scope . mapping . dataProperties ) {
2839- var dp = $scope . mapping . dataProperties [ ind ] ;
2840- if ( $scope . tableColumns . indexOf ( dp . column ) == - 1 )
2841- dp . column = null ;
2842- }
2843- for ( var ind in $scope . mapping . objectProperties ) {
2844- var op = $scope . mapping . objectProperties [ ind ] ;
2845- if ( $scope . tableColumns . indexOf ( op . column ) == - 1 )
2846- op . column = null ;
2847- op . join . table1 = $scope . mapping . table ;
2848- for ( var i in op . join . columns ) {
2849- if ( $scope . tableColumns . indexOf ( op . join . columns [ i ] . first ) == - 1 )
2850- op . join . columns [ i ] . first = null ;
2851- }
2877+ $scope . tableColumns = columns ;
2878+ $scope . tableColumns [ $scope . mapping . table ] = columns ;
2879+ updatePropertiesColumns ( ) ;
2880+ } , function ( response ) {
2881+ //todo
2882+ } ) ;
2883+ } ;
2884+
2885+ $scope . updateLinkingTable = function ( property ) {
2886+ if ( $scope . tableColumns [ property . join . linkingTable ] != undefined ) {
2887+ property . join . linkingTableStructure = $scope . tableColumns [ property . join . linkingTable ] ;
2888+ if ( property . join . linkingTableStructure . indexOf ( property . join . linkingTableColumn1 ) == - 1 ) property . join . linkingTableColumn1 = null ;
2889+ if ( property . join . linkingTableStructure . indexOf ( property . join . linkingTableColumn2 ) == - 1 ) property . join . linkingTableColumn2 = null ;
2890+ return ;
2891+ }
2892+ $http ( {
2893+ url : d2rqServiceUrl + "/database/columns/get" ,
2894+ method : "GET" ,
2895+ params : { connection : $scope . datasource . dbConnection , table : property . join . linkingTable } ,
2896+ dataType : "json" ,
2897+ headers : { "Content-Type" :"application/json; charset=utf-8" }
2898+ } ) . then ( function ( response ) {
2899+ var result = response . data ;
2900+ var columns = [ ]
2901+ for ( var ind in result ) {
2902+ columns . push ( result [ ind ] . column ) ;
28522903 }
2904+ $scope . tableColumns [ $scope . mapping . table ] = columns ;
2905+ property . join . linkingTableStructure = columns ;
2906+ if ( property . join . linkingTableStructure . indexOf ( property . join . linkingTableColumn1 ) == - 1 ) property . join . linkingTableColumn1 = null ;
2907+ if ( property . join . linkingTableStructure . indexOf ( property . join . linkingTableColumn2 ) == - 1 ) property . join . linkingTableColumn2 = null ;
28532908 } , function ( response ) {
28542909 //todo
28552910 } ) ;
@@ -2877,12 +2932,13 @@ var D2RQMappingCtrl = function($scope, $http, $q, flash, ServerErrorResponse, Ac
28772932 , property : null //ontology class property object
28782933 , column : null //column name (string)
28792934 } ;
2935+ var emptyJoinConditions = { type :"" , table1 :"" , table2 :"" , linkingTable :"" , table1column :"" , table2column :"" , linkingTableColumn1 :"" , linkingTableColumn2 :"" } ;
28802936 var emptyObjectProperty = { id : 0
28812937 , property : null //ontology class property object
28822938 , mappingType :"" //string ($scope.objectPropMappingTypes)
28832939 , column : null //string
28842940 , ref :null //mapping object
2885- , join :{ table1 : "" , table2 : "" , columns : [ { first : "" , second : "" } ] , type : "EQ" }
2941+ , join :angular . copy ( emptyJoinConditions )
28862942 } ;
28872943 var emptyMapping = { name :""
28882944 , group : null //mapping group object
@@ -2978,7 +3034,7 @@ var D2RQMappingCtrl = function($scope, $http, $q, flash, ServerErrorResponse, Ac
29783034 $scope . mapping . name = mapping . name ;
29793035 $scope . mapping . group = mappingGroup ;
29803036
2981- $http . get ( d2rqServiceUrl + "/data/groups/" + mappingGroup . compositeData + "/metadata/get" )
3037+ var dataRequest = $http . get ( d2rqServiceUrl + "/data/groups/" + mappingGroup . compositeData + "/metadata/get" )
29823038 . then ( function ( response ) {
29833039 $scope . datasource = response . data ;
29843040
@@ -3015,7 +3071,7 @@ var D2RQMappingCtrl = function($scope, $http, $q, flash, ServerErrorResponse, Ac
30153071 $scope . datasource = { data :[ ] } ;
30163072 } ) ;
30173073
3018- $http . get ( d2rqServiceUrl + "/ontologies/" + mappingGroup . ontology + "/classes/mappingscheme/get" )
3074+ var ontoRequest = $http . get ( d2rqServiceUrl + "/ontologies/" + mappingGroup . ontology + "/classes/mappingscheme/get" )
30193075 . then ( function ( response ) {
30203076 $scope . ontologyClasses = response . data ;
30213077 //set mapping class
@@ -3060,10 +3116,34 @@ var D2RQMappingCtrl = function($scope, $http, $q, flash, ServerErrorResponse, Ac
30603116 }
30613117 }
30623118 }
3063- $scope . mapping . objectProperties . push ( { id : id , property : property ,
3064- mappingType : op . uriColumn == null ? "ref" : "column" ,
3065- column : op . uriColumn == null ? null : op . uriColumn . second , ref : ref ,
3066- join : op . tableJoinConditions == null || op . tableJoinConditions . length == 0 ? { table1 :mapping . classMappingTable . table , table2 :ref == null ? null : ref . classMappingTable . table , columns :[ { first :"" , second :"" } ] , type :"EQ" } : op . tableJoinConditions [ 0 ] } ) ;
3119+ var joinConditions = angular . copy ( emptyJoinConditions ) ;
3120+ joinConditions . table1 = mapping . classMappingTable . table ;
3121+ joinConditions . table2 = ref == null ? null : ref . classMappingTable . table ;
3122+ if ( op . tableJoinConditions != null ) {
3123+ if ( op . tableJoinConditions . length == 1 ) {
3124+ joinConditions . type = "fk" ;
3125+ joinConditions . table1column = op . tableJoinConditions [ 0 ] . columns [ 0 ] . first ;
3126+ joinConditions . table2column = op . tableJoinConditions [ 0 ] . columns [ 0 ] . second ;
3127+ } else if ( op . tableJoinConditions . length == 2 ) {
3128+ joinConditions . type = "linkingTable" ;
3129+ if ( op . tableJoinConditions [ 0 ] . table1 == joinConditions . table1 ) {
3130+ joinConditions . linkingTable = op . tableJoinConditions [ 0 ] . table2 ;
3131+ joinConditions . table1column = op . tableJoinConditions [ 0 ] . columns [ 0 ] . first ;
3132+ joinConditions . linkingTableColumn1 = op . tableJoinConditions [ 0 ] . columns [ 0 ] . second ;
3133+ joinConditions . linkingTableColumn2 = op . tableJoinConditions [ 1 ] . columns [ 0 ] . first ;
3134+ joinConditions . table2column = op . tableJoinConditions [ 1 ] . columns [ 0 ] . second ;
3135+ } else if ( op . tableJoinConditions [ 1 ] . table1 == joinConditions . table1 ) {
3136+ joinConditions . linkingTable = op . tableJoinConditions [ 1 ] . table2 ;
3137+ joinConditions . table1column = op . tableJoinConditions [ 1 ] . columns [ 0 ] . first ;
3138+ joinConditions . linkingTableColumn1 = op . tableJoinConditions [ 1 ] . columns [ 0 ] . second ;
3139+ joinConditions . linkingTableColumn2 = op . tableJoinConditions [ 0 ] . columns [ 0 ] . first ;
3140+ joinConditions . table2column = op . tableJoinConditions [ 0 ] . columns [ 0 ] . second ;
3141+ }
3142+ }
3143+ }
3144+ var mappingObjectProp = { id : id , property : property , mappingType : op . uriColumn == null ? "ref" : "column" ,
3145+ column : op . uriColumn == null ? null : op . uriColumn . second , ref : ref , join : joinConditions } ;
3146+ $scope . mapping . objectProperties . push ( mappingObjectProp ) ;
30673147 id = id + 1 ;
30683148 }
30693149 if ( $scope . mapping . objectProperties . length == 0 ) {
@@ -3074,6 +3154,14 @@ var D2RQMappingCtrl = function($scope, $http, $q, flash, ServerErrorResponse, Ac
30743154 //todo
30753155 } ) ;
30763156
3157+ $q . all ( [ dataRequest , ontoRequest ] ) . then ( function ( values ) {
3158+ for ( var ind in $scope . mapping . objectProperties ) {
3159+ if ( $scope . mapping . objectProperties [ ind ] . join . type == "linkingTable" ) {
3160+ $scope . updateLinkingTable ( $scope . mapping . objectProperties [ ind ] ) ;
3161+ }
3162+ }
3163+ } ) ;
3164+
30773165 $scope . mapping . ptype = mapping . classMappingTable . uriColumn == null ? "patternColumns" : "uriColumn" ;
30783166 $scope . mapping . uriColumn = mapping . classMappingTable . uriColumn ;
30793167 $scope . mapping . patternColumns = mapping . classMappingTable . patternColumns == null ? [ ] : mapping . classMappingTable . patternColumns ;
@@ -3130,7 +3218,7 @@ var D2RQMappingCtrl = function($scope, $http, $q, flash, ServerErrorResponse, Ac
31303218 $scope . mapping . objectProperties . splice ( index , 1 ) ;
31313219 if ( $scope . mapping . objectProperties . length == 0 ) {
31323220 var emptyProp = angular . copy ( emptyObjectProperty ) ;
3133- emptyProp . table1 = $scope . mapping . table ;
3221+ emptyProp . join . table1 = $scope . mapping . table ;
31343222 $scope . mapping . objectProperties . push ( emptyProp ) ;
31353223 }
31363224 } ;
@@ -3213,12 +3301,19 @@ var D2RQMappingCtrl = function($scope, $http, $q, flash, ServerErrorResponse, Ac
32133301 , range : "http://www.w3.org/2002/07/owl#Thing" //range is not really used in d2rq mapping generation (in case of mapping reference) byt must be not null
32143302 , tableJoinConditions : [ ]
32153303 } ;
3216- var joinCondRes = { table1 :op . join . table1 , table2 :op . join . table2 , columns :[ ] , type :op . join . type } ;
3217- for ( var jci in op . join . columns ) {
3218- if ( op . join . columns [ jci ] . first != "" && op . join . columns [ jci ] . first != null && op . join . columns [ jci ] . second != "" && op . join . columns [ jci ] . second != null )
3219- joinCondRes . columns . push ( op . join . columns [ jci ] ) ;
3304+ if ( op . join . table1column != null && op . join . table1column != "" && op . join . table2column != null && op . join . table2column != "" ) {
3305+ if ( op . join . linkingTable == null || op . join . linkingTable == "" ) {
3306+ var joinCondRes = { table1 :op . join . table1 , table2 :op . join . table2 , columns :[ { first :op . join . table1column , second :op . join . table2column } ] , type :"EQ" } ;
3307+ p . tableJoinConditions . push ( joinCondRes ) ;
3308+ } else {
3309+ if ( op . join . linkingTableColumn1 != null && op . join . linkingTableColumn1 != "" && op . join . linkingTableColumn2 != null && op . join . linkingTableColumn2 != "" ) {
3310+ var joinCondRes1 = { table1 :op . join . table1 , table2 :op . join . linkingTable , columns :[ { first :op . join . table1column , second :op . join . linkingTableColumn1 } ] , type :"EQ" } ;
3311+ var joinCondRes2 = { table1 :op . join . linkingTable , table2 :op . join . table2 , columns :[ { first :op . join . linkingTableColumn2 , second :op . join . table2column } ] , type :"EQ" } ;
3312+ p . tableJoinConditions . push ( joinCondRes1 ) ;
3313+ p . tableJoinConditions . push ( joinCondRes2 ) ;
3314+ }
3315+ }
32203316 }
3221- if ( joinCondRes . columns . length > 0 ) p . tableJoinConditions . push ( joinCondRes ) ;
32223317 mappingTable . objectProperties . push ( p ) ;
32233318 }
32243319 }
@@ -3256,7 +3351,7 @@ var D2RQMappingCtrl = function($scope, $http, $q, flash, ServerErrorResponse, Ac
32563351 url : d2rqServiceUrl + "/mappings/" + $scope . mapping . id + "/update" ,
32573352 method : "POST" ,
32583353 dataType : "json" ,
3259- data : { mappingTable : mappingTable } ,
3354+ data : { name : $scope . mapping . name , mappingTable : mappingTable } ,
32603355 headers : { "Content-Type" :"application/json; charset=utf-8" }
32613356 } ) . then ( function ( response ) {
32623357 $scope . refreshMappingGroups ( ) . then ( function ( response ) {
0 commit comments