Skip to content

Commit a4efa74

Browse files
committedDec 4, 2016
Automatically detect whether proxy is needed.
- Remove checkbox for proxy on start view. - Put proxy url into separate config files for development and production.
1 parent a8192f5 commit a4efa74

10 files changed

+78
-111
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ coverage/
33
dist/
44
.idea/
55
.vscode/
6+
production.conf.json
7+
development.conf.json

‎app/components/start/start.ctrl.js

+2-22
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
* @param {$location} $location
66
* @param {Data} Data
77
* @param {View} View
8-
* @param {Requests} Requests
98
* @param {RequestConfig} RequestConfig
109
* @param {Endpoints} Endpoints
1110
*
1211
* @ngInject
1312
*/
14-
function startCtrl($log, $location, Data, View, Requests, RequestConfig, Endpoints) {
13+
function startCtrl($log, $location, Data, View, RequestConfig, Endpoints) {
1514

1615
const start = this;
1716

18-
start.proxyAvailable = __PROXY__; // eslint-disable-line no-undef
19-
2017
start.endpoints = [];
2118

2219
start.endpoint = RequestConfig.getEndpointURL() || '';
@@ -25,15 +22,6 @@ function startCtrl($log, $location, Data, View, Requests, RequestConfig, Endpoin
2522

2623
start.endpointAlert = true;
2724

28-
/**
29-
* This function is triggered every time the proxy flag is toggled.
30-
*/
31-
start.updateUseProxy = function () {
32-
Requests.clear();
33-
$log.warn('[Start] Cleared old requests.');
34-
start.loadProxyEndpoints();
35-
};
36-
3725
/**
3826
* Shows the graph for the current endpoint and clears all data if endpoint has changed.
3927
*/
@@ -51,7 +39,7 @@ function startCtrl($log, $location, Data, View, Requests, RequestConfig, Endpoin
5139
Data.initMaps();
5240
}
5341

54-
RequestConfig.setUseProxy(start.useProxy);
42+
RequestConfig.setUseProxy(false);
5543

5644
if (start.endpoint !== undefined && start.endpoint.length > 0) {
5745
$log.debug('[Start] Show Graph!');
@@ -104,14 +92,6 @@ function startCtrl($log, $location, Data, View, Requests, RequestConfig, Endpoin
10492
*/
10593
start.loadEndpoints = function () {
10694
Endpoints.getNonProxyEndpoints().then(handleEndpointListResponse, handleEndpointListError);
107-
108-
if (start.useProxy) {
109-
start.loadProxyEndpoints();
110-
}
111-
};
112-
113-
start.loadProxyEndpoints = function () {
114-
$log.debug('[Start] Also load endpoints only accessible via proxy.');
11595
Endpoints.getProxyEndpoints().then(handleEndpointListResponse, handleEndpointListError);
11696
};
11797

‎app/components/start/start.html

-11
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@ <h1>LD-VOWL</h1>
3838
</uib-alert>
3939
</div>
4040
</div>
41-
42-
<div class="form-group" ng-if="start.proxyAvailable">
43-
<div class="col-sm-offset-2 col-sm-10">
44-
<div class="checkbox">
45-
<label>
46-
<input type="checkbox" ng-model="start.useProxy" ng-change="start.updateUseProxy()">
47-
Use local proxy
48-
</label>
49-
</div>
50-
</div>
51-
</div><!-- end of .form-group -->
5241
</form><!-- end of .form-horizontal -->
5342
</div><!-- end of .well -->
5443
</div><!-- end of .container -->

‎app/nonproxy_endpoints.json

+16-32
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,42 @@
66
{
77
"name": "BCN Datos",
88
"url": "http://datos.bcn.cl/sparql",
9-
"description": "",
10-
"proxyNeeded": false
9+
"description": ""
1110
},
1211
{
1312
"name": "Database Center for Life Science (DBCLS)",
1413
"url": "http://data.allie.dbcls.jp/sparql",
15-
"description": "",
16-
"proxyNeeded": false
14+
"description": ""
1715
},
1816
{
1917
"name": "dbpedia",
2018
"url": "http://dbpedia.org/sparql",
21-
"description": "",
22-
"proxyNeeded": false
19+
"description": ""
2320
},
2421
{
2522
"name": "Dutch Ships and Sailors (DSS)",
2623
"url": "http://dutchshipsandsailors.nl/data/sparql/",
27-
"description": "maritime historical data set",
28-
"proxyNeeded": false
24+
"description": "maritime historical data set"
2925
},
3026
{
3127
"name": "Dutch Ships and Sailors (DSS) Semantic Layer",
3228
"url": "http://semanticweb.cs.vu.nl/dss/sparql/",
33-
"description": "",
34-
"proxyNeeded": false
29+
"description": ""
3530
},
3631
{
3732
"name": "EBI BioModels Database",
3833
"url": "https://www.ebi.ac.uk/rdf/services/biomodels/sparql",
39-
"description": "",
40-
"proxyNeeded": false
34+
"description": ""
4135
},
4236
{
4337
"name": "EBI Biosamples Database",
4438
"url": "https://www.ebi.ac.uk/rdf/services/biosamples/sparql",
45-
"description": "",
46-
"proxyNeeded": false
39+
"description": ""
4740
},
4841
{
4942
"name": "EBI ChEMBL",
5043
"url": "https://www.ebi.ac.uk/rdf/services/chembl/sparql",
51-
"description": "",
52-
"proxyNeeded": false
44+
"description": ""
5345
},
5446
{
5547
"name": "Enipedia",
@@ -58,14 +50,12 @@
5850
{
5951
"name": "Environment Agency Bathing Water Quality",
6052
"url": "http://environment.data.gov.uk/sparql/bwq/query",
61-
"description": "",
62-
"proxyNeeded": false
53+
"description": ""
6354
},
6455
{
6556
"name": "EUscreen Linked Open Data Pilot",
6657
"url": "http://lod.euscreen.eu/sparql",
67-
"description": "about television",
68-
"proxyNeeded": false
58+
"description": "about television"
6959
},
7060
{
7161
"name": "FOODpedia",
@@ -107,8 +97,7 @@
10797
{
10898
"name": "MORElab",
10999
"url": "http://apps.morelab.deusto.es/labman/sparql",
110-
"description": "",
111-
"proxyNeeded": true
100+
"description": ""
112101
},
113102
{
114103
"name": "Nobelprize.org",
@@ -125,34 +114,29 @@
125114
{
126115
"name": "Springer LOD Conference Portal",
127116
"url": "http://lod.springer.com/sparql",
128-
"description": "about scientific publications at springer",
129-
"proxyNeeded": false
117+
"description": "about scientific publications at springer"
130118
},
131119
{
132120
"name": "Swiss Federal Statistics Office Linked Data",
133121
"url": "http://bfs.270a.info/sparql",
134-
"description": "swiss statistics",
135-
"proxyNeeded": false
122+
"description": "swiss statistics"
136123
},
137124
{
138125
"name": "Transparency International Linked Data",
139126
"url": "http://transparency.270a.info/sparql",
140-
"description": "data set about corruption",
141-
"proxyNeeded": false
127+
"description": "data set about corruption"
142128
},
143129
{
144130
"name": "WKD - Arbeitsrechtsthesaurus",
145131
"url": "http://vocabulary.wolterskluwer.de/PoolParty/sparql/arbeitsrecht"
146132
},
147133
{
148134
"name": "WKD - Gerichtsthesaurus",
149-
"url": "http://vocabulary.wolterskluwer.de/PoolParty/sparql/court",
150-
"proxyNeeded": false
135+
"url": "http://vocabulary.wolterskluwer.de/PoolParty/sparql/court"
151136
},
152137
{
153138
"name": "ww1lod",
154139
"url": "http://ldf.fi/ww1lod/sparql",
155-
"description": "about WW1",
156-
"proxyNeeded": false
140+
"description": "about WW1"
157141
}
158142
]

‎app/services/extractors/class-extractor.srv.js

+22-18
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class ClassExtractor extends Extractor {
4444
this.setBlacklist(classInput.split(','));
4545
} else {
4646
// set up new blacklists
47-
for (var type in CLASS_BLACKLIST) {
47+
for (let type in CLASS_BLACKLIST) {
4848
if (CLASS_BLACKLIST.hasOwnProperty(type) && type !== 'SKOS') {
49-
for (var i = 0; i < CLASS_BLACKLIST[type].length; i++) {
49+
for (let i = 0; i < CLASS_BLACKLIST[type].length; i++) {
5050
this.blacklist.push(PREFIX[type] + CLASS_BLACKLIST[type][i]);
5151
}
5252
}
@@ -69,11 +69,10 @@ class ClassExtractor extends Extractor {
6969

7070
let limit = this.reqConfig.getLimit() || 10;
7171

72-
const requestURL = this.reqConfig.getRequestURL();
73-
7472
const self = this;
7573

7674
function doQuery(lastTry = false, offset = 0, limit = 10) {
75+
let requestURL = self.reqConfig.getRequestURL();
7776
let query = self.queryFactory.getClassQuery(limit, offset);
7877

7978
self.$log.debug(`[Classes] Send Request with offset ${offset}...`);
@@ -89,31 +88,30 @@ class ClassExtractor extends Extractor {
8988

9089
let fetchMore = 0;
9190

92-
for (let i = 0; i < bindings.length; i++) {
93-
94-
var currentClassURI = bindings[i].class.value;
91+
bindings.forEach((binding) => {
92+
let currentClassURI = binding.class.value;
9593

9694
if (currentClassURI.match(/^http.*/) && !self.inBlacklist(currentClassURI) &&
97-
bindings[i].instanceCount !== undefined) {
98-
var node = {};
95+
binding.instanceCount !== undefined) {
96+
let node = {};
9997

10098
node.uri = currentClassURI;
101-
node.name = (bindings[i].label !== undefined) ? bindings[i].label.value : '';
102-
node.value = parseInt(bindings[i].instanceCount.value);
99+
node.name = (binding.label !== undefined) ? binding.label.value : '';
100+
node.value = parseInt(binding.instanceCount.value);
103101
node.type = 'class';
104102
node.active = false;
105-
var newClassId = self.nodes.addNode(node);
103+
const newClassId = self.nodes.addNode(node);
106104

107105
classIds.push(newClassId);
108106

109-
if (bindings[i].class !== undefined && bindings[i].class.value !== undefined) {
107+
if (binding.class !== undefined && binding.class.value !== undefined) {
110108
self.requestClassLabel(newClassId, currentClassURI);
111109
}
112110
} else {
113111
self.$log.debug(`[Classes] Class '${currentClassURI}' is either blacklisted or has an invalid URI!`);
114112
fetchMore++;
115113
}
116-
}
114+
});
117115

118116
if (fetchMore === 0) {
119117
deferred.resolve(classIds);
@@ -142,19 +140,25 @@ class ClassExtractor extends Extractor {
142140
}, function handleErrorExtractingClasses(err) {
143141
if (err.config.timeout.$$state.value === 'canceled') {
144142
self.$log.warn('[Class Extractor] Class extraction was canceled!');
143+
deferred.reject(classIds);
145144
} else {
146145
self.$log.error(err);
147-
}
148146

149-
// TODO check whether this was because of CORS
150-
deferred.reject(classIds);
147+
if (!self.reqConfig.getUseProxy()) {
148+
self.$log.warn('Might need a proxy here, try again...');
149+
self.reqConfig.setUseProxy(true);
150+
doQuery(false, 0, limit);
151+
} else {
152+
deferred.reject(classIds);
153+
}
154+
}
151155
})
152156
.finally(function () {
153157
self.promises.removePromise(promiseId);
154158
});
155159
} // end of doQuery()
156160

157-
doQuery(false, 0,limit);
161+
doQuery(false, 0, limit);
158162

159163
return deferred.promise;
160164
}

‎app/services/model/nodes.srv.js

+25-14
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
*/
1212
function nodesService($log, Properties, Prefixes, RequestConfig) {
1313

14-
var classUriIdMap = new Map();
15-
var nodes = new Map();
14+
let classUriIdMap = new Map();
15+
let nodes = new Map();
1616
let equivalentClasses = new Map();
1717

1818
const classDatatypesMap = new Map();
1919

20-
var subClassSet = new Set();
20+
let subClassSet = new Set();
2121

2222
const that = this;
2323

@@ -131,7 +131,7 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
131131
/**
132132
* Add a new node to the graph.
133133
*
134-
* @param {*} newNode - the node which should be added to the graph
134+
* @param {{uri: string, type: string}} newNode - the node which should be added to the graph
135135
* @return {string} id of the new node
136136
*/
137137
that.addNode = function (newNode) {
@@ -206,7 +206,7 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
206206
* @returns {*}
207207
*/
208208
that.getById = function (idToSearch) {
209-
var nodeToReturn = null;
209+
let nodeToReturn = null;
210210

211211
if (idToSearch !== undefined && typeof idToSearch === 'string') {
212212
nodeToReturn = nodes.get(idToSearch);
@@ -221,9 +221,9 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
221221
* @returns {number} number of instances
222222
*/
223223
that.getInstanceCountById = function (id) {
224-
var instanceCount = -1;
224+
let instanceCount = -1;
225225

226-
var searchedItem = nodes.get(id);
226+
const searchedItem = nodes.get(id);
227227

228228
if (searchedItem !== undefined && searchedItem.hasOwnProperty('value')) {
229229
instanceCount = searchedItem.value;
@@ -275,7 +275,7 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
275275
* @param {string} commentToAdd - the comment to add to the node with the given id
276276
*/
277277
that.insertComment = function (id, commentToAdd) {
278-
var searchedItem = nodes.get(id);
278+
const searchedItem = nodes.get(id);
279279

280280
if (searchedItem !== undefined) {
281281
searchedItem.comment = commentToAdd;
@@ -285,8 +285,14 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
285285
}
286286
};
287287

288+
/**
289+
* Set the given URI for the node with the also given id.
290+
*
291+
* @param {string} id
292+
* @param {string} newUri
293+
*/
288294
that.setURI = function (id, newUri) {
289-
var nodeToChange = nodes.get(id);
295+
const nodeToChange = nodes.get(id);
290296

291297
if (nodeToChange !== undefined) {
292298
nodeToChange.uri = newUri;
@@ -304,7 +310,7 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
304310
that.setTypesLoaded = function (classId) {
305311
if (classId !== undefined && typeof classId === 'string') {
306312

307-
var clazz = nodes.get(classId);
313+
const clazz = nodes.get(classId);
308314

309315
if (clazz !== undefined && clazz.type === 'class') {
310316
clazz.typesLoaded = true;
@@ -398,11 +404,16 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
398404
return nodeToReturn;
399405
};
400406

407+
/**
408+
* Removes all given nodes from the node map.
409+
*
410+
* @param {Array} nodeArr - an array of nodes to be removed
411+
*/
401412
that.removeNodes = function (nodeArr) {
402413
if (nodeArr !== undefined && nodeArr.length > 0) {
403-
for (let i = 0; i < nodeArr.length; i++) {
404-
nodes.delete(nodeArr[i]);
405-
}
414+
nodeArr.forEach((node) => {
415+
nodes.delete(node);
416+
});
406417
}
407418
};
408419

@@ -413,7 +424,7 @@ function nodesService($log, Properties, Prefixes, RequestConfig) {
413424
* @return {number} the new value of the node or -1 if node was not found
414425
*/
415426
that.incValueOfId = function (id) {
416-
var searchedItem = nodes.get(id);
427+
const searchedItem = nodes.get(id);
417428

418429
if (searchedItem !== undefined && searchedItem.hasOwnProperty('value')) {
419430
searchedItem.value += 1;

‎app/services/requests/request-config.srv.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
function requestConfig($cookies) {
1010

1111
const cookiePrefix = 'ldvowl_';
12-
const proxyURL = 'http://localhost/proxy.php';
12+
const proxyURL = __PROXY_URL__ || 'http://localhost/proxy.php'; // eslint-disable-line no-undef
1313

1414
let endpointURL = $cookies.get(cookiePrefix + 'endpoint') || '';
1515
let useProxy = $cookies.get(cookiePrefix + 'proxy') || 'false';
@@ -97,8 +97,8 @@ function requestConfig($cookies) {
9797
* @param {boolean} useProxy - true if proxy should be used, false otherwise
9898
*/
9999
self.setUseProxy = function (useProxy) {
100-
useProxy = (useProxy) ? 'true' : 'false';
101-
$cookies.put(cookiePrefix + 'proxy', useProxy);
100+
const proxyFlag = (useProxy) ? 'true' : 'false';
101+
$cookies.put(cookiePrefix + 'proxy', proxyFlag);
102102
};
103103

104104
self.getLimit = function () {
@@ -125,7 +125,7 @@ function requestConfig($cookies) {
125125
};
126126

127127
self.getLabelLanguage = function () {
128-
var cookieLang = $cookies.get(cookiePrefix + 'lang');
128+
const cookieLang = $cookies.get(cookiePrefix + 'lang');
129129
if (cookieLang !== undefined) {
130130
labelLanguage = cookieLang;
131131
}

‎package.json

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ld-vowl",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "Extract ontology information out of arbitrary SPARQL endpoints and visualize it using a slightly adjusted form of VOWL.",
55
"author": "Marc Weise <weisemc@studi.informatik.uni-stuttgart.de>",
66
"scripts": {
@@ -19,12 +19,7 @@
1919
"bugs": {
2020
"url": "https://github.com/VisualDataWeb/LD-VOWL/issues"
2121
},
22-
"keywords": [
23-
"Linked Data",
24-
"SPARQL",
25-
"Visualization",
26-
"VOWL"
27-
],
22+
"keywords": ["Linked Data", "SPARQL", "Visualization", "VOWL"],
2823
"dependencies": {
2924
"angular": "1.4.8",
3025
"angular-animate": "1.4.8",
@@ -66,6 +61,7 @@
6661
"isparta-loader": "~2.0.0",
6762
"istanbul-instrumenter-loader": "~0.2.0",
6863
"jasmine-core": "~2.4.1",
64+
"jest": "^17.0.3",
6965
"jest-cli": "^17.0.0",
7066
"karma": "~0.13.19",
7167
"karma-babel-preprocessor": "~6.0.1",
@@ -89,8 +85,8 @@
8985
},
9086
"jest": {
9187
"verbose": true,
92-
"globals": {
93-
"__LOGGING__": true,
88+
"globals": {
89+
"__LOGGING__": true,
9490
"__SESSION_STORAGE__": false,
9591
"__VERSION__": "1.1.1",
9692
"__PROXY__": true

‎webpack.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = {
3434
new webpack.DefinePlugin({
3535
__LOGGING__: true,
3636
__PROXY__: true,
37+
__PROXY_URL__: JSON.stringify(require('./development.conf.json').proxyUrl),
3738
__SESSION_STORAGE__: true,
3839
__SHOW_ENDPOINT__: true,
3940
__VERSION__: JSON.stringify(require('./package.json').version)

‎webpack.production.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module.exports = {
1818
'angular-animate',
1919
'angular-cookies',
2020
'd3',
21-
'bootstrap-webpack',
2221
'angular-ui-bootstrap'
2322
]
2423
},
@@ -47,6 +46,7 @@ module.exports = {
4746
new webpack.DefinePlugin({
4847
__LOGGING__: false,
4948
__PROXY__: true,
49+
__PROXY_URL__: JSON.stringify(require('./production.conf.json').proxyUrl),
5050
__SESSION_STORAGE__: false,
5151
__SHOW_ENDPOINT__: true,
5252
__VERSION__: JSON.stringify(require('./package.json').version)

0 commit comments

Comments
 (0)
Please sign in to comment.