-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logic to handle task source history. Starting without any storage…
… yet.
- Loading branch information
1 parent
254d328
commit 82412ac
Showing
12 changed files
with
236 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package core.userDefinedTask.internals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** Contains information about the source history of a task. */ | ||
public class TaskSourceHistory { | ||
|
||
private List<TaskSourceHistoryEntry> entries; | ||
|
||
public TaskSourceHistory() { | ||
this.entries = new ArrayList<>(); | ||
} | ||
|
||
/** | ||
* Finds a particular entry given the timestamp. | ||
* | ||
* @param timestamp the timestamp to find the entry for. | ||
* @return the found entry, or null if no entry was found. | ||
*/ | ||
public TaskSourceHistoryEntry findEntry(long timestamp) { | ||
for (TaskSourceHistoryEntry entry : entries) { | ||
if (entry.getCreated().getTimeInMillis() == timestamp) { | ||
return entry; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
// Adds a single entry to the history. | ||
public void addEntry(TaskSourceHistoryEntry entry) { | ||
this.entries.add(entry); | ||
} | ||
|
||
/// Adds all history to this history. | ||
public void addHistory(TaskSourceHistory history) { | ||
entries.addAll(history.entries); | ||
entries.sort((e1, e2) -> e2.getCreated().compareTo(e1.getCreated())); | ||
} | ||
|
||
// Returns the list of entries sorted in reverse chronological order. | ||
public List<TaskSourceHistoryEntry> getEntries() { | ||
return entries.stream().sorted((e1, e2) -> e2.getCreated().compareTo(e1.getCreated())).collect(Collectors.toList()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/core/userDefinedTask/internals/TaskSourceHistoryEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package core.userDefinedTask.internals; | ||
|
||
import java.util.Calendar; | ||
|
||
/** Holds a single entry of source history. */ | ||
public class TaskSourceHistoryEntry { | ||
private String sourcePath; | ||
private Calendar created; | ||
|
||
private TaskSourceHistoryEntry(String sourcePath, Calendar created) { | ||
this.sourcePath = sourcePath; | ||
this.created = created; | ||
} | ||
|
||
public static TaskSourceHistoryEntry of(String path) { | ||
return new TaskSourceHistoryEntry(path, Calendar.getInstance()); | ||
} | ||
|
||
public String getSourcePath() { | ||
return sourcePath; | ||
} | ||
|
||
public Calendar getCreated() { | ||
return created; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/core/webui/server/handlers/internals/tasks/GetTaskSourceHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package core.webui.server.handlers.internals.tasks; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
import org.apache.http.HttpException; | ||
import org.apache.http.HttpRequest; | ||
import org.apache.http.nio.protocol.HttpAsyncExchange; | ||
import org.apache.http.protocol.HttpContext; | ||
|
||
import core.userDefinedTask.UserDefinedAction; | ||
import core.webui.server.handlers.AbstractSingleMethodHttpHandler; | ||
import core.webui.webcommon.HttpServerUtilities; | ||
|
||
public class GetTaskSourceHandler extends AbstractSingleMethodHttpHandler { | ||
|
||
public GetTaskSourceHandler() { | ||
super(AbstractSingleMethodHttpHandler.GET_METHOD); | ||
} | ||
|
||
@Override | ||
protected Void handleAllowedRequestWithBackend(HttpRequest request, HttpAsyncExchange exchange, HttpContext context) | ||
throws HttpException, IOException { | ||
String uriString = request.getRequestLine().getUri(); | ||
Map<String, String> params = HttpServerUtilities.parseGetParameters(uriString); | ||
if (params == null) { | ||
return HttpServerUtilities.prepareHttpResponse(exchange, 500, "Failed to parse URL " + uriString); | ||
} | ||
|
||
String id = params.get("id"); | ||
if (id == null || id.isEmpty()) { | ||
return HttpServerUtilities.prepareHttpResponse(exchange, 400, "Task ID is empty or not provided."); | ||
} | ||
|
||
String timestampString = params.get("timestamp"); | ||
if (timestampString == null || timestampString.isEmpty()) { | ||
return HttpServerUtilities.prepareHttpResponse(exchange, 400, "Timestamp is empty or not provided."); | ||
} | ||
|
||
UserDefinedAction action = backEndHolder.getTask(id); | ||
if (action == null) { | ||
return HttpServerUtilities.prepareHttpResponse(exchange, 404, "No action for ID " + id + "."); | ||
} | ||
|
||
Long timestamp = Long.parseLong(timestampString); | ||
String sourceCode = backEndHolder.getSourceForTask(action, timestamp); | ||
if (sourceCode == null) { | ||
return HttpServerUtilities.prepareHttpResponse(exchange, 500, "No source code found for task " + id + "."); | ||
} | ||
|
||
return HttpServerUtilities.prepareTextResponse(exchange, 200, sourceCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/core/webui/server/handlers/renderedobjects/RenderedTaskSourceHistory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package core.webui.server.handlers.renderedobjects; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import core.userDefinedTask.internals.TaskSourceHistory; | ||
|
||
public class RenderedTaskSourceHistory { | ||
|
||
private List<RenderedTaskSourceHistoryEntry> entries; | ||
|
||
public static RenderedTaskSourceHistory of(String taskId, TaskSourceHistory history) { | ||
RenderedTaskSourceHistory result = new RenderedTaskSourceHistory(); | ||
result.entries = history.getEntries().stream().map(e -> RenderedTaskSourceHistoryEntry.of(taskId, e)).collect(Collectors.toList()); | ||
return result; | ||
} | ||
|
||
public List<RenderedTaskSourceHistoryEntry> getEntries() { | ||
return entries; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/core/webui/server/handlers/renderedobjects/RenderedTaskSourceHistoryEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package core.webui.server.handlers.renderedobjects; | ||
|
||
import core.userDefinedTask.internals.TaskSourceHistoryEntry; | ||
import utilities.DateUtility; | ||
|
||
public class RenderedTaskSourceHistoryEntry { | ||
private String taskId; | ||
private String createdTime; | ||
private String createdTimeMillis; | ||
|
||
public static RenderedTaskSourceHistoryEntry of(String taskId, TaskSourceHistoryEntry entry) { | ||
RenderedTaskSourceHistoryEntry result = new RenderedTaskSourceHistoryEntry(); | ||
result.taskId = taskId; | ||
result.createdTime = DateUtility.calendarToTimeString(entry.getCreated()); | ||
result.createdTimeMillis = entry.getCreated().getTimeInMillis() + ""; | ||
return result; | ||
} | ||
|
||
public String getTaskId() { | ||
return taskId; | ||
} | ||
public String getCreatedTime() { | ||
return createdTime; | ||
} | ||
public String getCreatedTimeMillis() { | ||
return createdTimeMillis; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/staticContent/webui/templates/fragments/task_source_history.ftlh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<#macro fragment> | ||
<#if task.hasSourceHistory == "true"> | ||
<h1> Source history </h1> | ||
<table> | ||
<tbody> | ||
<#list task.sourceHistory.entries as entry> | ||
<tr> | ||
<td><a href="/internals/get/task-source?id=${entry.taskId}×tamp=${entry.createdTimeMillis}"> ${entry.createdTime} </a></td> | ||
</tr> | ||
</#list> | ||
</tbody> | ||
</table> | ||
</#if> | ||
</#macro> | ||
|
||
<@fragment/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters