Class: MtkController

Inherits:
ApplicationController show all
Defined in:
lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb

Instance Method Summary collapse

Instance Method Details

#auto_complete_for_add_file_Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 38

def auto_complete_for_add_file_
  p=params[ "add_file[]" ].to_s
  puts "p=#{p}"
  @filter_result=Array.new
  Dir.glob("#{p}*").each { |f|
    puts "f=#{f}"
    h=Hash.new
    h["to_s"]=f
    @filter_result << h 
    break if @filter_result.length > 10
  }
  render :inline => "<%= auto_complete_result @filter_result, 'to_s' %>"
end

#auto_complete_for_filter_containsObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 51

def auto_complete_for_filter_contains
  puts "@@@@@@@@@@@@@@\ncall auto_complete_for_contact_name"
  post_init
  puts "0 params"
  params.each{|p,v|
    puts "auto #{p}-->#{v}"
  }
  puts "1 params"
  
  filter=params[ :filter ][:contains].to_s
  filter=/#{filter}/
  #puts "params.raw_post=#{params.raw_post} size=#{@model.size}"
  @filter_result=Array.new
  @model.each_value {  |res|
    #puts "filter=#{filter} #{res.to_s} #{res.class.name}"
    if (res.to_s =~ filter)
      h=Hash.new
      h["to_s"]="^#{res.to_s}$"
      @filter_result << h 
      break if @filter_result.length > 10
    end
  }
  #puts "filter!, #{filter} #{@filter_result.length}"
  render :inline => "<%= auto_complete_result @filter_result, 'to_s' %>"
  #render :partials => contact
end

#clearObject



24
25
26
27
28
29
30
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 24

def clear
  post_init
  @loader.reset
  post_init

  #MtkWebContext::RModel=Model.new
end

#dotObject



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 325

def dot 
  uri=params["uri"]
  method=params["method"]

  post_init
  obj=@model[uri]

  fn="#{Dir.tmpdir}/#{method}-#{obj.object_id}"

  obj.mtk_writeSession("#{fn}.dot") {
    obj.instance_eval(method)
  }

  cmd="dot -Tgif -o#{fn}.gif #{fn}.dot" 
  system(cmd)
  send_file "#{fn}.gif", :type => 'image/gif', :disposition => 'inline'

end

#echoObject



268
269
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 268

def echo
end

#exitServerObject



343
344
345
346
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 343

def exitServer
 puts "Exiting server"
 Process.exit!(0)
end

#indexObject

MtkWebContext::RModel=Model.new



31
32
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 31

def index
end

#last_generatedObject



34
35
36
37
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 34

def last_generated
  post_init
  @generated=@model.fileGenerated
end

#loadLocalRDFUpdateFileObject



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 229

def loadLocalRDFUpdateFile
  post_init
  fn=params["file"]
  puts "\"File\"=\"#{fn}\""
  @loader.addModelFile(fn)
  #@model.loadModelFromFile(fn)
  @model.mtk_context(:build => '../build/') {
    @model.java_generate
  }
  render_text <<END 
XMDA SERVER WAS SUCCESSFULLY CONTACTED
File loaded  : #{fn}
updateCount  : #{@model.updateCount}
Nbr Resources: #{@model.length}
Generation   : disabled
END
end

#loadLocalRDFUpdateFileWithCookieObject



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 250

def loadLocalRDFUpdateFileWithCookie
  p=session[:count]
  p=1 if !p
  p=p+1
  session[:count]=p
  render_text "Yes ! call count:#{p} "

  m=session[:rdfModel]
  if m==nil	
    m=Crdf_Repository.new
    m.loadUml2
  end
  m.loadModelFromFile("../../fr.ft.emf2rdf.generator/tests-data/simple1.uml2.tests.output.nt")

  m.generate

  session[:rdfModel]=m
end

#modelObject



319
320
321
322
323
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 319

def model
  post_init
  show_obj(@model,"")
  #render :action=> "show"
end

#model_statObject



246
247
248
249
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 246

def model_stat
  post_init
  render_text "#{@model.length} ressources"
end

#pdfObject

essai pdf



308
309
310
311
312
313
314
315
316
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 308

def pdf
  require "pdf/writer"
  _pdf = PDF::Writer.new
  _pdf.select_font "Times-Roman"
  _pdf.text "Hello, Ruby.", :font_size => 72, :justification => :center

  send_data _pdf.render, :filename => "hello.pdf",
    :type => "application/pdf"
end

#post_initObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 13

def post_init
  puts "initialize!"

  @loader=Crdf_loader.instance
  #@loader.loadProfile

  @model=@loader.rdf_Repository
  #MtkWebContext::RModel
  #@model.init
end

#searchObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 80

def search
  post_init
  
  params.each {|k,v|
    puts("params #{k} --> #{v.class} #{v}")
  }
  
  filter=params[:filter][:contains].to_s
  puts "filter=#{filter}"
  filter=/#{filter}/
  search_result=@model.reject {  |key,res|
    #puts "filter=#{filter} #{res.to_s} #{res.class.name}"
    !(res.to_s =~ filter)
  }

  if search_result.size == 1
    search_result.each { |key,res|
      redirect_to :action => "show", :uri => key 
    }
  else
    @search_result=search_result
    @filter=filter
    #@model=m
    render :action=> "search_result"
  end
