Verified Commit 8d00e984 authored by Lukas Wiest's avatar Lukas Wiest 🚂
Browse files

refactor(model): rename result classes to not hold product name

parent 321f22be
package de.hftstuttgart.models; package de.hftstuttgart.models;
public class ModocotResult public class Result
{ {
public String name; public String name;
public int state; public int state;
......
...@@ -3,9 +3,9 @@ package de.hftstuttgart.models; ...@@ -3,9 +3,9 @@ package de.hftstuttgart.models;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class ModocotResultSummary public class ResultSummary
{ {
public long timestamp = System.currentTimeMillis() / 1000; public long timestamp = System.currentTimeMillis() / 1000;
public String globalStacktrace = null; public String globalStacktrace = null;
public Set<ModocotResult> results = new HashSet<>(); public Set<Result> results = new HashSet<>();
} }
package de.hftstuttgart.rest.v1.task; package de.hftstuttgart.rest.v1.task;
import de.hftstuttgart.models.ModocotResultSummary; import de.hftstuttgart.models.ResultSummary;
import de.hftstuttgart.utils.*; import de.hftstuttgart.utils.*;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -45,8 +45,8 @@ public class TaskUpload { ...@@ -45,8 +45,8 @@ public class TaskUpload {
} }
@RequestMapping(method = RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
public ModocotResultSummary uploadAndTestFile(@RequestParam("taskFile") MultipartFile taskFileRef, public ResultSummary uploadAndTestFile(@RequestParam("taskFile") MultipartFile taskFileRef,
@RequestParam("assignmentId") String assignmentId @RequestParam("assignmentId") String assignmentId
) throws IOException, InterruptedException { ) throws IOException, InterruptedException {
LOG.info("submission for testing received"); LOG.info("submission for testing received");
...@@ -81,7 +81,7 @@ public class TaskUpload { ...@@ -81,7 +81,7 @@ public class TaskUpload {
// run test // run test
LOG.debug("calling test execution"); LOG.debug("calling test execution");
ModocotResultSummary resultSummary = executeTestUtil.runTests(assignmentId, workDirectory); ResultSummary resultSummary = executeTestUtil.runTests(assignmentId, workDirectory);
if (mimeInfo.equals("text/plain")) { if (mimeInfo.equals("text/plain")) {
LOG.info("check for provided Ticketsystem information"); LOG.info("check for provided Ticketsystem information");
......
...@@ -3,7 +3,7 @@ package de.hftstuttgart.utils; ...@@ -3,7 +3,7 @@ package de.hftstuttgart.utils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.dockerjava.api.model.Bind; import com.github.dockerjava.api.model.Bind;
import com.github.dockerjava.api.model.Volume; import com.github.dockerjava.api.model.Volume;
import de.hftstuttgart.models.ModocotResultSummary; import de.hftstuttgart.models.ResultSummary;
import org.apache.log4j.LogManager; import org.apache.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
...@@ -44,7 +44,7 @@ public class ExecuteTestUtil { ...@@ -44,7 +44,7 @@ public class ExecuteTestUtil {
this.testTmpPathModocot = Paths.get(env.getProperty("modocot.tests.tmp.dir")); this.testTmpPathModocot = Paths.get(env.getProperty("modocot.tests.tmp.dir"));
} }
public ModocotResultSummary runTests(String assignmentId, Path workDirectory) throws IOException, InterruptedException { public ResultSummary runTests(String assignmentId, Path workDirectory) throws IOException, InterruptedException {
// define paths for the test, the submission and where the result is to be expected afterwards // define paths for the test, the submission and where the result is to be expected afterwards
Path testPath = Paths.get(workDirectory.toAbsolutePath().toString(), "test"); Path testPath = Paths.get(workDirectory.toAbsolutePath().toString(), "test");
...@@ -115,9 +115,9 @@ public class ExecuteTestUtil { ...@@ -115,9 +115,9 @@ public class ExecuteTestUtil {
LOG.debug("parse results json"); LOG.debug("parse results json");
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
ModocotResultSummary resultSummary = objectMapper.readValue( ResultSummary resultSummary = objectMapper.readValue(
resultFile.toURI().toURL(), resultFile.toURI().toURL(),
ModocotResultSummary.class); ResultSummary.class);
return resultSummary; return resultSummary;
} }
......
package de.hftstuttgart.utils; package de.hftstuttgart.utils;
import de.hftstuttgart.models.ModocotResult; import de.hftstuttgart.models.Result;
import de.hftstuttgart.models.ModocotResultSummary; import de.hftstuttgart.models.ResultSummary;
import de.hftstuttgart.unifiedticketing.core.Filter; import de.hftstuttgart.unifiedticketing.core.Filter;
import de.hftstuttgart.unifiedticketing.core.Ticket; import de.hftstuttgart.unifiedticketing.core.Ticket;
import de.hftstuttgart.unifiedticketing.core.TicketBuilder; import de.hftstuttgart.unifiedticketing.core.TicketBuilder;
...@@ -29,7 +29,7 @@ public class UnifiedTicketingUtil { ...@@ -29,7 +29,7 @@ public class UnifiedTicketingUtil {
private final static String MODOCOT_LABEL = "MoDoCoT created"; private final static String MODOCOT_LABEL = "MoDoCoT created";
private final static String MODOCOT_TITLE = " | " + MODOCOT_LABEL; private final static String MODOCOT_TITLE = " | " + MODOCOT_LABEL;
public static String createTicketDescriptionFromResult(TicketSystem ts, ModocotResult result, boolean compilationError) { public static String createTicketDescriptionFromResult(TicketSystem ts, Result result, boolean compilationError) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
// heading // heading
...@@ -73,7 +73,7 @@ public class UnifiedTicketingUtil { ...@@ -73,7 +73,7 @@ public class UnifiedTicketingUtil {
return sb.toString(); return sb.toString();
} }
public static String createTicketTitleFromResult(TicketSystem ts, ModocotResult result, boolean compilationError) { public static String createTicketTitleFromResult(TicketSystem ts, Result result, boolean compilationError) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String separator = " | "; String separator = " | ";
...@@ -97,7 +97,7 @@ public class UnifiedTicketingUtil { ...@@ -97,7 +97,7 @@ public class UnifiedTicketingUtil {
return sb.toString(); return sb.toString();
} }
public static Ticket createTicketFromResult(TicketSystem ts, ModocotResult result, boolean compilationError) { public static Ticket createTicketFromResult(TicketSystem ts, Result result, boolean compilationError) {
TicketBuilder tb = ts.createTicket() TicketBuilder tb = ts.createTicket()
.title(createTicketTitleFromResult(ts, result, compilationError)) .title(createTicketTitleFromResult(ts, result, compilationError))
.description(createTicketDescriptionFromResult(ts, result, compilationError)); .description(createTicketDescriptionFromResult(ts, result, compilationError));
...@@ -142,7 +142,7 @@ public class UnifiedTicketingUtil { ...@@ -142,7 +142,7 @@ public class UnifiedTicketingUtil {
return ret; return ret;
} }
public static String getHashForFailure(ModocotResult result) { public static String getHashForFailure(Result result) {
MessageDigest digest; MessageDigest digest;
try { try {
...@@ -166,7 +166,7 @@ public class UnifiedTicketingUtil { ...@@ -166,7 +166,7 @@ public class UnifiedTicketingUtil {
return hexString.substring(hexString.length() - 9, hexString.length() - 1); return hexString.substring(hexString.length() - 9, hexString.length() - 1);
} }
public static void processResult(TicketSystem ts, Set<Ticket> tickets, ModocotResult result, boolean compilationError) { public static void processResult(TicketSystem ts, Set<Ticket> tickets, Result result, boolean compilationError) {
LOG.debug(String.format("retrieving hash for %s", result.name)); LOG.debug(String.format("retrieving hash for %s", result.name));
String hash = getHashForFailure(result); String hash = getHashForFailure(result);
...@@ -195,7 +195,7 @@ public class UnifiedTicketingUtil { ...@@ -195,7 +195,7 @@ public class UnifiedTicketingUtil {
* @param meta student uploaded file * @param meta student uploaded file
* @param resultSummary summary from the testrunner container * @param resultSummary summary from the testrunner container
*/ */
public static void reportResults(InputStream meta, ModocotResultSummary resultSummary) { public static void reportResults(InputStream meta, ResultSummary resultSummary) {
try { try {
reportResults(meta, resultSummary, false); reportResults(meta, resultSummary, false);
} catch (InterruptedException e) { } catch (InterruptedException e) {
...@@ -212,7 +212,7 @@ public class UnifiedTicketingUtil { ...@@ -212,7 +212,7 @@ public class UnifiedTicketingUtil {
* @param wait if we should block until the ticket creation has finished * @param wait if we should block until the ticket creation has finished
* @throws InterruptedException * @throws InterruptedException
*/ */
public static void reportResults(InputStream meta, ModocotResultSummary resultSummary, boolean wait) throws InterruptedException { public static void reportResults(InputStream meta, ResultSummary resultSummary, boolean wait) throws InterruptedException {
LOG.debug("preparing thread for ticket result submitting"); LOG.debug("preparing thread for ticket result submitting");
Thread unifiedTicketingUtil = new Thread(() -> { Thread unifiedTicketingUtil = new Thread(() -> {
...@@ -257,7 +257,7 @@ public class UnifiedTicketingUtil { ...@@ -257,7 +257,7 @@ public class UnifiedTicketingUtil {
} }
} }
public static void reportToTicketsystem(TicketSystem ts, ModocotResultSummary resultSummary) { public static void reportToTicketsystem(TicketSystem ts, ResultSummary resultSummary) {
// tickets existing yet // tickets existing yet
LOG.debug("fetching existing tickets"); LOG.debug("fetching existing tickets");
Set<Ticket> tickets = fetchExistingModocotTickets(ts); Set<Ticket> tickets = fetchExistingModocotTickets(ts);
...@@ -265,18 +265,18 @@ public class UnifiedTicketingUtil { ...@@ -265,18 +265,18 @@ public class UnifiedTicketingUtil {
// for each fail or compile error // for each fail or compile error
LOG.debug("start failed tests reporting"); LOG.debug("start failed tests reporting");
resultSummary.results.stream() resultSummary.results.stream()
.filter(r -> r.state == ModocotResult.State.FAILURE.ordinal()) .filter(r -> r.state == Result.State.FAILURE.ordinal())
.forEach(f -> processResult(ts, tickets, f, false)); .forEach(f -> processResult(ts, tickets, f, false));
LOG.debug("start compilation errors reporting"); LOG.debug("start compilation errors reporting");
resultSummary.results.stream() resultSummary.results.stream()
.filter(r -> r.state == ModocotResult.State.COMPILATIONERROR.ordinal()) .filter(r -> r.state == Result.State.COMPILATIONERROR.ordinal())
.forEach(c -> processResult(ts, tickets, c, true)); .forEach(c -> processResult(ts, tickets, c, true));
LOG.debug("closing all remaining tickets, no longer appeared"); LOG.debug("closing all remaining tickets, no longer appeared");
tickets.forEach(ticket -> ticket.close().save()); tickets.forEach(ticket -> ticket.close().save());
} }
public static Ticket updateTicketFromResult(TicketSystem ts, Ticket ticket, ModocotResult result, boolean compilationError) { public static Ticket updateTicketFromResult(TicketSystem ts, Ticket ticket, Result result, boolean compilationError) {
ticket ticket
.open() .open()
.setTitle(createTicketTitleFromResult(ts, result, compilationError)) .setTitle(createTicketTitleFromResult(ts, result, compilationError))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment