From f2e83e8cd4f8ded7b56e4ea0f58a502648fecec0 Mon Sep 17 00:00:00 2001 From: Jacob Burenstam Date: Mon, 22 May 2017 23:54:38 +0200 Subject: [PATCH] AF compliance --- data/municipality-codes.csv | 2 ++ lib/arbetsformedlingen/client.rb | 2 +- lib/arbetsformedlingen/models/company.rb | 5 ++++- lib/arbetsformedlingen/models/packet.rb | 5 ++++- lib/arbetsformedlingen/models/position.rb | 12 ++++++++++++ lib/arbetsformedlingen/models/publication.rb | 11 ++++++++--- lib/arbetsformedlingen/models/schedule.rb | 4 +++- lib/arbetsformedlingen/output_builder.rb | 13 +++++++++---- 8 files changed, 43 insertions(+), 11 deletions(-) diff --git a/data/municipality-codes.csv b/data/municipality-codes.csv index 94f3616..e4f083f 100644 --- a/data/municipality-codes.csv +++ b/data/municipality-codes.csv @@ -1,3 +1,5 @@ +Unspecified workplace within Sweden,9090 +Any country outside of Sweden,9999 Ale,1440 Alingsås,1489 Alvesta,0764 diff --git a/lib/arbetsformedlingen/client.rb b/lib/arbetsformedlingen/client.rb index 8a3a561..d42ae20 100644 --- a/lib/arbetsformedlingen/client.rb +++ b/lib/arbetsformedlingen/client.rb @@ -22,4 +22,4 @@ def self.post_job_url ROUTES.fetch(:post_job_url) end end -end \ No newline at end of file +end diff --git a/lib/arbetsformedlingen/models/company.rb b/lib/arbetsformedlingen/models/company.rb index bb70557..06ba1a5 100644 --- a/lib/arbetsformedlingen/models/company.rb +++ b/lib/arbetsformedlingen/models/company.rb @@ -41,7 +41,10 @@ def to_h # Formats a Company Identification Number the way Arbetsformedlingen likes it def cin_arbetsformedlingen(cin) - String.new(cin.dup).insert(6, '-').insert(0, '46-') + String.new(cin.dup). + delete('-'). + insert(6, '-'). + insert(0, '46-') end end end diff --git a/lib/arbetsformedlingen/models/packet.rb b/lib/arbetsformedlingen/models/packet.rb index 50fdcdb..9b45949 100644 --- a/lib/arbetsformedlingen/models/packet.rb +++ b/lib/arbetsformedlingen/models/packet.rb @@ -17,12 +17,15 @@ module Arbetsformedlingen end class Packet < Model + DEFAULT_PACKET_ID = 1 + def initialize(attributes:, publication:, document:, position:) hash = attributes @publication = publication @document = document @position = position - super(PacketSchema.call(hash.merge(id: hash[:job_id]))) + id = hash.fetch(:id, DEFAULT_PACKET_ID) + super(PacketSchema.call(hash.merge(id: id))) end def to_h diff --git a/lib/arbetsformedlingen/models/position.rb b/lib/arbetsformedlingen/models/position.rb index 13520c1..434a33f 100644 --- a/lib/arbetsformedlingen/models/position.rb +++ b/lib/arbetsformedlingen/models/position.rb @@ -38,7 +38,19 @@ def to_h hash[:salary] = @salary.to_h hash[:qualifications] = @qualifications.map(&:to_h) hash[:application_method] = @application_method.to_h + full_address = build_full_address(hash.fetch(:address)) + hash[:address][:full_address] = full_address if full_address hash end + + def build_full_address(address) + return unless address.key?(:street) || address.key?(:zip) || address.key?(:city) + + [ + address.fetch(:street), + address.fetch(:zip), + address[:city] + ].compact.join(', ') + end end end diff --git a/lib/arbetsformedlingen/models/publication.rb b/lib/arbetsformedlingen/models/publication.rb index 95db254..9374107 100644 --- a/lib/arbetsformedlingen/models/publication.rb +++ b/lib/arbetsformedlingen/models/publication.rb @@ -7,17 +7,22 @@ module Arbetsformedlingen predicates(Predicates) end - required(:publish_at_date, :string).filled(:yyyy_mm_dd?) + required(:unpublish_at, :string).filled(:yyyy_mm_dd?) required(:name, Types::StrippedString).filled required(:email, Types::StrippedString).filled(:str?, :email?) + + optional(:publish_at, :string).filled(:yyyy_mm_dd?) end class Publication < Model def initialize(hash) data = hash.dup - publish_date = data[:publish_at_date] || Time.now.utc + publish_date = data[:publish_at] || Time.now.utc + + data[:publish_at] = publish_date.strftime('%Y-%m-%d') + data[:unpublish_at] = data[:unpublish_at]&.strftime('%Y-%m-%d') - data[:publish_at_date] = publish_date.strftime('%Y-%m-%d') + # TODO: Validate that unpublish_at - publish_at is not greater that 180 days super(PublicationSchema.call(data)) end diff --git a/lib/arbetsformedlingen/models/schedule.rb b/lib/arbetsformedlingen/models/schedule.rb index 64617a6..6ad3360 100644 --- a/lib/arbetsformedlingen/models/schedule.rb +++ b/lib/arbetsformedlingen/models/schedule.rb @@ -27,7 +27,9 @@ class Schedule < Model def initialize(hash) data = hash.dup - data[:position_duration_code] = duration_code(data[:start_date], data[:end_date]) + duration_code = duration_code(data[:start_date], data[:end_date]) + data[:position_duration_code] = duration_code + data[:full_time] = duration_code == -1 super(ScheduleSchema.call(data)) end diff --git a/lib/arbetsformedlingen/output_builder.rb b/lib/arbetsformedlingen/output_builder.rb index efeeece..cac820c 100644 --- a/lib/arbetsformedlingen/output_builder.rb +++ b/lib/arbetsformedlingen/output_builder.rb @@ -103,7 +103,10 @@ def append_post_detail(node, packet_data) publication = packet_data.fetch(:publication) node.PostDetail do |detail| - detail.EndDate { |n| n.Date(publication.fetch(:publish_at_date)) } + if publication[:publish_at] + detail.StartDate { |n| n.Date(publication.fetch(:publish_at)) } + end + detail.EndDate { |n| n.Date(publication.fetch(:unpublish_at)) } detail.PostedBy do |posted| posted.Contact do |contact| @@ -198,15 +201,17 @@ def append_schedule(node, schedule) end def append_delivery_address(node, data) + return node unless data.key?(:full_address) || data.key?(:street) + node.DeliveryAddress do |d_address| - d_address.AddressLine(data.fetch(:full_address)) - d_address.StreetName(data.fetch(:street)) + d_address.AddressLine(data.fetch(:full_address)) if data.key?(:full_address) + d_address.StreetName(data.fetch(:street)) if data.key?(:street) end end def append_job_position_address(node, address) node.PostalAddress do |a_node| - a_node.CountryCode(address.fetch(:country_code)) + a_node.CountryCode('SE')) a_node.PostalCode(address.fetch(:zip)) if address.key?(:zip) a_node.Municipality(address.fetch(:municipality)) append_delivery_address(a_node, address)