end

#search_formObject

render :partials => contact



77
78
79
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 77

def search_form
  post_init
end

#search_resultObject



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 106

def search_result
  post_init
  filter=params[ "filter[x]" ].to_s
  filter=/#{filter}/
  @model=m
  @search_result=@model.reject {  |key,res|
    #puts "filter=#{filter} #{res.to_s} #{res.class.name}"
    !(res.to_s =~ filter)
  }
  render :action=> "search_result"
end

#setupObject



271
272
273
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 271

def setup 
  redirect_to :action => "setup_form"
end

#setup_changeObject



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 280

def setup_change
  post_init

  add_file=params["add_file[]"]
  if !add_file.nil? && add_file.length>0
    puts "add_file=#{add_file}"
    @loader.addModelFile(add_file)
  end

  key=1000
  @loader.availableProfiles.each { |prof|
    key=key+1
    puts "!!!!!!!!"
    puts params["check_#{key}"]
    puts params["check_#{key}"]=="1"
    if params["check_#{key}"]=="1"
      puts "add #{prof}"
      @loader.activeProfiles.add(prof) 
    else
      puts "delete #{prof}"
      @loader.activeProfiles.delete(prof) 
    end

  }
  redirect_to :action => "setup_form"
end

#setup_formObject



274
275
276
277
278
279
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 274

def setup_form
  post_init
  @activeProfiles=@loader.activeProfiles
  @availableProfiles=@loader.availableProfiles
  @sourceFiles=@loader.sourceFiles
end

#showObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 118

def  show
  post_init
  #m=session[:rdfModel]
  #model=MtkWebContext::RModel
  #model.init
  uri=params["uri"]
              

  obj=@model[uri]

  if obj==nil
    puts "object not found (uri=#{uri})!!!!"
    #@model=model.reject { false }
    @uri=uri
    render :action=> "not_found"
    puts "object not found!!!!"
    return
  end
  puts "object found (uri=#{uri})!!!!"
  onglet_actif=params["onglet"]
  onglet_actif="" if onglet_actif.nil?

  show_obj(obj,onglet_actif)
end

#show_obj(obj, onglet_actif) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/ontomde-core/inspector/rails/app/controllers/mtk_controller.rb', line 142

def  show_obj(obj,onglet_actif)


  #out="
  #	uri=#{uri}<br>
  #	model=#{@model==nil ? 'nil' : 'model loaded'}<br>
  #	obj=#{obj==nil ? 'nil' : 'objet loaded'}<br>
  #"

  puts "obj.class.name=#{obj.class.name}"

  methods=Hash.new
  vides=Array.new
  erreurs=Array.new
  onglets=Set.new
  onglets << ""

  on_demand=%w{ rdfx_clone }
  black_list=%w{to_enum enum_for extended_by instance_values instance_variables object_id private_methods public_methods rdf_Repository to_a to_yaml to_yaml_style to_yaml_properties instance_eval instance_values private_methods object_id decode_b require_gem protected_methods silence_stderr enable_warnings ext_ instance_exec method_missing silence_stream silence_warnings singleton_methods subclasses_of to_json with_options stringify_keys  symbolize_keys to_hash to_options  to_set to_xml  with_indifferent_access init_notUsed require_gem_with_options require_library_or_gem }

  on_demand.reject!{ |elt| params["on_demand"]==elt }

  obj.methods.find_all { |a|  
    #puts "operation:#{a} one=#{(a.to_s=~/^.*_one[0]$/)and true}"
    a =~/^[a-zA-Z]+_[_a-zA-Z0-9]*\??$/  and !black_list.include?(a) and !on_demand.include?(a) and !(a=~/^.*_xxxone[0]$/) #and ! a=~ "_dot"
  }.sort{|a,b| a<=>b}.each {|m|


    #puts "operation=#{m} !!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    #if(on_demand.include?(a)
    r=nil

    sos=@model.mtk_stringWriteSession() {
      begin
 obj.mtk_context(:contextReturnKeyIfEmpty => true) {
         r=eval("obj.#{m}")
 }
        #puts "          post eval"
      rescue Warning =>warn
        if m=~/.*_one$/ 
          erreurs.push(m) 
          next
        end
        puts"warn=#{warn.message}"
        r="Warning:"+warn.message.split(/:/,4)[3]
        puts "          rescue"
      rescue StandardError =>boom
        puts "          rescue eval (!!)"
        puts "boom      #{boom.to_s}"
        erreurs.push(m)
        next
      end
    }
    puts "sos=#{sos}/#{sos.to_s} #{sos.class.name}"

    r=sos.to_s if sos!=nil
    if(r==nil) 
      vides.push(m) 
      next
    end

    r=[r] if !r.respond_to?(:each)
    if(r.length<=0) 
      vides.push(m) 
    else
      #on ajoute m
      prefix=m.split(/_/,3)[0]
      onglets << prefix 
      methods[m]=r
    end
  }

  @obj=obj
  @methods=methods
  @vides=vides		
  #@model=@model	
  @erreurs=erreurs
  @on_demand=on_demand	
  @onglets=onglets
  @onglet_actif=onglet_actif

	
end