40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/circuitdata/compatibility_checker.rb', line 40
def perform_comparison(product_data, check_data, schema, type)
case type
when 'restricted'
check_hash = check_data.dig(:open_trade_transfer_package, :profiles, :restricted, :printed_circuits_fabrication_data)
when 'enforced'
check_hash = check_data.dig(:open_trade_transfer_package, :profiles, :enforced, :printed_circuits_fabrication_data)
when 'capabilities'
check_hash = check_data.dig(:open_trade_transfer_package, :capabilities, :printed_circuits_fabrication_data)
else
check_hash = {}
end
common_hash = schema.dig(:properties, :open_trade_transfer_package, :properties, :products, :patternProperties, :'^(?!generic$).*', :properties, :printed_circuits_fabrication_data, :properties)
check_hash.each do |k, v|
v.each do |kl1, vl1|
common_hash[k.to_sym]||= {:type => 'object', :properties => {}}
common_hash[:stackup][:properties][:specified][:properties][k.to_sym] ||= {:type => 'object', :properties => {}}
case vl1.class.name
when 'String'
if vl1.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$")
from, too = vl1.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$").captures
case type
when 'restricted'
new_hash = {:not => {:allOf => [{:minimum => from.to_f},{:maximum => too.to_f}]}}
else
new_hash = eval("{:minimum => #{from}, :maximum => #{too}}")
end
else
enum = []
vl1.split(',').each {|enumvalue| enum << enumvalue.strip}
case type
when 'restricted'
new_hash = {:not => {:anyOf => [{ :enum => ''}]}}
new_hash[:not][:anyOf][0][:enum] = enum
else
new_hash = eval("{:enum => #{enum}}")
end
end
when 'Numeric', 'Float'
case type
when 'restricted'
new_hash = {:not => {:allOf => [{:minimum => vl1.to_f},{:maximum => vl1.to_f}]}}
else
new_hash = eval("{:enum => [#{vl1.to_s}]}")
end
end
common_hash[k.to_sym][:properties][kl1.to_sym] = new_hash
common_hash[:stackup][:properties][:specified][:properties][k.to_sym][:properties][kl1.to_sym] = new_hash
end if v.is_a? Hash
common_hash[k.to_sym][:additionalProperties] = false if (v.is_a?(Hash) && type == 'capabilities')
end
begin
validation_errors = JSON::Validator.fully_validate(schema.to_json, product_data, :errors_as_objects => true)
if validation_errors.any?
@fh[:error] = true
@fh[:message] = 'The product to check did not meet the requirements'
validation_errors.each do |error|
error_array = []
begin
error_array << error[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema[\\s\\S]*)$").captures[1]
rescue
error_array << error[:message]
end
@fh[:errors][type.to_sym][error[:fragment]] = error_array
end
end
rescue JSON::Schema::ReadFailed
@fh[:error] = true
@fh[:message] = "Could not read the submitted `#{type}` schema"
rescue JSON::Schema::SchemaError
@fh[:error] = true
@fh[:message] = "Something was wrong with the submitted `#{type}` schema"
end
end
|