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

Commit 11deb0e

Browse files
committed
integrated contribution update to limes and import, fixed several bugs in coev
1 parent 0567296 commit 11deb0e

File tree

31 files changed

+317
-163
lines changed

31 files changed

+317
-163
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
<artifactId>tomcat7-maven-plugin</artifactId>
206206
<version>2.2</version>
207207
<configuration>
208-
<server>localhost</server>
208+
<server>generator</server>
209209
<url>${tomcat.deploy.url}</url>
210210
<path>/${project.build.finalName}</path>
211211
<update>true</update>

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

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

3+
import org.hibernate.validator.constraints.NotEmpty;
4+
35

46
/**
57
* This bean is for adding information about the changes made to a graph
@@ -9,9 +11,12 @@
911
*/
1012
public class Contribution {
1113

14+
@NotEmpty
1215
private String namedGraph;
1316
private String date;
17+
@NotEmpty
1418
private String source;
19+
@NotEmpty
1520
private String contributor;
1621

1722

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

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import java.io.OutputStream;
66
import java.io.OutputStreamWriter;
77
import java.io.Writer;
8+
import java.text.SimpleDateFormat;
89
import java.util.ArrayList;
10+
import java.util.Calendar;
11+
import java.util.GregorianCalendar;
912
import java.util.Iterator;
1013
import java.util.List;
1114
import java.util.Map.Entry;
@@ -46,11 +49,15 @@
4649

4750
import com.fasterxml.jackson.databind.JsonNode;
4851
import com.fasterxml.jackson.databind.ObjectMapper;
52+
import com.google.gson.Gson;
4953
import com.google.gson.JsonObject;
5054
import com.ontos.ldiw.vocabulary.LDIWO;
5155

5256
import eu.geoknow.generator.configuration.FrameworkConfiguration;
5357
import eu.geoknow.generator.exceptions.InformationMissingException;
58+
import eu.geoknow.generator.graphs.GraphsManager;
59+
import eu.geoknow.generator.graphs.beans.Contribution;
60+
import eu.geoknow.generator.graphs.beans.NamedGraph;
5461
import eu.geoknow.generator.rdf.SecureRdfStoreManagerImpl;
5562
import eu.geoknow.generator.users.FrameworkUserManager;
5663
import eu.geoknow.generator.users.UserProfile;
@@ -148,31 +155,14 @@ public Response post(@PathParam("sessionToken") String sessionToken, @Context Ur
148155
MultivaluedMap<String, String> formParams) throws Exception {
149156

150157
String username = "";
151-
/*
152-
* retrieves form user that created that session and the rdfUser and paswword for that user
153-
*/
154158
try {
155-
String query =
156-
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" + "\n" + "SELECT ?user FROM <"
157-
+ sessionsGraph + "> WHERE { ?user " + " <" + LDIWO.sessionToken + "> \""
158-
+ sessionToken + "\"^^xsd:string .}";
159-
160-
String result = frameworkRdfStoreManager.execute(query, jsonResponseFormat);
161-
162-
ObjectMapper mapper = new ObjectMapper();
163-
JsonNode rootNode = mapper.readTree(result);
164-
Iterator<JsonNode> bindingsIter = rootNode.path("results").path("bindings").elements();
165-
166-
if (bindingsIter.hasNext()) {
167-
JsonNode bindingNode = bindingsIter.next();
168-
username = bindingNode.get("user").path("value").textValue();
169-
}
170-
159+
username = getUser(sessionToken);
171160
} catch (Exception e) {
172161
log.error(e);
173162
e.printStackTrace();
174163
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
175164
}
165+
176166
log.debug("user:" + username + "-");
177167
if (username.equals(""))
178168
return Response.status(Response.Status.NOT_FOUND).build();
@@ -223,6 +213,30 @@ public void write(OutputStream os) throws IOException, WebApplicationException {
223213

224214
}
225215

216+
private String getUser(String sessionToken) throws Exception {
217+
/*
218+
* retrieves form user that created that session and the rdfUser and paswword for that user
219+
*/
220+
String username = "";
221+
String query =
222+
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" + "\n" + "SELECT ?user FROM <"
223+
+ sessionsGraph + "> WHERE { ?user " + " <" + LDIWO.sessionToken + "> \""
224+
+ sessionToken + "\"^^xsd:string .}";
225+
226+
String result = frameworkRdfStoreManager.execute(query, jsonResponseFormat);
227+
228+
ObjectMapper mapper = new ObjectMapper();
229+
JsonNode rootNode = mapper.readTree(result);
230+
Iterator<JsonNode> bindingsIter = rootNode.path("results").path("bindings").elements();
231+
232+
if (bindingsIter.hasNext()) {
233+
JsonNode bindingNode = bindingsIter.next();
234+
username = bindingNode.get("user").path("value").textValue();
235+
}
236+
return username;
237+
238+
}
239+
226240
@DELETE
227241
@Path("{sessionToken}")
228242
public Response delete(@PathParam("sessionToken") String sessionToken, @CookieParam(
@@ -257,4 +271,55 @@ public Response delete(@PathParam("sessionToken") String sessionToken, @CookiePa
257271

258272
return Response.status(Response.Status.NO_CONTENT).build();
259273
}
274+
275+
/**
276+
* Update the metadata of a contributiuon
277+
*
278+
* @param sessionToken
279+
* @param userc
280+
* @param token
281+
* @return
282+
*/
283+
@PUT
284+
@Path("{sessionToken}")
285+
public Response addContribution(@PathParam("sessionToken") String sessionToken,
286+
Contribution contribution) {
287+
288+
/*
289+
* Check that the session exists
290+
*/
291+
String username = "";
292+
try {
293+
username = getUser(sessionToken);
294+
} catch (Exception e) {
295+
log.error(e);
296+
e.printStackTrace();
297+
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
298+
}
299+
300+
log.debug("user:" + username + "-");
301+
if (username.equals(""))
302+
return Response.status(Response.Status.UNAUTHORIZED).build();
303+
304+
try {
305+
if (contribution.getDate() == null) {
306+
// 2015-06-12T14:35:00
307+
Calendar cal = GregorianCalendar.getInstance();
308+
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
309+
format.setCalendar(cal);
310+
contribution.setDate(format.format(cal.getTime()));
311+
}
312+
GraphsManager manager = new GraphsManager();
313+
NamedGraph graph = manager.addContribution(contribution);
314+
315+
Gson gson = new Gson();
316+
String json = "{ \"namedgraph\" : " + gson.toJson(graph) + "}";
317+
return Response.status(Response.Status.OK).entity(json).type(MediaType.APPLICATION_JSON)
318+
.build();
319+
320+
} catch (Exception e) {
321+
log.error(e);
322+
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
323+
}
324+
}
260325
}

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

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

33
import java.io.IOException;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Calendar;
46
import java.util.Collection;
7+
import java.util.GregorianCalendar;
58
import java.util.HashMap;
69
import java.util.Iterator;
710
import java.util.List;
@@ -183,6 +186,13 @@ public Response addContribution(@CookieParam(value = "user") Cookie userc, @Cook
183186
}
184187

185188
try {
189+
if (contribution.getDate() == null) {
190+
// 2015-06-12T14:35:00
191+
Calendar cal = GregorianCalendar.getInstance();
192+
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
193+
format.setCalendar(cal);
194+
contribution.setDate(format.format(cal.getTime()));
195+
}
186196
GraphsManager manager = new GraphsManager();
187197
NamedGraph graph = manager.addContribution(contribution);
188198

src/main/java/eu/geoknow/generator/workflow/BatchAdminClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public class BatchAdminClient {
6767
/**
6868
* Retrieves the execution detail of an execution.
6969
*
70+
*
71+
* http://generator.geoknow.eu:8080/spring-batch-admin-geoknow/jobs/executions/0.json?
72+
*
7073
* @param jobName name of the job
7174
* @param executionNum number of the job execution it is not the ID
7275
* @param springBatchServiceUri the URI of Spring Batch Admin
@@ -80,9 +83,11 @@ public static JobExecutionWrapper getExecutionDetail(String jobName, String exec
8083
IOException, ServiceNotAvailableException, ServiceInternalServerError {
8184
// first, we need to get the resource with ID. the URI is:
8285
// http://localhost:8080/spring-batch-admin-geoknow/jobs/jobName/execNumber.json
86+
log.debug(springBatchServiceUri + "/jobs/" + jobName + "/" + executionNum + ".json");
8387
HttpGet jobInstance =
8488
new HttpGet(springBatchServiceUri + "/jobs/" + jobName + "/" + executionNum + ".json");
8589
String jsonString = apiRequest(jobInstance);
90+
log.debug(jsonString);
8691
// create Java object
8792
ObjectMapper mapper = new ObjectMapper();
8893
JobInstanceWrapper jobInst = mapper.readValue(jsonString, JobInstanceWrapper.class);

src/main/java/eu/geoknow/generator/workflow/JobsManager.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ public List<Registration> getUserJobs(UserProfile user) throws Exception {
122122
+ "> ?targetGraph ;" + "<" + LDIWO.xmlDefinition.getURI() + "> ?xml . " + "}";
123123
log.debug(query);
124124

125-
String result =
126-
frameworkRdfStoreManager.execute(query, MediaType.SPARQL_JSON_RESPONSE_FORMAT);
125+
String result = frameworkRdfStoreManager.execute(query, MediaType.SPARQL_JSON_RESPONSE_FORMAT);
127126
log.debug(result);
128127
ObjectMapper mapper = new ObjectMapper();
129128
JsonNode rootNode = mapper.readTree(result);
@@ -306,8 +305,7 @@ public Registration getJob(String jobName, UserProfile user) throws Exception {
306305
+ "> ?created }";
307306
log.debug(query);
308307

309-
String result =
310-
frameworkRdfStoreManager.execute(query, MediaType.SPARQL_JSON_RESPONSE_FORMAT);
308+
String result = frameworkRdfStoreManager.execute(query, MediaType.SPARQL_JSON_RESPONSE_FORMAT);
311309
log.debug(result);
312310
ObjectMapper mapper = new ObjectMapper();
313311
JsonNode rootNode = mapper.readTree(result);
@@ -335,7 +333,7 @@ public JobExecutions getExcecutions(Registration job) throws IOException, Except
335333

336334
if (job.getJobInstances().size() > 0) {
337335
Set<Integer> instances = job.getJobInstances().keySet();
338-
log.debug(instances.size() + "instances ");
336+
log.debug(instances.size() + " instances ");
339337
Iterator<Integer> it = instances.iterator();
340338

341339
while (it.hasNext()) {
@@ -418,8 +416,7 @@ private boolean jobExist(String jobName, String userUri) throws IOException, Exc
418416
"ASK { GRAPH <" + jobsGraph + "> {<" + uriBase + jobName + "> <" + DCTerms.creator.getURI()
419417
+ "> <" + userUri + "> }}";
420418
log.debug(query);
421-
String result =
422-
frameworkRdfStoreManager.execute(query, MediaType.SPARQL_JSON_RESPONSE_FORMAT);
419+
String result = frameworkRdfStoreManager.execute(query, MediaType.SPARQL_JSON_RESPONSE_FORMAT);
423420

424421
ObjectMapper mapper = new ObjectMapper();
425422
JsonNode rootNode = mapper.readTree(result);

src/main/resources/framework-components.ttl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
a lds:StorageService ;
3131
rdfs:label "Virtuoso Conductor" ;
3232
lds:password "dba"^^xsd:string ;
33-
lds:serviceUrl <http://192.168.2.22:8890/conductor> ;
34-
lds:connectionString "jdbc:virtuoso://192.168.2.22:1111/"^^xsd:string;
33+
lds:serviceUrl <http://localhost:8890/conductor> ;
34+
lds:connectionString "jdbc:virtuoso://localhost:1111/"^^xsd:string;
3535
lds:user "dba"^^xsd:string .
3636

3737
# #######################################################################################
@@ -42,15 +42,15 @@
4242
a lds:SecuredSPARQLEndPointService;
4343
rdfs:label "Virtuoso Auth-SPARQLEndpoint" ;
4444
lds:password "generator"^^xsd:string ;
45-
lds:serviceUrl <http://192.168.2.22:8890/sparql-auth> ;
46-
void:sparqlEndpoint <http://192.168.2.22:8890/sparql-auth> ;
45+
lds:serviceUrl <http://localhost:8890/sparql-auth> ;
46+
void:sparqlEndpoint <http://localhost:8890/sparql-auth> ;
4747
lds:user "generator"^^xsd:string .
4848

4949
:VirtuosoEndpoint
5050
a lds:SPARQLEndPointService;
5151
rdfs:label "Virtuoso Public Endpoint" ;
52-
void:sparqlEndpoint <http://192.168.2.22:8890/sparql-auth> ;
53-
lds:serviceUrl <http://192.168.2.22:8890/sparql> .
52+
void:sparqlEndpoint <http://localhost:8890/sparql-auth> ;
53+
lds:serviceUrl <http://localhost:8890/sparql> .
5454

5555
:SpringBatch
5656
a lds:StackComponent ;
@@ -64,7 +64,7 @@
6464
rdfs:label "SpringBatch" ;
6565
dcterms:description "Provides functionality to create scheduled jobs and workflows."^^xsd:string ;
6666
lds:serviceUrl <http://localhost:8080/spring-batch-admin-geoknow/> ;
67-
ontos:springBatchAdminJobsDir "/Users/alejandragarciarojas/Services/tomcat/webapps/spring-batch-admin-geoknow/WEB-INF/classes/META-INF/batch-jobs/"^^xsd:string .
67+
ontos:springBatchAdminJobsDir "/var/generator/jobs/"^^xsd:string .
6868

6969
:RdfImport
7070
a lds:StackComponent ;

src/main/webapp/index.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,27 @@
7070
</li>
7171
</ul>
7272

73-
7473
<ul class="nav navbar-nav navbar-right">
7574

76-
7775
<li class="navbar-text" ng-if="isUserAuthenticated() && $root.isSystemSetUp">
7876
Logged in as <strong>{{currentAccount.username}}</strong>
7977
</li>
8078

8179
<li ng-if="isUserAuthenticated() && $root.isSystemSetUp">
82-
<a href="" ng-click="logout()">
80+
<a href="" ng-click="logout()">
8381
<div class="glyphicon glyphicon-log-out"></div>Logout</a>
8482
</li>
8583

8684
<li ng-if="!isUserAuthenticated() && $root.isSystemSetUp">
87-
<a href="" ng-click="signUp()">
88-
<div class="glyphicon glyphicon-log-in"></div> Sing Up </a>
85+
<a href="" ng-click="signUp()">Sing Up </a>
8986
</li>
9087

9188

9289
<li ng-if="!isUserAuthenticated() && $root.isSystemSetUp">
9390
<a href="" ng-click="login()">
9491
<div class="glyphicon glyphicon-log-in"></div> Log In </a>
9592
</li>
96-
</ul>
93+
</ul>
9794
</div><!-- /.navbar-collapse -->
9895
</div><!-- /.container-fluid -->
9996
</nav>

src/main/webapp/js/app.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ app.config(function($routeSegmentProvider, $routeProvider)
8181
resolve: {
8282
settings : function (ConfigurationService){
8383
return ConfigurationService.getSettings();
84+
},
85+
CoevolutionServiceInit : function(CoevolutionService){
86+
return CoevolutionService.promise;
8487
}
85-
// }
86-
// userInfo : function(UsersService) {
87-
// return UsersService.readUserNamesEmails();
88-
// }
8988
}
9089
})
9190
.within()

src/main/webapp/js/controllers.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ function StackMenuCtrl($scope, AccountService, ConfigurationService, Ns) {
2323

2424
ConfigurationService.getIntegratedComponents().then(
2525
function(resp){
26-
console.log(resp);
2726
var tools = resp.integrated;
2827
for(var i in tools){
2928
var category = tools[i].type.replace("http://stack.linkeddata.org/ldis-schema/",'');
@@ -34,7 +33,6 @@ function StackMenuCtrl($scope, AccountService, ConfigurationService, Ns) {
3433
requiredServices:[] };
3534
categoryToMenu[category].items.push(item);
3635
}
37-
console.log(categoryToMenu);
3836

3937
$scope.groups = [];
4038
for(var i in categoryToMenu)

0 commit comments

Comments
 (0)