circuitdata 0.3.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/Rakefile +8 -0
- data/lib/circuitdata.rb +76 -388
- data/lib/circuitdata/bk_comparer.rb +106 -0
- data/lib/circuitdata/compatibility_checker.rb +119 -0
- data/lib/circuitdata/file_comparer.rb +243 -0
- data/lib/circuitdata/schema_files/v1/ottp_circuitdata_schema.json +5587 -0
- data/lib/circuitdata/schema_files/v1/ottp_circuitdata_schema_definitions.json +1139 -0
- data/lib/circuitdata/schema_files/v1/ottp_circuitdata_skeleton_schema.json +55 -0
- data/lib/circuitdata/schema_files/v1/ottp_schema_definitions.json +102 -0
- data/lib/circuitdata/version.rb +1 -1
- metadata +10 -3
- data/lib/tasks/circuitdata_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa1f26f00a6e37eddbd191f4c07e20cd6549403d
|
4
|
+
data.tar.gz: 22e2442da385848cb8836ede71d6f747bf8f8cf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c98b789d6a3299aa7494eefcf0b291be7aa7769015006d9984748f1c8ba39a282fe0ad997913dcb89e89a1f75fa231eac27d242a15ca7e07f8af619e65d16d0
|
7
|
+
data.tar.gz: 8996afcb18cd0c8cd8d26c08dd53f637f12f0dd3932b37a414a1ccfae9915ae2e2d00545cf0598317e4411c371e0f8ff4562887ee17e65f6a9d6586906223870
|
data/README.md
CHANGED
@@ -40,6 +40,17 @@ require 'circuitdata'
|
|
40
40
|
2.3.0 :009 > # Turn off validation against the schema
|
41
41
|
2.3.0 :008 > Circuitdata.compatibility_checker( 'testfile-product.json', 'testfile-profile-restricted.json', false )
|
42
42
|
=> {:error=>true, :errormessage=>"The product to check did not meet the requirements", :validationserrors=>{}, :restrictederrors=>{"#/open_trade_transfer_package/products/testproduct/printed_circuits_fabrication_data/board/thickness"=>["of type number matched the disallowed schema"]}, :enforcederrors=>{}, :capabilitieserrors=>{}}
|
43
|
+
2.3.0 :005 > # Run a test with several files against each other and get a complete list of values and conflicts, and a summary
|
44
|
+
2.3.0 :006 > product1 = File.join(File.dirname(__FILE__), 'test/test_data/test_product1.json')
|
45
|
+
=> "./test/test_data/test_product1.json"
|
46
|
+
2.3.0 :007 > profile_restricted = File.join(File.dirname(__FILE__), 'test/test_data/testfile-profile-restricted.json')
|
47
|
+
=> "./test/test_data/testfile-profile-restricted.json"
|
48
|
+
2.3.0 :008 > profile_default = File.join(File.dirname(__FILE__), 'test/test_data/testfile-profile-default.json')
|
49
|
+
=> "./test/test_data/testfile-profile-default.json"
|
50
|
+
2.3.0 :009 > file_hash = {product1: product1, restricted: profile_restricted, default: profile_default}
|
51
|
+
=> {:product1=>"./test/test_data/test_product1.json", :restricted=>"./test/test_data/testfile-profile-restricted.json", :default=>"./test/test_data/testfile-profile-default.json"}
|
52
|
+
2.3.0 :010 > Circuitdata.compare_files(file_hash, true)
|
53
|
+
=> {:error=>false, :message=>nil, :conflict=>false, :product_name=>"testproduct", :columns=>[:summary, :product1, :restricted, :default], :master_column=>nil, :rows=>{:rigid_conductive_layer=>{:count=>{:product1=>{:value=>11, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :restricted=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :default=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :summary=>{:value=>11, :conflict=>false, :conflicts_with=>[:product1], :conflict_message=>[]}}, :minimum_external_track_width=>{:product1=>{:value=>0.14, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :restricted=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :default=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :summary=>{:value=>0.14, :conflict=>false, :conflicts_with=>[:product1], :conflict_message=>[]}}, :minimum_external_spacing_width=>{:product1=>{:value=>0.14, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :restricted=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :default=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :summary=>{:value=>0.14, :conflict=>false, :conflicts_with=>[:product1], :conflict_message=>[]}}, :copper_foil_roughness=>{:product1=>{:value=>"L", :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :restricted=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :default=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :summary=>{:value=>"L", :conflict=>false, :conflicts_with=>[:product1], :conflict_message=>[]}}}, :legend=>{:color=>{:product1=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :restricted=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :default=>{:value=>"white", :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :summary=>{:value=>"white", :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}}}, :array=>{:fiducials_number=>{:product1=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :restricted=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :default=>{:value=>3, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :summary=>{:value=>3, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}}, :fiducials_shape=>{:product1=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :restricted=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :default=>{:value=>"circle", :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :summary=>{:value=>"circle", :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}}, :breakaway_method=>{:product1=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :restricted=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :default=>{:value=>"routing", :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :summary=>{:value=>"routing", :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}}, :mouse_bites=>{:product1=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :restricted=>{:value=>nil, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :default=>{:value=>true, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}, :summary=>{:value=>true, :conflict=>false, :conflicts_with=>[], :conflict_message=>[]}}}}}
|
43
54
|
```
|
44
55
|
|
45
56
|
## License
|
data/Rakefile
ADDED
data/lib/circuitdata.rb
CHANGED
@@ -1,432 +1,120 @@
|
|
1
1
|
module Circuitdata
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
if checksjson["open_trade_transfer_package"].has_key? "profiles"
|
31
|
-
if checksjson["open_trade_transfer_package"]["profiles"].has_key? "enforced"
|
32
|
-
if checksjson["open_trade_transfer_package"]["profiles"]["enforced"].length > 0
|
33
|
-
profile_enforced = true
|
34
|
-
end
|
35
|
-
end
|
36
|
-
if checksjson["open_trade_transfer_package"]["profiles"].has_key? "restricted"
|
37
|
-
if checksjson["open_trade_transfer_package"]["profiles"]["restricted"].length > 0
|
38
|
-
profile_restricted = true
|
39
|
-
end
|
40
|
-
end
|
41
|
-
if checksjson["open_trade_transfer_package"]["profiles"].has_key? "defaults"
|
42
|
-
if checksjson["open_trade_transfer_package"]["profiles"]["defaults"].length > 0
|
43
|
-
profile_defaults = true
|
44
|
-
end
|
45
|
-
end
|
2
|
+
# SHOULD ONLY HOUSE COMMON FUNCTIONS ONLY
|
3
|
+
require 'active_support/all'
|
4
|
+
require 'circuitdata/file_comparer'
|
5
|
+
require 'circuitdata/compatibility_checker'
|
6
|
+
|
7
|
+
def self.get_data_summary(data)
|
8
|
+
types = []
|
9
|
+
wrapper = data&.dig(:open_trade_transfer_package)
|
10
|
+
types << 'profile_restricted' unless wrapper&.dig(:profiles, :restricted).nil?
|
11
|
+
types << 'profile_enforced' unless wrapper&.dig(:profiles, :enforced).nil?
|
12
|
+
types << 'profile_defaults' unless wrapper&.dig(:profiles, :defaults).nil?
|
13
|
+
types << 'capabilities' unless wrapper&.dig(:capabilities).nil?
|
14
|
+
|
15
|
+
products = wrapper&.dig(:products)
|
16
|
+
product_names = products.nil? ? [] : products.keys# this will return all the product names
|
17
|
+
types << 'product' if product_names.any?
|
18
|
+
# loop through the products
|
19
|
+
products.each do |k, v|
|
20
|
+
if v&.dig(:stackup, :specification_level) == 'specified' && !v&.dig(:stackup, :specification_level, :specified).nil?
|
21
|
+
types << 'stackup'
|
46
22
|
end
|
47
|
-
|
48
|
-
if checksjson["open_trade_transfer_package"]["capabilities"].length > 0
|
49
|
-
capabilities = true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
return number_of_products, stackup, profile_defaults, profile_restricted, profile_enforced, capabilities
|
54
|
-
end
|
23
|
+
end unless products.nil?
|
55
24
|
|
56
|
-
|
25
|
+
return product_names, types
|
26
|
+
end
|
57
27
|
|
58
|
-
|
28
|
+
def self.read_json(file)
|
59
29
|
require 'json'
|
30
|
+
error, message, data = false, nil, nil
|
60
31
|
|
61
|
-
|
62
|
-
message = ""
|
63
|
-
returncontent = nil
|
64
|
-
if content.is_a? Hash
|
32
|
+
if file.is_a? Hash
|
65
33
|
begin
|
66
|
-
|
34
|
+
data = file
|
35
|
+
data.deep_symbolize_keys!
|
67
36
|
rescue
|
68
37
|
error = true
|
69
38
|
message = "Could not convert the Hash into JSON"
|
70
39
|
end
|
71
40
|
else
|
72
41
|
begin
|
73
|
-
open(
|
74
|
-
|
42
|
+
open(file) do |f|
|
43
|
+
data = JSON.parse(f.read, symbolize_names: true)
|
75
44
|
end
|
76
45
|
rescue
|
77
46
|
error = true
|
78
47
|
message = "Could not read the file"
|
79
48
|
end
|
80
49
|
end
|
81
|
-
return error, message,
|
50
|
+
return error, message, data
|
82
51
|
end
|
83
52
|
|
84
53
|
def self.validate(content)
|
85
54
|
require 'json-schema'
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
message = ""
|
90
|
-
validationserrors = {}
|
55
|
+
error, message, validations_errors = false, nil, {}
|
56
|
+
schema = File.join(File.dirname(__FILE__), 'circuitdata/schema_files/v1/ottp_circuitdata_schema.json')
|
57
|
+
# schema = 'http://schema.circuitdata.org/v1/ottp_circuitdata_schema.json'
|
91
58
|
|
92
59
|
begin
|
93
|
-
validated = JSON::Validator.fully_validate(
|
60
|
+
validated = JSON::Validator.fully_validate(schema, content, :errors_as_objects => true)
|
94
61
|
rescue JSON::Schema::ReadFailed
|
95
|
-
|
96
|
-
message = "Could not read the schema
|
62
|
+
error = true
|
63
|
+
message = "Could not read the validating schema"
|
97
64
|
rescue JSON::Schema::SchemaError
|
98
|
-
|
99
|
-
message = "
|
65
|
+
error = true
|
66
|
+
message = "There is something was wrong with the validating schema"
|
100
67
|
end
|
101
|
-
unless
|
68
|
+
unless error
|
102
69
|
if validated.count > 0
|
103
70
|
error = true
|
104
71
|
message = "Could not validate the file against the CircuitData json schema"
|
105
|
-
validated.each do |
|
106
|
-
|
72
|
+
validated.each do |val_error|
|
73
|
+
validations_errors[val_error[:fragment]] = [] unless validations_errors.has_key? val_error[:fragment]
|
107
74
|
begin
|
108
|
-
|
75
|
+
keep = val_error[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema\\sfile[\\s\\S]*)$").captures[1]
|
109
76
|
rescue
|
110
|
-
keep =
|
77
|
+
keep = val_error[:message]
|
111
78
|
end
|
112
|
-
|
79
|
+
validations_errors[val_error[:fragment]] << keep
|
113
80
|
end
|
114
81
|
end
|
115
82
|
end
|
116
|
-
return error, message,
|
83
|
+
return error, message, validations_errors
|
117
84
|
end
|
118
85
|
|
119
|
-
def self.compare_files(
|
120
|
-
|
121
|
-
|
122
|
-
ra = {
|
123
|
-
error: false,
|
124
|
-
errormessage: "",
|
125
|
-
summary: {},
|
126
|
-
conflicts: {},
|
127
|
-
files: []
|
128
|
-
}
|
129
|
-
if not list.is_a? Array
|
130
|
-
ra[:error] = true
|
131
|
-
ra[:errormessage] = "You have to feed this function with a list of files or hashes"
|
132
|
-
return ra
|
133
|
-
end
|
134
|
-
list.each do |totest|
|
135
|
-
error, message, returncontent = self.read_json(totest)
|
136
|
-
#puts returncontent
|
137
|
-
ra[:summary] = ra[:summary].merge(returncontent)
|
138
|
-
ra[:files] << totest
|
139
|
-
end
|
140
|
-
return ra
|
86
|
+
def self.compare_files(file_hash, validate_origins=false)
|
87
|
+
comparer = FileComparer.new(file_hash, validate_origins)
|
88
|
+
comparer.compare
|
141
89
|
end
|
142
90
|
|
143
|
-
def self.compatibility_checker(
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
require 'json-schema'
|
148
|
-
|
149
|
-
$jsonschema_v1 = 'http://schema.circuitdata.org/v1/ottp_circuitdata_schema.json'
|
150
|
-
|
151
|
-
# prepare the return
|
152
|
-
returnarray = {
|
153
|
-
error: false,
|
154
|
-
errormessage: "",
|
155
|
-
validationserrors: {},
|
156
|
-
restrictederrors: {},
|
157
|
-
enforcederrors: {},
|
158
|
-
capabilitieserrors: {},
|
159
|
-
contains: {
|
160
|
-
file1: {
|
161
|
-
products: 0,
|
162
|
-
stackup: false,
|
163
|
-
profile_defaults: false,
|
164
|
-
profile_enforced: false,
|
165
|
-
profile_restricted: false,
|
166
|
-
capabilities: false
|
167
|
-
},
|
168
|
-
file2: {
|
169
|
-
products: 0,
|
170
|
-
stackup: false,
|
171
|
-
profile_defaults: false,
|
172
|
-
profile_enforced: false,
|
173
|
-
profile_restricted: false,
|
174
|
-
capabilities: false
|
175
|
-
}
|
176
|
-
}
|
177
|
-
}
|
178
|
-
|
179
|
-
# Check the files or hashes
|
180
|
-
#
|
181
|
-
returnarray[:error], returnarray[:errormessage], json_productfile = self.read_json(productfile)
|
182
|
-
return returnarray if returnarray[:error]
|
183
|
-
if not checksfile.nil?
|
184
|
-
returnarray[:error], returnarray[:errormessage], json_checksfile = self.read_json(checksfile)
|
185
|
-
return returnarray if returnarray[:error]
|
186
|
-
end
|
187
|
-
|
188
|
-
# Validate the original files against the CircuitData schema
|
189
|
-
if validate_origins
|
190
|
-
returnarray[:error], returnarray[:errormessage], returnarray[:validationserrors] = self.validate(json_productfile)
|
191
|
-
return returnarray if returnarray[:error]
|
192
|
-
if not checksfile.nil?
|
193
|
-
returnarray[:error], returnarray[:errormessage], returnarray[:validationserrors] = self.validate(json_checksfile)
|
194
|
-
return returnarray if returnarray[:error]
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
# Check against the content
|
199
|
-
returnarray[:contains][:file1][:products], returnarray[:contains][:file1][:stackup], returnarray[:contains][:file1][:profile_defaults], returnarray[:contains][:file1][:profile_restricted], returnarray[:contains][:file1][:profile_enforced], returnarray[:contains][:file1][:capabilities] = self.content(json_productfile)
|
200
|
-
if not checksfile.nil?
|
201
|
-
returnarray[:contains][:file2][:products], returnarray[:contains][:file2][:stackup], returnarray[:contains][:file2][:profile_defaults], returnarray[:contains][:file2][:profile_restricted], returnarray[:contains][:file2][:profile_enforced], returnarray[:contains][:file2][:capabilities] = self.content(json_checksfile)
|
202
|
-
end
|
203
|
-
|
204
|
-
if not checksfile.nil?
|
205
|
-
|
206
|
-
# Create the JSON
|
207
|
-
restrictedschema = enforcedschema = capabilityschema = {
|
208
|
-
"$schema": "http://json-schema.org/draft-04/schema#",
|
209
|
-
"type": "object",
|
210
|
-
"additionalProperties": false,
|
211
|
-
"required": ["open_trade_transfer_package"],
|
212
|
-
"properties": {
|
213
|
-
"open_trade_transfer_package": {
|
214
|
-
"type": "object",
|
215
|
-
"properties": {
|
216
|
-
"version": {
|
217
|
-
"type": "string",
|
218
|
-
"pattern": "^1.0$"
|
219
|
-
},
|
220
|
-
"information": {
|
221
|
-
"$ref": "https://raw.githubusercontent.com/elmatica/Open-Trade-Transfer-Package/master/v1/ottp_schema_definitions.json#/definitions/information"
|
222
|
-
},
|
223
|
-
"products": {
|
224
|
-
"type": "object",
|
225
|
-
"properties": {
|
226
|
-
"generic": {
|
227
|
-
"type": "object",
|
228
|
-
"properties": {},
|
229
|
-
"id": "generic",
|
230
|
-
"description": "this should validate any element under generic to be valid"
|
231
|
-
}
|
232
|
-
},
|
233
|
-
"patternProperties": {
|
234
|
-
"^(?!generic$).*": {
|
235
|
-
"type": "object",
|
236
|
-
"required": ["printed_circuits_fabrication_data"],
|
237
|
-
"properties": {
|
238
|
-
"printed_circuits_fabrication_data": {
|
239
|
-
"type": "object",
|
240
|
-
"required": ["version"],
|
241
|
-
"properties": {
|
242
|
-
"stackup": {
|
243
|
-
"type": "object",
|
244
|
-
"properties": {
|
245
|
-
"specified": {
|
246
|
-
"type": "object",
|
247
|
-
"properties": {
|
248
|
-
}
|
249
|
-
}
|
250
|
-
}
|
251
|
-
}
|
252
|
-
}
|
253
|
-
}
|
254
|
-
}
|
255
|
-
}
|
256
|
-
}
|
257
|
-
}
|
258
|
-
}
|
259
|
-
}
|
260
|
-
}
|
261
|
-
}
|
262
|
-
|
263
|
-
if returnarray[:contains][:file1][:product] or returnarray[:contains][:file1][:stackup]
|
264
|
-
# RUN THROUGH THE ENFORCED
|
265
|
-
if returnarray[:contains][:file2][:profile_enforced]
|
266
|
-
json_checksfile["open_trade_transfer_package"]["profiles"]["enforced"]["printed_circuits_fabrication_data"].each do |key, value|
|
267
|
-
if json_checksfile["open_trade_transfer_package"]["profiles"]["enforced"]["printed_circuits_fabrication_data"][key].is_a? Hash
|
268
|
-
json_checksfile["open_trade_transfer_package"]["profiles"]["enforced"]["printed_circuits_fabrication_data"][key].each do |subkey, subvalue|
|
269
|
-
enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym] = {:type => "object", :properties => {} } unless enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties].has_key? key.to_sym
|
270
|
-
enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym] = {:type => "object", :properties => {} } unless enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties].has_key? key.to_sym
|
271
|
-
if subvalue.is_a? String
|
272
|
-
if subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$") #This is a value range
|
273
|
-
from, too = subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$").captures
|
274
|
-
newhash = eval("{:minimum => #{from}, :maximum => #{too}}")
|
275
|
-
enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
|
276
|
-
enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
|
277
|
-
else # This is a normal string - check for commas
|
278
|
-
enum = []
|
279
|
-
subvalue.split(',').each { |enumvalue| enum << enumvalue.strip }
|
280
|
-
enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => #{enum}}")
|
281
|
-
enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => #{enum}}")
|
282
|
-
end
|
283
|
-
elsif subvalue.is_a? Numeric # This is a normal string
|
284
|
-
enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => [#{subvalue.to_s}]}")
|
285
|
-
enforcedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => [#{subvalue.to_s}]}")
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
begin
|
291
|
-
enforcedvalidate = JSON::Validator.fully_validate(enforcedschema.to_json, json_productfile, :errors_as_objects => true)
|
292
|
-
rescue JSON::Schema::ReadFailed
|
293
|
-
$errors = true
|
294
|
-
returnarray[:error] = true
|
295
|
-
returnarray[:errormessage] = "Could not read the schema #{$jsonschema_v1}"
|
296
|
-
rescue JSON::Schema::SchemaError
|
297
|
-
$errors = true
|
298
|
-
returnarray[:error] = true
|
299
|
-
returnarray[:errormessage] = "Something was wrong with the schema #{$jsonschema_v1}"
|
300
|
-
end
|
301
|
-
unless $errors
|
302
|
-
if enforcedvalidate.count > 0
|
303
|
-
returnarray[:error] = true
|
304
|
-
returnarray[:errormessage] = "The product to check did not meet the requirements"
|
305
|
-
enforcedvalidate.each do |valerror|
|
306
|
-
returnarray[:enforcederrors][valerror[:fragment]] = [] unless returnarray[:enforcederrors].has_key? valerror[:fragment]
|
307
|
-
begin
|
308
|
-
scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema[\\s\\S]*)$").captures
|
309
|
-
rescue
|
310
|
-
keep = valerror[:message]
|
311
|
-
end
|
312
|
-
returnarray[:enforcederrors][valerror[:fragment]] << keep
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
end
|
317
|
-
# RUN THROUGH THE RESTRICTED
|
318
|
-
if returnarray[:contains][:file2][:profile_restricted]
|
319
|
-
json_checksfile["open_trade_transfer_package"]["profiles"]["restricted"]["printed_circuits_fabrication_data"].each do |key, value|
|
320
|
-
if json_checksfile["open_trade_transfer_package"]["profiles"]["restricted"]["printed_circuits_fabrication_data"][key].is_a? Hash
|
321
|
-
json_checksfile["open_trade_transfer_package"]["profiles"]["restricted"]["printed_circuits_fabrication_data"][key].each do |subkey, subvalue|
|
322
|
-
restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym] = {:type => "object", :properties => {} } unless restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties].has_key? key.to_sym
|
323
|
-
restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym] = {:type => "object", :properties => {} } unless restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties].has_key? key.to_sym
|
324
|
-
if subvalue.is_a? String
|
325
|
-
if subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$") #This is a value range
|
326
|
-
from, too = subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$").captures
|
327
|
-
newhash = {:not => {:allOf => [{:minimum => from.to_f},{:maximum => too.to_f}]}}
|
328
|
-
restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
|
329
|
-
restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
|
330
|
-
else # This is a normal string - check for commas
|
331
|
-
newhash = {:not => {:anyOf => [{ :enum => ""}]}}
|
332
|
-
enum = []
|
333
|
-
subvalue.split(',').each { |enumvalue| enum << enumvalue.strip }
|
334
|
-
newhash[:not][:anyOf][0][:enum] = enum
|
335
|
-
restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
|
336
|
-
restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
|
337
|
-
end
|
338
|
-
elsif subvalue.is_a? Numeric # This is a normal string
|
339
|
-
newhash = {:not => {:allOf => [{:minimum => subvalue.to_f},{:maximum => subvalue.to_f}]}}
|
340
|
-
restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
|
341
|
-
restrictedschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|
346
|
-
begin
|
347
|
-
restrictedvalidate = JSON::Validator.fully_validate(restrictedschema.to_json, json_productfile, :errors_as_objects => true)
|
348
|
-
rescue JSON::Schema::ReadFailed
|
349
|
-
$errors = true
|
350
|
-
returnarray[:error] = true
|
351
|
-
returnarray[:errormessage] = "Could not read the schema #{$jsonschema_v1}"
|
352
|
-
rescue JSON::Schema::SchemaError
|
353
|
-
$errors = true
|
354
|
-
returnarray[:error] = true
|
355
|
-
returnarray[:errormessage] = "Something was wrong with the schema #{$jsonschema_v1}"
|
356
|
-
end
|
357
|
-
unless $errors
|
358
|
-
if restrictedvalidate.count > 0
|
359
|
-
returnarray[:error] = true
|
360
|
-
returnarray[:errormessage] = "The product to check did not meet the requirements"
|
361
|
-
restrictedvalidate.each do |valerror|
|
362
|
-
returnarray[:restrictederrors][valerror[:fragment]] = [] unless returnarray[:restrictederrors].has_key? valerror[:fragment]
|
363
|
-
begin
|
364
|
-
scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema[\\s\\S]*)$").captures
|
365
|
-
rescue
|
366
|
-
keep = valerror[:message]
|
367
|
-
end
|
368
|
-
returnarray[:restrictederrors][valerror[:fragment]] << keep
|
369
|
-
end
|
370
|
-
end
|
371
|
-
end
|
372
|
-
end
|
373
|
-
# RUN THROUGH THE CAPABILITIES
|
374
|
-
if returnarray[:contains][:file2][:capabilities]
|
375
|
-
json_checksfile["open_trade_transfer_package"]["capabilities"]["printed_circuits_fabrication_data"].each do |key, value|
|
376
|
-
if json_checksfile["open_trade_transfer_package"]["capabilities"]["printed_circuits_fabrication_data"][key].is_a? Hash
|
377
|
-
json_checksfile["open_trade_transfer_package"]["capabilities"]["printed_circuits_fabrication_data"][key].each do |subkey, subvalue|
|
378
|
-
capabilityschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym] = {:type => "object", :properties => {} } unless capabilityschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties].has_key? key.to_sym
|
379
|
-
capabilityschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym] = {:type => "object", :properties => {} } unless capabilityschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties].has_key? key.to_sym
|
380
|
-
if subvalue.is_a? String
|
381
|
-
if subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$") #This is a value range
|
382
|
-
from, too = subvalue.match("^(\\d*|\\d*.\\d*)\\.\\.\\.(\\d*|\\d*.\\d*)$").captures
|
383
|
-
newhash = eval("{:minimum => #{from}, :maximum => #{too}}")
|
384
|
-
capabilityschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
|
385
|
-
capabilityschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = newhash
|
386
|
-
else # This is a normal string - check for commas
|
387
|
-
enum = []
|
388
|
-
subvalue.split(',').each { |enumvalue| enum << enumvalue.strip }
|
389
|
-
capabilityschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => #{enum}}")
|
390
|
-
capabilityschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => #{enum}}")
|
391
|
-
end
|
392
|
-
elsif subvalue.is_a? Numeric # This is a normal string
|
393
|
-
capabilityschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => [#{subvalue.to_s}]}")
|
394
|
-
capabilityschema[:properties][:open_trade_transfer_package][:properties][:products][:patternProperties][:"^(?!generic$).*"][:properties][:printed_circuits_fabrication_data][:properties][:stackup][:properties][:specified][:properties][key.to_sym][:properties][subkey.to_sym] = eval("{:enum => [#{subvalue.to_s}]}")
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
end
|
399
|
-
begin
|
400
|
-
capabilitiesvalidate = JSON::Validator.fully_validate(capabilityschema.to_json, json_productfile, :errors_as_objects => true)
|
401
|
-
rescue JSON::Schema::ReadFailed
|
402
|
-
$errors = true
|
403
|
-
returnarray[:error] = true
|
404
|
-
returnarray[:errormessage] = "Could not read the schema #{$jsonschema_v1}"
|
405
|
-
rescue JSON::Schema::SchemaError
|
406
|
-
$errors = true
|
407
|
-
returnarray[:error] = true
|
408
|
-
returnarray[:errormessage] = "Something was wrong with the schema #{$jsonschema_v1}"
|
409
|
-
end
|
410
|
-
unless $errors
|
411
|
-
if capabilitiesvalidate.count > 0
|
412
|
-
returnarray[:error] = true
|
413
|
-
returnarray[:errormessage] = "The product to check did not meet the requirements"
|
414
|
-
capabilitiesvalidate.each do |valerror|
|
415
|
-
returnarray[:capabilitieserrors][valerror[:fragment]] = [] unless returnarray[:capabilitieserrors].has_key? valerror[:fragment]
|
416
|
-
begin
|
417
|
-
scrap, keep, scrap2 = valerror[:message].match("^(The\\sproperty\\s\\'[\\s\\S]*\\'\\s)([\\s\\S]*)(\\sin\\sschema[\\s\\S]*)$").captures
|
418
|
-
rescue
|
419
|
-
keep = valerror[:message]
|
420
|
-
end
|
421
|
-
returnarray[:capabilitieserrors][valerror[:fragment]] << keep
|
422
|
-
end
|
423
|
-
end
|
424
|
-
end
|
425
|
-
end
|
426
|
-
end
|
427
|
-
end
|
428
|
-
|
429
|
-
return returnarray
|
91
|
+
def self.compatibility_checker(product_file, check_file=nil, validate_origins=false)
|
92
|
+
checker = CompatibilityChecker.new(product_file, check_file, validate_origins)
|
93
|
+
checker.start_check
|
94
|
+
end
|
430
95
|
|
96
|
+
def self.test
|
97
|
+
product1 = File.join(File.dirname(__FILE__), '../test/test_data/test_product1.json')
|
98
|
+
product2 = File.join(File.dirname(__FILE__), '../test/test_data/test_product2.json')
|
99
|
+
profile_restricted = File.join(File.dirname(__FILE__), '../test/test_data/testfile-profile-restricted.json')
|
100
|
+
profile_enforced = File.join(File.dirname(__FILE__), '../test/test_data/testfile-profile-enforced.json')
|
101
|
+
profile_default = File.join(File.dirname(__FILE__), '../test/test_data/testfile-profile-default.json')
|
102
|
+
capabilities = File.join(File.dirname(__FILE__), '../test/test_data/testfile-capability.json')
|
103
|
+
|
104
|
+
# TEST WITH NON SCHEMA COMPATIBLE JSON
|
105
|
+
# puts 'testing validation with non schema compatible json'
|
106
|
+
# puts Circuitdata.compatibility_checker(fail_product)
|
107
|
+
# puts "\n"
|
108
|
+
|
109
|
+
# TEST THE COMPATIBILITY CHECKER FUNCTION FIRST:
|
110
|
+
puts "\nTesting compatibility_checker: - the capabilities"
|
111
|
+
puts Circuitdata.compatibility_checker(product1, capabilities)
|
112
|
+
puts "\n"
|
113
|
+
|
114
|
+
# THEN TEST THE COMPARE FILES:
|
115
|
+
puts "Testing file comparison"
|
116
|
+
# file_hash = {product1: product1, product2: product2, restricted: profile_restricted, enforced: profile_enforced, default: profile_default, capability: capabilities}
|
117
|
+
file_hash = {product1: product1, product2: product2, restricted: profile_restricted, enforced: profile_enforced, default: profile_default}
|
118
|
+
Circuitdata.compare_files(file_hash, true)
|
431
119
|
end
|
432
120
|
end
|