Skip to content

Commit

Permalink
jsonldtransfor & ics provider
Browse files Browse the repository at this point in the history
  • Loading branch information
simon louvet committed May 13, 2024
1 parent 983d5cd commit cd2588b
Show file tree
Hide file tree
Showing 19 changed files with 6,428 additions and 34 deletions.
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
},
"incrementTable": {
"price": 20
},
"jsonLdConversion": {
"price": 20
}
},
"googleAuth": {
Expand Down
17 changes: 10 additions & 7 deletions core/dataTraitmentLibrary/file_convertor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// rdf_traitment.js pour les fichiers owl, rdf et ttl
// --------------------------------------------------------------------------------

var exel = require('./exel/exel_traitment.js');
var rdf = require('./rdf/rdf_traitment.js');
var xml = require('./xml/xml_traitment.js');
var csv = require('./csv/csv_traitment.js');
var ics = require('./ics/index.js');
const exel = require('./exel/exel_traitment.js');
const rdf = require('./rdf/rdf_traitment.js');
const xml = require('./xml/xml_traitment.js');
const csv = require('./csv/csv_traitment.js');
const ics = require('./ics/index.js');
var zlib = require('zlib');
const JSZip = require('jszip');

Expand Down Expand Up @@ -43,9 +43,12 @@ function _buildFile(filename, dataString, dataBuffer, out, contentType) {
resolve(exel.json_to_exel(JSON.parse(dataString)));
break;
case ("rdf+xml"):
//console.log('ALLO');
resolve(rdf.json_to_rdf(JSON.parse(dataString)));
break;
case ("ics"):
//console.log('ALLO');
resolve(ics.json_to_ics(JSON.parse(dataString)));
break;
default:
//console.log("in default")
reject("erreur, votre fichier n'est pas au bon format");
Expand Down Expand Up @@ -88,7 +91,7 @@ function _data_from_file(filename, dataBuffer, contentType) {
const zip = new JSZip();
try {
const contents = await zip.loadAsync(dataBuffer);
console.log('UNZIP!!',contents)
// console.log('UNZIP!!',contents)
let files=[];
for (const fileName of Object.keys(zip.files)) {
const fileObject=zip.files[fileName]
Expand Down
25 changes: 21 additions & 4 deletions core/dataTraitmentLibrary/ics/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';
var ics = require('ics-to-json').default;
const ics = require('ics-to-json').default;
const {default : icalParser} = require('ical-js-parser');

module.exports = {
icstojson: _icstojson,
json_to_ics: _jsontoics,
};


Expand All @@ -18,15 +20,30 @@ function decode_utf8(s) {
}

function _icstojson(icsData) {
// console.log(icsData);
// console.log('ics',ics);
return new Promise((resolve, reject) => {
try {
const data = ics(icsData);
const data = icalParser.toJSON(icsData);
resolve(data);
}catch(e){
console.log(e);
reject(e);
}
});
}

function _jsontoics(jsonData, header) {
return new Promise((resolve, reject) => {
try {
const resultJSON = icalParser.toString(jsonData);
resolve(resultJSON);
}catch(e){
console.log(e);
resolve({
error:{
message: "Unable to parse the data, see https://www.npmjs.com/package/ical-js-parser and https://en.wikipedia.org/wiki/ICalendar",
libMessage : e.message
}
});
}
});
}
5 changes: 5 additions & 0 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"ical-js-parser": "^0.7.4"
}
}
28 changes: 28 additions & 0 deletions core/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


datez@0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/datez/-/datez-0.0.7.tgz#8cb1df78e6eef4b57b3cd9611257a957529b911e"
integrity sha512-r6Nr29nROX54OzZ8oosRSXzqRR2xpPIu8tdRsWnBitj7QYKpwUZz33h6q0zf64KDfopBozrmNbx/TsMLGCM4cg==
dependencies:
timezone-soft "1.4.1"

ical-js-parser@^0.7.4:
version "0.7.4"
resolved "https://registry.yarnpkg.com/ical-js-parser/-/ical-js-parser-0.7.4.tgz#343ad3331b72d10dc45d7062b0e937d0113962c4"
integrity sha512-8eI+xp+kIbMdozFoGjtDQPQkjYQNYY8D4LzGkCLJiSgwpxFio2gUKjtCuKpzvglIzpXy7GBSEQ/ekwRRInpmlA==
dependencies:
datez "0.0.7"
luxon "3.1.1"

luxon@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/luxon/-/luxon-3.1.1.tgz#b492c645b2474fb86f3bd3283213846b99c32c1e"
integrity sha512-Ah6DloGmvseB/pX1cAmjbFvyU/pKuwQMQqz7d0yvuDlVYLTs2WeDHQMpC8tGjm1da+BriHROW/OEIT/KfYg6xw==

timezone-soft@1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/timezone-soft/-/timezone-soft-1.4.1.tgz#854eb224545645d9ddad8bcd09144522b0652156"
integrity sha512-AnKhVnQmOjKHhdQXXe7cO7MyRGIHEGzedax4Y2N7nOr9dOYEFEBkWFJJwJTvPQvXsEtbWfa6xJj34iZKdC+W+g==
2 changes: 2 additions & 0 deletions engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@
"fs": "0.0.1-security",
"himalaya": "^1.1.0",
"http": "0.0.0",
"ical-js-parser": "^0.7.4",
"ics-to-json": "^1.0.0",
"intl": "1.2.4",
"isobject": "^4.0.0",
"json2yaml": "^1.1.0",
"jsonld": "^8.3.2",
"jsonld-streaming-parser": "^2.0.2",
"jsonpath-object-transform": "^1.0.4",
"jszip": "^3.10.1",
Expand Down
1 change: 1 addition & 0 deletions engine/services/technicalComponentDirectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ module.exports = {
regex: require('../workspaceComponentExecutor/regex.js'),
slice: require('../workspaceComponentExecutor/slice.js'),
incrementTable: require('../workspaceComponentExecutor/incrementTable.js'),
jsonLdConversion: require('../workspaceComponentExecutor/jsonld-conversion.js'),
// ---ENDOFPART---
}
14 changes: 10 additions & 4 deletions engine/workspaceComponentExecutor/httpConsumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs');
const https = require('https');
const fileLib = require('../../core/lib/file_lib.js')
const fileConvertor = require('../../core/dataTraitmentLibrary/file_convertor.js')
const dotProp = require('dot-prop')

class HttpConsumer {
constructor () {
Expand All @@ -15,7 +16,7 @@ class HttpConsumer {
this.xml2js = require('xml2js');
this.propertyNormalizer = require('../utils/propertyNormalizer.js');
this.config = require('../configuration.js');
this.himalaya = require('himalaya')
this.himalaya = require('himalaya');
}

convertResponseToData (response,componentConfig) {
Expand Down Expand Up @@ -93,21 +94,26 @@ class HttpConsumer {


let body;
let bodyObject = flowData[0].data;
if (componentConfig.bodyPath && componentConfig.bodyPath.length>0){
bodyObject = dotProp.get(bodyObject, componentConfig.bodyPath)
}


if(componentConfig.noBody!=true && flowData){
// console.log("here ",flowData[0].data);
switch (componentConfig.contentType) {
case 'text/plain':
body = flowData[0].data
body = bodyObject.toString();
// "airSensors,sensor_id=TLM0201";
break;
//console.log("new here ! ",flowData[0].data);
case 'application/json':
case 'application/ld+json':
body = JSON.stringify(flowData[0].data);
body = JSON.stringify(bodyObject);
break;
case 'application/x-www-form-urlencoded':
body = this.formUrlencoded(flowData[0].data)
body = this.formUrlencoded(bodyObject)
break;
default:
reject(new Error(`${componentConfig.contentType} contentType not Supported by this component`));
Expand Down
25 changes: 25 additions & 0 deletions engine/workspaceComponentExecutor/jsonld-conversion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

const jsonld = require('jsonld')

class JsonLdConversion {
constructor () {}
pull (data, flowData, pullParams) {
const specificData = data.specificData;
return new Promise(async (resolve, reject) => {
try {
let result=flowData[0].data;
console.log('specificData',specificData)
if (specificData.configObject){
result = await jsonld.frame(result, specificData.configObject);
}
resolve({
data: result
})
} catch (e) {
reject (e)
}
})
}
}
module.exports = new JsonLdConversion()
Loading

0 comments on commit cd2588b

Please sign in to comment.