rtriplify 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +41 -3
- data/lib/app/controllers/triplify_controller.rb +67 -67
- data/lib/app/helpers/triplify_helper.rb +1 -5
- data/lib/config/{database.yml → database_1.yml} +77 -57
- data/lib/model.rb +93 -46
- data/lib/rtriplify.rb +10 -11
- data/lib/tripleizer.rb +371 -116
- data/lib/triplify_metadata.rb +3 -3
- data/rails/init.rb +2 -2
- metadata +17 -7
- data/lib/triplify/acts_ass_yaffle.rb +0 -0
- data/lib/triplify.rb +0 -11
data/README
CHANGED
@@ -1,18 +1,56 @@
|
|
1
|
-
|
1
|
+
rTriplify
|
2
2
|
========
|
3
3
|
|
4
|
-
|
4
|
+
rTriplify is a ruby clone of the triplify-php version. It is used to create
|
5
|
+
a rdf-mapping of your existing database and serve it out to the (semantic)-web.
|
5
6
|
|
7
|
+
rTriplify uses the rails database models to generate your rdf-data.
|
8
|
+
|
9
|
+
It comes with most of the origin features of triplify.
|
10
|
+
Please have a look at ..... to see the full features list.
|
11
|
+
|
12
|
+
In addition you have the possibility to generate RDFa -Data and place it inside of
|
13
|
+
your webpage as a hidden div. Please be aware that this is not the clean way to
|
14
|
+
serve your content as RDFa. But I think, if you have generated the mapping file
|
15
|
+
for your database it's just the consequence to place RDFa on your page instead.
|
16
|
+
rTriplify gives you the right tools to place RDFa tags on your Webpage without having
|
17
|
+
to do a full code review of your templates. And of course, search engines like google
|
18
|
+
and yahoo already watch for these tags. Google already rewards RDFa tags with some specials.
|
19
|
+
For further informations please see here [1] or [2] here
|
20
|
+
|
21
|
+
|
22
|
+
Links:
|
23
|
+
[1]http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=99170
|
24
|
+
[2]http://developer.yahoo.com/searchmonkey/ (sadly this project has been rejected)
|
6
25
|
|
7
26
|
Example
|
8
27
|
=======
|
9
28
|
|
10
29
|
gem install rtriplify
|
11
30
|
|
31
|
+
then place a triplify.yml file in the config folder of your RoR-application.
|
32
|
+
Probably it's the best idea to use the sample config file included in the gem or
|
33
|
+
you can download the sample file here [3] too.
|
34
|
+
|
35
|
+
Usaly the sample config has all configuration possibilitys inside of it and
|
36
|
+
it's well documented. I think you can start now and change the config so that it
|
37
|
+
will fit to your Application.
|
38
|
+
|
39
|
+
Now, you want to see your nice RDF-Data?
|
40
|
+
|
41
|
+
just add following route in the route.config:
|
42
|
+
|
43
|
+
map.connect 'triplify/*specs', :controller => 'triplify', :action => "tripleize"
|
44
|
+
|
45
|
+
that's it. Now just go to http://your-app.com/triplify/ and you will get the full
|
46
|
+
RDF dump of your database. (If you haven't changed the data-depth part in the config)
|
12
47
|
|
48
|
+
That's all the magic.
|
49
|
+
For detailed documentation I'll go on detail on some of the config sections.
|
13
50
|
|
14
51
|
|
15
|
-
Example goes here.
|
16
52
|
|
17
53
|
|
54
|
+
Links:
|
55
|
+
[3] sample config
|
18
56
|
Copyright (c) 2010 Nico Patitz, released under the MIT license
|
@@ -1,95 +1,95 @@
|
|
1
1
|
require 'configatron'
|
2
2
|
|
3
3
|
class TriplifyController < ActionController::Base
|
4
|
-
|
5
|
-
|
6
|
-
#render all models
|
7
|
-
ret=""
|
4
|
+
|
5
|
+
def tripleize
|
8
6
|
t = Tripleizer.new
|
9
|
-
|
7
|
+
t.base_uri = t.uri request.env['REQUEST_URI'].to_s
|
10
8
|
|
11
|
-
filename = '
|
9
|
+
filename = 'data.n3'
|
12
10
|
headers.merge!(
|
13
11
|
'Content-Type' => 'text/rdf+n3',
|
14
12
|
'Content-Disposition' => "attachment; filename=\"#{filename}\"",
|
15
13
|
'Content-Transfer-Encoding' => 'binary'
|
16
14
|
)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
|
16
|
+
t.output_json = request.content_type.try(:to_sym)==:json
|
17
|
+
content_type = t.output_json ? 'application/json' : 'text/plain'
|
18
|
+
render :content_type => content_type , :text => proc { |response, output|
|
19
|
+
t.output = output
|
20
|
+
case params[:specs].length
|
21
|
+
when 0
|
22
|
+
t.write_rdf_head
|
23
|
+
all t
|
24
|
+
when 1
|
25
|
+
t.base_uri = t.base_uri.to_s[0..t.base_uri.to_s.index(params[:specs][0].to_s)-1]
|
26
|
+
t.write_rdf_head
|
27
|
+
model t, params[:specs][0]
|
28
|
+
when 2
|
29
|
+
t.base_uri = t.base_uri.to_s[0..t.base_uri.to_s.index(params[:specs][0].to_s)-1]
|
30
|
+
t.write_rdf_head
|
31
|
+
index t, params[:specs]
|
29
32
|
end
|
33
|
+
|
30
34
|
t_metadata = TriplifyMetadata.new
|
31
|
-
t
|
32
|
-
|
35
|
+
t_metadata.write_metadata(t)
|
36
|
+
output.write t.json if t.output_json
|
33
37
|
}
|
34
38
|
end
|
35
39
|
|
36
|
-
|
40
|
+
private
|
41
|
+
|
42
|
+
def all t
|
43
|
+
#get all models
|
44
|
+
#render all models
|
37
45
|
ret=""
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
t.write_rdf_head(output)
|
42
|
-
model_group= params[:model].to_s #TODO:groß/kleinschreibung.capitalize
|
43
|
-
model_group.downcase!
|
44
|
-
params[:id] ? entries= [params[:id]] : entries = :all
|
45
|
-
#TODO: multiple models
|
46
|
-
models = t.search_models model_group
|
47
|
-
models.each do |model_name, model_attributes|
|
46
|
+
model_groups = eval("configatron.query").to_hash
|
47
|
+
model_groups.each do |model_group_name,model_group|
|
48
|
+
model_group.each do |model_name,model_attributes|
|
48
49
|
if model_name.to_s =="sql_query"
|
49
|
-
t.write_sql(model_group_name,model_attributes,output)
|
50
|
+
t.write_sql(model_group_name,model_attributes,t.output)
|
50
51
|
else
|
51
|
-
t.write_model(model_name,
|
52
|
+
t.write_model(model_name,model_group_name)
|
52
53
|
end
|
53
54
|
end
|
54
|
-
|
55
|
-
|
56
|
-
}
|
55
|
+
end
|
56
|
+
""
|
57
57
|
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
model = eval(model)
|
71
|
-
dtypes =t.dbd_types model
|
72
|
-
|
73
|
-
model= model.find(:all)
|
74
|
-
mapping =eval("configatron.query."+controller+"."+key.to_s).to_hash
|
59
|
+
#get all models
|
60
|
+
def model t, model_group
|
61
|
+
models = t.search_models model_group
|
62
|
+
models.values[0].each do |model_name, model_attributes|
|
63
|
+
if model_name.to_s =="sql_query"
|
64
|
+
t.write_sql(model_group_name,model_attributes,output)
|
65
|
+
else
|
66
|
+
t.write_model(model_name, models.keys[0])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
75
70
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
71
|
+
# get a defined model with given id
|
72
|
+
def index t,param
|
73
|
+
subclass,id = param
|
74
|
+
models = t.search_models subclass
|
75
|
+
models.values[0].each do |model_name, model_attributes|
|
76
|
+
if model_name.to_s =="sql_query"
|
77
|
+
#some magic is needed here ..parse the sql query?
|
78
|
+
else
|
79
|
+
m = Model.new model_name, models.keys[0].to_s
|
80
|
+
row_values=m.get_row_by_id(id).first
|
81
|
+
c1=Hash.new
|
82
|
+
if row_values
|
83
|
+
m.model.columns_hash.each_with_index do |column_name,i|
|
84
|
+
c1[column_name[0]]=eval("row_values.#{column_name}")
|
84
85
|
end
|
85
|
-
|
86
|
-
|
87
|
-
#render :text => t.make_triples(c1, controller , "", t.dbd_types)
|
86
|
+
t.extract_id_line model_attributes, c1,row_values,m.get_datatypes
|
87
|
+
t.make_triples(c1, models.keys[0].to_s , "", m.get_datatypes)
|
88
88
|
end
|
89
89
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
90
|
+
|
91
|
+
end
|
92
|
+
#render :text => t.make_triples(c1, controller , "", t.dbd_types)
|
93
|
+
|
94
94
|
end
|
95
95
|
end
|
@@ -1,3 +1,14 @@
|
|
1
|
+
# Please note that this configuration file is using the yaml syntax.
|
2
|
+
# If your application doesn't start after installing the rtriplify syntax
|
3
|
+
# please make sure, you configured everything properly. Especially in the
|
4
|
+
# query-configuration section you have to take care. Easiest way is to use
|
5
|
+
# an editor for it. For example Netbeans already have a build in one.
|
6
|
+
|
7
|
+
# Please be sure having configured your database configuration properly
|
8
|
+
|
9
|
+
|
10
|
+
# all namespaces for your application. Please use them in your application to
|
11
|
+
# get the data better linked
|
1
12
|
namespaces:
|
2
13
|
vocabulary: http://your-webapp.com/vocabulary/
|
3
14
|
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
|
@@ -17,12 +28,48 @@ namespaces:
|
|
17
28
|
daml: http://www.daml.org/2001/09/countries/iso-3166-ont#
|
18
29
|
|
19
30
|
#queries:
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
31
|
+
# In general there are two possibilites to configure your rdf Data. First is by
|
32
|
+
# using sql queries like in the php version of triplify. Please have a look at
|
33
|
+
# http://triplify.svn.sourceforge.net/viewvc/triplify/triplify-php/config.dist.php?view=markup
|
34
|
+
# to find out how to configure.
|
35
|
+
#
|
36
|
+
# Secound possibility and may be the more "rails-way" is to use active record.
|
37
|
+
# you have two hierarchy levels for configuration. First, the group and secound,
|
38
|
+
# the Active record model.
|
39
|
+
# A configuration line in the model has always the Schema
|
40
|
+
# nameOfField: ar_field
|
41
|
+
# ID field has a special meaning. The ID field is always the Subject of the RDF
|
42
|
+
# triples.
|
43
|
+
# If your model has a relation to another Model you can reference the field by using
|
44
|
+
# the "->" symbol. For example if your Country has States just reference it by
|
45
|
+
# " state->State: states" before the "->"-Symbol the predicate is written. after the Symbol the
|
46
|
+
# referencing model is notated
|
47
|
+
# Additional you can define a filter e.g.
|
48
|
+
# filter:
|
49
|
+
# ID: ">213 and id <224"
|
50
|
+
# Note: in some case lower and Uppercase Notation is Important.
|
51
|
+
# the "id" field is alway written uppercase.
|
52
|
+
# group is written lowercase
|
53
|
+
# Model are written Capitalized like using it in ruby.
|
54
|
+
# first time you may be a little bit irritated, but up to now there is
|
55
|
+
# no better solution for this issue.
|
56
|
+
|
23
57
|
|
24
58
|
query:
|
25
|
-
|
59
|
+
shipping: #the group write it lowercase
|
60
|
+
|
61
|
+
ShippingMethod:
|
62
|
+
gr:DeliveryModeParcelService: name
|
63
|
+
zone->zone: zone
|
64
|
+
|
65
|
+
Zone:
|
66
|
+
rdfs:label: name
|
67
|
+
rdfs:comment: description
|
68
|
+
|
69
|
+
ZoneMember:
|
70
|
+
zone->zone: zone
|
71
|
+
Country->Country: zoneable
|
72
|
+
|
26
73
|
Country: #the model name...write it capitalized
|
27
74
|
ID: iso
|
28
75
|
daml:name: iso_name
|
@@ -44,23 +91,12 @@ query:
|
|
44
91
|
abrr: abbr
|
45
92
|
Country->Country: country
|
46
93
|
|
47
|
-
# Zone:
|
48
|
-
# ID: name
|
49
|
-
# description: description
|
50
|
-
# ZoneMembers->ZoneMembers: zone_member
|
51
|
-
|
52
|
-
# ZoneMembers:
|
53
|
-
# Zone->Zone: zone
|
54
|
-
# type: zoneable_type
|
55
|
-
# Country->Country: zoneable
|
56
|
-
|
57
94
|
product: #the group write it lowercase
|
58
95
|
Product: #the model name...write it capitalized
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
Property->Propery: properties
|
96
|
+
rdfs:label: name
|
97
|
+
rdfs:comment: description
|
98
|
+
ID: permalink
|
99
|
+
Property->Property: properties
|
64
100
|
PropertyValue->ProductProperty: product_properties
|
65
101
|
OptionType->OptionType: option_types
|
66
102
|
CategoryName: tax_category.name
|
@@ -96,14 +132,16 @@ query:
|
|
96
132
|
|
97
133
|
|
98
134
|
Variant:
|
135
|
+
gr:hasBusinessFunction: "gr:Sell"
|
99
136
|
Product->Product: product
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
137
|
+
ID: sku
|
138
|
+
#gr:hasCurrency
|
139
|
+
gr:hasCurrencyValue: price
|
140
|
+
gr:weight: weight
|
141
|
+
gr:height: height
|
142
|
+
gr:width: width
|
143
|
+
gr:depth: depth
|
144
|
+
#count_on_hand: count_on_hand
|
107
145
|
OptionValue->OptionValue: option_values
|
108
146
|
|
109
147
|
Taxon:
|
@@ -121,8 +159,6 @@ query:
|
|
121
159
|
Variant->Variant: variants
|
122
160
|
OptionType->OptionType: option_type
|
123
161
|
|
124
|
-
|
125
|
-
|
126
162
|
user:
|
127
163
|
User:
|
128
164
|
firstname: ship_address.firstname
|
@@ -151,7 +187,7 @@ query:
|
|
151
187
|
# specifies, which columns are references to objects of which type.
|
152
188
|
|
153
189
|
objectProperties:
|
154
|
-
has_creator:
|
190
|
+
has_creator: person
|
155
191
|
|
156
192
|
# Objects are classified according to their type. However, you can specify
|
157
193
|
# a mapping here, if objects of a certain type should be associated with a
|
@@ -159,8 +195,12 @@ objectProperties:
|
|
159
195
|
# unsure it is safe to leave this configuration array empty.
|
160
196
|
#
|
161
197
|
classMap:
|
162
|
-
|
198
|
+
Movie: foaf:person
|
199
|
+
Product: gr:ProductOrServiceModel
|
200
|
+
ShippingMethod: gr:DeliveryMethod
|
201
|
+
Variant:
|
163
202
|
|
203
|
+
#the licence under which you publish your data
|
164
204
|
license: http://creativecommons.org/licenses/by/3.0/us/
|
165
205
|
|
166
206
|
# Additional metadata
|
@@ -171,6 +211,7 @@ metadata:
|
|
171
211
|
dc:title: test
|
172
212
|
dc:publisher: test
|
173
213
|
|
214
|
+
# not yet
|
174
215
|
# Set this to true in order to register your linked data endpoint with the
|
175
216
|
# Triplify registry (http://triplify.org/Registry).
|
176
217
|
# Registering is absolutely recommended, since that allows other Web sites
|
@@ -180,8 +221,8 @@ metadata:
|
|
180
221
|
# the triplify folder, or at: http://triplify.org/Registry
|
181
222
|
|
182
223
|
register: true
|
183
|
-
ttl: 0
|
184
|
-
cachedir: cache
|
224
|
+
#ttl: 0
|
225
|
+
#cachedir: cache
|
185
226
|
|
186
227
|
# Linked Data Depth
|
187
228
|
#
|
@@ -195,7 +236,7 @@ cachedir: cache
|
|
195
236
|
# content will be exposed on the instance level, e.g. when /triplify/user/1/
|
196
237
|
# is accessed.
|
197
238
|
#
|
198
|
-
LinkedDataDepth: 2
|
239
|
+
# LinkedDataDepth: 2
|
199
240
|
|
200
241
|
# Callback Functions
|
201
242
|
#
|
@@ -215,10 +256,7 @@ pingback:
|
|
215
256
|
# Whether X-Pingback header should be exposed and XML-RPC is active.
|
216
257
|
enabled: true
|
217
258
|
#Whether to write Pingbacks with the instance data.
|
218
|
-
write: true
|
219
|
-
#Whether to use mod_rewrite, if it is available...
|
220
|
-
use_mod_rewrite: true
|
221
|
-
|
259
|
+
write: true
|
222
260
|
|
223
261
|
# metadata
|
224
262
|
|
@@ -227,14 +265,11 @@ pingback:
|
|
227
265
|
##
|
228
266
|
|
229
267
|
# You have to specify the operator of this Triplify service. The operator is
|
230
|
-
# usually you or your group or
|
268
|
+
# usually you or your group or organizationlly you or your group or organiz.
|
231
269
|
# There are two options to specify the operator. The first option is an HTTP
|
232
270
|
# URI that identifies the operator. This is the preferred option.
|
233
271
|
#
|
234
|
-
|
235
|
-
#/* The second option is the specification by providing a name, a homepage
|
236
|
-
# * address, and a URI that identifies the type of the operator.
|
237
|
-
# */
|
272
|
+
|
238
273
|
operator_name:
|
239
274
|
operator_homepage:
|
240
275
|
operator_type:
|
@@ -242,21 +277,6 @@ operator_type:
|
|
242
277
|
#// $provenance['OperatorType'] = 'http://swrc.ontoware.org/ontology#ResearchGroup';
|
243
278
|
|
244
279
|
|
245
|
-
#/* If you have an HTTP URI that identifies your triplified dataset (and that
|
246
|
-
# * links to a voiD description of your dataset) specify it here:
|
247
|
-
# */
|
248
|
-
dataset:
|
249
|
-
|
250
|
-
#/* If you have an HTTP URI that identifies the accessed database server specify
|
251
|
-
# * it here:
|
252
|
-
# */
|
253
|
-
database_server:
|
254
|
-
|
255
|
-
#/* If you have an HTTP URI that identifies the configuration file used by your
|
256
|
-
# * Triplify installation specify it here:
|
257
|
-
# */
|
258
|
-
mapping:
|
259
|
-
|
260
280
|
#
|
261
281
|
#//
|
262
282
|
#// END OF CONFIGURATION
|
data/lib/model.rb
CHANGED
@@ -5,24 +5,37 @@ require 'configatron'
|
|
5
5
|
class Model
|
6
6
|
attr_accessor :model
|
7
7
|
attr_accessor :model_name
|
8
|
-
attr_accessor :model_attributes
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
attr_accessor :model_attributes
|
9
|
+
attr_accessor :model_class
|
10
|
+
|
11
|
+
#hard coded mapping look mapping table
|
12
|
+
@mapping
|
13
|
+
|
14
|
+
|
15
|
+
def initialize model_name, model_class, var=nil
|
16
|
+
@model_name= model_name
|
17
|
+
@model_class= model_class
|
13
18
|
#read the model attributes
|
14
|
-
@model_attributes = get_model_attributes model_name
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
@model = get_model
|
19
|
-
|
19
|
+
@model_attributes = get_model_attributes model_name,model_class
|
20
|
+
@model = var ? var : get_model
|
21
|
+
@mapping = Hash[ "binary"=>"base64Binary","boolean"=>"boolean","date"=>"date","datetime"=>"dateTime","decimal"=>"decimal","float"=>"float","integer"=>"integer","string"=>"string","text"=>"string","time"=>"time","timestamp"=>"dateTime",]
|
20
22
|
end
|
23
|
+
|
21
24
|
|
22
25
|
def get_model
|
23
26
|
eval(@model_name.to_s)
|
24
27
|
end
|
25
|
-
|
28
|
+
|
29
|
+
def get_const input
|
30
|
+
#remove function name
|
31
|
+
input = input.to_s
|
32
|
+
input = input[6..input.index(')')-1]
|
33
|
+
|
34
|
+
const = input.index(",")? input.split(",")[0]:input
|
35
|
+
datatype = input.index(",")? input.split(",")[1]: "xsd:String"
|
36
|
+
return [const,datatype]
|
37
|
+
end
|
38
|
+
|
26
39
|
###
|
27
40
|
# *returns the filter of the model
|
28
41
|
#*@remove if filter should be removed from model_attributes list
|
@@ -41,53 +54,83 @@ class Model
|
|
41
54
|
|
42
55
|
def get_include
|
43
56
|
ret = Array.new
|
44
|
-
model_attributes.select {|k,v| k.to_s.include?("->")}.each do |attribute|
|
45
|
-
ref_model = attribute[1]
|
46
|
-
|
47
|
-
|
57
|
+
# model_attributes.select {|k,v| k.to_s.include?("->")}.each do |attribute|
|
58
|
+
# ref_model = attribute[0].to_s.split("->")[1]
|
59
|
+
# get_model_model(@model_class).each do |r_mod|
|
60
|
+
# ret.push(r_mod.to_s.capitalize.to_sym)
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
|
64
|
+
model_attributes.select {|k,v| v.to_s.include?("*")}.each do |attribute|
|
65
|
+
m_class,field=attribute[1].to_s.split("*")
|
66
|
+
#get model
|
67
|
+
ret.push(m_class.downcase.to_sym) unless ret.index(m_class.downcase.to_sym) || m_class[0..5]=="MODEL("
|
48
68
|
end
|
69
|
+
|
49
70
|
model_attributes.select {|k,v| v.to_s.include?(".")}.each do |attribute|
|
50
|
-
ref_model = attribute[1].split(".")[0]
|
71
|
+
ref_model = attribute[1].split(".")[0].to_s.downcase
|
51
72
|
#get model
|
52
|
-
ret.push(ref_model.
|
73
|
+
ret.push(ref_model.to_sym) unless ret.index(ref_model.to_sym)
|
53
74
|
end
|
54
75
|
ret
|
55
76
|
end
|
56
77
|
|
57
|
-
def get_model_attributes key
|
78
|
+
def get_model_attributes key, model_class
|
58
79
|
model_groups = eval("configatron.query").to_hash
|
59
80
|
model_groups.each do |model_group_name,model_group|
|
60
|
-
|
61
|
-
|
62
|
-
|
81
|
+
if model_group_name.to_s==model_class.to_s
|
82
|
+
hello="hello"
|
83
|
+
model_group.each do |model_name_query,attributes|
|
84
|
+
return attributes if model_name_query.to_s.downcase == key.to_s.downcase
|
63
85
|
end
|
64
86
|
end
|
65
87
|
end
|
66
88
|
nil
|
67
89
|
end
|
68
90
|
|
91
|
+
def get_model_model model_class
|
92
|
+
model_groups = eval("configatron.query").to_hash
|
93
|
+
model_groups.each do |model_group_name,model_group|
|
94
|
+
if model_group_name==model_class
|
95
|
+
return model_group.keys
|
96
|
+
end
|
97
|
+
end
|
98
|
+
nil
|
99
|
+
end
|
100
|
+
|
69
101
|
def read_attributes
|
70
102
|
get_model_attributes @model_name
|
71
103
|
end
|
72
104
|
|
73
|
-
def get_datatypes
|
74
|
-
#hard coded mapping look mapping table
|
75
|
-
mapping = Hash[ "binary"=>"base64Binary","boolean"=>"boolean","date"=>"date","datetime"=>"dateTime","decimal"=>"decimal","float"=>"float","integer"=>"integer","string"=>"string","text"=>"string","time"=>"time","timestamp"=>"dateTime",]
|
105
|
+
def get_datatypes
|
76
106
|
dtypes = Hash.new
|
77
107
|
@model.columns_hash.each_key do |m|
|
78
108
|
#make xsd datatye
|
79
|
-
dtypes[m.to_s] ="xsd:#{mapping[@model.columns_hash[m].type.to_s] }"
|
109
|
+
dtypes[m.to_s] ="xsd:#{@mapping[@model.columns_hash[m].type.to_s] }"
|
80
110
|
end
|
81
111
|
#replace mapping
|
82
112
|
@model_attributes.each do |k,v|
|
83
|
-
|
113
|
+
if ((v.include? "*") ||(v.include? "." )) && v.to_s[0..5]!="Model("
|
114
|
+
field,model = k.to_s.split "->"
|
115
|
+
unless model
|
116
|
+
#todo: get datatype..thats a little bit tricky at this point
|
117
|
+
# v.gsub!("*",".")
|
118
|
+
# a,db_field= v.to_s.split "."
|
119
|
+
# t = eval("#{model}.columns_hash[db_field.to_s].type.to_s.downcase")
|
120
|
+
# dtypes[k.to_s]="xsd:#{@mapping[t]}"
|
121
|
+
end
|
122
|
+
else
|
123
|
+
dtypes[k.to_s]=dtypes[v.to_s]
|
124
|
+
end
|
84
125
|
end
|
85
126
|
dtypes
|
86
127
|
end
|
87
128
|
|
88
129
|
def get_rows
|
89
130
|
#make filter
|
131
|
+
|
90
132
|
t = @model
|
133
|
+
return t if t.class == Array
|
91
134
|
filter = get_filter(true)
|
92
135
|
include = get_include
|
93
136
|
|
@@ -106,6 +149,29 @@ class Model
|
|
106
149
|
end
|
107
150
|
t
|
108
151
|
end
|
152
|
+
|
153
|
+
def get_row_by_id id
|
154
|
+
#make filter
|
155
|
+
t = @model
|
156
|
+
filter = get_filter(true)
|
157
|
+
include = get_include
|
158
|
+
find_command = "find_all_by_#{get_key.to_s.downcase}"
|
159
|
+
|
160
|
+
if include.empty?
|
161
|
+
if filter
|
162
|
+
t = eval("t.#{find_command}(#{id}, :conditions =>filter)")
|
163
|
+
else
|
164
|
+
t = eval("t.#{find_command}(#{id})")
|
165
|
+
end
|
166
|
+
else
|
167
|
+
if filter
|
168
|
+
t = eval("t.#{find_command}(#{id},:include => include, :conditions => filter)")
|
169
|
+
else
|
170
|
+
t = eval("t.#{find_command}(\"#{id}\",:include => include)")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
t
|
174
|
+
end
|
109
175
|
|
110
176
|
def get_key
|
111
177
|
id_keys = @model_attributes.to_hash.keys
|
@@ -115,24 +181,5 @@ class Model
|
|
115
181
|
return :id if id_key.empty?
|
116
182
|
return @model_attributes[id_key[0].to_sym]
|
117
183
|
end
|
118
|
-
|
119
|
-
# def extract_id_line model_attributes, line,item,dtypes
|
120
|
-
# #look if id is mapped to another field
|
121
|
-
# id_keys = model_attributes.to_hash.keys
|
122
|
-
# #hotfix..bad performance
|
123
|
-
# id_keys.map!{|k| k.to_s }
|
124
|
-
# id_key= id_keys.select{|k| k =~/^(ID|id|iD|Id)$/ }
|
125
|
-
# if id_key.empty?
|
126
|
-
# line[:id] = item.id
|
127
|
-
# else
|
128
|
-
# line[:id] = eval("item.#{model_attributes[id_key[0].to_sym]}")
|
129
|
-
# #set the correct datatype for it
|
130
|
-
# dtypes["id"]= line[:id].class.to_s.downcase
|
131
|
-
# #remove the id line
|
132
|
-
# line.delete id_key[0].to_sym
|
133
|
-
# end
|
134
|
-
# end
|
135
|
-
|
136
|
-
|
137
184
|
|
138
185
|
end
|