-
Notifications
You must be signed in to change notification settings - Fork 119
Adding Research Outputs (DB and model components only) #2739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2d5db6f
Merge pull request #229 from DMPRoadmap/master
briri c909906
sym linked necessary files and ignored others
briri 6c4a7bc
add research_outputs and mime_types
briri a9cfcf4
add new mime_types Rake task to upgrade task
briri 9bb4358
reverted sym links
briri 651d238
reverted gitignore changes
briri f818701
Merge branch 'development' of https://github.com/DMPRoadmap/roadmap i…
briri cd6fc96
Merge branch 'DMPRoadmap-development' into roadmap-development
briri faf52ec
reverted blank lines added to bottom of a few configs
briri 6083af4
reverted issue with open_aire config
briri ede3ef1
Merge branch 'development' into research-outputs
briri cf2f00d
minor text change to comment in open_aire initializer to force ruboco…
briri 4a91f23
Merge branch 'research-outputs' of https://github.com/CDLUC3/dmptool …
briri 5ccbcd4
Remove blank line added to open_aire initializer by Atom to fix rubocop
briri 858bd9d
Merge pull request #231 from DMPRoadmap/development
briri eece759
add research_outputs and mime_types
briri f051e3d
Merge branch 'research-outputs' of https://github.com/CDLUC3/dmptool …
briri c7f3ee2
Merge branch 'development' into research-outputs
briri 3f4502f
updated schema date in schema.rb
briri 0b2b64e
Merge branch 'research-outputs' of https://github.com/CDLUC3/dmptool …
briri e53c0a1
Merge branch 'development' into research-outputs
briri 3fa829e
removed dupplicate copy of open_aire initializer
briri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # == Schema Information | ||
| # | ||
| # Table name: mime_types | ||
| # | ||
| # id :bigint not null, primary key | ||
| # category :string not null | ||
| # description :string not null | ||
| # value :string not null | ||
| # created_at :datetime not null | ||
| # updated_at :datetime not null | ||
| # | ||
| # Indexes | ||
| # | ||
| # index_mime_types_on_value (value) | ||
| # | ||
| class MimeType < ApplicationRecord | ||
|
|
||
| include ValidationMessages | ||
|
|
||
| # ================ | ||
| # = Associations = | ||
| # ================ | ||
|
|
||
| has_many :research_outputs | ||
|
|
||
| # =============== | ||
| # = Validations = | ||
| # =============== | ||
|
|
||
| validates :category, :description, :value, presence: { message: PRESENCE_MESSAGE } | ||
|
|
||
| # ========== | ||
| # = Scopes = | ||
| # ========== | ||
|
|
||
| # Retrieves the unique list of categories | ||
| scope :categories, -> { pluck(:category).uniq.sort { |a, b| a <=> b } } | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # == Schema Information | ||
| # | ||
| # Table name: research_outputs | ||
| # | ||
| # id :bigint not null, primary key | ||
| # abbreviation :string | ||
| # access :integer default(0), not null | ||
| # byte_size :bigint | ||
| # coverage_end :datetime | ||
| # coverage_region :string | ||
| # coverage_start :datetime | ||
| # description :text | ||
| # display_order :integer | ||
| # is_default :boolean default("false") | ||
| # mandatory_attribution :text | ||
| # output_type :integer default(3), not null | ||
| # output_type_description :string | ||
| # personal_data :boolean | ||
| # release_date :datetime | ||
| # sensitive_data :boolean | ||
| # title :string not null | ||
| # created_at :datetime not null | ||
| # updated_at :datetime not null | ||
| # mime_type_id :integer | ||
| # plan_id :integer | ||
| # | ||
| # Indexes | ||
| # | ||
| # index_research_outputs_on_output_type (output_type) | ||
| # index_research_outputs_on_plan_id (plan_id) | ||
| # | ||
| class ResearchOutput < ApplicationRecord | ||
|
|
||
| include Identifiable | ||
| include ValidationMessages | ||
|
|
||
| enum output_type: %i[audiovisual collection data_paper dataset event image | ||
| interactive_resource model_representation physical_object | ||
| service software sound text workflow other] | ||
|
|
||
| enum access: %i[open embargoed restricted closed] | ||
|
|
||
| # ================ | ||
| # = Associations = | ||
| # ================ | ||
|
|
||
| belongs_to :plan, optional: true | ||
| belongs_to :mime_type, optional: true | ||
|
|
||
| # =============== | ||
| # = Validations = | ||
| # =============== | ||
|
|
||
| validates_presence_of :output_type, :access, :title, message: PRESENCE_MESSAGE | ||
| validates_uniqueness_of :title, :abbreviation, scope: :plan_id | ||
|
|
||
| # Ensure presence of the :output_type_description if the user selected 'other' | ||
| validates_presence_of :output_type_description, if: -> { other? }, message: PRESENCE_MESSAGE | ||
| # Ensure that :coverage_start comes before :coverage_end | ||
| validate :end_date_after_start_date | ||
|
|
||
| # ==================== | ||
| # = Instance methods = | ||
| # ==================== | ||
|
|
||
| # :mime_type is only applicable for certain :output_types | ||
| # This method returns the applicable :mime_types | ||
| def available_mime_types | ||
| cat = %w[audio video] if audiovisual? || sound? | ||
| cat = %w[image] if image? | ||
| cat = %w[model] if model_representation? | ||
| cat = %w[text] if data_paper? || dataset? || text? | ||
|
|
||
| cat.present? ? MimeType.where(category: cat).order(:description) : [] | ||
| end | ||
|
|
||
| # TODO: placeholders for once the License, Repository, Metadata Standard and | ||
| # Resource Type Lookups feature is built. | ||
| # | ||
| # Be sure to add the scheme in the appropriate upgrade task (and to the | ||
| # seed.rb as well) | ||
| def licenses | ||
| # scheme = IdentifierScheme.find_by(name: '[name of license scheme]') | ||
| # return [] unless scheme.present? | ||
| # identifiers.select { |id| id.identifier_scheme = scheme } | ||
| [] | ||
| end | ||
|
|
||
| def repositories | ||
| # scheme = IdentifierScheme.find_by(name: '[name of repository scheme]') | ||
| # return [] unless scheme.present? | ||
| # identifiers.select { |id| id.identifier_scheme = scheme } | ||
| [] | ||
| end | ||
|
|
||
| def metadata_standards | ||
| # scheme = IdentifierScheme.find_by(name: '[name of openaire scheme]') | ||
| # return [] unless scheme.present? | ||
| # identifiers.select { |id| id.identifier_scheme = scheme } | ||
| [] | ||
| end | ||
|
|
||
| def resource_types | ||
| # scheme = IdentifierScheme.find_by(name: '[name of resource_type scheme]') | ||
| # return [] unless scheme.present? | ||
| # identifiers.select { |id| id.identifier_scheme = scheme } | ||
| [] | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # Validation to prevent end date from coming before the start date | ||
| def end_date_after_start_date | ||
| # allow nil values | ||
| return true if coverage_end.blank? || coverage_start.blank? | ||
|
|
||
| errors.add(:coverage_end, _("must be after the start date")) if coverage_end < coverage_start | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| class CreateResearchOutputs < ActiveRecord::Migration[5.2] | ||
| def change | ||
| create_table :research_outputs do |t| | ||
| t.integer :plan_id, index: true | ||
| t.integer :output_type, null: false, index: true, default: 3 | ||
| t.string :output_type_description | ||
| t.string :title, null: false | ||
| t.string :abbreviation | ||
| t.integer :display_order | ||
| t.boolean :is_default | ||
| t.text :description | ||
| t.integer :mime_type_id | ||
| t.integer :access, null: false, default: 0 | ||
| t.datetime :release_date | ||
| t.boolean :personal_data | ||
| t.boolean :sensitive_data | ||
| t.bigint :byte_size | ||
| t.text :mandatory_attribution | ||
| t.datetime :coverage_start | ||
| t.datetime :coverage_end | ||
| t.string :coverage_region | ||
| t.timestamps null: false | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| class CreateMimeTypes < ActiveRecord::Migration[5.2] | ||
| def change | ||
| create_table :mime_types do |t| | ||
| t.string :description, null: false | ||
| t.string :category, null: false | ||
| t.string :value, null: false, index: true | ||
| t.timestamps | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'httparty' | ||
|
|
||
| namespace :mime_types do | ||
|
|
||
| IANA_BASE_URL = "https://www.iana.org/assignments/media-types".freeze | ||
|
|
||
| desc "Fetch all of the latest MIME types and load into the DB" | ||
| task load: :environment do | ||
| %w[application.csv audio.csv font.csv image.csv message.csv model.csv | ||
| multipart.csv text.csv video.csv].each do |file_name| | ||
| fetch_and_process_mime_type_file(url: "#{IANA_BASE_URL}/#{file_name}") | ||
| end | ||
| end | ||
|
|
||
| def fetch_and_process_mime_type_file(url:) | ||
| p "Processing #{url}" | ||
| body = fetch_csv_file(url: url) | ||
| p " Unable to process the specified URL" unless body.present? | ||
|
|
||
| csv = CSV.parse(body, headers: true, force_quotes: true, encoding: 'iso-8859-1:utf-8') | ||
| p " Invalid CSV format. Expecting a 'Name' and 'Template' column" unless csv.headers.include?("Name") && | ||
| csv.headers.include?("Template") | ||
| process_mime_file(csv: csv) | ||
| p " Done" | ||
| rescue StandardError => e | ||
| p " Error processing CSV content - #{e.message}" | ||
| end | ||
|
|
||
| def process_mime_file(csv:) | ||
| return unless csv.is_a?(CSV::Table) | ||
|
|
||
| csv.each do |line| | ||
| next unless line["Template"].present? && line["Name"].present? | ||
|
|
||
| type = MimeType.find_or_initialize_by(value: line["Template"].downcase) | ||
| type.description = line["Name"] | ||
| type.category = line["Template"].split("/").first.downcase | ||
| type.save | ||
| end | ||
| end | ||
|
|
||
| def fetch_csv_file(url:) | ||
| return nil unless url.present? | ||
|
|
||
| payload = HTTParty.get(url, debug: false) | ||
| return nil unless payload.code == 200 | ||
|
|
||
| payload.body | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # == Schema Information | ||
| # | ||
| # Table name: mime_types | ||
| # | ||
| # id :bigint not null, primary key | ||
| # category :string not null | ||
| # description :string not null | ||
| # value :string not null | ||
| # created_at :datetime not null | ||
| # updated_at :datetime not null | ||
| # | ||
| # Indexes | ||
| # | ||
| # index_mime_types_on_value (value) | ||
| # | ||
| FactoryBot.define do | ||
| factory :mime_type do | ||
| category { %w[application audio audio image text video].sample } | ||
| description { Faker::Lorem.sentence } | ||
| value { "#{category}/#{Faker::Lorem.word}" } | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for updating this.