@igea/oac_backend 1.0.16 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@igea/oac_backend",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Backend service for the OAC project",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -27,8 +27,7 @@
27
27
  "knex": "3.1.0",
28
28
  "libxmljs2": "0.37.0",
29
29
  "pg": "8.16.3",
30
- "strip-bom": "5.0.0",
31
- "xslt-processor": "3.3.1"
30
+ "strip-bom": "5.0.0"
32
31
  },
33
32
  "devDependencies": {
34
33
  "chai": "5.2.1",
@@ -16,7 +16,10 @@
16
16
  "protocol": "http",
17
17
  "host": "127.0.0.1",
18
18
  "port": "3333",
19
- "dataset": "oac"
19
+ "dataset": "oac",
20
+ "vocabularies": {
21
+ "prefix": "diagnostica"
22
+ }
20
23
  },
21
24
  "jwt_secret": "@igea#"
22
25
  }
@@ -16,7 +16,10 @@
16
16
  "protocol": "http",
17
17
  "host": "127.0.0.1",
18
18
  "port": "3333",
19
- "dataset": "oac"
19
+ "dataset": "oac",
20
+ "vocabularies": {
21
+ "prefix": "diagnostica"
22
+ }
20
23
  },
21
24
  "jwt_secret": "@igea#"
22
25
  }
package/src/index.js CHANGED
@@ -10,12 +10,7 @@ const jwtLib = jwtLibFactory({
10
10
  excludePaths: [
11
11
  `/${serviceName}/auth/authenticate`,
12
12
  `/${serviceName}/auth/echo`,
13
- `/${serviceName}/health`,
14
-
15
- `/${serviceName}/fuseki/count/entities`,
16
- `/${serviceName}/fuseki/export/rdf/campione/1`,
17
- `/${serviceName}/fuseki/export/turtle/campione/1`
18
-
13
+ `/${serviceName}/health`
19
14
  ],
20
15
  signOptions: { expiresIn: '15m' }
21
16
  });
@@ -5,11 +5,8 @@ const {XmlParser, Xslt} = XsltProcessor;
5
5
  const libxmljs = require('libxmljs2');
6
6
  const { exec } = require('child_process');
7
7
  const stripBom = require('strip-bom').default;
8
- const xslt = new Xslt({
9
- escape: false,
10
- outputMethod: 'text'
11
- });
12
- const xmlParser = new XmlParser();
8
+ const config = require('../../config');
9
+ const VocabPrefix = config.fuseki.vocabularies.prefix || 'diagnostica';
13
10
 
14
11
 
