Class: Labels::VersionsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/labels/versions_controller.rb

Instance Method Summary collapse

Instance Method Details

#branchObject

Raises:

  • (ActiveRecord::RecordNotFound)


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/labels/versions_controller.rb', line 40

def branch
  current_label = Iqvoc::XLLabel.base_class.by_origin(params[:origin]).published.last
  raise ActiveRecord::RecordNotFound.new("Couldn't find published Label with origin '#{params[:origin]}'") unless current_label
  raise "There is already an unpublished version for Label '#{params[:origin]}'" if Iqvoc::XLLabel.base_class.by_origin(params[:origin]).unpublished.last
  authorize! :branch, current_label
  new_version = nil
  ActiveRecord::Base.transaction do
    new_version = current_label.branch(current_user)
    new_version.save!
  end
  flash[:success] = t("txt.controllers.versioning.branched")
  redirect_to edit_label_path(:published => 0, :id => new_version, :check_associations_in_editing_mode => true)
end

#consistency_checkObject

Raises:

  • (ActiveRecord::RecordNotFound)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/labels/versions_controller.rb', line 82

def consistency_check
  label = Iqvoc::XLLabel.base_class.by_origin(params[:origin]).unpublished.last
  raise ActiveRecord::RecordNotFound unless label

  authorize! :check_consistency, label

  if label.valid_with_full_validation?
    flash[:success] = t("txt.controllers.versioning.consistency_check_success")
    redirect_to label_path(:published => 0, :id => label)
  else
    flash[:error] = t("txt.controllers.versioning.consistency_check_error")
    redirect_to edit_label_path(:published => 0, :id => label, :full_consistency_check => 1)
  end
end

#lockObject

Raises:

  • (ActiveRecord::RecordNotFound)


54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/labels/versions_controller.rb', line 54

def lock
  new_version = Iqvoc::XLLabel.base_class.by_origin(params[:origin]).unpublished.last
  raise ActiveRecord::RecordNotFound.new("Couldn't find unpublished Label with origin '#{params[:origin]}'") unless new_version
  raise "Label with origin '#{params[:origin]}' has already been locked." if new_version.locked?

  authorize! :lock, new_version

  new_version.lock_by_user(current_user.id)
  new_version.save!

  flash[:success] = t("txt.controllers.versioning.locked")
  redirect_to edit_label_path(:published => 0, :id => new_version)
end

#mergeObject

Raises:

  • (ActiveRecord::RecordNotFound)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/labels/versions_controller.rb', line 3

def merge
  current_label = Iqvoc::XLLabel.base_class.by_origin(params[:origin]).published.last
  new_version = Iqvoc::XLLabel.base_class.by_origin(params[:origin]).unpublished.last
  raise ActiveRecord::RecordNotFound.new("Couldn't find unpublished label with origin '#{params[:origin]}'") unless new_version
  authorize! :merge, new_version

  ActiveRecord::Base.transaction do
    if current_label.blank? || current_label.destroy
      new_version.publish
      new_version.unlock
      if new_version.valid_with_full_validation?
        new_version.save
        begin
         # TODO if RdfStore.update(new_version.rdf_uri, label_url(:id => new_version, :format => :ttl))
         #   new_version.update_attribute(:rdf_updated_at, 1.seconds.since)
         # end
        rescue Exception => e
          handle_virtuoso_exception(e.message)
        end
        if new_version.has_concept_or_label_relations?
          flash[:success] = t("txt.controllers.versioning.published")
          redirect_to label_path(:id => new_version)
        else
          flash[:error] = t("txt.controllers.versioning.published_with_warning")
          redirect_to label_path(:id => new_version)
        end
      else
        flash[:error] = t("txt.controllers.versioning.merged_publishing_error")
        redirect_to label_path(:published => 0, :id => new_version)
      end
    else
      flash[:error] = t("txt.controllers.versioning.merged_delete_error")
      redirect_to label_path(:published => 0, :id => new_version)
    end
  end
end

#to_reviewObject

Raises:

  • (ActiveRecord::RecordNotFound)


97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/labels/versions_controller.rb', line 97

def to_review
  label = Iqvoc::XLLabel.base_class.by_origin(params[:origin]).unpublished.last
  raise ActiveRecord::RecordNotFound unless label

  authorize! :send_to_review, label

  label.to_review
  label.save!
  flash[:success] = t("txt.controllers.versioning.to_review_success")
  redirect_to label_path(:published => 0, :id => label)
end

#unlockObject

Raises:

  • (ActiveRecord::RecordNotFound)


68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/labels/versions_controller.rb', line 68

def unlock
  new_version = Iqvoc::XLLabel.base_class.by_origin(params[:origin]).unpublished.last
  raise ActiveRecord::RecordNotFound.new("Couldn't find unpublished Label with origin '#{params[:origin]}'") unless new_version
  raise "Label with origin '#{params[:origin]}' wasn't locked." unless new_version.locked?

  authorize! :unlock, new_version

  new_version.unlock
  new_version.save!

  flash[:success] = t("txt.controllers.versioning.unlocked")
  redirect_to label_path(:published => 0, :id => new_version)
end