Skip to content

Commit

Permalink
refs #123 - update
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoV-PDMFC committed Oct 14, 2022
1 parent 4540f65 commit 7110919
Show file tree
Hide file tree
Showing 22 changed files with 141 additions and 189 deletions.
20 changes: 20 additions & 0 deletions fgt-dsu-wizard/commands/environment.js
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 8 additions & 4 deletions fgt-dsu-wizard/commands/setBatchSSI.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const {getDomain, getBricksDomain, BRICKS_DOMAIN_KEY} = require("./environment");


/**
* Defines how to create the keyssi for a batch dsu
Expand All @@ -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);
}
Expand All @@ -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 = {
Expand Down
13 changes: 9 additions & 4 deletions fgt-dsu-wizard/commands/setIndividualProductSSI.js
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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);
}
Expand All @@ -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 = {
Expand Down
13 changes: 8 additions & 5 deletions fgt-dsu-wizard/commands/setOrderLineSSI.js
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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);
}
Expand All @@ -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 = {
Expand Down
12 changes: 8 additions & 4 deletions fgt-dsu-wizard/commands/setOrderSSI.js
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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);
}
Expand All @@ -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 = {
Expand Down
12 changes: 11 additions & 1 deletion fgt-dsu-wizard/commands/setParticipantSSI.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
}

Expand All @@ -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 = {
Expand Down
12 changes: 8 additions & 4 deletions fgt-dsu-wizard/commands/setProductSSI.js
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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);
}
Expand All @@ -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 = {
Expand Down
11 changes: 7 additions & 4 deletions fgt-dsu-wizard/commands/setSaleSSI.js
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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);
}
Expand All @@ -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 = {
Expand Down
12 changes: 8 additions & 4 deletions fgt-dsu-wizard/commands/setShipmentCodeSSI.js
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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);
}
Expand All @@ -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 = {
Expand Down
11 changes: 7 additions & 4 deletions fgt-dsu-wizard/commands/setShipmentLineSSI.js
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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);
}
Expand All @@ -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 = {
Expand Down
12 changes: 8 additions & 4 deletions fgt-dsu-wizard/commands/setShipmentSSI.js
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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);
}
Expand All @@ -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 = {
Expand Down
11 changes: 7 additions & 4 deletions fgt-dsu-wizard/commands/setStatusSSI.js
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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);
}
Expand All @@ -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 = {
Expand Down
Loading

0 comments on commit 7110919

Please sign in to comment.