Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #50 from IntersectAustralia/HCSVLAB-1185
Browse files Browse the repository at this point in the history
HCSVLAB-1185 Fix redirections of web ingest actions
  • Loading branch information
matthew-intersect committed Dec 7, 2015
2 parents 042a064 + 998f8a3 commit 2ea5183
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $(window).load(function() {

$(function () {
var alert = $('.alert');
if (alert.length > 0) {
if (alert.length > 0 && !alert.hasClass('permanent')) {
alert.slideDown();

alertTimeout = 9000;
Expand Down
21 changes: 9 additions & 12 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ def advanced_search_syntax
def show
if Item.where(id: params[:id]).count != 0
@item = Item.find_by_handle("#{params[:collection]}:#{params[:itemId]}")
render 'catalog/processing_show' and return if @processing_index

@response, @document = get_solr_response_for_doc_id

# For some reason blacklight stopped to fullfill the counter value in the session since we changed
Expand Down Expand Up @@ -606,9 +608,10 @@ def document
#
def invalid_solr_id_error
respond_to do |format|
format.html { flash[:error] = "Sorry, you have requested a document that doesn't exist."
params.delete(:id)
redirect_to catalog_path() and return
format.html {
flash[:error] = "Sorry, you have requested a document that doesn't exist."
params.delete(:id)
redirect_to catalog_path() and return
}
format.any { render :json => {:error => "not-found"}.to_json, :status => 404 }
end
Expand Down Expand Up @@ -935,14 +938,8 @@ def check_item_indexed
begin
item = Item.find(params[:id])
if item.indexed_at.nil?
respond_to do |format|
format.html {
flash.keep(:notice) # Persist flash notices from the previous request
flash[:error] = "Sorry, the item you requested is being indexed and will be available shortly. You may need to wait a few moments and refresh the page to see your item."
redirect_to root_url and return
}
format.json { render :json => {:error => "not-found"}.to_json, :status => 404 }
end
@processing_index = true
flash.keep(:notice)
end
rescue ActiveRecord::RecordNotFound
return
Expand All @@ -954,7 +951,7 @@ def check_item_indexed
#
def wrapped_enforce_show_permissions(opts={})
begin
enforce_show_permissions(opts)
enforce_show_permissions(opts) unless @processing_index
rescue Hydra::AccessDenied => e
respond_to do |format|
format.html { raise e }
Expand Down
26 changes: 26 additions & 0 deletions app/views/catalog/processing_show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.span9

%h1= @item.handle

.well.clearfix
.pull-left
= link_back_to_catalog
- if can? :delete_item_via_web_app, @item.collection
= render "delete_item"
.pull-right
= link_to "#{t('blacklight.search.start_over')}", catalog_index_path, :id => "startOverLink", :class => "btn"

%h3
%span Item Details
%dl.dl-horizontal.dl-invert
.alert.alert-warning.permanent
This item is currently being indexed meaning the item and document metadata is currently unavailable. Please wait a few moments then refresh the page to try again.

%h3
%span Documents
%dl.dl-horizontal.dl-invert
- if can? :web_add_document, @item.collection
%br
= link_to "Add New Document", web_add_document_path, :id => 'add_new_document', :class => "btn"

= render 'shared/nectar_attribution'
4 changes: 4 additions & 0 deletions app/views/catalog/processing_show.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object @item
node(:@context) { annotation_context_url }
node(:"#{PROJECT_PREFIX_NAME}:catalog_url") { catalog_url(@item.collection.name, @item.get_name) }
node(:"#{PROJECT_PREFIX_NAME}:metadata") { "processing" }
15 changes: 15 additions & 0 deletions features/api.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,21 @@ Feature: Browsing via API
{"success":["item1"]}
"""

@api_add_item
Scenario: Add item and view item via API while processing index
Given I make a JSON post request for the collections page with the API token for "[email protected]" with JSON params
| name | collection_metadata |
| Test | {"@context": {"Test": "http://collection.test", "dc": "http://purl.org/dc/elements/1.1/", "dcmitype": "http://purl.org/dc/dcmitype/", "marcrel": "http://www.loc.gov/loc.terms/relators/", "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs": "http://www.w3.org/2000/01/rdf-schema#", "xsd": "http://www.w3.org/2001/XMLSchema#" }, "@id": "http://collection.test", "@type": "dcmitype:Collection", "dc:creator": "Pam Peters", "dc:rights": "All rights reserved to Data Owner", "dc:subject": "English Language", "dc:title": "A test collection", "marcrel:OWN": "Data Owner"} |
When I make a JSON post request for the collection page for id "Test" with the API token for "[email protected]" with JSON params
| items |
| [ { "metadata": { "@context": { "ausnc": "http://ns.ausnc.org.au/schemas/ausnc_md_model/", "corpus": "http://ns.ausnc.org.au/corpora/", "dc": "http://purl.org/dc/terms/", "dcterms": "http://purl.org/dc/terms/", "foaf": "http://xmlns.com/foaf/0.1/", "hcsvlab": "http://hcsvlab.org/vocabulary/", "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdfs": "http://www.w3.org/2000/01/rdf-schema#", "xsd": "http://www.w3.org/2001/XMLSchema#" }, "@graph": [ { "@id": "item1", "@type": "ausnc:AusNCObject", "ausnc:document": [ { "@id": "document1", "@type": "foaf:Document", "dcterms:extent": 1234, "dcterms:identifier": "document1.txt", "dcterms:source": { "@id": "file:///data/test_collections/ausnc/test/document1.txt" }, "dcterms:title": "document1#Text", "dcterms:type": "Text" } ], "dcterms:identifier": "item1", "dcterms:isPartOf": { "@id": "corpus:Test" }, "hcsvlab:indexable_document": { "@id": "document1.txt" }, "hcsvlab:display_document": { "@id": "document1.txt" } } ] } } ] |
And I should get a 200 response code
And I make a JSON request for the catalog page for "test:item1" with the API token for "[email protected]"
Then the JSON response should be:
"""
{"@context":"http://example.org/schema/json-ld", "alveo:catalog_url":"http://example.org/catalog/test/item1", "alveo:metadata":"processing"}
"""

@api_delete_item
Scenario: Delete an item from a non-existing collection
When I make a JSON delete request for the delete item "item1" from collection "Test" page with the API token for "[email protected]"
Expand Down
3 changes: 2 additions & 1 deletion features/document_create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ Feature: Creating Documents
And I am on the add document page for "test:item1"
And I attach the file "test/samples/api/sample1.txt" to "document_file"
And I press "Create"
Then the file "sample1.txt" should exist in the directory for the collection "test"
Then I should be on the catalog page for "test:item1"
And the file "sample1.txt" should exist in the directory for the collection "test"
And the document "sample1.txt" under item "item1" in collection "test" should exist in the database
And Sesame should contain a document with uri "http://www.example.com/catalog/test/item1/document/sample1.txt" in collection "test"
And Sesame should contain a document with file_name "sample1.txt" in collection "test"
Expand Down
4 changes: 2 additions & 2 deletions features/item_create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ Feature: Creating Items
When I fill in "item_name" with "<name>"
And I fill in "item_title" with "<title>"
And I press "Create"
Then I should be on the home page
Then I should be on the catalog page for "<collection_name>:<sanitised_name>"
And I should see "Created new item: <sanitised_name> ×"
And I should see "Sorry, the item you requested is being indexed and will be available shortly. You may need to wait a few moments and refresh the page to see your item. ×"
And I should see "This item is currently being indexed meaning the item and document metadata is currently unavailable. Please wait a few moments then refresh the page to try again."
Examples:
| collection_name | name | sanitised_name | title |
| test | test | test | Test |
Expand Down

0 comments on commit 2ea5183

Please sign in to comment.