Skip to content

Commit df7747c

Browse files
committed
Set dates server side
1 parent b0b8dc7 commit df7747c

File tree

3 files changed

+45
-8
lines changed

3 files changed

+45
-8
lines changed

server/src/main/java/org/diskproject/server/api/impl/DiskResource.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,18 @@ public String reloadVocabularies() {
9898
@Override
9999
public Hypothesis addHypothesis(
100100
@JsonProperty("hypothesis") Hypothesis hypothesis) {
101+
102+
String username = (String) request.getAttribute("username");
103+
if (username != null) {
104+
hypothesis.setAuthor(username);
105+
}
101106
return this.repo.addHypothesis(USERNAME, hypothesis);
102107
}
103108

104109
@GET
105110
@Path("hypotheses")
106111
@Override
107112
public List<TreeItem> listHypotheses() {
108-
String username = (String) request.getAttribute("username");
109-
System.out.println( "user: " + username);
110113
return this.repo.listHypotheses(USERNAME);
111114
}
112115

@@ -124,6 +127,10 @@ public Hypothesis getHypothesis(
124127
public Hypothesis updateHypothesis(
125128
@PathParam("id") String id,
126129
@JsonProperty("hypothesis") Hypothesis hypothesis) {
130+
String username = (String) request.getAttribute("username");
131+
if (username != null) {
132+
hypothesis.setAuthor(username);
133+
}
127134
return this.repo.updateHypothesis(USERNAME, id, hypothesis);
128135
}
129136

@@ -185,6 +192,11 @@ public void updateAssertions (
185192
@Override
186193
public LineOfInquiry addLOI(
187194
@JsonProperty("loi") LineOfInquiry loi) {
195+
196+
String username = (String) request.getAttribute("username");
197+
if (username != null) {
198+
loi.setAuthor(username);
199+
}
188200
return this.repo.addLOI(USERNAME, loi);
189201
}
190202

@@ -209,6 +221,10 @@ public LineOfInquiry getLOI(
209221
public LineOfInquiry updateLOI(
210222
@PathParam("id") String id,
211223
@JsonProperty("loi") LineOfInquiry loi) {
224+
String username = (String) request.getAttribute("username");
225+
if (username != null) {
226+
loi.setAuthor(username);
227+
}
212228
return this.repo.updateLOI(USERNAME, id, loi);
213229
}
214230

server/src/main/java/org/diskproject/server/filters/KeycloakAuthenticationFilter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public void filter(ContainerRequestContext requestContext) throws IOException {
3636
String token = requestContext.getHeaderString("authorization");
3737
if (token != null) {
3838
KeycloakUser user = KeycloakSessions.getKeycloakUser(token);
39-
if (user != null && user.username != null)
39+
if (user != null && user.username != null) {
4040
requestContext.setProperty("username", user.username);
41+
//System.out.println("Token received: " + user.username);
42+
}
4143
else
4244
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).entity("Access denied").build());
4345
}

server/src/main/java/org/diskproject/server/repository/DiskRepository.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class DiskRepository extends WriteKBRepository {
6666
static DiskRepository singleton;
6767
private static boolean creatingKB = false;
6868

69-
private static SimpleDateFormat dateformatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
69+
private static SimpleDateFormat dateformatter = new SimpleDateFormat("HH:mm:ss yyyy-MM-dd");
7070
Pattern varPattern = Pattern.compile("\\?(.+?)\\b");
7171
Pattern varCollPattern = Pattern.compile("\\[\\s*\\?(.+?)\\s*\\]");
7272

@@ -525,6 +525,14 @@ public Hypothesis addHypothesis (String username, Hypothesis hypothesis) {
525525
String name = hypothesis.getName();
526526
String desc = hypothesis.getDescription();
527527
String question = hypothesis.getQuestion();
528+
String dateCreated = hypothesis.getDateCreated();
529+
if (dateCreated == null || dateCreated.equals("")) {
530+
//SET DATE
531+
hypothesis.setDateCreated(dateformatter.format(new Date()));
532+
} else {
533+
//Update date
534+
hypothesis.setDateModified(dateformatter.format(new Date()));
535+
}
528536
if (name != null && desc != null && question != null && !name.equals("") && !desc.equals("") && !question.equals("")) {
529537
String id = hypothesis.getId();
530538
if (id == null || id.equals("")) // Create new Hypothesis ID
@@ -577,6 +585,14 @@ public LineOfInquiry addLOI(String username, LineOfInquiry loi) {
577585
String name = loi.getName();
578586
String desc = loi.getDescription();
579587
String question = loi.getQuestion();
588+
String dateCreated = loi.getDateCreated();
589+
if (dateCreated == null || dateCreated.equals("")) {
590+
//SET DATE
591+
loi.setDateCreated(dateformatter.format(new Date()));
592+
} else {
593+
//Update date
594+
loi.setDateModified(dateformatter.format(new Date()));
595+
}
580596
if (name != null && desc != null && question != null &&
581597
!name.equals("") && !desc.equals("") && !question.equals("") &&
582598
writeLOI(username, loi)
@@ -1137,6 +1153,7 @@ public List<TriggeredLOI> queryHypothesis(String username, String id) {
11371153
tloi.setMetaWorkflows(
11381154
this.getTLOIBindings(username, loi.getMetaWorkflows(), dataVarBindings, endpoint));
11391155
tloi.setDataQuery(dq);
1156+
tloi.setDateCreated(dateformatter.format(new Date()));
11401157
tloi.setRelevantVariables(loi.getRelevantVariables());
11411158
tloi.setExplanation(loi.getExplanation());
11421159
tlois.add(tloi);
@@ -1554,7 +1571,6 @@ public void deleteAssertion(String username, Graph assertion) {
15541571

15551572
public Map<String, String> getNarratives (String username, String tloid) {
15561573
Map<String,String> narratives = new HashMap<String, String>();
1557-
//if (true) return narratives;
15581574
TriggeredLOI tloi = this.getTriggeredLOI(username, tloid);
15591575
if (tloi != null) {
15601576
String hypId = tloi.getParentHypothesisId();
@@ -1594,7 +1610,6 @@ public Map<String, String> getNarratives (String username, String tloid) {
15941610
len = ds.getBindingAsArray().length > len ? ds.getBindingAsArray().length : len;
15951611
}
15961612
if (allCollections) {
1597-
//dataset += "<table>";
15981613
dataset += "<table><thead><tr><td><b>#</b></td>";
15991614
for (VariableBinding ds: wf.getBindings()) {
16001615
dataset += "<td><b>" + ds.getVariable() + "</b></td>";
@@ -1636,6 +1651,11 @@ public Map<String, String> getNarratives (String username, String tloid) {
16361651

16371652
String pval = df.format(confidence);
16381653
//Execution narratives
1654+
//String executionTemplate = "The Hypothesis with title: <b>${HYP.NAME}</b> was runned <span class=\"${TLOI.STATUS}\">${TLOI.STATUS}</span>"
1655+
// + "with the Line of Inquiry: <b>${LOI.NAME}"</b>."
1656+
// + "The LOI triggered the <a target=\"_blank\" href="{WF.getWorkflowLink()}">workflow on WINGS</a>"
1657+
// + " where it was tested with the following datasets:<div class=\"data-list\"><ol> ${[WF.getInputFiles]}"
1658+
// + "</ol></div>The resulting p-value is $(tloi.pval).";
16391659
String execution = "The Hypothesis with title: <b>" + hyp.getName()
16401660
+ "</b> was runned <span class=\"" + tloi.getStatus() + "\">"
16411661
+ tloi.getStatus() + "</span>"
@@ -1751,8 +1771,7 @@ public List<TriggeredLOI> runHypothesisAndLOI (String username, String hypid, St
17511771
//Set basic metadata
17521772
tloi.setAuthor("System");
17531773
Date date = new Date();
1754-
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss yyyy-MM-dd");
1755-
tloi.setDateCreated(formatter.format(date));
1774+
tloi.setDateCreated(dateformatter.format(date));
17561775
addTriggeredLOI(username, tloi);
17571776
//match = tloi;
17581777
break;

0 commit comments

Comments
 (0)