diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/SubmissionController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/SubmissionController.java index b1f02a39..84f500b9 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/SubmissionController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/SubmissionController.java @@ -14,6 +14,7 @@ import com.ugent.pidgeon.postgre.models.types.UserRole; import com.ugent.pidgeon.postgre.repository.*; import com.ugent.pidgeon.util.*; +import java.util.logging.Level; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; @@ -93,7 +94,10 @@ private DockerOutput runDockerTest(ZipFile file, TestEntity testEntity, Path out List artifacts = model.getArtifacts(); // filehandler copy zips - Filehandler.copyFilesAsZip(artifacts, outputPath); + if (!artifacts.isEmpty()) { + Filehandler.copyFilesAsZip(artifacts, outputPath); + } + // cleanup docker model.cleanUp(); @@ -256,14 +260,14 @@ public ResponseEntity submitFile(@RequestParam("file") MultipartFile file, @P submission.setStructureFeedback(structureTestResult.feedback); } // Check if docker tests succeed - dockerOutput = runDockerTest(new ZipFile(savedFile), testEntity, Filehandler.getSubmissionPath(projectid, groupId, submission.getId())); + dockerOutput = runDockerTest(new ZipFile(savedFile), testEntity, Filehandler.getSubmissionPath(projectid, groupId, submission.getId()).resolve("artifacts.zip")); if (dockerOutput == null) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body("Error while running docker tests."); } // Representation of dockerOutput, this will be a json(easily displayable in frontend) if it is a template test // or a string if it is a simple test - submission.setDockerFeedback(dockerOutput.toString()); + submission.setDockerFeedback(dockerOutput.getFeedbackAsString()); submission.setDockerAccepted(dockerOutput.isAllowed()); } submission.setTestFinished(true); @@ -274,6 +278,7 @@ public ResponseEntity submitFile(@RequestParam("file") MultipartFile file, @P return ResponseEntity.ok(entityToJsonConverter.getSubmissionJson(submissionEntity)); } catch (Exception e) { + Logger.getGlobal().log(Level.SEVERE, e.getMessage(), e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Error while saving file: " + e.getMessage()); } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/controllers/TestController.java b/backend/app/src/main/java/com/ugent/pidgeon/controllers/TestController.java index 173dc7d7..2712b85c 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/controllers/TestController.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/controllers/TestController.java @@ -108,6 +108,9 @@ private ResponseEntity alterTests( if (dockerTemplate != null && dockerTemplate.isBlank()) { dockerTemplate = null; } + if (structureTemplate != null && structureTemplate.isBlank()) { + structureTemplate = null; + } CheckResult> updateCheckResult = testUtil.checkForTestUpdate(projectId, user, dockerImage, null, null, httpMethod); @@ -263,8 +266,12 @@ public ResponseEntity getTestPropertyCheckAdmin(long projectId, Auth auth, Fu return ResponseEntity.status(projectCheck.getStatus()).body(projectCheck.getMessage()); } TestEntity testEntity = projectCheck.getData(); - return ResponseEntity.ok(propertyGetter.apply(testEntity)); + if (testEntity == null) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body("No tests found for project with id: " + projectId); + } + return propertyGetter.apply(testEntity) == null ? ResponseEntity.status(HttpStatus.NOT_FOUND).body("No test found") : ResponseEntity.ok(propertyGetter.apply(testEntity)); } + public ResponseEntity getTestProperty(long projectId, Auth auth, Function propertyGetter) { TestEntity testEntity = testUtil.getTestIfExists(projectId); if (testEntity == null) { diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerOutput.java b/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerOutput.java index d155b037..4fc07377 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerOutput.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerOutput.java @@ -1,5 +1,8 @@ package com.ugent.pidgeon.model.submissionTesting; +import java.util.List; + public interface DockerOutput { public boolean isAllowed(); + public String getFeedbackAsString(); } diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerTemplateTestOutput.java b/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerTemplateTestOutput.java index 610edd83..688f00c0 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerTemplateTestOutput.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerTemplateTestOutput.java @@ -20,7 +20,7 @@ public DockerTemplateTestOutput(List subtestResults, boolea this.allowed = allowed; } @Override - public String toString(){ + public String getFeedbackAsString(){ // json representation of the tests String subTestsJson = "["; for (DockerSubtestResult subtestResult : subtestResults) { diff --git a/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerTestOutput.java b/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerTestOutput.java index fd2b088f..316d9cfd 100644 --- a/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerTestOutput.java +++ b/backend/app/src/main/java/com/ugent/pidgeon/model/submissionTesting/DockerTestOutput.java @@ -15,4 +15,9 @@ public DockerTestOutput(List logs, Boolean allowed) { public boolean isAllowed() { return allowed; } + + @Override + public String getFeedbackAsString() { + return String.join("", logs); + } }