Skip to content

Commit

Permalink
only throw error on formatted fields if they are required by the work…
Browse files Browse the repository at this point in the history
… type
  • Loading branch information
orangewolf committed Aug 13, 2023
1 parent 4d36f44 commit 0e2fd32
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions app/models/concerns/bulkrax/has_local_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ def add_local
parsed_metadata['format'] = parse_format(parsed_metadata['format']) if parsed_metadata['format']
end

def form_class
return false unless parsed_metadata['model'].present?
@form_class ||= "Hyrax::#{parsed_metadata['model']}Form".constantize
end

def validate?(attribute)
form_class.required_fields.include?(attribute)
end

def parse_year(src)
src = src.strip.chomp
return src unless validate?(:year)
valid = src.match?(/^(19|20)\d{2}$/)
error_msg = %("#{src}" is not a 4 digit year.)
valid ? src : (raise ::StandardError, error_msg)
Expand All @@ -21,9 +31,12 @@ def parse_format(src)
src.map do |format|
# will return nil if it doesn't match with any format label
label = Hyrax::FormatService.label_from_alt(format)
valid = label.present?
error_msg = %("#{format}" is not a valid type of format.)
valid ? label : (raise ::StandardError, error_msg)
if validate?(:format)
valid = label.present?
error_msg = %("#{format}" is not a valid type of format.)
raise(::StandardError, error_msg) unless valid
end
label
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ services:
condition: service_started
initialize_app:
condition: service_completed_successfully
expose:
ports:
- 3000

worker:
Expand Down

0 comments on commit 0e2fd32

Please sign in to comment.