diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index 12dc9388d..c51a10ed3 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -285,7 +285,7 @@ def safe_params ActiveModelSerializers::Deserialization.jsonapi_parse!( params, only: [ - :name, "displayName", :symbol, :description, :website, :joined, "organizationType", "focusArea", "consortiumLead", "systemEmail", "groupEmail", "isActive", "passwordInput", :country, "billingInformation",{ "billingInformation": ["postCode", :state, :city, :address, :department, :organization, :country]}, "rorId", "twitterHandle","memberType", + :name, "displayName", :symbol, :description, :website, :joined, "organizationType", "focusArea", "consortiumLead", "systemEmail", "groupEmail", "isActive", "passwordInput", :country, "billingInformation", { "billingInformation": ["postCode", :state, :city, :address, :department, :organization, :country]}, "rorId", "twitterHandle","memberType", "technicalContact",{ "technicalContact": [:email, "givenName", "familyName"]}, "secondaryTechnicalContact",{ "secondaryTechnicalContact": [:email, "givenName", "familyName"]}, "secondaryBillingContact",{ "secondaryBillingContact": [:email, "givenName", "familyName"]}, diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 1337ac6cd..5e0615d96 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -183,7 +183,7 @@ def set_repository def safe_params fail JSON::ParserError, "You need to provide a payload following the JSONAPI spec" unless params[:data].present? ActiveModelSerializers::Deserialization.jsonapi_parse!( - params, only: [:symbol, :name, "contactName", "contactEmail", :domains, :provider, :url, "repositoryType", { "repositoryType" => [] }, :description, :language, { language: [] }, "alternateName", :software, "targetId", "isActive", "passwordInput", "clientType", :re3data, :opendoar, :issn, { issn: [] }, :certificate, { certificate: [] }], + params, only: [:symbol, :name, "contactName", "contactEmail", :domains, :provider, :url, "repositoryType", { "repositoryType" => [] }, :description, :language, { language: [] }, "alternateName", :software, "targetId", "isActive", "passwordInput", "clientType", :re3data, :opendoar, :issn, { issn: [:issnl, :print, :electronic] }, :certificate, { certificate: [] }], keys: { "contactName" => :contact_name, "contactEmail" => :contact_email, "targetId" => :target_id, "isActive" => :is_active, "passwordInput" => :password_input, "clientType" => :client_type, "alternateName" => :alternate_name, "repositoryType" => :repository_type } ) end diff --git a/app/models/client.rb b/app/models/client.rb index 070308d3b..96511cffb 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -80,7 +80,10 @@ class Client < ActiveRecord::Base indexes :provider_id, type: :keyword indexes :re3data_id, type: :keyword indexes :opendoar_id, type: :integer - indexes :issn, type: :keyword + indexes :issn, type: :object, properties: { + issnl: { type: :keyword }, + electronic: { type: :keyword }, + print: { type: :keyword }} indexes :prefix_ids, type: :keyword indexes :name, type: :text, fields: { keyword: { type: "keyword" }, raw: { type: "text", analyzer: "string_lowercase", "fielddata": true }} indexes :alternate_name, type: :text, fields: { keyword: { type: "keyword" }, raw: { type: "text", analyzer: "string_lowercase", "fielddata": true }} @@ -115,7 +118,7 @@ def as_indexed_json(options={}) "provider_id" => provider_id, "re3data_id" => re3data_id, "opendoar_id" => opendoar_id, - "issn" => Array.wrap(issn), + "issn" => issn, "prefix_ids" => prefix_ids, "name" => name, "alternate_name" => alternate_name, @@ -261,7 +264,15 @@ def to_jsonapi def check_issn Array.wrap(issn).each do |i| - errors.add(:issn, "ISSN #{i} is in the wrong format.") unless /\A\d{4}(-)?\d{3}[0-9X]+\z/.match(i) + if i["issnl"].present? + errors.add(:issn, "ISSN-L #{i["issnl"]} is in the wrong format.") unless /\A\d{4}(-)?\d{3}[0-9X]+\z/.match(i["issnl"]) + end + if i["electronic"].present? + errors.add(:issn, "ISSN (electronic) #{i["electronic"]} is in the wrong format.") unless /\A\d{4}(-)?\d{3}[0-9X]+\z/.match(i["electronic"]) + end + if i["print"].present? + errors.add(:issn, "ISSN (print) #{i["print"]} is in the wrong format.") unless /\A\d{4}(-)?\d{3}[0-9X]+\z/.match(i["print"]) + end end end @@ -303,7 +314,7 @@ def set_defaults self.contact_name = "" unless contact_name.present? self.domains = "*" unless domains.present? self.client_type = "repository" unless client_type.present? - self.issn = [] if issn.blank? || client_type == "repository" + self.issn = {} if issn.blank? || client_type == "repository" self.certificate = [] if certificate.blank? || client_type == "periodical" self.repository_type = [] if repository_type.blank? || client_type == "periodical" self.is_active = is_active ? "\x01" : "\x00" diff --git a/app/models/doi.rb b/app/models/doi.rb index 59c3b1f8a..53c358d00 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -588,9 +588,23 @@ def self.convert_affiliation_by_id(options={}) elsif c["affiliation"].is_a?(String) c["affiliation"] = [{ "name" => c["affiliation"] }] should_update = true - else c["affiliation"].is_a?(Hash) + elsif c["affiliation"].is_a?(Hash) c["affiliation"] = Array.wrap(c["affiliation"]) should_update = true + elsif c["affiliation"].is_a?(Array) + c["affiliation"].map do |a| + if a.nil? + should_update = true + + a + elsif a.is_a?(String) + should_update = true + + { "name" => a } + else + a + end + end.compact end c @@ -602,9 +616,23 @@ def self.convert_affiliation_by_id(options={}) elsif c["affiliation"].is_a?(String) c["affiliation"] = [{ "name" => c["affiliation"] }] should_update = true - else c["affiliation"].is_a?(Hash) + elsif c["affiliation"].is_a?(Hash) c["affiliation"] = Array.wrap(c["affiliation"]) should_update = true + elsif c["affiliation"].is_a?(Array) + c["affiliation"].map do |a| + if a.nil? + should_update = true + + a + elsif a.is_a?(String) + should_update = true + + { "name" => a } + else + a + end + end.compact end c diff --git a/spec/models/client_spec.rb b/spec/models/client_spec.rb index f472263f2..b65d0f9c8 100644 --- a/spec/models/client_spec.rb +++ b/spec/models/client_spec.rb @@ -35,21 +35,21 @@ let(:client) { build(:client, provider: provider, client_type: "periodical") } it "should support issn" do - client.issn = ["1544-9173"] + client.issn = { "issnl" => "1544-9173" } expect(client.save).to be true expect(client.errors.details).to be_empty end it "should support multiple issn" do - client.issn = ["1544-9173", "1545-7885"] + client.issn = { "electronic" => "1544-9173", "print" => "1545-7885" } expect(client.save).to be true expect(client.errors.details).to be_empty end it "should reject invalid issn" do - client.issn = ["1544-91XX"] + client.issn = { "issnl" => "1544-91XX" } expect(client.save).to be false - expect(client.errors.details).to eq(:issn=>[{:error=>"ISSN 1544-91XX is in the wrong format."}]) + expect(client.errors.details).to eq(:issn=>[{:error=>"ISSN-L 1544-91XX is in the wrong format."}]) end end