Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General: Include more information in course archive #7199

Merged
merged 22 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c9382d6
include more information for PE in course archive
tobias-lippert Sep 11, 2023
b4f3793
start implementing export changes
tobias-lippert Sep 12, 2023
cd1b2c6
finish implementation for now
tobias-lippert Sep 12, 2023
ba1c5d9
fix exercise details not included in download
tobias-lippert Sep 14, 2023
34023dc
fix remaining tests, better test archiving of PE
tobias-lippert Sep 14, 2023
6e72f1b
remove unnecessary call to schedule directory deletion
tobias-lippert Sep 14, 2023
9452f1f
Merge branch 'develop' into enhancement/archive-more-information-for-pe
tobias-lippert Sep 14, 2023
5c30d51
address max comments
tobias-lippert Sep 14, 2023
0ab4554
wrap PE export in try catch block
tobias-lippert Sep 14, 2023
9d8e097
Merge branch 'develop' into enhancement/archive-more-information-for-pe
tobias-lippert Sep 15, 2023
c33d041
fixes after merge
tobias-lippert Sep 15, 2023
e0ff895
move all services that have something to do with export to its own pa…
tobias-lippert Sep 15, 2023
d70d9a6
Merge branch 'develop' into enhancement/archive-more-information-for-pe
tobias-lippert Sep 15, 2023
f341d37
add more javadoc and make pe archival export more failsafe
tobias-lippert Sep 15, 2023
eb0ef6d
move missed classes to export package and move data export classes to…
tobias-lippert Sep 15, 2023
454ded1
make constructors public again
tobias-lippert Sep 15, 2023
91a893d
do not pull on get for now and fix directory structure
tobias-lippert Sep 15, 2023
4d754c5
make exercise directory name definitely unique
tobias-lippert Sep 15, 2023
81971b5
fix repo cloning in temp directory not working
tobias-lippert Sep 15, 2023
818f311
fix temporary directory creation
tobias-lippert Sep 15, 2023
18aaada
Merge branch 'develop' into enhancement/archive-more-information-for-pe
Sep 16, 2023
6d93acc
Merge branch 'develop' into enhancement/archive-more-information-for-pe
tobias-lippert Sep 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
tobias-lippert marked this conversation as resolved.
Show resolved Hide resolved
*/
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
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