From 3e7f61c4d11553534754a76debc97ac6b586fb56 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 5 Sep 2024 16:26:10 +1000 Subject: [PATCH 1/3] Add new DFC vocabulary So that we can use order states programmatically. --- .../dfc_provider/app/services/dfc_loader.rb | 15 +- .../script/update-dfc-vocabularies | 1 + .../spec/services/dfc_loader_spec.rb | 6 + engines/dfc_provider/vendor/vocabulary.json | 351 ++++++++++++++++++ 4 files changed, 370 insertions(+), 3 deletions(-) create mode 100644 engines/dfc_provider/vendor/vocabulary.json diff --git a/engines/dfc_provider/app/services/dfc_loader.rb b/engines/dfc_provider/app/services/dfc_loader.rb index 1fae62f9f4f..471f19b94b3 100644 --- a/engines/dfc_provider/app/services/dfc_loader.rb +++ b/engines/dfc_provider/app/services/dfc_loader.rb @@ -2,15 +2,24 @@ class DfcLoader def self.connector - @connector ||= load_vocabularies + unless @connector + @connector = DataFoodConsortium::Connector::Connector.instance + load_vocabularies + end + + @connector + end + + def self.vocabulary(name) + @vocabs ||= {} + @vocabs[name] ||= connector.__send__(:loadThesaurus, read_file(name)) end def self.load_vocabularies - connector = DataFoodConsortium::Connector::Connector.instance connector.loadMeasures(read_file("measures")) connector.loadFacets(read_file("facets")) connector.loadProductTypes(read_file("productTypes")) - connector + vocabulary("vocabulary") # order states etc end def self.read_file(name) diff --git a/engines/dfc_provider/script/update-dfc-vocabularies b/engines/dfc_provider/script/update-dfc-vocabularies index 1097b06044d..81f5d481075 100755 --- a/engines/dfc_provider/script/update-dfc-vocabularies +++ b/engines/dfc_provider/script/update-dfc-vocabularies @@ -9,3 +9,4 @@ mkdir -p "$dst" curl --location "$src/facets.json" > "$dst/facets.json" curl --location "$src/measures.json" > "$dst/measures.json" curl --location "$src/productTypes.json" > "$dst/productTypes.json" +curl --location "$src/vocabulary.json" > "$dst/vocabulary.json" diff --git a/engines/dfc_provider/spec/services/dfc_loader_spec.rb b/engines/dfc_provider/spec/services/dfc_loader_spec.rb index 93ae98de9df..7e7d383ac6c 100644 --- a/engines/dfc_provider/spec/services/dfc_loader_spec.rb +++ b/engines/dfc_provider/spec/services/dfc_loader_spec.rb @@ -21,4 +21,10 @@ ) expect(result["dfc-b:name"]).to eq "Tomato" end + + it "loads vocabularies" do + terms = DfcLoader.vocabulary("vocabulary") + expect(terms.STATES.ORDERSTATE.HELD.semanticId) + .to eq "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Held" + end end diff --git a/engines/dfc_provider/vendor/vocabulary.json b/engines/dfc_provider/vendor/vocabulary.json new file mode 100644 index 00000000000..4dd405056e6 --- /dev/null +++ b/engines/dfc_provider/vendor/vocabulary.json @@ -0,0 +1,351 @@ +[ { + "@graph" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#", + "@type" : [ "http://www.w3.org/2002/07/owl#Ontology" ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Cancelled", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#OrderState" + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#PaymentState" + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#FulfilmentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Cancelled" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Complete", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#OrderState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Complete" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary", + "@type" : [ "http://www.w3.org/2004/02/skos/core#ConceptScheme" ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "DFC_Vocabulary" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Draft", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#OrderState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Draft" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Fulfilled", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#FulfilmentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Fulfilled" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#FulfilmentState", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#States" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Fulfilment state" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Held", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#OrderState" + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#FulfilmentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Held" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#OrderState", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#States" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Order state" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Paid", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#PaymentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Paid" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#PaymentState", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#States" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Payment state" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#States", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "States" + } ], + "http://www.w3.org/2004/02/skos/core#topConceptOf" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Unfulfilled", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#FulfilmentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Unfulfilled" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#Unpaid", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#PaymentState" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Unpaid" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#accept", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "accept" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#c_734fc709", + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "FulfilmentState" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#combine", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "combine" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#consume", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "consume" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#dropoff", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "dropoff" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#lower", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "lower" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#modify", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "modify" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#move", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "move" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#pickup", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "pickup" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#produce", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "produce" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#raise", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "raise" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#separate", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "separate" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "Transformation type" + } ], + "http://www.w3.org/2004/02/skos/core#topConceptOf" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ] + }, { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#use", + "@type" : [ "http://www.w3.org/2004/02/skos/core#Concept" ], + "http://www.w3.org/2004/02/skos/core#broader" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#transformationType" + } ], + "http://www.w3.org/2004/02/skos/core#inScheme" : [ { + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#DFC_Vocabulary" + } ], + "http://www.w3.org/2004/02/skos/core#prefLabel" : [ { + "@language" : "en", + "@value" : "use" + } ] + } ], + "@id" : "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#" +} ] \ No newline at end of file From c4c95d472ed8d8691bf3b21baf67f72adde67568 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 22 Nov 2024 13:57:35 +1100 Subject: [PATCH 2/3] Use defined DFC orders states --- app/services/fdc_backorderer.rb | 10 +- app/services/fdc_offer_broker.rb | 7 +- .../dfc_provider/app/services/dfc_loader.rb | 7 + .../dfc_provider/spec/services/dfc_io_spec.rb | 23 + .../dfc_provider/vendor/context_1.8.2.json | 450 ++++++++++++++++++ spec/jobs/complete_backorder_job_spec.rb | 9 +- 6 files changed, 496 insertions(+), 10 deletions(-) create mode 100644 engines/dfc_provider/vendor/context_1.8.2.json diff --git a/app/services/fdc_backorderer.rb b/app/services/fdc_backorderer.rb index b77e69f4cf7..33318a8c832 100644 --- a/app/services/fdc_backorderer.rb +++ b/app/services/fdc_backorderer.rb @@ -36,7 +36,7 @@ def lookup_open_order(ofn_order) .map { |id| find_order(id) } .compact # Just in case someone completed the order without updating our database: - .select { |o| o.orderStatus[:path] == "Held" } + .select { |o| o.orderStatus == order_status.HELD } .first # The DFC Connector doesn't recognise status values properly yet. # So we are overriding the value with something that can be exported. @@ -52,7 +52,7 @@ def lookup_open_order(ofn_order) def find_last_open_order graph = import(urls.orders_url) open_orders = graph&.select do |o| - o.semanticType == "dfc-b:Order" && o.orderStatus[:path] == "Held" + o.semanticType == "dfc-b:Order" && o.orderStatus == order_status.HELD end return if open_orders.blank? @@ -160,4 +160,10 @@ def build_sale_session(order) session.semanticId = urls.sale_session_url end end + + private + + def order_status + DfcLoader.vocabulary("vocabulary").STATES.ORDERSTATE + end end diff --git a/app/services/fdc_offer_broker.rb b/app/services/fdc_offer_broker.rb index ee7814463ef..2e81e6cee32 100644 --- a/app/services/fdc_offer_broker.rb +++ b/app/services/fdc_offer_broker.rb @@ -33,8 +33,7 @@ def wholesale_product(product_id) production_flow = catalog_item("#{product_id}/AsPlannedProductionFlow") if production_flow - wholesale_product_id = production_flow.product - catalog_item(wholesale_product_id) + production_flow.product else # We didn't find a wholesale variant, falling back to the given product. catalog_item(product_id) @@ -57,7 +56,7 @@ def wholesale_to_retail(wholesale_product_id) consumption_flow = catalog_item( production_flow.semanticId.sub("AsPlannedProductionFlow", "AsPlannedConsumptionFlow") ) - retail_product_id = consumption_flow.product + retail_product_id = consumption_flow.product.semanticId contained_quantity = consumption_flow.quantity.value.to_i @@ -77,7 +76,7 @@ def catalog_item(id) end def flow_producing(wholesale_product_id) - @production_flows_by_product_id ||= production_flows.index_by(&:product) + @production_flows_by_product_id ||= production_flows.index_by { |flow| flow.product.semanticId } @production_flows_by_product_id[wholesale_product_id] end diff --git a/engines/dfc_provider/app/services/dfc_loader.rb b/engines/dfc_provider/app/services/dfc_loader.rb index 471f19b94b3..cba654a2ff9 100644 --- a/engines/dfc_provider/app/services/dfc_loader.rb +++ b/engines/dfc_provider/app/services/dfc_loader.rb @@ -4,12 +4,19 @@ class DfcLoader def self.connector unless @connector @connector = DataFoodConsortium::Connector::Connector.instance + load_context load_vocabularies end @connector end + def self.load_context + JSON::LD::Context.add_preloaded("http://www.datafoodconsortium.org/") { + JSON::LD::Context.parse(read_file("context_1.8.2")["@context"]) + } + end + def self.vocabulary(name) @vocabs ||= {} @vocabs[name] ||= connector.__send__(:loadThesaurus, read_file(name)) diff --git a/engines/dfc_provider/spec/services/dfc_io_spec.rb b/engines/dfc_provider/spec/services/dfc_io_spec.rb index 58194ce2041..3596db8fb45 100644 --- a/engines/dfc_provider/spec/services/dfc_io_spec.rb +++ b/engines/dfc_provider/spec/services/dfc_io_spec.rb @@ -9,6 +9,12 @@ let(:enterprise) do DataFoodConsortium::Connector::Enterprise.new("Pete's Pumpkins") end + let(:order) do + DataFoodConsortium::Connector::Order.new("https://example.net", orderStatus: orderstate.HELD) + end + let(:orderstate) do + DfcLoader.vocabulary("vocabulary").STATES.ORDERSTATE + end describe ".export" do it "exports nothing" do @@ -33,5 +39,22 @@ *%w(@id @type dfc-b:affiliates) ) end + + it "recognises loaded vocabularies" do + json = DfcIo.export(order) + result = JSON.parse(json) + + expect(result["dfc-b:hasOrderStatus"]).to eq "dfc-v:Held" + end + end + + describe ".import" do + it "recognises loaded vocabularies" do + json = DfcIo.export(order) + result = DfcIo.import(json) + result = DfcIo.import(DfcIo.export(order)) + + expect(result.orderStatus).to eq orderstate.HELD + end end end diff --git a/engines/dfc_provider/vendor/context_1.8.2.json b/engines/dfc_provider/vendor/context_1.8.2.json new file mode 100644 index 00000000000..d574d54c724 --- /dev/null +++ b/engines/dfc_provider/vendor/context_1.8.2.json @@ -0,0 +1,450 @@ +{ + "@context": { + "rdfs": "http://www.w3.org/2000/01/rdf-schema#", + "skos" : "http://www.w3.org/2004/02/skos/core#", + "dfc": "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_FullModel.owl#", + "dc": "http://purl.org/dc/elements/1.1/#", + "dfc-b": "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_BusinessOntology.owl#", + "dfc-t": "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_TechnicalOntology.owl#", + "dfc-m": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/measures.rdf#", + "dfc-pt": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/productTypes.rdf#", + "dfc-f": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/facets.rdf#", + "dfc-v": "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#", + "ontosec": "http://www.semanticweb.org/ontologies/2008/11/OntologySecurity.owl#", + "dfc-b:DFC_BusinessOntology_ObjectProperty": { + "@type": "@id" + }, + "dfc-b:DFC_Interface_Property": { + "@type": "@id" + }, + "dfc-b:addressOf": { + "@type": "@id" + }, + "dfc-b:affiliatedTo": { + "@type": "@id" + }, + "dfc-b:affiliates": { + "@type": "@id" + }, + "dfc-b:allergenCharacteristicOf": { + "@type": "@id" + }, + "dfc-b:belongsTo": { + "@type": "@id" + }, + "dfc-b:brandOf": { + "@type": "@id" + }, + "dfc-b:certificateOf": { + "@type": "@id" + }, + "dfc-b:characteristicOf": { + "@type": "@id" + }, + "dfc-b:claimOf": { + "@type": "@id" + }, + "dfc-b:composedOf": { + "@type": "@id" + }, + "dfc-b:composes": { + "@type": "@id" + }, + "dfc-b:concernedBy": { + "@type": "@id" + }, + "dfc-b:concerns": { + "@type": "@id" + }, + "dfc-b:constituedBy": { + "@type": "@id" + }, + "dfc-b:constitutes": { + "@type": "@id" + }, + "dfc-b:consumedBy": { + "@type": "@id" + }, + "dfc-b:consumes": { + "@type": "@id" + }, + "dfc-b:containerInformationOf": { + "@type": "@id" + }, + "dfc-b:coordinatedBy": { + "@type": "@id" + }, + "dfc-b:coordinates": { + "@type": "@id" + }, + "dfc-b:definedBy": { + "@type": "@id" + }, + "dfc-b:defines": { + "@type": "@id" + }, + "dfc-b:deliveredAt": { + "@type": "@id" + }, + "dfc-b:facetOf": { + "@type": "@id" + }, + "dfc-b:from": { + "@type": "@id" + }, + "dfc-b:geographicalOriginOf": { + "@type": "@id" + }, + "dfc-b:hasAddress": { + "@type": "@id" + }, + "dfc-b:hasAllergenCharacteristic": { + "@type": "@id" + }, + "dfc-b:hasAllergenDimension": { + "@type": "@id" + }, + "dfc-b:hasBrand": { + "@type": "@id" + }, + "dfc-b:hasCertification": { + "@type": "@id" + }, + "dfc-b:hasCharacteristic": { + "@type": "@id" + }, + "dfc-b:hasClaim": { + "@type": "@id" + }, + "dfc-b:hasContainerInformation": { + "@type": "@id" + }, + "dfc-b:hasDimension": { + "@type": "@id" + }, + "dfc-b:hasFacet": { + "@type": "@id" + }, + "dfc-b:hasFulfilmentStatus": { + "@type": "@id" + }, + "dfc-b:hasGeographicalOrigin": { + "@type": "@id" + }, + "dfc-b:hasIngredient": { + "@type": "@id" + }, + "dfc-b:hasInput": { + "@type": "@id" + }, + "dfc-b:hasLabellingCharacteristic": { + "@type": "@id" + }, + "dfc-b:hasLabellingDimension": { + "@type": "@id" + }, + "dfc-b:hasMainContact": { + "@type": "@id" + }, + "dfc-b:hasNatureOrigin": { + "@type": "@id" + }, + "dfc-b:hasNutrientCharacteristic": { + "@type": "@id" + }, + "dfc-b:hasNutrientDimension": { + "@type": "@id" + }, + "dfc-b:hasObject": { + "@type": "@id" + }, + "dfc-b:hasOffer": { + "@type": "@id" + }, + "dfc-b:hasOption": { + "@type": "@id" + }, + "dfc-b:hasOrderStatus": { + "@type": "@id" + }, + "dfc-b:hasOutput": { + "@type": "@id" + }, + "dfc-b:hasPart": { + "@type": "@id" + }, + "dfc-b:hasPartOrigin": { + "@type": "@id" + }, + "dfc-b:hasPaymentMethod": { + "@type": "@id" + }, + "dfc-b:hasPaymentStatus": { + "@type": "@id" + }, + "dfc-b:hasPhoneNumber": { + "@type": "@id" + }, + "dfc-b:hasPhysicalCharacteristic": { + "@type": "@id" + }, + "dfc-b:hasPhysicalDimension": { + "@type": "@id" + }, + "dfc-b:hasPrice": { + "@type": "@id" + }, + "dfc-b:hasProcess": { + "@type": "@id" + }, + "dfc-b:hasQuantity": { + "@type": "@id" + }, + "dfc-b:hasReference": { + "@type": "@id" + }, + "dfc-b:hasSocialMedia": { + "@type": "@id" + }, + "dfc-b:hasStatus": { + "@type": "@id" + }, + "dfc-b:hasTemperature": { + "@type": "@id" + }, + "dfc-b:hasTransformationType": { + "@type": "@id" + }, + "dfc-b:hasType": { + "@type": "@id" + }, + "dfc-b:hasUnit": { + "@type": "@id" + }, + "dfc-b:holds": { + "@type": "@id" + }, + "dfc-b:hostedAt": { + "@type": "@id" + }, + "dfc-b:hosts": { + "@type": "@id" + }, + "dfc-b:identifiedBy": { + "@type": "@id" + }, + "dfc-b:identifies": { + "@type": "@id" + }, + "dfc-b:industrializedBy": { + "@type": "@id" + }, + "dfc-b:industrializes": { + "@type": "@id" + }, + "dfc-b:inputOf": { + "@type": "@id" + }, + "dfc-b:isIngredientOf": { + "@type": "@id" + }, + "dfc-b:isPriceOf": { + "@type": "@id" + }, + "dfc-b:isTemperatureOf": { + "@type": "@id" + }, + "dfc-b:labellingCharacteristicOf": { + "@type": "@id" + }, + "dfc-b:listedIn": { + "@type": "@id" + }, + "dfc-b:lists": { + "@type": "@id" + }, + "dfc-b:localizedBy": { + "@type": "@id" + }, + "dfc-b:localizes": { + "@type": "@id" + }, + "dfc-b:mainContactOf": { + "@type": "@id" + }, + "dfc-b:maintainedBy": { + "@type": "@id" + }, + "dfc-b:maintains": { + "@type": "@id" + }, + "dfc-b:managedBy": { + "@type": "@id" + }, + "dfc-b:manages": { + "@type": "@id" + }, + "dfc-b:natureOriginOf": { + "@type": "@id" + }, + "dfc-b:nutrientCharacteristicOf": { + "@type": "@id" + }, + "dfc-b:objectOf": { + "@type": "@id" + }, + "dfc-b:offeredThrough": { + "@type": "@id" + }, + "dfc-b:offers": { + "@type": "@id" + }, + "dfc-b:offersTo": { + "@type": "@id" + }, + "dfc-b:optionOf": { + "@type": "@id" + }, + "dfc-b:orderedBy": { + "@type": "@id" + }, + "dfc-b:orders": { + "@type": "@id" + }, + "dfc-b:outputOf": { + "@type": "@id" + }, + "dfc-b:ownedBy": { + "@type": "@id" + }, + "dfc-b:owns": { + "@type": "@id" + }, + "dfc-b:paidWith": { + "@type": "@id" + }, + "dfc-b:partOf": { + "@type": "@id" + }, + "dfc-b:partOriginOf": { + "@type": "@id" + }, + "dfc-b:phoneNumberOf": { + "@type": "@id" + }, + "dfc-b:physicalCharacteristicOf": { + "@type": "@id" + }, + "dfc-b:pickedUpAt": { + "@type": "@id" + }, + "dfc-b:processOf": { + "@type": "@id" + }, + "dfc-b:producedBy": { + "@type": "@id" + }, + "dfc-b:produces": { + "@type": "@id" + }, + "dfc-b:proposedBy": { + "@type": "@id" + }, + "dfc-b:proposes": { + "@type": "@id" + }, + "dfc-b:referenceOf": { + "@type": "@id" + }, + "dfc-b:referencedBy": { + "@type": "@id" + }, + "dfc-b:references": { + "@type": "@id" + }, + "dfc-b:refersTo": { + "@type": "@id" + }, + "dfc-b:representedBy": { + "@type": "@id" + }, + "dfc-b:represents": { + "@type": "@id" + }, + "dfc-b:requestedBy": { + "@type": "@id" + }, + "dfc-b:requests": { + "@type": "@id" + }, + "dfc-b:satisfiedBy": { + "@type": "@id" + }, + "dfc-b:satisfies": { + "@type": "@id" + }, + "dfc-b:selectedBy": { + "@type": "@id" + }, + "dfc-b:selects": { + "@type": "@id" + }, + "dfc-b:sells": { + "@type": "@id" + }, + "dfc-b:socialMediaOf": { + "@type": "@id" + }, + "dfc-b:soldBy": { + "@type": "@id" + }, + "dfc-b:storedIn": { + "@type": "@id" + }, + "dfc-b:stores": { + "@type": "@id" + }, + "dfc-b:suppliedBy": { + "@type": "@id" + }, + "dfc-b:supplies": { + "@type": "@id" + }, + "dfc-b:suppliesTo": { + "@type": "@id" + }, + "dfc-b:to": { + "@type": "@id" + }, + "dfc-b:tracedBy": { + "@type": "@id" + }, + "dfc-b:traces": { + "@type": "@id" + }, + "dfc-b:transformedBy": { + "@type": "@id" + }, + "dfc-b:transforms": { + "@type": "@id" + }, + "dfc-b:typeOf": { + "@type": "@id" + }, + "dfc-b:uses": { + "@type": "@id" + }, + "dfc-t:represent": { + "@type": "@id" + }, + "dfc-t:hasPivot": { + "@type": "@id" + }, + "dfc-t:hostedBy": { + "@type": "@id" + }, + "dfc-t:owner": { + "@type": "@id" + } + } +} \ No newline at end of file diff --git a/spec/jobs/complete_backorder_job_spec.rb b/spec/jobs/complete_backorder_job_spec.rb index 7e575a33806..503342edc05 100644 --- a/spec/jobs/complete_backorder_job_spec.rb +++ b/spec/jobs/complete_backorder_job_spec.rb @@ -36,6 +36,7 @@ let(:beans) { ofn_order.line_items[0].variant } let(:chia) { chia_item.variant } let(:chia_item) { ofn_order.line_items[1] } + let(:order_status) { DfcLoader.vocabulary("vocabulary").STATES.ORDERSTATE } describe "#perform" do before do @@ -69,8 +70,8 @@ subject.perform(user, distributor, order_cycle, order.semanticId) current_order = orderer.find_order(order.semanticId) }.to change { - current_order.orderStatus[:path] - }.from("Held").to("Complete") + current_order.orderStatus + }.from(order_status.HELD).to(order_status.COMPLETE) .and change { current_order.lines[0].quantity.to_i }.from(3).to(2) @@ -99,8 +100,8 @@ subject.perform(user, distributor, order_cycle, order.semanticId) current_order = orderer.find_order(order.semanticId) }.to change { - current_order.orderStatus[:path] - }.from("Held").to("Complete") + current_order.orderStatus + }.from(order_status.HELD).to(order_status.COMPLETE) .and change { current_order.lines.count }.from(1).to(0) From 5719d0682d1ffd0389e544a2675cd2792e110ff2 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 29 Nov 2024 12:23:51 +1100 Subject: [PATCH 3/3] Remove duplicate lines, dev leftovers --- engines/dfc_provider/spec/services/dfc_io_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/engines/dfc_provider/spec/services/dfc_io_spec.rb b/engines/dfc_provider/spec/services/dfc_io_spec.rb index 3596db8fb45..ff729fbf867 100644 --- a/engines/dfc_provider/spec/services/dfc_io_spec.rb +++ b/engines/dfc_provider/spec/services/dfc_io_spec.rb @@ -50,8 +50,6 @@ describe ".import" do it "recognises loaded vocabularies" do - json = DfcIo.export(order) - result = DfcIo.import(json) result = DfcIo.import(DfcIo.export(order)) expect(result.orderStatus).to eq orderstate.HELD