Skip to content

Commit

Permalink
General: Include more information in course archive (#7199)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-lippert authored and florian-glombik committed Sep 17, 2023
1 parent 7f44443 commit 53c6ba9
Show file tree
Hide file tree
Showing 37 changed files with 694 additions and 425 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import de.tum.in.www1.artemis.security.SecurityUtils;
import de.tum.in.www1.artemis.service.dto.StudentDTO;
import de.tum.in.www1.artemis.service.exam.ExamDeletionService;
import de.tum.in.www1.artemis.service.export.CourseExamExportService;
import de.tum.in.www1.artemis.service.notifications.GroupNotificationService;
import de.tum.in.www1.artemis.service.tutorialgroups.TutorialGroupService;
import de.tum.in.www1.artemis.service.user.UserService;
Expand All @@ -71,7 +72,7 @@
public class CourseService {

@Value("${artemis.course-archives-path}")
private String courseArchivesDirPath;
private Path courseArchivesDirPath;

private final Logger log = LoggerFactory.getLogger(CourseService.class);

Expand Down Expand Up @@ -753,7 +754,7 @@ public void archiveCourse(Course course) {

try {
// Create course archives directory if it doesn't exist
Files.createDirectories(Path.of(courseArchivesDirPath));
Files.createDirectories(courseArchivesDirPath);
log.info("Created the course archives directory at {} because it didn't exist.", courseArchivesDirPath);

// Export the course to the archives' directory.
Expand Down
49 changes: 20 additions & 29 deletions src/main/java/de/tum/in/www1/artemis/service/FileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ private String moveFileIfTemporaryAndReturnPath(String path, String targetFolder
* Convert the given public file url to its corresponding local path
*
* @param publicPath the public file url to convert
* @throws FilePathParsingException if the path is unknown
* @return the actual path to that file in the local filesystem
*/
public String actualPathForPublicPathOrThrow(String publicPath) {
Expand Down Expand Up @@ -432,8 +431,8 @@ public String actualPathForPublicPath(String publicPath) {
*
* @param actualPathString the path to the file in the local filesystem
* @param entityId the id of the entity associated with the file
* @throws FilePathParsingException if the path is unknown
* @return the public file url that can be used by users to access the file from outside
* @throws FilePathParsingException if the path is unknown
*/
public String publicPathForActualPathOrThrow(String actualPathString, @Nullable Long entityId) {
String publicPath = publicPathForActualPath(actualPathString, entityId);
Expand Down Expand Up @@ -1109,15 +1108,14 @@ public void scheduleForDirectoryDeletion(Path path, long delayInMinutes) {
*/
private Path getUniquePath(Path path) {
var uniquePath = path.resolve(String.valueOf(System.currentTimeMillis()));
if (!Files.exists(uniquePath) && Files.isDirectory(uniquePath)) {
if (!Files.exists(uniquePath) && Files.isDirectory(path)) {
try {
Files.createDirectories(uniquePath);
return Files.createDirectories(uniquePath);
}
catch (IOException e) {
log.warn("could not create the directories for the path {}", uniquePath);
}
}

return uniquePath;
}

Expand All @@ -1134,6 +1132,21 @@ public Path getTemporaryUniquePath(Path path, long deleteDelayInMinutes) {
return temporaryPath;
}

/**
* Create a unique path by appending a folder named with the current milliseconds (e.g. 1609579674868) of the system but does not create the folder.
* This is used when cloning the programming exercises into a new temporary directory because if we already create the directory, the git clone does not work anymore.
* The directory will be scheduled for deletion.
*
* @param path the original path, e.g. /opt/artemis/repos-download
* @param deleteDelayInMinutes the delay in minutes after which the path should be deleted
* @return the unique path, e.g. /opt/artemis/repos-download/1609579674868
*/
public Path getTemporaryUniquePathWithoutPathCreation(Path path, long deleteDelayInMinutes) {
var temporaryPath = path.resolve(String.valueOf(System.currentTimeMillis()));
scheduleForDirectoryDeletion(temporaryPath, deleteDelayInMinutes);
return temporaryPath;
}

/**
* create a directory at a given path
*
Expand All @@ -1149,23 +1162,6 @@ public void createDirectory(Path path) {
}
}

/**
* Write a given string into a file at a given path
*
* @param stringToWrite The string that will be written into a file
* @param path The path where the file will be written to
* @return Path to the written file
*/
public Path writeStringToFile(String stringToWrite, Path path) {
try (var outStream = new OutputStreamWriter(new FileOutputStream(path.toString()), UTF_8)) {
outStream.write(stringToWrite);
}
catch (IOException e) {
log.warn("Could not write given string in file {}.", path);
}
return path;
}

/**
* Serialize an object and write into file at a given path
*
Expand All @@ -1174,13 +1170,8 @@ public Path writeStringToFile(String stringToWrite, Path path) {
* @param path The path where the file will be written to
* @return Path to the written file
*/
public Path writeObjectToJsonFile(Object object, ObjectMapper objectMapper, Path path) {
try {
objectMapper.writeValue(path.toFile(), object);
}
catch (IOException e) {
log.warn("Could not write given object in file {}", path);
}
public Path writeObjectToJsonFile(Object object, ObjectMapper objectMapper, Path path) throws IOException {
objectMapper.writeValue(path.toFile(), object);
return path;
}

Expand Down
12 changes: 0 additions & 12 deletions src/main/java/de/tum/in/www1/artemis/service/ZipFileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ public void createTemporaryZipFile(Path zipFilePath, List<Path> paths, long dele
fileService.scheduleForDeletion(zipFilePath, deleteDelayInMinutes);
}

/**
* Create a zip file of the given paths and save it in the zipFilePath
*
* @param zipFilePath path where the zip file should be saved
* @param paths multiple paths that should be zipped
* @param pathsRoot the root path relative to <code>paths</code>
* @throws IOException if an error occurred while zipping
*/
public void createZipFile(Path zipFilePath, List<Path> paths, Path pathsRoot) throws IOException {
createZipFileFromPathStream(zipFilePath, paths.stream(), pathsRoot, null);
}

/**
* Recursively include all files in contentRootPath and create a zip file 'zipFileName' in the folder 'zipFileFolderName'
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import de.tum.in.www1.artemis.security.SecurityUtils;
import de.tum.in.www1.artemis.service.*;
import de.tum.in.www1.artemis.service.connectors.GitService;
import de.tum.in.www1.artemis.service.export.CourseExamExportService;
import de.tum.in.www1.artemis.service.messaging.InstanceMessageSendService;
import de.tum.in.www1.artemis.service.notifications.GroupNotificationService;
import de.tum.in.www1.artemis.service.plagiarism.PlagiarismCaseService.PlagiarismMapping;
Expand All @@ -62,7 +63,7 @@ public class ExamService {
private static final int EXAM_ACTIVE_DAYS = 7;

@Value("${artemis.course-archives-path}")
private String examArchivesDirPath;
private Path examArchivesDirPath;

private final Logger log = LoggerFactory.getLogger(ExamService.class);

Expand Down Expand Up @@ -1202,7 +1203,7 @@ public void archiveExam(Exam exam) {

try {
// Create exam archives directory if it doesn't exist
Files.createDirectories(Path.of(examArchivesDirPath));
Files.createDirectories(examArchivesDirPath);
log.info("Created the exam archives directory at {} because it didn't exist.", examArchivesDirPath);

// Export the exam to the archives directory.
Expand Down
Loading

0 comments on commit 53c6ba9

Please sign in to comment.