Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/datacite/lupo
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed May 10, 2019
2 parents 7035fee + df805e3 commit d0791fb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def index
}
render json: ProviderSerializer.new(@providers, options).serialized_json, status: :ok
end
header = %w(name provider_id year contact_name contact_address is_active description website region country logo_url focus_area organisation_type memmber_type address post_code city state twitter_handle ror_id role_name joined created updated deleted_at)
header = %w(accountName fabricaAccountId year contactName contact_address is_active accountDescription accountWebsite region country logo_url focusArea organisation_type accountType billingStreet billingPostalCode billingCity department billingOrganization billingState billingCountry twitter ror_id role_name joined created updated deleted_at)
format.csv { render request.format.to_sym => response.records.to_a, header: header }
end
rescue Elasticsearch::Transport::Transport::Errors::BadRequest => exception
Expand Down Expand Up @@ -192,7 +192,7 @@ def safe_params
# ]
# params.require(:data).permit(:type, attributes: attributes)
ActiveModelSerializers::Deserialization.jsonapi_parse!(
params, only: [:name, :symbol, :description, :website, :joined, "organizationType", "focusArea", :phone, "contactName", "contactEmail", "isActive", "passwordInput", :country, "billingInformation",{ "billingInformation": ["postCode", :state, :city, :address]}, "rorId", "twitterHandle" ],
params, only: [:name, :symbol, :description, :website, :joined, "organizationType", "focusArea", :phone, "contactName", "contactEmail", "isActive", "passwordInput", :country, "billingInformation",{ "billingInformation": ["postCode", :state, :city, :address, :department, :organization, :country]}, "rorId", "twitterHandle" ],
keys: { "organizationType" => :organization_type, "focusArea" => :focus_area, "contactName" => :contact_name, "contactEmail" => :contact_email, :country => :country_code, "isActive" => :is_active, "passwordInput" => :password_input, "billingInformation" => :billing_information , "postCode" => :post_code, "rorId" => :ror_id, "twitterHandle" =>:twitter_handle }
)
end
Expand Down
46 changes: 34 additions & 12 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Provider < ActiveRecord::Base
validates_inclusion_of :focus_area, :in => %w(biomedicalAndHealthSciences earthSciences humanities mathematicsAndComputerScience physicalSciencesAndEngineering socialSciences general), :message => "focus area %s is not included in the list", if: :focus_area?
validate :freeze_symbol, :on => :update
validates_format_of :ror_id, :with => /\A(?:(http|https):\/\/)?(?:ror\.org\/)?(0\w{6}\d{2})\z/, if: :ror_id?
validates_format_of :twitter_handle, :with => /\A[a-zA-Z0-9_]{1,15}\z/, if: :twitter_handle?

before_validation :set_region

Expand Down Expand Up @@ -101,7 +102,10 @@ class Provider < ActiveRecord::Base
indexes :billing_information, type: :object, properties: {
postCode: { type: :keyword },
state: { type: :text},
organization: { type: :text},
department: { type: :text},
city: { type: :text },
country: { type: :text },
address: { type: :text }}
indexes :created, type: :date
indexes :updated, type: :date
Expand Down Expand Up @@ -138,10 +142,13 @@ def as_indexed_json(options={})
"twitter_handle" => twitter_handle,
"ror_id" => ror_id,
"billing_information" => {
"address" => address,
"postCode" => post_code,
"state" => state,
"city" => city
"address" => billing_address,
"organization" => billing_organization,
"department" => billing_department,
"postCode" => billing_post_code,
"state" => billing_state,
"country" => billing_country,
"city" => billing_city
},
"created" => created,
"updated" => updated,
Expand Down Expand Up @@ -181,10 +188,13 @@ def csv
focus_area: focus_area,
organization_type: organization_type,
member_type: member_type,
address: address,
post_code: post_code,
city: city,
state: state,
billing_address: billing_address,
billing_post_code: billing_post_code,
billing_city: billing_city,
billing_department: billing_department,
billing_organization: billing_organization,
billing_state: billing_state,
billing_country: billing_country,
twitter_handle: twitter_handle,
ror_id: ror_id,
role_name: role_name,
Expand All @@ -209,22 +219,34 @@ def year
joined.year if joined.present?
end

def address
def billing_department
billing_information.fetch("department",nil) if billing_information.present?
end

def billing_organization
billing_information.fetch("organization",nil) if billing_information.present?
end


def billing_address
billing_information.fetch("address",nil) if billing_information.present?
end

def state
def billing_state
billing_information.fetch("state",nil) if billing_information.present?
end

def city
def billing_city
billing_information.fetch("city",nil) if billing_information.present?
end

def post_code
def billing_post_code
billing_information.fetch("post_code",nil) if billing_information.present?
end

def billing_country
billing_information.fetch("country",nil) if billing_information.present?
end

# count years account has been active. Ignore if deleted the same year as created
def cumulative_years
Expand Down

0 comments on commit d0791fb

Please sign in to comment.