Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3e69afd
MMT-2231 Add revisions page to published UMM-T page (#610)
ryanmiller-1 Jul 8, 2020
5e6a0a8
MMT-2288 Update jquery version that is being package for the preview …
ryanmiller-1 Jul 9, 2020
994cbb1
MMT-2230 (#608)
ryanmiller-1 Jul 9, 2020
31b1c59
MMT-2229 Adding delete for published tools
william-valencia Jul 10, 2020
986e271
MMT-2313: Added loss reporting route, added a display action to the c…
Jul 10, 2020
22a9fb8
MMT-2229 Updating not current provider modal
ryanmiller-1 Jul 10, 2020
db5af95
MMT-2229 Fixing the tool_permissions_spec
william-valencia Jul 13, 2020
47bf0b2
MMT-2229 Removing duplicate test
william-valencia Jul 13, 2020
daaa4cf
Fixing spacing for tools_permissions_spec.rb
william-valencia Jul 13, 2020
f58c6ad
MMT-2234 (#607)
ryanmiller-1 Jul 13, 2020
4fa3f5c
Hotfix/MMT-2231-1 Updating revisions helpers to sort by revision date…
ryanmiller-1 Jul 13, 2020
57b82a3
MMT-2313: added nokogiri/diff to gemfile, added hidden url endpoint f…
Jul 13, 2020
49c7dd9
MMT-2313: added loss reporting for arrays
Jul 13, 2020
67676fc
MMT-2313: Added comment to collections_controller
Jul 13, 2020
9eec788
MMT-2229 Modifying delete_tool_spec due to comments and fixing tool_p…
william-valencia Jul 14, 2020
e1eedaa
MMT-2229 Removing unneeded delete
william-valencia Jul 14, 2020
55a52ae
MMT-2229 Removing unneeded native_id_3
william-valencia Jul 14, 2020
d767d9f
MMT-2313: made changes as per MMT-2311-1 PR change requests
Jul 14, 2020
f05fef7
Merge branch 'master' into MMT-2229-Delete-Published-Tools
william-valencia Jul 14, 2020
ff40024
Merge pull request #614 from nasa/MMT-2229-Delete-Published-Tools
william-valencia Jul 14, 2020
83f5057
MMT-2313: Updated comparison logic to use nokogiri for array paths
Jul 15, 2020
affd9ab
MMT-2313: removed some comments and test code
Jul 15, 2020
7cae6d6
MMT-2313: Added custom function for hash mapping, finds the path for …
Jul 16, 2020
e23bb6a
MMT-2313: adjusted whitespace
Jul 16, 2020
04ce818
MMT-2232/2233 Revision viewing and reversion for tools (#617)
ryanmiller-1 Jul 17, 2020
50c0c0f
MMT-2313: added some comments
Jul 17, 2020
748631e
MMT-2313: increased readability of loss_report_output
Jul 20, 2020
d6d5077
MMT-2313: improved readability
Jul 20, 2020
52d5859
Hotfix/MMT-2232-1 Fixing tests bamboo started failing (#619)
ryanmiller-1 Jul 21, 2020
db730a0
MMT-2313: attempting to fix asterisk problem
Jul 21, 2020
d1854c8
MMT-2313 attempting to fix asterisk problem
Jul 21, 2020
e381d86
MMT-2306 Update FBM link for dMMT (#618)
ryanmiller-1 Jul 22, 2020
1bc3d15
MMT-2313: fix nokogiri problems
Jul 22, 2020
be69b30
MMT-2313: cleaned up inefficiencies, fixed bugs
Jul 22, 2020
34bb5fe
MMT-2313: fixed bugs, improved accuracy
Jul 24, 2020
a267e4c
MMT-2313: added some test code to be removed later
Jul 27, 2020
937342d
MMT-2313: Added some exception handling
Jul 28, 2020
fa56d22
MMT-2313: created specs and stored some sample reports
Jul 29, 2020
20fd9e2
MMT-2313: moved loss_report_samples_helper.rb and added it to the rai…
Jul 29, 2020
34891ec
MMT-2313: made changes per PR change requests
Jul 31, 2020
758e8fa
MMT-2313: removed unneeded comment
Jul 31, 2020
aa3e768
MMT-2313: removed an unecessary cmr call
Jul 31, 2020
24093ec
MMT-2313: made changes per PR change requests. Also removed loss_repo…
Aug 6, 2020
38b6d8f
MMT-2313: fixed fixture file paths
Aug 6, 2020
cd66642
MMT-2313: removed unncessary ternary operator
Aug 6, 2020
bb7e6bf
MMT-2313: made more PR change requests
Aug 10, 2020
573a151
MMT-2313: adjusted keyword arguments and a variable definition
Aug 10, 2020
2b18ad0
MMT-2350 adding a wait for indexing after deleting a provider in rese…
ryanmiller-1 Aug 10, 2020
35c022f
MMT-2313: changed use of hide_items parameter
Aug 11, 2020
858eba2
Merge branch 'master' of https://github.com/nasa/mmt into MMT-2313
Aug 11, 2020
dda75e5
MMT-2313: made :display non-default
Aug 11, 2020
bde318d
MMT-2313: completed change requests
Aug 11, 2020
cd12de0
MMT-2313: adjusted spec to be more universal
Aug 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ nohup.out

#backup files
*~

#ignore package
package-lock.json
package.json
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ gem 'aasm'

gem 'browser'

gem 'nokogiri-diff', '~> 0.2.0' # for comparing xml documents

# collections metadata preview
# run this command to work from a local copy of the gem's repo
# bundle config local.cmr_metadata_preview /path/to/local/git/repository
# make sure to delete the local config when done making changes to merge into master
# bundle config --delete local.cmr_metadata_preview
gem 'cmr_metadata_preview', git: 'https://git.earthdata.nasa.gov/scm/cmr/cmr_metadata_preview.git', ref: 'fff65949cc6'
gem 'cmr_metadata_preview', git: 'https://git.earthdata.nasa.gov/scm/cmr/cmr_metadata_preview.git', ref: '1f6ffd54d65'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand Down
11 changes: 8 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
GIT
remote: https://git.earthdata.nasa.gov/scm/cmr/cmr_metadata_preview.git
revision: fff65949cc62d397b0675e9fe46e962b8cf43228
ref: fff65949cc6
revision: 1f6ffd54d6570f9f920078a84fd51750db3c21ab
ref: 1f6ffd54d65
specs:
cmr_metadata_preview (0.2.2)
cmr_metadata_preview (0.2.3)
georuby
rails (~> 5.2.0)
sprockets (< 4.0)
Expand Down Expand Up @@ -195,6 +195,9 @@ GEM
nio4r (2.5.2)
nokogiri (1.10.9)
mini_portile2 (~> 2.4.0)
nokogiri-diff (0.2.0)
nokogiri (~> 1.5)
tdiff (~> 0.3, >= 0.3.2)
parallel (1.19.1)
parser (2.7.1.2)
ast (~> 2.4.0)
Expand Down Expand Up @@ -297,6 +300,7 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.4.2)
tdiff (0.3.4)
thor (1.0.1)
thread_safe (0.3.6)
tilt (2.0.10)
Expand Down Expand Up @@ -365,6 +369,7 @@ DEPENDENCIES
mini_racer
momentjs-rails
multi_xml
nokogiri-diff (~> 0.2.0)
pg
pundit
rack_session_access
Expand Down
10 changes: 10 additions & 0 deletions app/assets/javascripts/change_current_provider.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ $(document).ready ->
"Managing this service's collection associations"
when 'edit-tool'
'Editing this tool'
when 'clone-tool'
'Cloning this tool'
when 'delete-tool'
'Deleting this tool'
when 'reinstate-tool'
action = 'revert'
'Reinstating this tool'
when 'revert-tool'
action = 'revert'
'Reverting this tool'

$link.data('type', action)
$modal.find('span.provider').text(provider)
Expand Down
2 changes: 1 addition & 1 deletion app/concerns/cmr_collections_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def get_revisions(concept_id, revision_id)
# try again because CMR might be a little slow to index if it is a newly published revision
attempts = 0
while attempts < 20
revisions_response = cmr_client.get_collections({ concept_id: concept_id, all_revisions: true, include_granule_counts: true }, token)
revisions_response = cmr_client.get_collections({ concept_id: concept_id, all_revisions: true, include_granule_counts: true, sort_key: '-revision_date' }, token)
revisions = if revisions_response.success?
revisions_response.body.fetch('items', [])
else
Expand Down
53 changes: 51 additions & 2 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class CollectionsController < ManageCollectionsController
include ManageMetadataHelper
include CMRCollectionsHelper
include CollectionsHelper
include LossReportHelper

before_action :set_collection
before_action :ensure_correct_collection_provider, only: [:edit, :clone, :revert, :destroy]
Expand Down Expand Up @@ -115,6 +116,35 @@ def create_update_proposal
redirect_to collection_draft_proposal_path(proposal)
end

def loss_report
# When a user wants to use MMT to edit metadata that currently exists in a non-UMM form,
# it's important that they're able to see if any data loss occurs in the translation to umm.
# This method is needed to reference the appropriate helper and view for the lossiness report.
# If translated_collections contains an :error field, the error message will appear.

# this checks the 'hide_items' url parameter that is can be manually added. Its primary use is for developers
# that need to debug using the text_output
if params[:hide_items].nil? || params[:hide_items].downcase == 'true'
hide_items = true
elsif params[:hide_items].downcase == 'false'
hide_items = false
else
translated_collections = { error: 'Unknown value for the hide_items parameter. The format should be: ".../loss_report.text?hide_items=true" or ".../loss_report.text?hide_items=false"' }
end

translated_collections ||= prepare_translated_collections

respond_to do |format|
if translated_collections[:error]
format.text { render plain: translated_collections[:error] }
format.json { render json: JSON.pretty_generate(translated_collections) }
else
format.text { render plain: loss_report_output(translated_collections: translated_collections, hide_items: hide_items, display: 'text') }
format.json { render json: JSON.pretty_generate(loss_report_output(translated_collections: translated_collections, hide_items: hide_items, display: 'json')) }
end
end
end

private

def ensure_correct_collection_provider
Expand All @@ -127,6 +157,25 @@ def ensure_correct_collection_provider
render :show
end

def prepare_translated_collections
original_collection_native_xml = cmr_client.get_concept(params[:id],token, {})
return { error: 'Failed to retrieve collection from CMR' } unless original_collection_native_xml.success?

content_type = original_collection_native_xml.headers.fetch('content-type').split(';')[0]
return { error: 'This collection is already in UMM format so there is no loss report' } if content_type.include?('application/vnd.nasa.cmr.umm+json')

translated_collection_native_xml = cmr_client.translate_collection(JSON.pretty_generate(@collection), "application/#{Rails.configuration.umm_c_version}; charset=utf-8", content_type, skip_validation=true)
return { error: 'Failed to translate collection from UMM back to native format' } unless translated_collection_native_xml.success?

return {
original_collection_native_xml: original_collection_native_xml.body,
translated_collection_native_xml: translated_collection_native_xml.body,
original_collection_native_hash: Hash.from_xml(original_collection_native_xml.body),
translated_collection_native_hash: Hash.from_xml(translated_collection_native_xml.body),
native_format: content_type
}
end

def set_collection
@concept_id = params[:id]
@revision_id = params[:revision_id]
Expand All @@ -149,7 +198,7 @@ def set_collection
@download_xml_options.each do |download_option|
# gsub here is needed because of the iso-smap and application/iso:smap+xml format options
if native_format.gsub(':','').include?(download_option[:format].gsub('-', ''))
download_option[:title].concat(' (Native)')
download_option[:title].concat(' (Native)')
@download_xml_options.delete(download_option)
@download_xml_options.unshift(download_option)
break
Expand Down Expand Up @@ -201,7 +250,7 @@ def proposal_mode_enabled?
super
end
end

def select_revision
selected = @revisions.select {|r| r.fetch('meta')['revision-id'] && r.fetch('meta')['deleted'] == false && r.fetch('meta')['revision-id'].to_i < @revision_id.to_i}.first
selected.blank? ? nil : selected.fetch('meta')['revision-id']
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/manage_metadata_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def set_variable_information
# if the variable is not found, try again because CMR might be a little slow to index if it is a newly published record
attempts = 0
while attempts < 20
variables_search_response = cmr_client.get_variables(concept_id: @concept_id, all_revisions: true)
variables_search_response = cmr_client.get_variables(concept_id: @concept_id, all_revisions: true, sort_key: '-revision_date')

variable_data = if variables_search_response.success?
variables_search_response.body.fetch('items', [])
Expand Down Expand Up @@ -163,7 +163,7 @@ def set_service_information
# if the service is not found, try again because CMR might be a little slow to index if it is a newly published record
attempts = 0
while attempts < 20
services_search_response = cmr_client.get_services(concept_id: @concept_id, all_revisions: true)
services_search_response = cmr_client.get_services(concept_id: @concept_id, all_revisions: true, sort_key: '-revision_date')

service_data = if services_search_response.success?
services_search_response.body.fetch('items', [])
Expand Down Expand Up @@ -218,7 +218,7 @@ def set_tool_information
# if the tool is not found, try again because CMR might be a little slow to index if it is a newly published record
attempts = 0
while attempts < 20
tools_search_response = cmr_client.get_tools(concept_id: @concept_id, all_revisions: true)
tools_search_response = cmr_client.get_tools(concept_id: @concept_id, all_revisions: true, sort_key: '-revision_date')

tool_data = if tools_search_response.success?
tools_search_response.body.fetch('items', [])
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
class ToolsController < BasePublishedRecordController
include ManageMetadataHelper

before_action :set_tool, only: [:show, :edit] #, :clone, :destroy, :revisions, :revert, :download_json]
before_action :set_schema, only: [:show, :edit] #, :clone, :destroy]
before_action :set_tool, only: [:show, :edit, :clone, :destroy, :revisions, :revert, :download_json]
before_action :set_schema, only: [:show, :edit, :clone, :destroy]
before_action :ensure_supported_version, only: [:show, :edit]
before_action :ensure_correct_provider, only: [:edit] #, :clone, :destroy]
before_action :ensure_correct_provider, only: [:edit, :clone, :destroy]
before_action :set_preview, only: [:show]

# If clone is not defined like this performing the clone action leads to a `action not found error`
Expand Down
Loading