Class: Concepts::VersionsController

Inherits:
ApplicationController
  • Object
show all
Includes:
RdfSyncService::Helper
Defined in:
app/controllers/concepts/versions_controller.rb

Overview

Copyright 2011-2013 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Instance Method Summary collapse

Methods included from RdfSyncService::Helper

#triplestore_syncer

Instance Method Details

#branchObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/concepts/versions_controller.rb', line 59

def branch
  concept_scope = Iqvoc::Concept.base_class.by_origin(params[:origin])
  current_concept = concept_scope.published.last!

  if draft_concept = concept_scope.unpublished.last
    flash[:info] = t('txt.controllers.versioning.branch_error')
    redirect_to concept_path(published: 0, id: draft_concept)
  else
    authorize! :branch, current_concept

    new_version = nil
    ActiveRecord::Base.transaction do
      new_version = current_concept.branch
      new_version.save!
      Iqvoc.change_note_class.create! do |note|
        note.owner = new_version
        note.language = I18n.locale.to_s
        note.position = (current_concept.send(Iqvoc.change_note_class_name.to_relation_name).maximum(:position) || 0).succ
        note.annotations_attributes = [
          { namespace: 'dct', predicate: 'creator', value: current_user.name },
          { namespace: 'dct', predicate: 'modified', value: DateTime.now.to_s }
        ]
      end
    end
    flash[:success] = t('txt.controllers.versioning.branched')
    redirect_to edit_concept_path(published: 0, id: new_version)
  end
end

#consistency_checkObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/concepts/versions_controller.rb', line 88

def consistency_check
  concept = Iqvoc::Concept.base_class.
      by_origin(params[:origin]).
      unpublished.
      last!

  authorize! :check_consistency, concept

  if concept.publishable?
    flash[:success] = t('txt.controllers.versioning.consistency_check_success')
    redirect_to concept_path(published: 0, id: concept)
  else
    flash[:error] = t('txt.controllers.versioning.consistency_check_error')
    redirect_to concept_path(published: 0, id: concept, full_consistency_check: '1')
  end
end

#mergeObject



20
21
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
49
50
51
52
53
54
55
56
57
# File 'app/controllers/concepts/versions_controller.rb', line 20

def merge
  concept_scope = Iqvoc::Concept.base_class.by_origin(params[:origin])

  current_concept = concept_scope.published.last
  new_version = concept_scope.unpublished.last

  unless new_version
    raise ActiveRecord::RecordNotFound,
        "Can't find draft concept with origin '#{params[:origin]}'"
  end

  authorize! :merge, new_version

  ActiveRecord::Base.transaction do
    new_version.rdf_updated_at = nil
    new_version.publish

    if new_version.publishable?
      new_version.save

      if current_concept && !current_concept.destroy
        flash[:error] = t('txt.controllers.versioning.merged_delete_error')
        redirect_to concept_path(published: 0, id: new_version)
      end

      if Iqvoc.config['triplestore.autosync']
       synced = triplestore_syncer.sync([new_version]) # XXX: blocking
       flash[:warning] = 'triplestore synchronization failed' unless synced # TODO: i18n
      end

      flash[:success] = t('txt.controllers.versioning.published')
      redirect_to concept_path(id: new_version)
    else
      flash[:error] = t('txt.controllers.versioning.merged_publishing_error')
      redirect_to concept_path(published: 0, id: new_version)
    end
  end
end

#to_reviewObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/controllers/concepts/versions_controller.rb', line 105

def to_review
  concept = Iqvoc::Concept.base_class.
      by_origin(params[:origin]).
      unpublished.
      last!

  authorize! :send_to_review, concept

  # Only send the concept to review if it is publishable (e.g. consistency check is OK)
  if concept.publishable?
    concept.to_review
    concept.save!

    flash[:success] = t('txt.controllers.versioning.to_review_success')
    redirect_to concept_path(published: 0, id: concept)
  else
    flash[:error] = t('txt.controllers.versioning.consistency_check_error')
    redirect_to concept_path(published: 0, id: concept, full_consistency_check: '1')
  end
end