* VRFS-3431 - better response when creating HFA request
This commit is contained in:
parent
37d6c3e57c
commit
5ba03a2755
|
|
@ -0,0 +1,22 @@
|
|||
ActiveAdmin.register_page "Harry Fox Request" do
|
||||
menu :parent => 'JamTracks'
|
||||
|
||||
page_action :create_request, :method => :post do
|
||||
|
||||
name = params[:jam_ruby_jam_track_hfa_request][:name]
|
||||
|
||||
request = JamTrackHfaRequest.create(name)
|
||||
redirect_to admin_harry_fox_request_path, :notice => "Request created. Check Amazon S3 in the 'jamkazam' bucket; specifically #{request.request_csv_filename}"
|
||||
end
|
||||
|
||||
|
||||
content do
|
||||
semantic_form_for JamTrackHfaRequest.new, :url => admin_harry_fox_request_create_request_path, :builder => ActiveAdmin::FormBuilder do |f|
|
||||
f.inputs "New Harry Fox Licensing Request" do
|
||||
f.input :name, :hint => "Some sort of name to help us remember what this request was for"
|
||||
end
|
||||
f.actions
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -300,4 +300,5 @@ alter_band_profile_rate_defaults.sql
|
|||
repair_band_profile.sql
|
||||
jam_track_onboarding_enhancements.sql
|
||||
jam_track_name_drop_unique.sql
|
||||
jam_track_searchability.sql
|
||||
jam_track_searchability.sql
|
||||
harry_fox_agency.sql
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
ALTER TABLE jam_tracks ADD COLUMN server_fixation_date DATE DEFAULT NOW();
|
||||
ALTER TABLE jam_tracks ADD COLUMN hfa_license_status BOOLEAN DEFAULT FALSE;
|
||||
ALTER TABLE jam_tracks ADD COLUMN hfa_license_desired BOOLEAN DEFAULT TRUE;
|
||||
ALTER TABLE jam_tracks ADD COLUMN alternative_license_status BOOLEAN DEFAULT FALSE;
|
||||
ALTER TABLE jam_tracks ADD COLUMN hfa_license_number INTEGER;
|
||||
ALTER TABLE jam_tracks ADD COLUMN hfa_song_code VARCHAR;
|
||||
ALTER TABLE jam_tracks ADD COLUMN album_title VARCHAR;
|
||||
|
||||
CREATE TABLE jam_track_hfa_requests (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR NOT NULL,
|
||||
request_csv_filename VARCHAR,
|
||||
response_csv_filename VARCHAR,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
approved_at TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE jam_track_hfa_request_ids (
|
||||
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
jam_track_id VARCHAR(64) NOT NULL REFERENCES jam_tracks(id) ON DELETE SET NULL,
|
||||
jam_track_hfa_request_id INTEGER REFERENCES jam_track_hfa_requests(id) ON DELETE SET NULL,
|
||||
request_id INTEGER,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE SEQUENCE jam_track_hfa_request_id_seq;
|
||||
ALTER TABLE jam_track_hfa_request_ids ALTER COLUMN request_id SET DEFAULT nextval('jam_track_hfa_request_id_seq'::regclass);
|
||||
ALTER SEQUENCE jam_track_hfa_request_id_seq OWNED BY jam_track_hfa_request_ids.request_id;
|
||||
|
||||
ALTER TABLE ONLY jam_track_hfa_request_ids ALTER COLUMN request_id SET DEFAULT nextval('jam_track_hfa_request_id_seq'::regclass);
|
||||
|
|
@ -203,6 +203,8 @@ require "jam_ruby/models/email_batch_scheduled_sessions"
|
|||
require "jam_ruby/models/email_batch_set"
|
||||
require "jam_ruby/models/jam_track_licensor"
|
||||
require "jam_ruby/models/jam_track"
|
||||
require "jam_ruby/models/jam_track_hfa_request"
|
||||
require "jam_ruby/models/jam_track_hfa_request_id"
|
||||
require "jam_ruby/models/jam_track_track"
|
||||
require "jam_ruby/models/jam_track_right"
|
||||
require "jam_ruby/models/jam_track_tap_in"
|
||||
|
|
|
|||
|
|
@ -444,7 +444,7 @@ module JamRuby
|
|||
if is_tency_storage?
|
||||
jam_track.vendor_id = metadata[:id]
|
||||
jam_track.licensor = JamTrackLicensor.find_by_name('Tency Music')
|
||||
add_licensor_metadata('Tency Music', metalocation)
|
||||
#add_licensor_metadata('Tency Music', metalocation)
|
||||
end
|
||||
else
|
||||
if !options[:resync_audio]
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ module JamRuby
|
|||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def s3_manager(options={:bucket => nil, :public => false})
|
||||
@s3_manager ||= S3Manager.new(options[:bucket] ? options[:bucket] : (options[:public] ? APP_CONFIG.aws_bucket_public : APP_CONFIG.aws_bucket), APP_CONFIG.aws_access_key_id, APP_CONFIG.aws_secret_access_key)
|
||||
end
|
||||
end
|
||||
|
||||
def s3_manager(options={:bucket => nil, :public => false})
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ module JamRuby
|
|||
:original_artist, :songwriter, :publisher, :licensor, :licensor_id, :pro, :genres_jam_tracks_attributes, :sales_region, :price,
|
||||
:reproduction_royalty, :public_performance_royalty, :reproduction_royalty_amount,
|
||||
:licensor_royalty_amount, :pro_royalty_amount, :plan_code, :initial_play_silence, :jam_track_tracks_attributes,
|
||||
:jam_track_tap_ins_attributes, :genre_ids, :version, :jmep_json, :jmep_text, :pro_ascap, :pro_bmi, :pro_sesac, :duration, as: :admin
|
||||
:jam_track_tap_ins_attributes, :genre_ids, :version, :jmep_json, :jmep_text, :pro_ascap, :pro_bmi, :pro_sesac, :duration,
|
||||
:server_fixation_date, :hfa_license_status, :hfa_license_desired, :alternative_license_status, :hfa_license_number, :hfa_song_code, :album_title, as: :admin
|
||||
|
||||
validates :name, presence: true, length: {maximum: 200}
|
||||
validates :plan_code, presence: true, uniqueness: true, length: {maximum: 50 }
|
||||
|
|
@ -37,7 +38,13 @@ module JamRuby
|
|||
validates :public_performance_royalty, inclusion: {in: [nil, true, false]}
|
||||
validates :reproduction_royalty, inclusion: {in: [nil, true, false]}
|
||||
validates :public_performance_royalty, inclusion: {in: [nil, true, false]}
|
||||
validates :duration, numericality: {only_integer: true}, :allow_nil => true
|
||||
validates :duration, numericality: {only_integer: true}, :allow_nil => true
|
||||
validates :hfa_license_status, inclusion: {in: [true, false]}
|
||||
validates :hfa_license_desired, inclusion: {in: [true, false]}
|
||||
validates :alternative_license_status, inclusion: {in: [true, false]}
|
||||
validates :hfa_license_number, numericality: {only_integer: true}, :allow_nil => true
|
||||
validates :hfa_song_code, length: {maximum: 200}
|
||||
validates :album_title, length: {maximum: 200}
|
||||
|
||||
validates_format_of :reproduction_royalty_amount, with: /^\d+\.*\d{0,4}$/, :allow_blank => true
|
||||
validates_format_of :licensor_royalty_amount, with: /^\d+\.*\d{0,4}$/, :allow_blank => true
|
||||
|
|
|
|||
|
|
@ -0,0 +1,89 @@
|
|||
module JamRuby
|
||||
class JamTrackHfaRequest < ActiveRecord::Base
|
||||
include JamRuby::S3ManagerMixin
|
||||
|
||||
|
||||
@@log = Logging.logger[JamTrackHfaRequest]
|
||||
|
||||
attr_accessible :name, as: :admin
|
||||
|
||||
validates :name, presence: true, length: {maximum: 200}
|
||||
|
||||
def self.create(name)
|
||||
request = nil
|
||||
transaction do
|
||||
request = JamTrackHfaRequest.new
|
||||
request.name = name
|
||||
request.save!
|
||||
request.reload
|
||||
|
||||
requests = []
|
||||
JamTrack.where(hfa_license_status: false).where(hfa_license_desired: true).where(alternative_license_status: false).each do |jam_track|
|
||||
request_id = JamTrackHfaRequestId.new
|
||||
request_id.jam_track = jam_track
|
||||
request_id.jam_track_hfa_request = request
|
||||
request_id.save
|
||||
request_id.reload # to get back the request_id attribute
|
||||
requests << request_id
|
||||
end
|
||||
|
||||
request_name = "JamKazam-#{request.id}-#{request.created_at.to_date.to_s}.csv"
|
||||
Dir.mktmpdir do |tmp_dir|
|
||||
out = File.join(tmp_dir, request_name)
|
||||
|
||||
# Field 1 - HFA Agreement Code - Hardcode to "SSA".
|
||||
# Field 2 - Manufacturer Number - Hardcode to "M18303".
|
||||
# Field 3 - Transaction Date - Populate this field with the date that we generate this tab-delimited file, in the format YYYYMMDD - e.g. "20150813".
|
||||
# Field 4 - License Request Number - This one is slightly more involved. Basically, according to HFA we need to generate a unique numeric ID for each JamTrack license request (as opposed to each unique JamTrack, as we might need to make more than one request per JamTrack if such requests were to fail in some cases). This unique numeric ID per request should start with the number 1, and increment by 1. So I guess this feature will need to remember which of these IDs are used on each run it makes so that it knows where to start on the next run.
|
||||
# Field 7 - Total Playing Time - Minutes - We already have a JamTrack field for the duration of the JamTrack in seconds. We should keep that field, and keep using it as is. We need to use that field to populate this Field 7 and the next Field 8. So if the duration of the JamTrack in seconds were 90 seconds, then we should set Field 7 to "1" and Field 8 to "30" to signify a length of 1:30.
|
||||
# Field 8 - Total Playing Time - Seconds - See note above on Field 7.
|
||||
# Field 9 - Artist Name - Populate this field from the Artist Name field in the JamTrack record - e.g. "AC/DC".
|
||||
# Field 10 - Song Title - Populate this field from the Song Name field in the JamTrack record - e.g. "Back In Black".
|
||||
# Field 21 - Configuration Code - Hardcode to "SP".
|
||||
# Field 22 - License Type - Hardcode to "G".
|
||||
# Field 23 - Server Fixation Date - Set this to the approximate date that the JamTrack was uploaded to our servers, and format as YYYYMMDD - e.g. "20150813". I'm suggesting we update each JamTrack record with this date, just so that we have a record of this piece of data we submitted to HFA - even though HFA didn't seem at all clear about how this data is used or why it matters.
|
||||
# Field 24 - Rate Code - Hardcode to "S".
|
||||
# Field 37 - User Defined - Populate this field with our internal JamKazam unique JamTrack ID. This field value is supposed to be passed back to us from HFA in the processed output file, and we'll need this to associate the HFA License Number with our internal JamTrack ID.
|
||||
# Field 38 - Track ID - Let's also populate this field with our internal JamKazam unique JamTrack ID, just like Field 37, just for fun.
|
||||
|
||||
|
||||
CSV.open(out, "wb") do |csv|
|
||||
requests.each do |request|
|
||||
line = {}
|
||||
line['1'] = 'SSA'
|
||||
line['2'] = 'M18303'
|
||||
line['3'] = Time.now.to_date.strftime('%Y%m%d')
|
||||
line['4'] = request.request_id
|
||||
line['7'] = request.jam_track.duration / 60
|
||||
line['8'] = request.jam_track.duration % 60
|
||||
line['9'] = request.jam_track.original_artist
|
||||
line['10'] = request.jam_track.name
|
||||
line['21'] = 'SP'
|
||||
line['22'] = 'G'
|
||||
line['23'] = request.jam_track.server_fixation_date.strftime('%Y%m%d')
|
||||
line['24'] = 'S'
|
||||
line['37'] = request.jam_track.id
|
||||
line['38'] = request.jam_track.id
|
||||
|
||||
entry = []
|
||||
38.times do |i|
|
||||
entry << line[(i + 1).to_s]
|
||||
end
|
||||
csv << entry
|
||||
end
|
||||
end
|
||||
|
||||
upload_path = "harry_fox_requests/#{request_name}"
|
||||
s3_manager.upload(upload_path, out, content_type: 'text/csv')
|
||||
|
||||
request.request_csv_filename = upload_path
|
||||
request.save!
|
||||
end
|
||||
|
||||
|
||||
request
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
module JamRuby
|
||||
class JamTrackHfaRequestId < ActiveRecord::Base
|
||||
include JamRuby::S3ManagerMixin
|
||||
|
||||
before_create(:remove_attribute)
|
||||
|
||||
|
||||
|
||||
@@log = Logging.logger[JamTrackHfaRequestId]
|
||||
|
||||
attr_accessible :name, as: :admin
|
||||
|
||||
belongs_to :jam_track, class_name: "JamRuby::JamTrack"
|
||||
belongs_to :jam_track_hfa_request, class_name: "JamRuby::JamTrackHfaRequest"
|
||||
|
||||
validates :jam_track, presence: true
|
||||
validates :jam_track_hfa_request, presence:true
|
||||
|
||||
private
|
||||
|
||||
def remove_attribute
|
||||
@attributes.delete('request_id')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe JamTrackHfaRequest do
|
||||
include CarrierWave::Test::Matchers
|
||||
include UsesTempFiles
|
||||
|
||||
#let(:jamtrack1) {FactoryGirl.create(:jam_track, hfa_license_status: false, hfa_license_desired: true, alternative_license_status: false)
|
||||
let(:jamtrack1) {FactoryGirl.create(:jam_track, duration: 90, server_fixation_date: Time.now.to_date ) }
|
||||
|
||||
it "creates request" do
|
||||
|
||||
jamtrack1.touch
|
||||
JamTrackHfaRequest.create('request1')
|
||||
|
||||
request = JamTrackHfaRequest.first
|
||||
request.request_csv_filename.should_not be_nil
|
||||
|
||||
request_id = JamTrackHfaRequestId.first
|
||||
request_id.request_id.should_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue