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

Commit e27887c

Browse files
committed
update upload library
1 parent 27a9050 commit e27887c

33 files changed

+4572
-4021
lines changed

src/main/java/eu/geoknow/generator/graphs/GraphsManager.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.net.MalformedURLException;
55
import java.net.URL;
66
import java.util.Iterator;
7+
import java.util.List;
78

89
import javax.ws.rs.NotFoundException;
910

@@ -96,26 +97,30 @@ public NamedGraph addContribution(Contribution contribution) throws SPARQLEndpoi
9697
log.debug(contribution.getDate());
9798
// "2005-07-14T03:18:56+0100"^^xsd:dateTime
9899

99-
String source = contribution.getSource();
100+
List<String> sources = contribution.getSource();
100101

101102
// Check if the source is a URI
102-
try {
103-
URL url = new URL(contribution.getSource());
104-
source = "<" + contribution.getSource() + ">";
105-
} catch (MalformedURLException e) {
106-
source = "\"" + contribution.getSource() + "\"";
103+
String sourcesTriples = "";
104+
for (String source : sources) {
105+
try {
106+
new URL(source);
107+
source = "<" + source + ">";
108+
} catch (MalformedURLException e) {
109+
source = "\"" + source + "\"";
110+
}
111+
sourcesTriples += "?graph <" + DCTerms.source.getURI() + "> " + source + " . ";
107112
}
108113

114+
109115
String query =
110116
" WITH <" + graphsGraph + "> " + "DELETE { ?graph <" + DCTerms.modified.getURI() + "> ?m ."
111117
+ "?graph <" + VOID.triples.getURI() + "> ?t . " + "} INSERT { ?graph <"
112118
+ DCTerms.modified.getURI() + "> \"" + contribution.getDate() + "\" ." + "?graph <"
113119
+ VOID.triples.getURI() + "> " + triples + " . " + "?graph <"
114120
+ DCTerms.contributor.getURI() + "> <" + contribution.getContributor() + "> . "
115-
+ "?graph <" + DCTerms.source.getURI() + "> " + source + " . " + " } WHERE { <"
116-
+ contribution.getNamedGraph() + "> <" + SD.graph.getURI() + "> ?graph"
117-
+ " . OPTIONAL{ ?graph <" + DCTerms.modified.getURI() + "> ?m .?graph <"
118-
+ VOID.triples.getURI() + "> ?t .}}";
121+
+ sourcesTriples + " } WHERE { <" + contribution.getNamedGraph() + "> <"
122+
+ SD.graph.getURI() + "> ?graph" + " . OPTIONAL{ ?graph <" + DCTerms.modified.getURI()
123+
+ "> ?m .?graph <" + VOID.triples.getURI() + "> ?t .}}";
119124

120125
log.debug(query);
121126

src/main/java/eu/geoknow/generator/graphs/beans/Contribution.java

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

3+
import java.util.List;
4+
35
import org.hibernate.validator.constraints.NotEmpty;
46

57

@@ -15,7 +17,7 @@ public class Contribution {
1517
private String namedGraph;
1618
private String date;
1719
@NotEmpty
18-
private String source;
20+
private List<String> source;
1921
@NotEmpty
2022
private String contributor;
2123

@@ -36,11 +38,11 @@ public void setDate(String date) {
3638
this.date = date;
3739
}
3840

39-
public String getSource() {
41+
public List<String> getSource() {
4042
return source;
4143
}
4244

43-
public void setSource(String source) {
45+
public void setSource(List<String> source) {
4446
this.source = source;
4547
}
4648

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package eu.geoknow.generator.importer;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
36
import javax.validation.Valid;
47
import javax.validation.constraints.NotNull;
58

@@ -14,9 +17,13 @@ public class RdfImportConfig {
1417
private String sourceGraph;
1518
private String sourceEndpoint;
1619
private String sourceUrl;
17-
private String fileName;
20+
private List<String> files;
1821
private int triples;
1922

23+
public RdfImportConfig() {
24+
files = new ArrayList<String>();
25+
}
26+
2027
public String getTargetGraph() {
2128
return targetGraph;
2229
}
@@ -59,12 +66,12 @@ public void setSourceUrl(String sourceUrl) {
5966
this.sourceUrl = sourceUrl;
6067
}
6168

62-
public String getFileName() {
63-
return fileName;
69+
public List<String> getFiles() {
70+
return files;
6471
}
6572

66-
public void setFileName(String fileName) {
67-
this.fileName = fileName;
73+
public void setFiles(List<String> files) {
74+
this.files = files;
6875
}
6976

7077
public int getTriples() {

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,27 @@ public Response fromFile(@CookieParam(value = "user") Cookie userc,
7575

7676
log.debug(importConfig.getTargetGraph());
7777
// validate required values
78-
if (importConfig.getFileName().equals(""))
78+
if (importConfig.getFiles().isEmpty())
7979
return Response.status(Response.Status.BAD_REQUEST)
8080
.entity("List of files to be imported is required").build();
8181

82-
log.info("importing " + filePath + importConfig.getFileName());
8382
int triples = 0;
84-
HttpRdfInsert insert = new HttpRdfInsert(rdfStoreManager);
85-
try {
86-
Model model = ModelFactory.createDefaultModel();
87-
model.read(filePath + importConfig.getFileName());
88-
triples +=
89-
insert.httpInsert(importConfig.getTargetGraph(), model, config.getResourceNamespace());
90-
} catch (Exception e) {
91-
log.error(e);
92-
e.printStackTrace();
93-
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
83+
84+
for (String file : importConfig.getFiles()) {
85+
log.info("importing " + filePath + file);
86+
87+
HttpRdfInsert insert = new HttpRdfInsert(rdfStoreManager);
88+
try {
89+
Model model = ModelFactory.createDefaultModel();
90+
model.read(filePath + file);
91+
triples +=
92+
insert.httpInsert(importConfig.getTargetGraph(), model, config.getResourceNamespace());
93+
} catch (Exception e) {
94+
log.error(e);
95+
e.printStackTrace();
96+
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage())
97+
.build();
98+
}
9499
}
95100

96101
importConfig.setTriples(triples);

src/main/java/eu/geoknow/generator/servlets/UploadServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
115115
return;
116116
}
117117

118-
res.addResult(file.getAbsolutePath() + file.getName());
118+
res.addResult(file.getAbsolutePath());
119119
}
120120
res.setStatus("SUCESS");
121121
res.setMessage("Successfuly uploaded");

src/main/webapp/js/services/graph-service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ module.factory("GraphService", function ($http, $q, Config, ConfigurationService
555555

556556
// after some data updated into the graph, its metadata needs to be updated
557557
var addContribution = function(contribution){
558-
558+
console.log(contribution);
559559
return $http.put("rest/graphs", contribution).then(
560560
function(response){
561561
return response.data.namedgraph;

src/main/webapp/js/services/import-rdf-service.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ module.factory('ImportRdfService', function ($http, Ns) {
77

88
var service = {
99

10-
importFromFile : function(file, targetGraph){
10+
importFromFile : function(files, targetGraph){
11+
console.log(files);
1112
console.log(targetGraph);
1213
console.log(Ns.lengthen(targetGraph));
1314
var config ={
14-
fileName: file,
15+
files: files,
1516
targetGraph: Ns.lengthen(targetGraph)
1617
};
1718
console.log(config);

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

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

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

1111
var currentAccount = AccountService.getAccount();
1212

@@ -79,7 +79,7 @@ var ImportFormCtrl = function($scope, $http, ConfigurationService, flash, Accoun
7979
if($scope.sourceType.value == 'file'){
8080
$scope.newTarget ={
8181
prefix : "RdfImport" ,
82-
label : $scope.importRdf.source,
82+
label : "Import form " + $scope.importRdf.source.length +" files",
8383
description : "Import from file "+$scope.importRdf.source,
8484
};
8585
}
@@ -138,29 +138,57 @@ var ImportFormCtrl = function($scope, $http, ConfigurationService, flash, Accoun
138138

139139
/**
140140
For File Import
141-
**/
142-
$scope.$watch('importFile.files', function () {
143-
if($scope.importFile != undefined )
144-
$scope.upload($scope.importFile.files);
145-
});
146-
147-
$scope.upload = function (files) {
148-
if (files && files.length) {
149-
for (var i = 0; i < files.length; i++) {
150-
var file = files[i];
151-
Upload.upload({
152-
url: 'UploadServlet',
153-
file: file
154-
}).progress(function (evt) {
155-
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
156-
flash.success='progress: ' + parseInt(100.0 * evt.loaded / evt.total) + '% file :'+ evt.config.file.name;
157-
}).success(function (data, status, headers, config) {
158-
$scope.importRdf.source = config.file.name;
159-
$scope.updateNewTargetInfo();
141+
**/
142+
$scope.uploadSuceed = function(){
143+
144+
return ($scope.sourceType.value == 'file' && $scope.importRdf.source!=null)
145+
}
146+
147+
$scope.uploadFiles = function(files, errFiles) {
148+
149+
$scope.errFiles = errFiles;
150+
var promises = [];
151+
152+
angular.forEach(files, function(file) {
153+
154+
var deferred = $q.defer();
155+
file.upload = Upload.upload({
156+
url: 'UploadServlet',
157+
data: {file: file}
160158
});
161-
}
162-
}
163-
};
159+
160+
file.upload.then(function (response) {
161+
$timeout(function () {
162+
deferred.resolve(file.name);
163+
});
164+
}, function (response) {
165+
if (response.status > 0)
166+
flash.error = response.status + ': ' + response.data;
167+
}, function (evt) {
168+
var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
169+
flash.success='progress: ' + parseInt(100.0 * evt.loaded / evt.total) + '% file :'+ file.name;
170+
// file.progress = Math.min(100, parseInt(100.0 *
171+
// evt.loaded / evt.total));
172+
});
173+
174+
promises.push(deferred.promise);
175+
}); // foreach
176+
177+
$q.all(promises).then(
178+
// results: an array of data objects from each deferred.resolve(data) call
179+
function(results) {
180+
flash.success='Uploaded: ' + results ;
181+
$scope.importRdf.source = results;
182+
$scope.updateNewTargetInfo();
183+
},
184+
// error
185+
function(response) {
186+
console.log(response);
187+
}
188+
);
189+
}
190+
191+
164192

165193
$scope.isImporting = function(){
166194
return importing;
@@ -197,8 +225,6 @@ var ImportFormCtrl = function($scope, $http, ConfigurationService, flash, Accoun
197225
//success
198226
function (response){
199227

200-
console.log(response);
201-
202228
var imported = response.data.import;
203229

204230
var meta = {
@@ -210,7 +236,6 @@ var ImportFormCtrl = function($scope, $http, ConfigurationService, flash, Accoun
210236
// update the metadata of the graph
211237
GraphService.addContribution(meta).then(
212238
function(response){
213-
console.log(response);
214239
flash.success = "successfully imported " + imported.triples + " triples";
215240
$scope.resetValues();
216241
},
@@ -232,7 +257,6 @@ var ImportFormCtrl = function($scope, $http, ConfigurationService, flash, Accoun
232257

233258
initialise();
234259

235-
$scope.importFile.files = null;
236260
$scope.urlForm.$setPristine();
237261
$scope.fileForm.$setPristine();
238262
$scope.endpointForm.$setPristine();

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@ <h3 class="green bold">Import RDF Data</h3>
1717
<label for="inputFile" class="col-sm-2 control-label">File input</label>
1818
<!-- <input type="file" ng-file-select="onFileSelect($files)" > -->
1919
<div class="col-sm-8">
20-
<input type="file" ngf-select ng-model="importFile.files" accept=".nt,.n3,.ttl,.rdf" >
21-
<div class="error" ng-show="uploadedError()">File value is invalid or missed (for required fields)<span>{{uploadMessage}}</span></div>
20+
<!-- <input type="file" ngf-select ng-model="importFile.files" accept=".nt,.n3,.ttl,.rdf" > -->
21+
<button ngf-select="uploadFiles($files, $invalidFiles)" multiple accept=".nt,.n3,.ttl,.rdf">Select Files</button>
22+
23+
<div class="error">{{uploadMessageError}}</div>
24+
<br>
25+
<ul ng-show="uploadSuceed()">
26+
<li ng-repeat="f in importRdf.source">{{f}}</li>
27+
</ul>
28+
2229
</div>
2330
</div>
2431

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ <h5 class="green bold">TripleGeo Configuration</h5>
4949
</div>
5050
<div class="col-xs-8">
5151

52-
<button ngf-select="uploadFiles($files, $invalidFiles)" multiple accept="*/*" ngf-max-height="1000" ngf-max-size="1MB">Select Files</button>
53-
<ul ng-show="isUploading()">
54-
<li ng-repeat="f in files" style="font:smaller">{{f.name}} {{f.$errorParam}}
55-
<span class="progress" ng-show="f.progress >= 0">
56-
<span style="width:{{f.progress}}%"
57-
ng-bind="f.progress + '%'"></span>
58-
</span>
59-
</li>
60-
<li ng-repeat="f in errFiles" >{{f.name}} {{f.$error}} {{f.$errorParam}}
61-
</li>
62-
</ul>
63-
<br>
64-
{{errorMsg}}
52+
<button ngf-select="uploadFiles($files, $invalidFiles)" multiple accept="*/*" ngf-max-height="1000" ngf-max-size="1MB">Select Files</button>
53+
<ul ng-show="isUploading()">
54+
<li ng-repeat="f in files" style="font:smaller">{{f.name}} {{f.$errorParam}}
55+
<span class="progress" ng-show="f.progress >= 0">
56+
<span style="width:{{f.progress}}%"
57+
ng-bind="f.progress + '%'"></span>
58+
</span>
59+
</li>
60+
<li ng-repeat="f in errFiles" >{{f.name}} {{f.$error}} {{f.$errorParam}}
61+
</li>
62+
</ul>
63+
<br>
64+
{{errorMsg}}
6565
</div>
6666
</div>
6767
<div ng-show="tripleGeoConfig!=null">
@@ -99,8 +99,8 @@ <h5 class="green bold">TripleGeo Configuration</h5>
9999
<label class="green bold">Target Store Type</label>
100100
</div>
101101
<div class="input-group input-group-sm col-xs-2">
102-
<select class="form-control" id="targetStore" ng-options="option for option in options.targetStore" ng-model="tripleGeoConfig.targetStore"></select>
103-
</div>
102+
<select class="form-control" id="targetStore" ng-options="option for option in options.targetStore" ng-model="tripleGeoConfig.targetStore"></select>
103+
</div>
104104
</div>
105105
<br>
106106

0 commit comments

Comments
 (0)