Module: Cul::Hydra::Controllers::Aggregates

Extended by:
ActiveSupport::Concern
Defined in:
lib/cul_hydra/controllers/aggregates.rb

Instance Method Summary collapse

Instance Method Details

#createObject

Creates and Saves a Parent - Child relationship in the Child’s RELS-EXT If container_id is provided:

  • the File Asset will use RELS-EXT to assert that it’s a part of the specified container

  • the method will redirect to the container object’s edit view after saving



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
# File 'lib/cul_hydra/controllers/aggregates.rb', line 51

def create
  if params.has_key?(:aggregate_id)
    @resource = load_aggregate
    logger.debug @resource.class
    logger.debug @resource.datastreams["RELS-EXT"].content
    logger.debug @resource.to_rels_ext(@resource.pid)
    if !params[:asset_id].nil?
      associate_resource_with_container(@resource, params[:asset_id])
      @resource.save
      flash[:notice] = "Aggregated #{@resource.pid} under #{params[:asset_id]}."
    else
      flash[:notice] = "You must specify a container for the aggregate."
    end
  else
    flash[:notice] = "You must specify a resource to aggregate."
  end

  if !params[:asset_id].nil?
    redirect_params = {:controller=>"aggregates", :id=>params[:asset_id], :action=>:index}
  end

  redirect_params ||= {:action=>:index}

  redirect_to redirect_params
end

#destroyObject

Common destroy method for all AssetsControllers



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/cul_hydra/controllers/aggregates.rb', line 78

def destroy
  @resource = load_aggregate
  remove_resource_from_container(@resource, params[:asset_id])
  @resource.save

  flash[:notice] = "Deleted #{params[:id]} from #{params[:asset_id]}."
  if !params[:asset_id].nil?
    redirect_params = {:controller=>"aggregates", :id=>params[:asset_id], :action=>:index}
  end

  redirect_params ||= {:action=>:index}

  redirect_to redirect_params
end

#indexObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cul_hydra/controllers/aggregates.rb', line 17

def index

  if params[:layout] == "false"
    layout = false
  end
  container_uri = "info:fedora/#{params[:asset_id]}"
  escaped_uri = container_uri.gsub(/(:)/, '\\:')
  extra_controller_params =  {:q=>"cul_member_of_s:#{escaped_uri}"}
  @response, @document_list = get_search_results( extra_controller_params )
  
    # Including this line so permissions tests can be run against the container
  @container_response, @document = get_solr_response_for_doc_id(params[:asset_id])
  
  render :action=>params[:action], :layout=>layout
end

#load_aggregateObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cul_hydra/controllers/aggregates.rb', line 33

def load_aggregate
  if params.has_key? :aggregate_id
    af_base = ActiveFedora::Base.load_instance(params[:aggregate_id])
  else
    af_base = ActiveFedora::Base.load_instance(params[:id])
  end
  the_model = ActiveFedora::ContentModel.known_models_for( af_base ).first
  if the_model.nil? or the_model == ActiveFedora::Base
    the_model = DcDocument
  end

  @resource = the_model.load_instance(af_base.pid)
end