Class: TriplestoreSyncController

Inherits:
ApplicationController show all
Includes:
Iqvoc::RDFSync::Helper
Defined in:
app/controllers/triplestore_sync_controller.rb

Instance Method Summary collapse

Methods included from Iqvoc::RDFSync::Helper

#triplestore_syncer

Instance Method Details

#indexObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/triplestore_sync_controller.rb', line 22

def index
  authorize! :use, :dashboard

  flash.now[:info] = [I18n.t('txt.controllers.triplestore_sync.batch_hint',
      host: root_url(lang: nil))]

  if Iqvoc.config['triplestore.url'] == Iqvoc.config.defaults['triplestore.url']
    flash.now[:warning] = I18n.t('txt.controllers.triplestore_sync.config_warning')
  else
    host = Iqvoc.config['triplestore.url']
    username = Iqvoc.config['triplestore.username'].presence
    password = Iqvoc.config['triplestore.password'].presence
    target_info = host
    if username && password
      target_info = "#{target_info} (as #{username} with password)" # XXX: i18n
    elsif username
      target_info = "#{target_info} (as #{username})" # XXX: i18n
    end
    flash.now[:info] << I18n.t('txt.controllers.triplestore_sync.config_info',
        target_info: target_info)
  end

  # per-class pagination
  @candidates = Iqvoc::RDFSync.candidates.map do |records|
    records.page(params[:page])
  end
end

#syncObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/triplestore_sync_controller.rb', line 50

def sync
  authorize! :use, :dashboard

  flash[:error] = []
  begin
    success = triplestore_syncer.all # XXX: long-running
  rescue => exc
    success = false
    flash[:error] << exc.message
  end

  if success
    flash[:success] = I18n.t('txt.controllers.triplestore_sync.success')
  else
    flash[:error] << I18n.t('txt.controllers.triplestore_sync.error')
  end

  redirect_to action: 'index'
end