15
12
  class Parser{
@@ -45,7 +42,9 @@ class Parser{
45
42
  transform(xmlPath){
46
43
  return new Promise((resolve, reject) => {
47
44
  try{
48
- exec('xsltproc ' + this.xsltPath + ' ' + xmlPath, (err, stdout, stderr) => {
45
+ let command = 'xsltproc --stringparam prefix ' + VocabPrefix + ' ';
46
+ command += this.xsltPath + ' ' + xmlPath
47
+ exec(command, (err, stdout, stderr) => {
49
48
  if (err) {
50
49
  reject(err)
51
50
  }else{
@@ -7,11 +7,14 @@
7
7
  <xs:complexType>
8
8
  <xs:sequence>
9
9
  <!-- Required prefix element with a mandatory "value" attribute -->
10
+
11
+ <!--
10
12
  <xs:element name="prefix">
11
13
  <xs:complexType>
12
14
  <xs:attribute name="value" type="xs:string" use="required"/>
13
15
  </xs:complexType>
14
16
  </xs:element>
17
+ -->
15
18
 
16
19
  <!-- Multiple vocabulary entries -->
17
20
  <xs:element name="vocabulary" maxOccurs="unbounded">
@@ -4,11 +4,16 @@
4
4
 
5
5
  <xsl:output method="text" encoding="UTF-8"/>
6
6
 
7
+ <xsl:param name="prefix"/>
8
+
7
9
  <!-- Prendi il prefix e passa ai vocabolari -->
8
10
  <xsl:template match="/vocabularies">
11
+ <!--
9
12
  <xsl:variable name="prefix" select="prefix/@value"/>
13
+ -->
14
+
10
15
  <xsl:apply-templates select="vocabulary">
11
- <xsl:with-param name="prefix" select="$prefix"/>
16
+ <xsl:with-param name="prefix" select="concat($prefix,'/vocabularies')"/>
12
17
  </xsl:apply-templates>
13
18
  </xsl:template>
14
19
 
@@ -31,16 +36,34 @@
31
36
  <!-- Se NON ha sub-terms/term -->
32
37
  <xsl:when test="not(sub-terms/term)">
33
38
  <xsl:for-each select="name">
34
- <xsl:value-of select="$new-path"/>
35
- <xsl:text> rdfs:label "</xsl:text>
39
+ <xsl:value-of select="concat('&lt;',$new-path,'&gt;')"/>
40
+ <xsl:text> a crm:E55_Type rdfs:label "</xsl:text>
36
41
  <xsl:value-of select="."/>
37
42
  <xsl:text>"@</xsl:text>
38
43
  <xsl:value-of select="@lang"/>
39
- <xsl:text>&#10;</xsl:text>
44
+ <xsl:text> ; crm:P127_has_broader_term </xsl:text>
45
+ <xsl:value-of select="concat('&lt;',$path,'&gt;')"/>
46
+ <xsl:text> . &#10;</xsl:text>
40
47
  </xsl:for-each>
41
48
  </xsl:when>
42
49
  <xsl:otherwise>
50
+
51
+ <xsl:variable name="cid" select="@id"/>
52
+ <xsl:variable name="npath" select="concat($path, '/', $current-id)"/>
53
+
54
+ <xsl:for-each select="name">
55
+ <xsl:value-of select="concat('&lt;',$npath,'&gt;')"/>
56
+ <xsl:text> a crm:E55_Type rdfs:label "</xsl:text>
57
+ <xsl:value-of select="."/>
58
+ <xsl:text>"@</xsl:text>
59
+ <xsl:value-of select="@lang"/>
60
+ <xsl:text> ; crm:P127_has_broader_term </xsl:text>
61
+ <xsl:value-of select="concat('&lt;',$path,'&gt;')"/>
62
+ <xsl:text> . &#10;</xsl:text>
63
+ </xsl:for-each>
64
+
43
65
  <xsl:apply-templates select="sub-terms/term">
66
+ <xsl:with-param name="prev-path" select="$path"/>
44
67
  <xsl:with-param name="path" select="$new-path"/>
45
68
  </xsl:apply-templates>
46
69
  </xsl:otherwise>
@@ -26,9 +26,10 @@ describe('Vocabolaries.Parsers', () => {
26
26
  it('should transform the vocabolaries.xml file', async () => {
27
27
  const parser = Parser.GET_INSTANCE();
28
28
  var terms = await parser.transform(__dirname + '/vocabolaries.xml');
29
- expect(terms.length).to.be.equal(193);
30
- expect(terms[0]).to.be.equal('http://diagnostica/condizioni-ambientali/ambiente/buio rdfs:label "Buio"@it');
31
- expect(terms[1]).to.be.equal('http://diagnostica/condizioni-ambientali/ambiente/illuminato rdfs:label "Illuminato"@it');
29
+ console.log(terms.filter(n => n.indexOf('P127_has_broader_term') == -1))
30
+ expect(terms.length).to.be.equal(246);
31
+ expect(terms[0]).to.be.equal('<http://diagnostica/vocabularies/condizioni-ambientali> a crm:E55_Type rdfs:label "Condizioni ambientali"@it ; crm:P127_has_broader_term <http://diagnostica/vocabularies> .');
32
+ expect(terms[1]).to.be.equal('<http://diagnostica/vocabularies/condizioni-ambientali/ambiente> a crm:E55_Type rdfs:label "Ambiente"@it ; crm:P127_has_broader_term <http://diagnostica/vocabularies/condizioni-ambientali> .');
32
33
  });
33
34
 
34
35
  });
@@ -2,7 +2,9 @@
2
2
  <vocabularies>
3
3
 
4
4
  <!-- Prefissio per i vocabolari -->
5
+ <!--
5
6
  <prefix value="diagnostica"/>
7
+ -->
6
8
 
7
9
  <!-- Vocabolario per CONDIZIONI AMBIENTALI (1) -->
8
10
  <vocabulary>
@@ -1,50 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
- version="1.0">
4
-
5
- <xsl:output method="text" encoding="UTF-8"/>
6
-
7
- <!-- Prendi il prefix e passa ai vocabolari -->
8
- <xsl:template match="/vocabularies">
9
- <xsl:variable name="prefix" select="prefix/@value"/>
10
- <xsl:apply-templates select="vocabulary">
11
- <xsl:with-param name="prefix" select="$prefix"/>
12
- </xsl:apply-templates>
13
- </xsl:template>
14
-
15
- <!-- Vocabolario -->
16
- <xsl:template match="vocabulary">
17
- <xsl:param name="prefix"/>
18
- <xsl:variable name="vocab-id" select="@id"/>
19
- <xsl:apply-templates select="term">
20
- <xsl:with-param name="path" select="concat('http://', $prefix, $vocab-id)"/>
21
- </xsl:apply-templates>
22
- </xsl:template>
23
-
24
- <!-- Term ricorsivo -->
25
- <xsl:template match="term">
26
- <xsl:param name="path"/>
27
- <xsl:variable name="current-id" select="@id"/>
28
- <xsl:variable name="new-path" select="concat($path, '/', $current-id)"/>
29
-
30
- <xsl:choose>
31
- <!-- Se NON ha sub-terms/term -->
32
- <xsl:when test="not(sub-terms/term)">
33
- <xsl:for-each select="name">
34
- <xsl:value-of select="$new-path"/>
35
- <xsl:text> rdfs:label "</xsl:text>
36
- <xsl:value-of select="."/>
37
- <xsl:text>"@</xsl:text>
38
- <xsl:value-of select="@lang"/>
39
- <xsl:text>&#10;</xsl:text>
40
- </xsl:for-each>
41
- </xsl:when>
42
- <xsl:otherwise>
43
- <xsl:apply-templates select="sub-terms/term">
44
- <xsl:with-param name="path" select="$new-path"/>
45
- </xsl:apply-templates>
46
- </xsl:otherwise>
47
- </xsl:choose>
48
- </xsl:template>
49
-
50
- </xsl:stylesheet>