Skip to content
This repository was archived by the owner on Apr 22, 2022. It is now read-only.

Commit 2394166

Browse files
committed
several fixes
1 parent 58cb5c5 commit 2394166

File tree

15 files changed

+155
-73
lines changed

15 files changed

+155
-73
lines changed

src/main/java/eu/geoknow/generator/importer/HttpRdfInsert.java

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package eu.geoknow.generator.importer;
22

33
import java.io.ByteArrayOutputStream;
4-
import java.io.IOException;
54
import java.util.HashMap;
65
import java.util.UUID;
76

@@ -16,6 +15,7 @@
1615

1716
import eu.geoknow.generator.common.APP_CONSTANT;
1817
import eu.geoknow.generator.common.Queries;
18+
import eu.geoknow.generator.exceptions.ServiceInternalServerError;
1919
import eu.geoknow.generator.rdf.RdfStoreManager;
2020

2121
public class HttpRdfInsert {
@@ -28,25 +28,54 @@ public HttpRdfInsert(RdfStoreManager rdfStoreManager) {
2828
this.rdfStoreManager = rdfStoreManager;
2929
}
3030

31-
public int localCopy(String sourceGraph, String targetGraph) throws IOException, Exception {
31+
public int localCopy(String sourceGraph, String targetGraph) throws ServiceInternalServerError {
32+
try {
3233

33-
String query = "COPY <" + sourceGraph + "> TO <" + targetGraph + ">";
34-
log.debug(query);
35-
String res = rdfStoreManager.execute(query, APP_CONSTANT.SPARQL_JSON_RESPONSE_FORMAT);
36-
log.debug(res);
37-
return Queries.countGraphTriples(targetGraph, rdfStoreManager);
34+
String query = "COPY <" + sourceGraph + "> TO <" + targetGraph + ">";
35+
log.debug(query);
36+
String res = rdfStoreManager.execute(query, APP_CONSTANT.SPARQL_JSON_RESPONSE_FORMAT);
37+
log.debug(res);
38+
return Queries.countGraphTriples(targetGraph, rdfStoreManager);
39+
40+
} catch (Exception e) {
41+
e.printStackTrace();
42+
throw new ServiceInternalServerError(e.getMessage());
43+
44+
}
45+
46+
}
47+
48+
public int localAdd(String sourceGraph, String targetGraph) throws ServiceInternalServerError {
49+
try {
50+
int initialTriples = Queries.countGraphTriples(targetGraph, rdfStoreManager);
51+
String query = "ADD <" + sourceGraph + "> TO <" + targetGraph + ">";
52+
log.debug(query);
53+
String res = rdfStoreManager.execute(query, APP_CONSTANT.SPARQL_JSON_RESPONSE_FORMAT);
54+
log.debug(res);
55+
return Queries.countGraphTriples(targetGraph, rdfStoreManager) - initialTriples;
56+
} catch (Exception e) {
57+
e.printStackTrace();
58+
throw new ServiceInternalServerError(e.getMessage());
59+
60+
}
3861

3962
}
4063

41-
public int localAdd(String sourceGraph, String targetGraph) throws IOException, Exception {
64+
public int localInsertQuery(String quertString, String sourceGraph, String targetGraph)
65+
throws ServiceInternalServerError {
4266

43-
int initialTriples = Queries.countGraphTriples(targetGraph, rdfStoreManager);
44-
String query = "ADD <" + sourceGraph + "> TO <" + targetGraph + ">";
45-
log.debug(query);
46-
String res = rdfStoreManager.execute(query, APP_CONSTANT.SPARQL_JSON_RESPONSE_FORMAT);
47-
log.debug(res);
48-
return Queries.countGraphTriples(targetGraph, rdfStoreManager) - initialTriples;
67+
try {
68+
int initialTriples = Queries.countGraphTriples(targetGraph, rdfStoreManager);
69+
String query = quertString;
70+
log.debug(query);
71+
String res = rdfStoreManager.execute(query, APP_CONSTANT.SPARQL_JSON_RESPONSE_FORMAT);
72+
log.debug(res);
73+
return Queries.countGraphTriples(targetGraph, rdfStoreManager) - initialTriples;
74+
} catch (Exception e) {
75+
e.printStackTrace();
76+
throw new ServiceInternalServerError(e.getMessage());
4977

78+
}
5079
}
5180

5281
public int httpInsert(String graph, Model model, String uriBase) throws Exception {

src/main/java/eu/geoknow/generator/rest/ImportRdf.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package eu.geoknow.generator.rest;
22

3-
import java.io.ByteArrayInputStream;
43
import java.io.File;
54

65
import javax.servlet.ServletContext;
@@ -23,8 +22,8 @@
2322
import com.hp.hpl.jena.rdf.model.Model;
2423
import com.hp.hpl.jena.rdf.model.ModelFactory;
2524

26-
import eu.geoknow.generator.common.APP_CONSTANT;
2725
import eu.geoknow.generator.configuration.FrameworkConfiguration;
26+
import eu.geoknow.generator.exceptions.ServiceInternalServerError;
2827
import eu.geoknow.generator.importer.HttpRdfInsert;
2928
import eu.geoknow.generator.importer.RdfImportConfig;
3029
import eu.geoknow.generator.rdf.RdfStoreManager;
@@ -190,7 +189,7 @@ public Response fromEndpoint(@CookieParam(value = "user") Cookie userc, @CookieP
190189
Query query = QueryFactory.create(importConfig.getSparqlQuery());
191190
QueryExecution qexec =
192191
QueryExecutionFactory.sparqlService(importConfig.getSourceEndpoint(), query);
193-
qexec.close();
192+
194193
Model model = qexec.execConstruct();
195194
HttpRdfInsert insert = new HttpRdfInsert(rdfStoreManager);
196195
try {
@@ -201,7 +200,7 @@ public Response fromEndpoint(@CookieParam(value = "user") Cookie userc, @CookieP
201200
e.printStackTrace();
202201
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
203202
}
204-
203+
qexec.close();
205204
importConfig.setTriples(triples);
206205
Gson gson = new Gson();
207206
String json = "{ \"import\" : " + gson.toJson(importConfig) + "}";
@@ -251,14 +250,12 @@ public Response fromLocalQuery(@CookieParam(value = "user") Cookie userc, @Cooki
251250
else if (importConfig.getSparqlQuery().equals("COPY"))
252251
triples = insert.localCopy(importConfig.getSourceGraph(), importConfig.getTargetGraph());
253252
else {
254-
String res =
255-
rdfStoreManager.execute(importConfig.getSparqlQuery(),
256-
APP_CONSTANT.SPARQL_TURTLE_RESPONSE_FORMAT);
257-
Model model = ModelFactory.createDefaultModel();
258-
model.read(new ByteArrayInputStream(res.getBytes()), null);
259253
triples =
260-
insert.httpInsert(importConfig.getTargetGraph(), model, config.getResourceNamespace());
254+
insert.localInsertQuery(importConfig.getSparqlQuery(), importConfig.getSourceGraph(),
255+
importConfig.getTargetGraph());
261256
}
257+
} catch (ServiceInternalServerError e) {
258+
return Response.status(Response.Status.EXPECTATION_FAILED).entity(e.getMessage()).build();
262259
} catch (Exception e) {
263260
log.error(e);
264261
e.printStackTrace();

src/main/java/eu/geoknow/generator/rest/Publish.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public Response publish(@FormParam("endpointUri") String endpointUri,
125125
DataHandler dh = new DataHandler(config);
126126
dh.publishData();
127127
} catch (Exception e) {
128+
e.printStackTrace();
128129
logger.error(e);
129130
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
130131
.entity("{\"status\" : \"" + e.getMessage() + "\"}").build();

src/main/webapp/js/directives.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ module.directive('targetGraph', ['$parse', 'GraphService', function($parse, Grap
8282
};
8383

8484
$scope.describeGraph=function (ngraph) {
85-
return ngraph.graph.label + " | " + ngraph.name;
85+
return ngraph.graph.label + " (" + ngraph.name +")";
8686
}
8787

8888
$scope.createTargetGraph = function(){
@@ -135,14 +135,22 @@ module.directive('sourceGraph', ['$parse', 'GraphService', 'GraphGroupService',
135135
return GraphService.getAccessibleGraphs(false, false, true).then(function(graphs) {
136136
var ngraphs = graphs;
137137
GraphGroupService.getAllGraphGroups(true).then(function(groups) {
138-
ngraphs = ngraphs.concat(groups);
139-
$scope.readableGraphs = ngraphs;
138+
console.log(groups);
139+
ngraphs = ngraphs.concat(groups);
140+
console.log(ngraphs);
141+
$scope.readableGraphs = ngraphs;
140142
});
141143
});
142144
};
143145

144146
$scope.describeGraph=function (ngraph) {
145-
return ngraph.graph.label + " | " + ngraph.name;
147+
148+
if (ngraph.graph != undefined)
149+
return ngraph.graph.label + " (" + ngraph.name +")";
150+
else if (ngraph.namedGraphs != undefined)
151+
return ngraph.label + " (" + ngraph.namedGraphs.toString() +")";
152+
else
153+
return "";
146154
}
147155

148156
// notify that the input changed

src/main/webapp/js/settings/data-sources/data-sources.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ <h4>SPARQL Endpoint</h4>
2525
</td>
2626
<td>{{endpoint.uri}}</td>
2727
<td>{{endpoint.label}}</td>
28-
<td>{{endpoint.endpoint}}</td>
29-
<td>{{endpoint.homepage}}</td>
28+
<td><a href="{{endpoint.endpoint}}" target="_blanc">{{endpoint.endpoint}}</a></td>
29+
<td><a href="{{endpoint.homepage}}" target="_blanc">{{endpoint.homepage}}</a></td>
3030
</tr>
3131
</tbody>
3232
</table>

src/main/webapp/js/settings/named-graphs/graphs.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ <h4>
203203
<tbody>
204204
<tr ng-repeat="gg in graphgroups">
205205
<td>
206-
<button type="button" class="btn btn-default btn-xs" ng-click="deleteGroup('gg.name')"><span class="glyphicon glyphicon-trash"></span></button>
207-
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#modalGroup" ng-click="editGroup('gg.name');"><span class="glyphicon glyphicon-edit"></span></button>
206+
<button type="button" class="btn btn-default btn-xs" ng-click="deleteGroup(gg.name)"><span class="glyphicon glyphicon-trash"></span></button>
207+
<button type="button" class="btn btn-default btn-xs" data-toggle="modal" data-target="#modalGroup" ng-click="editGroup(gg.name);"><span class="glyphicon glyphicon-edit"></span></button>
208208
</td>
209209
<td>{{gg.name}}</td>
210210
<td>{{gg.label}}</td>

src/main/webapp/js/workbench/extraction-and-loading/import-rdf-controller.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
***************************************************************************************************/
88

9-
var ImportFormCtrl = function($scope, $http, $q, $timeout, ConfigurationService, flash, AccountService, GraphService, Ns, Upload, ImportRdfService, ServerErrorResponse, Helpers) {
9+
var ImportFormCtrl = function($scope, $http, $q, $timeout, ConfigurationService, flash, AccountService, AuthSessionService, GraphService, Ns, Upload, ImportRdfService, ServerErrorResponse, Helpers) {
1010

1111
var currentAccount = AccountService.getAccount();
1212

@@ -40,7 +40,7 @@ var ImportFormCtrl = function($scope, $http, $q, $timeout, ConfigurationService,
4040
graph : "",
4141
isNew : {
4242
prefix : "RdfImport" ,
43-
label : "",
43+
label : "RdfImport",
4444
description : ""
4545
}
4646
};
@@ -66,13 +66,19 @@ var ImportFormCtrl = function($scope, $http, $q, $timeout, ConfigurationService,
6666
if($scope.importLocal.action == 'QUERY'){
6767
$scope.importLocal.sparqlQuery = "INSERT { GRAPH <" + Ns.lengthen($scope.target.graph) + "> {?s ?p ?o}} "
6868
+ "WHERE {GRAPH <" + Ns.lengthen($scope.importRdf.source) + "> {?s ?p ?o}}";
69-
return true;
7069
}
7170
else
7271
$scope.importLocal.sparqlQuery = $scope.importLocal.action;
73-
return false;
7472
};
7573

74+
$scope.showInputQuery = function(){
75+
if($scope.importLocal.action == 'QUERY')
76+
return true;
77+
else
78+
return false;
79+
}
80+
81+
7682
$scope.updateNewTargetInfo = function(){
7783
console.log($scope.source.graph);
7884
if($scope.sourceType.value == 'file'){
@@ -103,6 +109,7 @@ var ImportFormCtrl = function($scope, $http, $q, $timeout, ConfigurationService,
103109
label : "Import from graph",
104110
description : "Import from graph "+$scope.importRdf.source,
105111
};
112+
$scope.updateSparqlCopyQuery();
106113
}
107114

108115
}
@@ -216,8 +223,18 @@ var ImportFormCtrl = function($scope, $http, $q, $timeout, ConfigurationService,
216223
importPromise = ImportRdfService.importFromFile($scope.importRdf.files, $scope.target.graph);
217224
else if($scope.sourceType.value == 'url')
218225
importPromise = ImportRdfService.importFromUrl($scope.importRdf.source, $scope.target.graph);
219-
else if($scope.sourceType.value == 'externalQuery')
220-
importPromise = ImportRdfService.importFromEndpoint(scope.importEndpoint.sparqlQuery, $scope.importRdf.source, $scope.target.graph);
226+
else if($scope.sourceType.value == 'externalQuery'){
227+
228+
if($scope.importRdf.source == ConfigurationService.getSPARQLEndpoint() ){
229+
importPromise = AuthSessionService.createSession().then(function(response){
230+
var authEndpoint = ConfigurationService.getFrameworkHomepage() + response.data.endpoint;
231+
return ImportRdfService.importFromEndpoint($scope.importEndpoint.sparqlQuery, authEndpoint, $scope.target.graph);
232+
});
233+
}
234+
else
235+
importPromise = ImportRdfService.importFromEndpoint($scope.importEndpoint.sparqlQuery, $scope.importRdf.source, $scope.target.graph);
236+
237+
}
221238
else if($scope.sourceType.value == 'localQuery')
222239
importPromise = ImportRdfService.importFromLocal($scope.importRdf.source, $scope.target.graph, $scope.importLocal.sparqlQuery);
223240

@@ -250,6 +267,7 @@ var ImportFormCtrl = function($scope, $http, $q, $timeout, ConfigurationService,
250267
});
251268

252269
},
270+
//error
253271
function(response) {
254272
flash.error = ServerErrorResponse.getMessage(response);
255273
importing = false;

src/main/webapp/js/workbench/extraction-and-loading/import-rdf.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ <h3 class="green bold">Import RDF Data</h3>
100100
<form ng-show="localQueryElements" class="form-horizontal InputForm" role="form" name="localForm" novalidate>
101101

102102
<source-graph graph-info="source" has-changed="updateNewTargetInfo()"></source-graph>
103-
<target-graph graph-info="target"></target-graph>
103+
<target-graph graph-info="target" has-changed="updateSparqlCopyQuery()"></target-graph>
104104

105105
<div class="form-group">
106106
<div class="col-sm-2"></div>
@@ -114,15 +114,15 @@ <h3 class="green bold">Import RDF Data</h3>
114114
Clone All Graph (will delete content in target graph)
115115
</label><br/>
116116
<label>
117-
<input type="radio" ng-model="importLocal.action" value="QUERY">
117+
<input type="radio" ng-model="importLocal.action" value="QUERY" ng-change="updateSparqlCopyQuery()" >
118118
Add Triples using a query
119119
</label>
120120
</div>
121121
</div>
122-
<div class="form-group" ng-show="updateSparqlCopyQuery()" >
122+
<div class="form-group" ng-show="showInputQuery()" >
123123
<label for="sparqlQuery" class="col-xs-2 control-label">Query</label>
124124
<div class="input-group col-sm-8">
125-
<textarea class="form-control" rows="3" ng-model="importLocal.sparqlQuery" id="sparqlQuery" name="sparqlQuery" required ></textarea>
125+
<textarea class="form-control" rows="5" ng-model="importLocal.sparqlQuery" id="sparqlQuery" name="sparqlQuery" required ></textarea>
126126
<div class="error" ng-show="localForm.sparqlQuery.$dirty && localForm.sparqlQuery.$invalid">Invalid:
127127
<span ng-show="localForm.sparqlQuery.$error.required">Specify the Query</span>
128128
</div>

src/main/webapp/js/workbench/extraction-and-loading/triplegeo-controller.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ var TripleGeoCtrl = function($scope, $http, $q, ConfigurationService, Components
5959
" values for the namespaces and prefixes nsPrefix=georesource",
6060
spatial: "Optional parameters. These fields should be filled in if a transformation between EPSG reference systems is needed. "+
6161
"If not specified, geometries are assumed to be WGS84 reference system (EPSG:4326).",
62-
other: "Optional parameter. Default languages for the labels created in the output RDF. By default, the value is English - en."
62+
other: "Optional parameter. Default languages for the labels created in the output RDF. By default, the value is English - en.",
63+
esriName: "The name of the field containting name of the shape of the smallest granularity e.g. the name of countryes, states",
64+
esriAttribute :"The name of the field that contains the UNIQUE id of the shape",
65+
esriType :"The RDF type to be set to the entity (i.e. schema:AdmnistrativeArea)",
66+
esriClass : "The name of the fileld that contaisn the type of the entity: e.g.: country, city, way, river"
6367
};
6468

6569
$scope.options = {
@@ -419,11 +423,11 @@ var TripleGeoCtrl = function($scope, $http, $q, ConfigurationService, Components
419423
targetStore : $scope.options.targetStore[0],
420424

421425
featureString: fileName.substring(0,fileName.length-4).toLowerCase(),
422-
attribute: "name",
426+
attribute: "",
423427
ignore: "UNK",
424428
type: "",
425-
name: "id",
426-
uclass: "type",
429+
name: "",
430+
uclass: "",
427431

428432
nsPrefix: "gkg",
429433
nsURI: ConfigurationService.getUriBase(),

src/main/webapp/js/workbench/extraction-and-loading/triplegeo.html

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ <h5 class="green bold">TripleGeo Configuration</h5>
152152
</div>
153153

154154
<div class="col-xs-2">
155-
<label class="green bold">Attribute *</label>
155+
<label class="green bold">ID field</label><i class="glyphicon glyphicon-question-sign" style="margin-left:5px" data-toggle="tooltip" data-original-title="{{tooltips.esriAttribute}}"></i>
156156
</div>
157157
<div class="input-group-sm col-xs-4">
158158
<input class="form-control" ng-model="tripleGeoConfig.attribute"></input>
@@ -161,13 +161,13 @@ <h5 class="green bold">TripleGeo Configuration</h5>
161161
<br>
162162
<div class="row">
163163
<div class="col-xs-2">
164-
<label class="green bold">Ignore *</label>
164+
<label class="green bold">Ignore</label>
165165
</div>
166166
<div class="input-group-sm col-xs-4">
167167
<input class="form-control" ng-model="tripleGeoConfig.ignore" required></input>
168168
</div>
169169
<div class="col-xs-2">
170-
<label class="green bold">Type *</label>
170+
<label class="green bold">Type</label><i class="glyphicon glyphicon-question-sign" style="margin-left:5px" data-toggle="tooltip" data-original-title="{{tooltips.esriType}}"></i>
171171
</div>
172172
<div class="input-group-sm col-xs-4">
173173
<input class="form-control" ng-model="tripleGeoConfig.type" required></input>
@@ -176,20 +176,19 @@ <h5 class="green bold">TripleGeo Configuration</h5>
176176
<br>
177177
<div class="row">
178178
<div class="col-xs-2">
179-
<label class="green bold">Name *</label>
179+
<label class="green bold">Name field</label><i class="glyphicon glyphicon-question-sign" style="margin-left:5px" data-toggle="tooltip" data-original-title="{{tooltips.esriName}}"></i>
180180
</div>
181181
<div class="input-group-sm col-xs-4">
182182
<input class="form-control" ng-model="tripleGeoConfig.name" required></input>
183183
</div>
184184
<div class="col-xs-2">
185-
<label class="green bold">Class *</label>
185+
<label class="green bold">Class field</label><i class="glyphicon glyphicon-question-sign" style="margin-left:5px" data-toggle="tooltip" data-original-title="{{tooltips.esriClass}}"></i>
186186
</div>
187187
<div class="input-group-sm col-xs-4">
188188
<input class="form-control" ng-model="tripleGeoConfig.uclass" required></input>
189189
</div>
190190
</div>
191191
<br>
192-
* required
193192
</div>
194193
<div ng-show="options.dbParams">
195194
<div class="row">
@@ -332,7 +331,7 @@ <h5 class="green bold">TripleGeo Configuration</h5>
332331
<br>
333332

334333
</div> <!-- form-->
335-
<br>
334+
<br>
336335
<div class="row" ng-show="actionButtons">
337336
<div class="col-xs-2">
338337
<a class="btn btn-sm btn-success btn-block" ng-click="CreateJob()">Create Job</a></div>

0 commit comments

Comments
 (0)