From 711091931bdebe4b58bdb2eff97b1a4219d7a1bd Mon Sep 17 00:00:00 2001 From: Tiago PDM Date: Fri, 14 Oct 2022 16:53:46 +0100 Subject: [PATCH] refs #123 - update --- fgt-dsu-wizard/commands/environment.js | 20 ++++++++++++ fgt-dsu-wizard/commands/setBatchSSI.js | 12 ++++--- .../commands/setIndividualProductSSI.js | 13 +++++--- fgt-dsu-wizard/commands/setOrderLineSSI.js | 13 +++++--- fgt-dsu-wizard/commands/setOrderSSI.js | 12 ++++--- fgt-dsu-wizard/commands/setParticipantSSI.js | 12 ++++++- fgt-dsu-wizard/commands/setProductSSI.js | 12 ++++--- fgt-dsu-wizard/commands/setSaleSSI.js | 11 ++++--- fgt-dsu-wizard/commands/setShipmentCodeSSI.js | 12 ++++--- fgt-dsu-wizard/commands/setShipmentLineSSI.js | 11 ++++--- fgt-dsu-wizard/commands/setShipmentSSI.js | 12 ++++--- fgt-dsu-wizard/commands/setStatusSSI.js | 11 ++++--- fgt-dsu-wizard/services/BatchService.js | 13 ++------ .../services/IndividualProductService.js | 14 ++------ fgt-dsu-wizard/services/OrderService.js | 19 +---------- fgt-dsu-wizard/services/ProductService.js | 11 +------ fgt-dsu-wizard/services/SaleService.js | 32 ++++++------------- .../services/ShipmentCodeService.js | 18 ++--------- .../services/ShipmentLineService.js | 25 ++++----------- fgt-dsu-wizard/services/ShipmentService.js | 26 +++------------ fgt-dsu-wizard/services/StatusService.js | 19 ++--------- octopus-freeze.json | 2 ++ 22 files changed, 141 insertions(+), 189 deletions(-) create mode 100644 fgt-dsu-wizard/commands/environment.js diff --git a/fgt-dsu-wizard/commands/environment.js b/fgt-dsu-wizard/commands/environment.js new file mode 100644 index 000000000..6c92ebd67 --- /dev/null +++ b/fgt-dsu-wizard/commands/environment.js @@ -0,0 +1,20 @@ +const TRACEABILITY_DOMAIN_KEY = "TRACEABILITY_DOMAIN"; +const BRICKS_DOMAIN_KEY = require('opendsu').constants.BRICKS_DOMAIN_KEY + +function getDomain(defaultDomain){ + if (!globalThis || !globalThis.process || !globalThis.process.env || !globalThis.process.env[TRACEABILITY_DOMAIN_KEY]) + return defaultDomain; + return globalThis.process.env[TRACEABILITY_DOMAIN_KEY]; +} + +function getBricksDomain(){ + if (!globalThis || !globalThis.process || !globalThis.process.env || !globalThis.process.env[BRICKS_DOMAIN_KEY]) + return undefined; + return globalThis.process.env[BRICKS_DOMAIN_KEY]; +} + +module.exports = { + getDomain, + getBricksDomain, + BRICKS_DOMAIN_KEY +} \ No newline at end of file diff --git a/fgt-dsu-wizard/commands/setBatchSSI.js b/fgt-dsu-wizard/commands/setBatchSSI.js index 39a7266ca..c79d9a3f8 100644 --- a/fgt-dsu-wizard/commands/setBatchSSI.js +++ b/fgt-dsu-wizard/commands/setBatchSSI.js @@ -1,3 +1,5 @@ +const {getDomain, getBricksDomain, BRICKS_DOMAIN_KEY} = require("./environment"); + /** * Defines how to create the keyssi for a batch dsu @@ -12,13 +14,15 @@ * @memberOf Commands */ function createBatchSSI(data, domain) { + domain = getDomain(domain) console.log("New BATCH_SSI in domain", domain); const openDSU = require('opendsu'); const keyssiSpace = openDSU.loadApi("keyssi"); let hint; - if (data[openDSU.constants.BRICKS_DOMAIN_KEY]) { - hint = {}; - hint[openDSU.constants.BRICKS_DOMAIN_KEY] = [domain, data[openDSU.constants.BRICKS_DOMAIN_KEY]].join('.'); + const bricksDomain = getBricksDomain(); + if (bricksDomain){ + hint = {} + hint[BRICKS_DOMAIN_KEY] = bricksDomain } return keyssiSpace.createArraySSI(domain, [data.gtin, data.batch], 'v0', hint ? JSON.stringify(hint) : undefined); } @@ -30,7 +34,7 @@ function createBatchSSI(data, domain) { */ function command(server){ const setSSI = require('../../pdm-dsu-toolkit/commands/setSSI'); - setSSI(server, "batch", createBatchSSI, "setBatchSSI", "traceability"); + setSSI(server, "batch", createBatchSSI, "setBatchSSI", getDomain("traceability")); } module.exports = { diff --git a/fgt-dsu-wizard/commands/setIndividualProductSSI.js b/fgt-dsu-wizard/commands/setIndividualProductSSI.js index eba591174..b2704ec66 100644 --- a/fgt-dsu-wizard/commands/setIndividualProductSSI.js +++ b/fgt-dsu-wizard/commands/setIndividualProductSSI.js @@ -1,3 +1,6 @@ +const {getDomain, getBricksDomain, BRICKS_DOMAIN_KEY} = require("./environment"); + + /** * Defines how to create the keyssi for a {@link Product} dsu * @param {object} data necessary properties: @@ -10,13 +13,15 @@ * @memberOf Commands */ function createIndividualProductSSI(data, domain) { + domain = getDomain(domain) console.log("New Individual PRODUCT_SSI in domain", domain); const openDSU = require('opendsu'); const keyssiSpace = openDSU.loadApi("keyssi"); let hint; - if (data[openDSU.constants.BRICKS_DOMAIN_KEY]) { - hint = {}; - hint[openDSU.constants.BRICKS_DOMAIN_KEY] = [domain, data[openDSU.constants.BRICKS_DOMAIN_KEY]].join('.'); + const bricksDomain = getBricksDomain(); + if (bricksDomain){ + hint = {} + hint[BRICKS_DOMAIN_KEY] = bricksDomain } return keyssiSpace.createArraySSI(domain, [data.gtin, data.batchNumber, data.serialNumber], 'v0', hint ? JSON.stringify(hint) : undefined); } @@ -28,7 +33,7 @@ function createIndividualProductSSI(data, domain) { */ function command(server){ const setSSI = require('../../pdm-dsu-toolkit/commands/setSSI'); - setSSI(server, "product", createIndividualProductSSI, "setProductSSI", "traceability"); + setSSI(server, "product", createIndividualProductSSI, "setProductSSI", getDomain("traceability")); } module.exports = { diff --git a/fgt-dsu-wizard/commands/setOrderLineSSI.js b/fgt-dsu-wizard/commands/setOrderLineSSI.js index da98d50b8..7077ef001 100644 --- a/fgt-dsu-wizard/commands/setOrderLineSSI.js +++ b/fgt-dsu-wizard/commands/setOrderLineSSI.js @@ -1,3 +1,5 @@ +const {getDomain, getBricksDomain, BRICKS_DOMAIN_KEY} = require("./environment"); + /** * Defines how to create the keyssi for an orderLine dsu * @param {object} data necessary properties: @@ -10,13 +12,14 @@ * @memberOf Commands */ function createOrderLineSSI(data, domain) { + domain = getDomain(domain) console.log("New ORDERLINE_SSI in domain ", domain); const openDSU = require('opendsu'); const keyssiSpace = openDSU.loadApi("keyssi"); - let hint; - if (data[openDSU.constants.BRICKS_DOMAIN_KEY]) { - hint = {}; - hint[openDSU.constants.BRICKS_DOMAIN_KEY] = [domain, data[openDSU.constants.BRICKS_DOMAIN_KEY]].join('.'); + const bricksDomain = getBricksDomain(); + if (bricksDomain){ + hint = {} + hint[BRICKS_DOMAIN_KEY] = bricksDomain } return keyssiSpace.createTemplateSeedSSI(domain, data.data, 'v0', hint ? JSON.stringify(hint) : undefined); } @@ -28,7 +31,7 @@ function createOrderLineSSI(data, domain) { */ function command(server){ const setSSI = require('../../pdm-dsu-toolkit/commands/setSSI'); - setSSI(server, "orderline", createOrderLineSSI, "setOrderLineSSI", "traceability"); + setSSI(server, "orderline", createOrderLineSSI, "setOrderLineSSI", getDomain("traceability")); } module.exports = { diff --git a/fgt-dsu-wizard/commands/setOrderSSI.js b/fgt-dsu-wizard/commands/setOrderSSI.js index 7974db21d..25d06b4a6 100644 --- a/fgt-dsu-wizard/commands/setOrderSSI.js +++ b/fgt-dsu-wizard/commands/setOrderSSI.js @@ -1,3 +1,4 @@ +const {getDomain, getBricksDomain, BRICKS_DOMAIN_KEY} = require("./environment"); /** * Defines how to create the keyssi for an {@link Order} dsu * @param {object} data necessary properties: @@ -10,13 +11,16 @@ * @memberOf Commands */ function createOrderSSI(data, domain) { + domain = getDomain(domain) + console.log("New ORDER_SSI in domain", domain); const openDSU = require('opendsu'); const keyssiSpace = openDSU.loadApi("keyssi"); let hint; - if (data[openDSU.constants.BRICKS_DOMAIN_KEY]) { - hint = {}; - hint[openDSU.constants.BRICKS_DOMAIN_KEY] = [domain, data[openDSU.constants.BRICKS_DOMAIN_KEY]].join('.'); + const bricksDomain = getBricksDomain(); + if (bricksDomain){ + hint = {} + hint[BRICKS_DOMAIN_KEY] = bricksDomain } return keyssiSpace.createTemplateSeedSSI(domain, data.data, 'v0', hint ? JSON.stringify(hint) : undefined); } @@ -28,7 +32,7 @@ function createOrderSSI(data, domain) { */ function command(server){ const setSSI = require('../../pdm-dsu-toolkit/commands/setSSI'); - setSSI(server, "order", createOrderSSI, "setOrderSSI", "traceability"); + setSSI(server, "order", createOrderSSI, "setOrderSSI", getDomain("traceability")); } module.exports = { diff --git a/fgt-dsu-wizard/commands/setParticipantSSI.js b/fgt-dsu-wizard/commands/setParticipantSSI.js index d61bf75d1..cd61ae8ed 100644 --- a/fgt-dsu-wizard/commands/setParticipantSSI.js +++ b/fgt-dsu-wizard/commands/setParticipantSSI.js @@ -1,3 +1,5 @@ +const {getBricksDomain, BRICKS_DOMAIN_KEY, getDomain} = require("./environment"); + /** * Creates a seedSSI meant to contain participant 'participant' data. * could be used as an identity @@ -7,9 +9,17 @@ * @memberOf Commands */ function createParticipantSSI(participant, domain) { + domain = getDomain(domain) + console.log("New Participant_SSI in domain", domain); const openDSU = require('opendsu'); const keyssiSpace = openDSU.loadApi("keyssi"); + let hint; + const bricksDomain = getBricksDomain(); + if (bricksDomain){ + hint = {} + hint[BRICKS_DOMAIN_KEY] = bricksDomain + } return keyssiSpace.buildTemplateSeedSSI(domain, participant.id + participant.name + participant.tin, undefined, 'v0', undefined); } @@ -20,7 +30,7 @@ function createParticipantSSI(participant, domain) { */ function command(server){ const setSSI = require('../../pdm-dsu-toolkit/commands/setSSI'); - setSSI(server, "participant", createParticipantSSI, "setParticipantSSI", "traceability"); + setSSI(server, "participant", createParticipantSSI, "setParticipantSSI", getDomain("traceability")); } module.exports = { diff --git a/fgt-dsu-wizard/commands/setProductSSI.js b/fgt-dsu-wizard/commands/setProductSSI.js index ff850ddf5..b3f715a6f 100644 --- a/fgt-dsu-wizard/commands/setProductSSI.js +++ b/fgt-dsu-wizard/commands/setProductSSI.js @@ -1,3 +1,4 @@ +const {getDomain, getBricksDomain, BRICKS_DOMAIN_KEY} = require("./environment"); /** * Defines how to create the keyssi for a {@link Product} dsu * @param {object} data necessary properties: @@ -10,13 +11,16 @@ * @memberOf Commands */ function createProductSSI(data, domain) { + domain = getDomain(domain) + console.log("New PRODUCT_SSI in domain", domain); const openDSU = require('opendsu'); const keyssiSpace = openDSU.loadApi("keyssi"); let hint; - if (data[openDSU.constants.BRICKS_DOMAIN_KEY]) { - hint = {}; - hint[openDSU.constants.BRICKS_DOMAIN_KEY] = [domain, data[openDSU.constants.BRICKS_DOMAIN_KEY]].join('.'); + const bricksDomain = getBricksDomain(); + if (bricksDomain){ + hint = {} + hint[BRICKS_DOMAIN_KEY] = bricksDomain } return keyssiSpace.createArraySSI(domain, [data.gtin], 'v0', hint ? JSON.stringify(hint) : undefined); } @@ -28,7 +32,7 @@ function createProductSSI(data, domain) { */ function command(server){ const setSSI = require('../../pdm-dsu-toolkit/commands/setSSI'); - setSSI(server, "product", createProductSSI, "setProductSSI", "traceability"); + setSSI(server, "product", createProductSSI, "setProductSSI", getDomain("traceability")); } module.exports = { diff --git a/fgt-dsu-wizard/commands/setSaleSSI.js b/fgt-dsu-wizard/commands/setSaleSSI.js index 75d1d72ae..d074388a0 100644 --- a/fgt-dsu-wizard/commands/setSaleSSI.js +++ b/fgt-dsu-wizard/commands/setSaleSSI.js @@ -1,3 +1,4 @@ +const {getDomain, getBricksDomain, BRICKS_DOMAIN_KEY} = require("./environment"); /** * Defines how to create the keyssi for a {@link Receipt} dsu * @param {object} data necessary properties: @@ -9,13 +10,15 @@ * @memberOf Commands */ function createSaleSSI(data, domain) { + domain = getDomain(domain) console.log("New Sale_SSI in domain", domain); const openDSU = require('opendsu'); const keyssiSpace = openDSU.loadApi("keyssi"); let hint; - if (data[openDSU.constants.BRICKS_DOMAIN_KEY]) { - hint = {}; - hint[openDSU.constants.BRICKS_DOMAIN_KEY] = [domain, data[openDSU.constants.BRICKS_DOMAIN_KEY]].join('.'); + const bricksDomain = getBricksDomain(); + if (bricksDomain){ + hint = {} + hint[BRICKS_DOMAIN_KEY] = bricksDomain } return keyssiSpace.createTemplateSeedSSI(domain, data.data.join(), 'v0', hint ? JSON.stringify(hint) : undefined); } @@ -26,7 +29,7 @@ function createSaleSSI(data, domain) { */ function command(server){ const setSSI = require('../../pdm-dsu-toolkit/commands/setSSI'); - setSSI(server, "sale", createSaleSSI, "setSaleSSI", "traceability"); + setSSI(server, "sale", createSaleSSI, "setSaleSSI", getDomain("traceability")); } module.exports = { diff --git a/fgt-dsu-wizard/commands/setShipmentCodeSSI.js b/fgt-dsu-wizard/commands/setShipmentCodeSSI.js index d84064acd..47d3ad325 100644 --- a/fgt-dsu-wizard/commands/setShipmentCodeSSI.js +++ b/fgt-dsu-wizard/commands/setShipmentCodeSSI.js @@ -1,3 +1,5 @@ +const {getBricksDomain, BRICKS_DOMAIN_KEY, getDomain} = require("./environment"); + /** * Defines how to create the keyssi for a {@link ShipmentLine} dsu * @param {object} data necessary properties: @@ -9,13 +11,15 @@ * @memberOf Commands */ function createShipmentCodeSSI(data, domain) { + domain = getDomain(domain); console.log("New SHIPMENTCODE_SSI in domain", domain); const openDSU = require('opendsu'); const keyssiSpace = openDSU.loadApi("keyssi"); let hint; - if (data[openDSU.constants.BRICKS_DOMAIN_KEY]) { - hint = {}; - hint[openDSU.constants.BRICKS_DOMAIN_KEY] = [domain, data[openDSU.constants.BRICKS_DOMAIN_KEY]].join('.'); + const bricksDomain = getBricksDomain(); + if (bricksDomain){ + hint = {} + hint[BRICKS_DOMAIN_KEY] = bricksDomain } return keyssiSpace.createTemplateSeedSSI(domain, data.data, 'v0', hint ? JSON.stringify(hint) : undefined); } @@ -26,7 +30,7 @@ function createShipmentCodeSSI(data, domain) { */ function command(server){ const setSSI = require('../../pdm-dsu-toolkit/commands/setSSI'); - setSSI(server, "shipmentcode", createShipmentCodeSSI, "setShipmentCodeSSI", "traceability"); + setSSI(server, "shipmentcode", createShipmentCodeSSI, "setShipmentCodeSSI", getDomain("traceability")); } module.exports = { diff --git a/fgt-dsu-wizard/commands/setShipmentLineSSI.js b/fgt-dsu-wizard/commands/setShipmentLineSSI.js index 087d1bc0e..13ae2a856 100644 --- a/fgt-dsu-wizard/commands/setShipmentLineSSI.js +++ b/fgt-dsu-wizard/commands/setShipmentLineSSI.js @@ -1,3 +1,4 @@ +const {getDomain, getBricksDomain, BRICKS_DOMAIN_KEY} = require("./environment"); /** * Defines how to create the keyssi for a {@link ShipmentLine} dsu * @param {object} data necessary properties: @@ -9,13 +10,15 @@ * @memberOf Commands */ function createShipmentLineSSI(data, domain) { + domain = getDomain(domain) console.log("New SHIPMENTLINE_SSI in domain", domain); const openDSU = require('opendsu'); const keyssiSpace = openDSU.loadApi("keyssi"); let hint; - if (data[openDSU.constants.BRICKS_DOMAIN_KEY]) { - hint = {}; - hint[openDSU.constants.BRICKS_DOMAIN_KEY] = [domain, data[openDSU.constants.BRICKS_DOMAIN_KEY]].join('.'); + const bricksDomain = getBricksDomain(); + if (bricksDomain){ + hint = {} + hint[BRICKS_DOMAIN_KEY] = bricksDomain } return keyssiSpace.createTemplateSeedSSI(domain, data.data, 'v0', hint ? JSON.stringify(hint) : undefined); } @@ -26,7 +29,7 @@ function createShipmentLineSSI(data, domain) { */ function command(server){ const setSSI = require('../../pdm-dsu-toolkit/commands/setSSI'); - setSSI(server, "shipmentline", createShipmentLineSSI, "setShipmentLineSSI", "traceability"); + setSSI(server, "shipmentline", createShipmentLineSSI, "setShipmentLineSSI", getDomain("traceability")); } module.exports = { diff --git a/fgt-dsu-wizard/commands/setShipmentSSI.js b/fgt-dsu-wizard/commands/setShipmentSSI.js index 2135d12ab..d88937c1b 100644 --- a/fgt-dsu-wizard/commands/setShipmentSSI.js +++ b/fgt-dsu-wizard/commands/setShipmentSSI.js @@ -1,3 +1,4 @@ +const {getDomain, getBricksDomain, BRICKS_DOMAIN_KEY} = require("./environment"); /** * Defines how to create the keyssi for a {@link Shipment} dsu * @param {object} data necessary properties: @@ -9,13 +10,16 @@ * @memberOf Commands */ function createShipmentSSI(data, domain) { + domain = getDomain(domain) + console.log("New SHIPMENT_SSI in domain", domain); const openDSU = require('opendsu'); const keyssiSpace = openDSU.loadApi("keyssi"); let hint; - if (data[openDSU.constants.BRICKS_DOMAIN_KEY]) { - hint = {}; - hint[openDSU.constants.BRICKS_DOMAIN_KEY] = [domain, data[openDSU.constants.BRICKS_DOMAIN_KEY]].join('.'); + const bricksDomain = getBricksDomain(); + if (bricksDomain){ + hint = {} + hint[BRICKS_DOMAIN_KEY] = bricksDomain } return keyssiSpace.createTemplateSeedSSI(domain, data.data, 'v0', hint ? JSON.stringify(hint) : undefined); } @@ -26,7 +30,7 @@ function createShipmentSSI(data, domain) { */ function command(server){ const setSSI = require('../../pdm-dsu-toolkit/commands/setSSI'); - setSSI(server, "shipment", createShipmentSSI, "setShipmentSSI", "traceability"); + setSSI(server, "shipment", createShipmentSSI, "setShipmentSSI", getDomain("traceability")); } module.exports = { diff --git a/fgt-dsu-wizard/commands/setStatusSSI.js b/fgt-dsu-wizard/commands/setStatusSSI.js index 5a66224da..924e49bf5 100644 --- a/fgt-dsu-wizard/commands/setStatusSSI.js +++ b/fgt-dsu-wizard/commands/setStatusSSI.js @@ -1,3 +1,4 @@ +const {getDomain, getBricksDomain, BRICKS_DOMAIN_KEY} = require("./environment"); /** * Defines how to create the keyssi for a orderLine dsu * @param {OrderStatus|ShipmentStatus} status. if status has the properties: @@ -8,13 +9,15 @@ * @memberOf Commands */ function createStatusSSI(status, domain) { + domain = getDomain(domain) console.log("New Status_SSI in domain", domain); const openDSU = require('opendsu'); const keyssiSpace = openDSU.loadApi("keyssi"); let hint; - if (status[openDSU.constants.BRICKS_DOMAIN_KEY]) { - hint = {}; - hint[openDSU.constants.BRICKS_DOMAIN_KEY] = [domain, status[openDSU.constants.BRICKS_DOMAIN_KEY]].join('.'); + const bricksDomain = getBricksDomain(); + if (bricksDomain){ + hint = {} + hint[BRICKS_DOMAIN_KEY] = bricksDomain } return keyssiSpace.createTemplateSeedSSI(domain, status, undefined, 'v0', hint ? JSON.stringify(hint) : undefined); } @@ -25,7 +28,7 @@ function createStatusSSI(status, domain) { */ function command(server){ const setSSI = require('../../pdm-dsu-toolkit/commands/setSSI'); - setSSI(server, "status", createStatusSSI, "setStatusSSI", "traceability"); + setSSI(server, "status", createStatusSSI, "setStatusSSI", getDomain("traceability")); } module.exports = { diff --git a/fgt-dsu-wizard/services/BatchService.js b/fgt-dsu-wizard/services/BatchService.js index ec1e3e5e9..a6e28ad11 100644 --- a/fgt-dsu-wizard/services/BatchService.js +++ b/fgt-dsu-wizard/services/BatchService.js @@ -18,21 +18,12 @@ function BatchService(domain, strategy){ let isSimple = strategies.SIMPLE === (strategy || strategies.SIMPLE); const statusService = new (require('./StatusService'))(domain, strategy); const productService = new ( require('./ProductService'))(domain, strategy); - const BRICKS_DOMAIN_KEY = require("opendsu").constants.BRICKS_DOMAIN_KEY - const getBricksDomainFromProcess = function(){ - if (!globalThis.process || !globalThis.process["BRICKS_DOMAIN"]) - return undefined; - return globalThis.process["BRICKS_DOMAIN"]; - } - - this.generateKey = function(gtin, batchNumber, bricksDomain){ + this.generateKey = function(gtin, batchNumber){ let keyGenData = { gtin: gtin, batch: batchNumber } - if (bricksDomain) - keyGenData[BRICKS_DOMAIN_KEY] = bricksDomain return keyGenFunction(keyGenData, domain); } @@ -115,7 +106,7 @@ function BatchService(domain, strategy){ return callback(_err); if (isSimple){ - let keySSI = this.generateKey(gtin, batch.batchNumber, getBricksDomainFromProcess()); + let keySSI = this.generateKey(gtin, batch.batchNumber); utils.selectMethod(keySSI)(keySSI, (err, dsu) => { if (err) return callback(err); diff --git a/fgt-dsu-wizard/services/IndividualProductService.js b/fgt-dsu-wizard/services/IndividualProductService.js index 6ba5f0466..fa4f378df 100644 --- a/fgt-dsu-wizard/services/IndividualProductService.js +++ b/fgt-dsu-wizard/services/IndividualProductService.js @@ -12,26 +12,16 @@ function IndividualProductService(domain, strategy){ const IndividualProduct = require('../model/IndividualProduct'); const endpoint = 'individualproduct'; const keyGenFunction = require('../commands/setIndividualProductSSI').createIndividualProductSSI; - const BRICKS_DOMAIN_KEY = require("opendsu").constants.BRICKS_DOMAIN_KEY - domain = domain || "default"; let isSimple = strategies.SIMPLE === (strategy || strategies.SIMPLE); - const getBricksDomainFromProcess = function(){ - if (!globalThis.process || !globalThis.process["BRICKS_DOMAIN"]) - return undefined; - return globalThis.process["BRICKS_DOMAIN"]; - } - - this.generateKey = function(gtin, batchNumber, serialNumber, bricksDomain){ + this.generateKey = function(gtin, batchNumber, serialNumber){ let keyGenData = { gtin: gtin, batchNumber: batchNumber, serialNumber: serialNumber } - if (bricksDomain) - keyGenData[BRICKS_DOMAIN_KEY] = bricksDomain return keyGenFunction(keyGenData, domain); } @@ -72,7 +62,7 @@ function IndividualProductService(domain, strategy){ return callback(err); if (isSimple){ - let keySSI = this.generateKey(product.gtin, product.batchNumber, product.serialNumber, getBricksDomainFromProcess()); + let keySSI = this.generateKey(product.gtin, product.batchNumber, product.serialNumber); utils.selectMethod(keySSI)(keySSI, (err, dsu) => { if (err) return callback(err); diff --git a/fgt-dsu-wizard/services/OrderService.js b/fgt-dsu-wizard/services/OrderService.js index fcfd0b904..9fac51387 100644 --- a/fgt-dsu-wizard/services/OrderService.js +++ b/fgt-dsu-wizard/services/OrderService.js @@ -1,7 +1,6 @@ const Utils = require('../../pdm-dsu-toolkit/services/utils'); const {STATUS_MOUNT_PATH, INFO_PATH, SHIPMENT_PATH, ORDER_MOUNT_PATH} = require('../constants'); const {OrderStatus, Batch} = require("../model"); -const {createBatchSSI: keyGenFunction} = require("../commands/setBatchSSI"); /** @@ -14,18 +13,12 @@ function OrderService(domain, strategy) { const strategies = require("../../pdm-dsu-toolkit/services/strategy"); const {Order, OrderStatus, utils} = require('../model'); const endpoint = 'order'; - const BRICKS_DOMAIN_KEY = require("opendsu").constants.BRICKS_DOMAIN_KEY domain = domain || "default"; const statusService = new (require('./StatusService'))(domain, strategy); let isSimple = strategies.SIMPLE === (strategy || strategies.SIMPLE); - const getBricksDomainFromProcess = function(){ - if (!globalThis.process || !globalThis.process["BRICKS_DOMAIN"]) - return undefined; - return globalThis.process["BRICKS_DOMAIN"]; - } this.resolveMAH = function(orderLine, callback){ const keyGen = require('../commands/setProductSSI').createProductSSI; @@ -204,19 +197,9 @@ function OrderService(domain, strategy) { }); } - this.generateKey = function(orderId, requesterId, bricksDomain){ - let keyGenFunction = require('../commands/setOrderSSI').createOrderSSI; - let keyGenData = { - data: orderId + requesterId - } - if (bricksDomain) - keyGenData[BRICKS_DOMAIN_KEY] = bricksDomain - return keyGenFunction(keyGenData, domain); - } - let createSimple = function (order, callback) { let keyGenFunction = require('../commands/setOrderSSI').createOrderSSI; - let templateKeySSI = this.generateKey(order.orderId, order.requesterId, getBricksDomainFromProcess()); + let templateKeySSI = keyGenFunction({data: order.orderId + order.requesterId}, domain); Utils.selectMethod(templateKeySSI)(templateKeySSI, (err, dsu) => { if (err) return callback(err); diff --git a/fgt-dsu-wizard/services/ProductService.js b/fgt-dsu-wizard/services/ProductService.js index 841c4ffaf..44ba526f8 100644 --- a/fgt-dsu-wizard/services/ProductService.js +++ b/fgt-dsu-wizard/services/ProductService.js @@ -15,20 +15,11 @@ function ProductService(domain, strategy){ domain = domain || "default"; let isSimple = strategies.SIMPLE === (strategy || strategies.SIMPLE); - const BRICKS_DOMAIN_KEY = require("opendsu").constants.BRICKS_DOMAIN_KEY - const getBricksDomainFromProcess = function(){ - if (!globalThis.process || !globalThis.process["BRICKS_DOMAIN"]) - return undefined; - return globalThis.process["BRICKS_DOMAIN"]; - } - - this.generateKey = function(gtin, bricksDomain){ + this.generateKey = function(gtin){ let keyGenData = { gtin: gtin } - if (bricksDomain) - keyGenData[BRICKS_DOMAIN_KEY] = bricksDomain return keyGenFunction(keyGenData, domain); } diff --git a/fgt-dsu-wizard/services/SaleService.js b/fgt-dsu-wizard/services/SaleService.js index 8c2cb482b..3562be251 100644 --- a/fgt-dsu-wizard/services/SaleService.js +++ b/fgt-dsu-wizard/services/SaleService.js @@ -16,15 +16,6 @@ function SaleService(domain, strategy){ domain = domain || "default"; let isSimple = strategies.SIMPLE === (strategy || strategies.SIMPLE); - const BRICKS_DOMAIN_KEY = require("opendsu").constants.BRICKS_DOMAIN_KEY - let keyGenFunction = require('../commands/setSaleSSI').createSaleSSI; - - const getBricksDomainFromProcess = function(){ - if (!globalThis.process || !globalThis.process["BRICKS_DOMAIN"]) - return undefined; - return globalThis.process["BRICKS_DOMAIN"]; - } - /** * Resolves the DSU and loads the OrderLine object with all its properties, mutable or not * @param {KeySSI} keySSI @@ -49,19 +40,6 @@ function SaleService(domain, strategy){ }); } - this.generateKey = function(sale, bricksDomain){ - let keyGenFunction = require('../commands/setSaleSSI').createSaleSSI; - let keyGenData = { - data: [ - sale.id, - sale.sellerId - ] - } - if (bricksDomain) - keyGenData[BRICKS_DOMAIN_KEY] = bricksDomain - return keyGenFunction(keyGenData, domain); - } - /** * Creates an orderLine DSU * @param {string | Sale} sale @@ -77,8 +55,16 @@ function SaleService(domain, strategy){ let data = typeof sale == 'object' ? JSON.stringify(sale) : sale; + let keyGenData = { + data: [ + sale.id, + sale.sellerId + ] + } + if (isSimple){ - let keySSI = this.generateKey(sale, getBricksDomainFromProcess()) + let keyGenFunction = require('../commands/setSaleSSI').createSaleSSI; + let keySSI = keyGenFunction(keyGenData, domain); utils.selectMethod(keySSI)(keySSI, (err, dsu) => { if (err) return callback(err); diff --git a/fgt-dsu-wizard/services/ShipmentCodeService.js b/fgt-dsu-wizard/services/ShipmentCodeService.js index 6796e2eb7..4b085a011 100644 --- a/fgt-dsu-wizard/services/ShipmentCodeService.js +++ b/fgt-dsu-wizard/services/ShipmentCodeService.js @@ -12,21 +12,12 @@ const {Shipment, ShipmentLine, ShipmentCode, TrackingCode} = require('../model') */ function ShipmentCodeService(domain, strategy){ const strategies = require("../../pdm-dsu-toolkit/services/strategy"); - let keyGenFunction = require('../commands/setShipmentCodeSSI').createShipmentCodeSSI; const endpoint = 'shipmentcode'; domain = domain || "default"; let isSimple = strategies.SIMPLE === (strategy || strategies.SIMPLE); - const BRICKS_DOMAIN_KEY = require("opendsu").constants.BRICKS_DOMAIN_KEY - - const getBricksDomainFromProcess = function(){ - if (!globalThis.process || !globalThis.process["BRICKS_DOMAIN"]) - return undefined; - return globalThis.process["BRICKS_DOMAIN"]; - } - this.getContainerGranularity = () => GRANULARITY.slice(); /** @@ -60,12 +51,6 @@ function ShipmentCodeService(domain, strategy){ }); } - this.generateKey = function(keyGenData, bricksDomain){ - if (bricksDomain) - keyGenData[BRICKS_DOMAIN_KEY] = bricksDomain - return keyGenFunction(keyGenData, domain); - } - /** * Creates an orderLine DSU * @param {ShipmentCode} shipmentCode @@ -78,7 +63,8 @@ function ShipmentCodeService(domain, strategy){ let data = typeof shipmentCode == 'object' ? JSON.stringify(shipmentCode) : shipmentCode; if (isSimple){ - let keySSI = this.generateKey('shipmentcode', getBricksDomainFromProcess()); + let keyGenFunction = require('../commands/setShipmentCodeSSI').createShipmentCodeSSI; + let keySSI = keyGenFunction('shipmentcode', domain); utils.selectMethod(keySSI)(keySSI, (err, dsu) => { if (err) return callback(err); diff --git a/fgt-dsu-wizard/services/ShipmentLineService.js b/fgt-dsu-wizard/services/ShipmentLineService.js index f42b8ea26..9481a9eee 100644 --- a/fgt-dsu-wizard/services/ShipmentLineService.js +++ b/fgt-dsu-wizard/services/ShipmentLineService.js @@ -12,30 +12,12 @@ function ShipmentLineService(domain, strategy){ const strategies = require("../../pdm-dsu-toolkit/services/strategy"); const {ShipmentLine} = require('../model'); const endpoint = 'shipmentline'; - const BRICKS_DOMAIN_KEY = require("opendsu").constants.BRICKS_DOMAIN_KEY - let keyGenFunction = require('../commands/setShipmentLineSSI').createShipmentLineSSI; - domain = domain || "default"; let isSimple = strategies.SIMPLE === (strategy || strategies.SIMPLE); const statusService = new (require('./StatusService'))(domain, strategy); - const getBricksDomainFromProcess = function(){ - if (!globalThis.process || !globalThis.process["BRICKS_DOMAIN"]) - return undefined; - return globalThis.process["BRICKS_DOMAIN"]; - } - - this.generateKey = function(shipmentId, shipmentLine, bricksDomain){ - let keyGenData = { - data: shipmentId + shipmentLine.senderId + shipmentLine.gtin + shipmentLine.batch - } - if (bricksDomain) - keyGenData[BRICKS_DOMAIN_KEY] = bricksDomain - return keyGenFunction(keyGenData, domain); - } - /** * Resolves the DSU and loads the OrderLine object with all its properties, mutable or not * @param {KeySSI} keySSI @@ -82,8 +64,13 @@ function ShipmentLineService(domain, strategy){ let data = typeof shipmentLine == 'object' ? JSON.stringify(shipmentLine) : shipmentLine; + let keyGenData = { + data: shipmentId + shipmentLine.senderId + shipmentLine.gtin + shipmentLine.batch + } + if (isSimple){ - let keySSI = this.generateKey(shipmentId, shipmentLine, getBricksDomainFromProcess()) + let keyGenFunction = require('../commands/setShipmentLineSSI').createShipmentLineSSI; + let keySSI = keyGenFunction(keyGenData, domain); utils.selectMethod(keySSI)(keySSI, (err, dsu) => { if (err) return callback(err); diff --git a/fgt-dsu-wizard/services/ShipmentService.js b/fgt-dsu-wizard/services/ShipmentService.js index eef0dcb3b..30968d02e 100644 --- a/fgt-dsu-wizard/services/ShipmentService.js +++ b/fgt-dsu-wizard/services/ShipmentService.js @@ -1,6 +1,6 @@ const utils = require('../../pdm-dsu-toolkit/services/utils'); const {STATUS_MOUNT_PATH, INFO_PATH, LINES_PATH, ORDER_MOUNT_PATH} = require('../constants'); -const {Shipment, ShipmentStatus} = require('../model'); +const {Shipment, ShipmentStatus, Status, Order} = require('../model'); /** * @param {string} domain: anchoring domain. defaults to 'default' * @param {strategy} strategy @@ -14,17 +14,10 @@ function ShipmentService(domain, strategy) { domain = domain || "default"; const shipmentLineService = new (require('./ShipmentLineService'))(domain, strategy); const statusService = new (require('./StatusService'))(domain, strategy); - const BRICKS_DOMAIN_KEY = require("opendsu").constants.BRICKS_DOMAIN_KEY - let keyGenFunction = require('../commands/setShipmentSSI').createShipmentSSI; + const shipmentCodeService = new (require('./ShipmentCodeService'))(domain, strategy); let isSimple = strategies.SIMPLE === (strategy || strategies.SIMPLE); - const getBricksDomainFromProcess = function(){ - if (!globalThis.process || !globalThis.process["BRICKS_DOMAIN"]) - return undefined; - return globalThis.process["BRICKS_DOMAIN"]; - } - let getDSUMountByPath = function(dsu, path, basePath, callback){ if (!callback && typeof basePath === 'function'){ callback = basePath; @@ -60,16 +53,6 @@ function ShipmentService(domain, strategy) { }); } - - this.generateKey = function(shipment, bricksDomain){ - let keyGenData = { - gtin: shipment.senderId + shipment.shipmentId - } - if (bricksDomain) - keyGenData[BRICKS_DOMAIN_KEY] = bricksDomain - return keyGenFunction(keyGenData, domain); - } - /** * Resolves the DSU and loads the Order object with all its properties, mutable or not * @param {KeySSI} keySSI @@ -175,8 +158,9 @@ function ShipmentService(domain, strategy) { }); } - this.createSimple = function (shipment, orderSSI, callback) { - let templateKeySSI = this.generateKey(shipment, getBricksDomainFromProcess()); + let createSimple = function (shipment, orderSSI, callback) { + let keyGenFunction = require('../commands/setShipmentSSI').createShipmentSSI; + let templateKeySSI = keyGenFunction({data: shipment.senderId + shipment.shipmentId}, domain); utils.selectMethod(templateKeySSI)(templateKeySSI, (err, dsu) => { if (err) return callback(err); diff --git a/fgt-dsu-wizard/services/StatusService.js b/fgt-dsu-wizard/services/StatusService.js index 99b9b5846..0df489b43 100644 --- a/fgt-dsu-wizard/services/StatusService.js +++ b/fgt-dsu-wizard/services/StatusService.js @@ -1,7 +1,6 @@ const utils = require('../../pdm-dsu-toolkit/services/utils'); const {INFO_PATH, LOG_PATH, EXTRA_INFO_PATH} = require('../constants'); const Status = require('../model/Status'); -const {createBatchSSI: keyGenFunction} = require("../commands/setBatchSSI"); /** * @param {string} domain: anchoring domain. defaults to 'default' @@ -13,7 +12,6 @@ function StatusService(domain, strategy){ const strategies = require("../../pdm-dsu-toolkit/services/strategy"); const OrderStatus = require('../model').OrderStatus; const endpoint = 'status'; - let keyGenFunction = require('../commands/setStatusSSI').createStatusSSI; domain = domain || "default"; let isSimple = strategies.SIMPLE === (strategy || strategies.SIMPLE); @@ -24,20 +22,6 @@ function StatusService(domain, strategy){ return utils.getResolver().createDSU; } - const BRICKS_DOMAIN_KEY = require("opendsu").constants.BRICKS_DOMAIN_KEY - - const getBricksDomainFromProcess = function(){ - if (!globalThis.process || !globalThis.process["BRICKS_DOMAIN"]) - return undefined; - return globalThis.process["BRICKS_DOMAIN"]; - } - - this.generateKey = function(status, bricksDomain){ - if (bricksDomain) - status[BRICKS_DOMAIN_KEY] = bricksDomain - return keyGenFunction(status, domain); - } - let createLog = function(id, prevStatus, status, timestamp){ const ts = timestamp ? timestamp : Date.now(); return prevStatus @@ -139,7 +123,8 @@ function StatusService(domain, strategy){ } if (isSimple){ - let keySSI = this.generateKey(status) + let keyGenFunction = require('../commands/setStatusSSI').createStatusSSI; + let keySSI = keyGenFunction(status, domain); selectMethod(keySSI)(keySSI, (err, dsu) => { if (err) return callback(err); diff --git a/octopus-freeze.json b/octopus-freeze.json index 5a31a9c06..ffc55eb48 100644 --- a/octopus-freeze.json +++ b/octopus-freeze.json @@ -1083,3 +1083,5 @@ + +