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

Development: Migrate file URL paths for various entities #10433

Open
wants to merge 128 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
0f75072
migrate assessment module rest path prefixes
ole-ve Feb 26, 2025
81e4287
remove "DONE" - comments
ole-ve Feb 26, 2025
f408890
migrate athena module rest path prefixes
ole-ve Feb 26, 2025
aeb3ca5
migrate atlas module rest path prefixes
ole-ve Feb 26, 2025
ca46817
fix some paths regarding assessment endpoints
ole-ve Feb 26, 2025
e839e09
temporarily add request matchers for old-styled admin and public endp…
ole-ve Feb 26, 2025
86a3d06
migrate communication module rest path prefixes
ole-ve Feb 26, 2025
aa43dcb
fix some atlas path
ole-ve Feb 26, 2025
9ae2a94
migrate core module rest path prefixes
ole-ve Feb 26, 2025
d13e105
fix some smaller path issues
ole-ve Feb 26, 2025
8fdf12a
migrate exam module rest path prefixes
ole-ve Feb 26, 2025
496209c
more fixes
ole-ve Feb 26, 2025
49eb7d5
exam module path fixes
ole-ve Feb 26, 2025
ae8fd54
migrate exercise module rest path prefixes (excluding server test code)
ole-ve Feb 26, 2025
04adc1c
smaller client fix
ole-ve Feb 26, 2025
849cfff
migrate fileupload module rest path prefixes (excluding server test c…
ole-ve Feb 26, 2025
5a45ea6
more client fixes
ole-ve Feb 26, 2025
81dda7d
several fixes
ole-ve Feb 26, 2025
f3562f4
migrate iris module rest path prefixes (excluding server test code)
ole-ve Feb 26, 2025
aa48b57
rename endpoints in exam tests
ole-ve Feb 26, 2025
de88b3d
rename endpoints in fileupload tests
ole-ve Feb 26, 2025
1602d3f
more smaller fixes
ole-ve Feb 26, 2025
9d9af72
migrate lecture module rest path prefixes (excluding server test code)
ole-ve Feb 26, 2025
685c289
more fixes
ole-ve Feb 26, 2025
36b1fdc
more fixes
ole-ve Feb 26, 2025
7108e60
more fixes
ole-ve Feb 26, 2025
6362b10
more fixes
ole-ve Feb 26, 2025
b8a1bf1
more fixes
ole-ve Feb 26, 2025
197cd45
replace api/lectures with api/lecture/lectures
ole-ve Feb 26, 2025
033ffad
fix plagiarism paths
ole-ve Feb 26, 2025
ba24444
fix ExerciseScoresChartResource base path
ole-ve Feb 26, 2025
775dfcb
revert changes to iris path
ole-ve Feb 26, 2025
872aab1
fix more paths
ole-ve Feb 26, 2025
5936790
fix more paths
ole-ve Feb 26, 2025
6c66748
more fixes
ole-ve Feb 26, 2025
58c1f4d
more fixes
ole-ve Feb 26, 2025
f905fa7
fix path in iris send status
ole-ve Feb 26, 2025
f8ff875
fix path in iris send status
ole-ve Feb 26, 2025
75acc9b
fix typo
ole-ve Feb 26, 2025
fde2402
revert unintentional gitlab url changes
ole-ve Feb 26, 2025
674781a
fix mock get any user
ole-ve Feb 26, 2025
7973676
fix saving markdown file
ole-ve Feb 26, 2025
071cd83
typo
ole-ve Feb 26, 2025
f16be46
pyris typos
ole-ve Feb 26, 2025
23725d8
further fixes
ole-ve Feb 26, 2025
a810471
fix dynamic building of paths
ole-ve Feb 26, 2025
169ab7e
more fixes
ole-ve Feb 27, 2025
bd2b523
more fixes
ole-ve Feb 27, 2025
36fae81
more fixes
ole-ve Feb 27, 2025
7b1cb3e
more fices
ole-ve Feb 27, 2025
590ceae
more fixes
ole-ve Feb 27, 2025
34fd067
migrate lti module
ole-ve Feb 27, 2025
33ca997
migrate modeling module
ole-ve Feb 27, 2025
93761ee
migrate plagiarism module
ole-ve Feb 27, 2025
a5b7114
migrate quiz module
ole-ve Feb 27, 2025
6eb1917
migrate text module
ole-ve Feb 27, 2025
1feadbf
migrate tutorialgroup module
ole-ve Feb 27, 2025
8dec13c
more fixes
ole-ve Feb 27, 2025
2cf79fc
migrate programming server code (Without server tests)
ole-ve Feb 27, 2025
1fa428e
migrate more
ole-ve Feb 27, 2025
4559011
migrate more
ole-ve Feb 27, 2025
026c167
migrate more
ole-ve Feb 27, 2025
264af9e
migrate more
ole-ve Feb 27, 2025
7812a05
migrate more
ole-ve Feb 27, 2025
e983c8d
migrate more
ole-ve Feb 27, 2025
6071d06
more fixes
ole-ve Feb 27, 2025
f8592c3
more fixes
ole-ve Feb 27, 2025
f904696
tackle e2e tests
ole-ve Feb 27, 2025
03ccb3b
typos
ole-ve Feb 27, 2025
9756d8e
typos
ole-ve Feb 27, 2025
ff0f074
client compilation
ole-ve Feb 27, 2025
8465aa5
smaller fixes
ole-ve Feb 27, 2025
597baec
smaller fixes
ole-ve Feb 27, 2025
08eb10c
more client test fixes
ole-ve Feb 27, 2025
565a634
smaller path adjustments
ole-ve Feb 27, 2025
838d6c7
client test adjustment
ole-ve Feb 27, 2025
41afc54
feedback
ole-ve Feb 27, 2025
b1e61f4
smaller fixes
ole-ve Feb 27, 2025
54efd06
fix numerous file paths
ole-ve Feb 27, 2025
7e9182e
remove debug logging for spring security
ole-ve Feb 27, 2025
c78a094
update missing path
ole-ve Feb 27, 2025
a7b7b7d
smaller typo
ole-ve Feb 27, 2025
3aec0a0
smaller typos
ole-ve Feb 27, 2025
4c52d9d
smaller typos
ole-ve Feb 27, 2025
134987e
smaller typos
ole-ve Feb 27, 2025
64f98c4
smaller typos
ole-ve Feb 27, 2025
7d00a13
more path fixes
ole-ve Feb 27, 2025
903a0e5
add an architecture test to validate the consistent endpoint prefix (…
ole-ve Feb 27, 2025
22c6ab1
delete unused class
ole-ve Feb 27, 2025
135e243
remove unused constants
ole-ve Feb 27, 2025
d5853d0
fix submission-export.service.ts
ole-ve Feb 27, 2025
3238ec9
fix grading scale endpoint URL in e2e test
ole-ve Feb 27, 2025
e0bf066
adapt more tests
ole-ve Feb 27, 2025
13b25cd
fix title name service
ole-ve Feb 27, 2025
5182db2
fix upcoming exercise client path
ole-ve Feb 27, 2025
8a0eacf
migrate asset paths in java migration
ole-ve Feb 27, 2025
53048b8
load and update asset paths in batches
ole-ve Feb 27, 2025
1ad7746
remove unused constructor args
ole-ve Feb 27, 2025
1124398
Merge branch 'develop' into chore/migrate-asset-paths
ole-ve Mar 2, 2025
9aa0d73
fix transactional exclusion test for migration entry using transactional
ole-ve Mar 2, 2025
2f85448
migrate using liquibase instead of java migrations
ole-ve Mar 2, 2025
2225ee2
extend migrated column names to descriptions, hints, etc.
ole-ve Mar 3, 2025
5ad1d55
add migration for competency description
ole-ve Mar 3, 2025
926f287
remove comment
ole-ve Mar 3, 2025
a64876c
add migration for exam.start_text
ole-ve Mar 3, 2025
8a66746
remove comments
ole-ve Mar 3, 2025
4f02340
add script to migrate Jenkins build plan definitions
ole-ve Mar 4, 2025
fb8bb3b
improve error message
ole-ve Mar 4, 2025
2931320
fix build-plan regex
ole-ve Mar 4, 2025
b0a8457
fix missing JENKINS_HOME
ole-ve Mar 4, 2025
d4c5853
add progress indicator for number scanned files
ole-ve Mar 4, 2025
077914f
move number scanned files to end of loop
ole-ve Mar 4, 2025
bee4968
reduce coupling from api base url onto entities
ole-ve Mar 4, 2025
156b707
fix migration paths
ole-ve Mar 4, 2025
ff14137
typo
ole-ve Mar 4, 2025
6052e30
fix some server tests
ole-ve Mar 4, 2025
f2b2c44
fix remaining server tests
ole-ve Mar 4, 2025
fb53c3d
improve consistency of path matcher in where clause
ole-ve Mar 4, 2025
17d0b15
exclude rows from migration that potentially cause high load on the DB
ole-ve Mar 6, 2025
cc3deda
Merge branch 'develop' into chore/migrate-asset-paths
MaximilianAnzinger Mar 10, 2025
e354320
remove path migrations for text_block entities
ole-ve Mar 12, 2025
44edb7d
Merge branch 'develop' into chore/migrate-asset-paths
MaximilianAnzinger Mar 13, 2025
6836eb3
Merge branch 'develop' into chore/migrate-asset-paths
krusche Mar 13, 2025
fe65084
set courseIconPath in CourseManagementAPIRequests#createCourse
ole-ve Mar 14, 2025
4cb1864
set cropped image when no course stored in route data
ole-ve Mar 14, 2025
7652e02
another place to set croppedImage
ole-ve Mar 14, 2025
39b62cc
another approach
ole-ve Mar 14, 2025
7d59761
typo
ole-ve Mar 14, 2025
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 @@ -41,6 +41,15 @@ public final class Constants {

public static final int MAX_ENVIRONMENT_VARIABLES_DOCKER_FLAG_LENGTH = 1000;

/**
* The default REST/URL-path prefix for accessing file uploads.
* Don't use this constant elsewhere than in the Presentation-Layer to reduce
* coupling between the persistence layer {@link de.tum.cit.aet.artemis.core.domain.DomainObject }) and the
* presentation layer ({@link org.springframework.web.bind.annotation.RestController}).
* There might be exceptions if the path can be considered part of the business logic, and not presentation.
*/
public static final String ARTEMIS_FILE_PATH_PREFIX = "/api/core/files/";

/**
* This constant determines how many seconds after the exercise due dates submissions will still be considered rated.
* Submissions after the grace period exceeded will be flagged as illegal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,35 @@ public static Path actualPathForPublicPath(URI publicPath) {
String filename = path.getFileName().toString();

// check for known path to convert
if (uriPath.startsWith("/api/core/files/temp")) {
if (uriPath.startsWith("temp")) {
return getTempFilePath().resolve(filename);
}
if (uriPath.startsWith("/api/core/files/drag-and-drop/backgrounds")) {
if (uriPath.startsWith("drag-and-drop/backgrounds")) {
return getDragAndDropBackgroundFilePath().resolve(filename);
}
if (uriPath.startsWith("/api/core/files/drag-and-drop/drag-items")) {
if (uriPath.startsWith("drag-and-drop/drag-items")) {
return getDragItemFilePath().resolve(filename);
}
if (uriPath.startsWith("/api/core/files/course/icons")) {
if (uriPath.startsWith("course/icons")) {
return getCourseIconFilePath().resolve(filename);
}
if (uriPath.startsWith("/api/core/files/user/profile-pictures")) {
if (uriPath.startsWith("user/profile-pictures")) {
return getProfilePictureFilePath().resolve(filename);
}
if (uriPath.startsWith("/api/core/files/exam-user/signatures")) {
if (uriPath.startsWith("exam-user/signatures")) {
return getExamUserSignatureFilePath().resolve(filename);
}
if (uriPath.startsWith("/api/core/files/exam-user")) {
if (uriPath.startsWith("exam-user")) {
return getStudentImageFilePath().resolve(filename);
}
if (uriPath.startsWith("/api/core/files/attachments/lecture")) {
String lectureId = path.getName(5).toString();
if (uriPath.startsWith("attachments/lecture")) {
String lectureId = path.getName(2).toString();
return getLectureAttachmentFilePath().resolve(Path.of(lectureId, filename));
}
if (uriPath.startsWith("/api/core/files/attachments/attachment-unit")) {
if (uriPath.startsWith("attachments/attachment-unit")) {
return actualPathForPublicAttachmentUnitFilePath(publicPath, filename);
}
if (uriPath.startsWith("/api/core/files/file-upload-exercises")) {
if (uriPath.startsWith("file-upload-exercises")) {
return actualPathForPublicFileUploadExercisesFilePath(publicPath, filename);
}

Expand All @@ -146,13 +146,13 @@ public static Path actualPathForPublicPath(URI publicPath) {

private static Path actualPathForPublicAttachmentUnitFilePath(URI publicPath, String filename) {
Path path = Path.of(publicPath.getPath());
if (!publicPath.toString().contains("/slide")) {
String attachmentUnitId = path.getName(5).toString();
if (!publicPath.toString().contains("slide")) {
String attachmentUnitId = path.getName(2).toString();
return getAttachmentUnitFilePath().resolve(Path.of(attachmentUnitId, filename));
}
try {
String attachmentUnitId = path.getName(5).toString();
String slideId = path.getName(7).toString();
String attachmentUnitId = path.getName(2).toString();
String slideId = path.getName(4).toString();
// check if the ids are valid long values
Long.parseLong(attachmentUnitId);
Long.parseLong(slideId);
Expand All @@ -166,8 +166,8 @@ private static Path actualPathForPublicAttachmentUnitFilePath(URI publicPath, St
private static Path actualPathForPublicFileUploadExercisesFilePath(URI publicPath, String filename) {
Path path = Path.of(publicPath.getPath());
try {
String expectedExerciseId = path.getName(4).toString();
String expectedSubmissionId = path.getName(6).toString();
String expectedExerciseId = path.getName(1).toString();
String expectedSubmissionId = path.getName(3).toString();
Long exerciseId = Long.parseLong(expectedExerciseId);
Long submissionId = Long.parseLong(expectedSubmissionId);
return FileUploadSubmission.buildFilePath(exerciseId, submissionId).resolve(filename);
Expand Down Expand Up @@ -213,25 +213,25 @@ public static URI publicPathForActualPath(Path path, @Nullable Long entityId) {
return URI.create(FileService.DEFAULT_FILE_SUBPATH + filename);
}
if (path.startsWith(getDragAndDropBackgroundFilePath())) {
return URI.create("/api/core/files/drag-and-drop/backgrounds/" + id + "/" + filename);
return URI.create("drag-and-drop/backgrounds/" + id + "/" + filename);
}
if (path.startsWith(getDragItemFilePath())) {
return URI.create("/api/core/files/drag-and-drop/drag-items/" + id + "/" + filename);
return URI.create("drag-and-drop/drag-items/" + id + "/" + filename);
}
if (path.startsWith(getCourseIconFilePath())) {
return URI.create("/api/core/files/course/icons/" + id + "/" + filename);
return URI.create("course/icons/" + id + "/" + filename);
}
if (path.startsWith(getProfilePictureFilePath())) {
return URI.create("/api/core/files/user/profile-pictures/" + id + "/" + filename);
return URI.create("user/profile-pictures/" + id + "/" + filename);
}
if (path.startsWith(getExamUserSignatureFilePath())) {
return URI.create("/api/core/files/exam-user/signatures/" + id + "/" + filename);
return URI.create("exam-user/signatures/" + id + "/" + filename);
}
if (path.startsWith(getStudentImageFilePath())) {
return URI.create("/api/core/files/exam-user/" + id + "/" + filename);
return URI.create("exam-user/" + id + "/" + filename);
}
if (path.startsWith(getLectureAttachmentFilePath())) {
return URI.create("/api/core/files/attachments/lecture/" + id + "/" + filename);
return URI.create("attachments/lecture/" + id + "/" + filename);
}
if (path.startsWith(getAttachmentUnitFilePath())) {
return publicPathForActualAttachmentUnitFilePath(path, filename, id);
Expand All @@ -244,15 +244,15 @@ public static URI publicPathForActualPath(Path path, @Nullable Long entityId) {
}

private static URI publicPathForActualAttachmentUnitFilePath(Path path, String filename, String id) {
if (!path.toString().contains("/slide")) {
return URI.create("/api/core/files/attachments/attachment-unit/" + id + "/" + filename);
if (!path.toString().contains("slide")) {
return URI.create("attachments/attachment-unit/" + id + "/" + filename);
}
try {
// The last name is the file name, the one before that is the slide number and the one before that is the attachmentUnitId, in which we are interested
// (e.g. uploads/attachments/attachment-unit/941/slide/1/State_pattern_941_Slide_1.png)
final String expectedAttachmentUnitId = path.getName(path.getNameCount() - 4).toString();
final long attachmentUnitId = Long.parseLong(expectedAttachmentUnitId);
return URI.create("/api/core/files/attachments/attachment-unit/" + attachmentUnitId + "/slide/" + id + "/" + filename);
return URI.create("attachments/attachment-unit/" + attachmentUnitId + "/slide/" + id + "/" + filename);
}
catch (IllegalArgumentException e) {
throw new FilePathParsingException("Unexpected String in upload file path. AttachmentUnit ID should be present here: " + path, e);
Expand All @@ -264,7 +264,7 @@ private static URI publicPathForActualFileUploadExercisesFilePath(Path path, Str
// The last name is the file name, the one before that is the submissionId and the one before that is the exerciseId, in which we are interested
final var expectedExerciseId = path.getName(path.getNameCount() - 3).toString();
final long exerciseId = Long.parseLong(expectedExerciseId);
return URI.create("/api/core/files/file-upload-exercises/" + exerciseId + "/submissions/" + id + "/" + filename);
return URI.create("file-upload-exercises/" + exerciseId + "/submissions/" + id + "/" + filename);
}
catch (IllegalArgumentException e) {
throw new FilePathParsingException("Unexpected String in upload file path. Exercise ID should be present here: " + path, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ public class FileService implements DisposableBean {
private final Set<String> allowedFileExtensions = Set.of("png", "jpg", "jpeg", "gif", "svg", "pdf", "zip", "tar", "txt", "rtf", "md", "htm", "html", "json", "doc", "docx",
"csv", "xls", "xlsx", "ppt", "pptx", "pages", "pages-tef", "numbers", "key", "odt", "ods", "odp", "odg", "odc", "odi", "odf");

public static final String MARKDOWN_FILE_SUBPATH = "/api/core/files/markdown/";
private static final String MARKDOWN_FILE_SUBPATH = "markdown/";

public static final String DEFAULT_FILE_SUBPATH = "/api/core/files/temp/";
public static final String DEFAULT_FILE_SUBPATH = "temp/";

public static final String BACKGROUND_FILE_SUBPATH = "/api/core/files/drag-and-drop/backgrounds/";
public static final String BACKGROUND_FILE_SUBPATH = "drag-and-drop/backgrounds/";

public static final String PICTURE_FILE_SUBPATH = "/api/core/files/drag-and-drop/drag-items/";
public static final String PICTURE_FILE_SUBPATH = "drag-and-drop/drag-items/";

/**
* These directories get falsely marked as files and should be ignored during copying.
Expand Down Expand Up @@ -161,7 +161,7 @@ public static String sanitizeFilename(String filename) {
* @param file The file to be uploaded with a maximum file size set in resources/config/application.yml
* @param keepFilename specifies if original file name should be kept
* @param markdown boolean which is set to true, when we are uploading a file within the markdown editor
* @return The API path of the file
* @return The public path of the file
*/
@NotNull
public URI handleSaveFile(MultipartFile file, boolean keepFilename, boolean markdown) {
Expand Down Expand Up @@ -205,8 +205,7 @@ public FilePathInformation handleSaveFileInConversation(MultipartFile file, Long
copyFile(file, filePath);

String currentFilename = filePath.getFileName().toString();
return new FilePathInformation(filePath, URI.create("/api/core/files/courses/" + courseId + "/conversations/" + conversationId + "/").resolve(currentFilename),
sanitizedOriginalFilename);
return new FilePathInformation(filePath, URI.create("courses/" + courseId + "/conversations/" + conversationId + "/").resolve(currentFilename), sanitizedOriginalFilename);
}

/**
Expand Down
31 changes: 25 additions & 6 deletions src/main/java/de/tum/cit/aet/artemis/core/web/FileResource.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.tum.cit.aet.artemis.core.web;

import static de.tum.cit.aet.artemis.core.config.Constants.ARTEMIS_FILE_PATH_PREFIX;
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;
import static org.apache.velocity.shaded.commons.io.FilenameUtils.getBaseName;
import static org.apache.velocity.shaded.commons.io.FilenameUtils.getExtension;
Expand Down Expand Up @@ -192,12 +193,13 @@ public ResponseEntity<String> saveMarkdownFileForConversation(@RequestParam(valu
throw new ResponseStatusException(HttpStatus.PAYLOAD_TOO_LARGE, "The file is too large. Maximum file size is " + Constants.MAX_FILE_SIZE_COMMUNICATION + " bytes.");
}
var filePathInformation = fileService.handleSaveFileInConversation(file, courseId, conversationId);
String responsePath = filePathInformation.publicPath().toString();
String publicPath = filePathInformation.publicPath().toString();

fileUploadService.createFileUpload(responsePath, filePathInformation.serverPath().toString(), filePathInformation.filename(), conversationId,
fileUploadService.createFileUpload(publicPath, filePathInformation.serverPath().toString(), filePathInformation.filename(), conversationId,
FileUploadEntityType.CONVERSATION);

// return path for getting the file
String responsePath = getResponsePathFromPublicPathString(publicPath);
String responseBody = "{\"path\":\"" + responsePath + "\"}";

return ResponseEntity.created(new URI(responsePath)).body(responseBody);
Expand All @@ -218,15 +220,16 @@ public ResponseEntity<byte[]> getMarkdownFileForConversation(@PathVariable Long
log.debug("REST request to get file for markdown in conversation: File {} for conversation {} in course {}", filename, conversationId, courseId);
sanitizeFilenameElseThrow(filename);

var path = FilePathService.getMarkdownFilePathForConversation(courseId, conversationId);
var publicPath = FilePathService.getMarkdownFilePathForConversation(courseId, conversationId);
Path responsePath = getResponsePathFromPublicPath(publicPath);

var fileUpload = fileUploadService.findByPath("/api/core/files/courses/" + courseId + "/conversations/" + conversationId + "/" + filename);
var fileUpload = fileUploadService.findByPath("courses/" + courseId + "/conversations/" + conversationId + "/" + filename);

if (fileUpload.isPresent()) {
return buildFileResponse(path, filename, Optional.ofNullable(fileUpload.get().getFilename()), true);
return buildFileResponse(responsePath, filename, Optional.ofNullable(fileUpload.get().getFilename()), true);
}

return buildFileResponse(path, filename, true);
return buildFileResponse(responsePath, filename, true);
}

/**
Expand Down Expand Up @@ -658,6 +661,22 @@ private ResponseEntity<byte[]> buildFileResponse(Path path, String filename, Opt
}
}

private Path getResponsePathFromPublicPath(@NotNull Path publicPath) {
// fail-safe to raise awareness if the public path is not correct (should not happen)
if (publicPath.startsWith(ARTEMIS_FILE_PATH_PREFIX)) {
throw new IllegalArgumentException("The public path should not contain the Artemis file path prefix");
}
return Path.of(ARTEMIS_FILE_PATH_PREFIX, publicPath.toString());
}

private String getResponsePathFromPublicPathString(@NotNull String publicPath) {
// fail-safe to raise awareness if the public path is not correct (should not happen)
if (publicPath.startsWith(ARTEMIS_FILE_PATH_PREFIX)) {
throw new IllegalArgumentException("The public path should not contain the Artemis file path prefix");
}
return ARTEMIS_FILE_PATH_PREFIX + publicPath;
}

private Path getActualPathFromPublicPathString(@NotNull String publicPath) {
if (publicPath == null) {
throw new EntityNotFoundException("No file linked");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.tum.cit.aet.artemis.exercise.service;

import static de.tum.cit.aet.artemis.core.config.Constants.ARTEMIS_FILE_PATH_PREFIX;
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.io.IOException;
Expand Down Expand Up @@ -41,13 +42,17 @@ public abstract class ExerciseWithSubmissionsExportService {

public static final String EXPORTED_EXERCISE_PROBLEM_STATEMENT_FILE_PREFIX = "Problem-Statement";

private static final String EMBEDDED_FILE_MARKDOWN_SYNTAX_REGEX = "\\[.*] *\\(/api/core/files/markdown/.*\\)";
// Dependency to ARTEMIS_FILE_PATH_PREFIX is OK because parsing problem statements is business logic
private static final String EMBEDDED_FILE_MARKDOWN_SYNTAX_REGEX = String.format("\\[.*] *\\(%smarkdown/.*\\)", ARTEMIS_FILE_PATH_PREFIX);

private static final String EMBEDDED_FILE_MARKDOWN_WITH_HOVERTEXT = "\\(/api/core/files/markdown/.* \".*\"\\)";
// Dependency to ARTEMIS_FILE_PATH_PREFIX is OK because parsing problem statements is business logic
private static final String EMBEDDED_FILE_MARKDOWN_WITH_HOVERTEXT = String.format("\\(%smarkdown/.* \".*\"\\)", ARTEMIS_FILE_PATH_PREFIX);

private static final String EMBEDDED_FILE_HTML_SYNTAX_REGEX = "<img src=\"/api/core/files/markdown/.*\".*>";
// Dependency to ARTEMIS_FILE_PATH_PREFIX is OK because parsing problem statements is business logic
private static final String EMBEDDED_FILE_HTML_SYNTAX_REGEX = String.format("<img src=\"%smarkdown/.*\".*>", ARTEMIS_FILE_PATH_PREFIX);

private static final String API_MARKDOWN_FILE_PATH = "/api/core/files/markdown/";
// Dependency to ARTEMIS_FILE_PATH_PREFIX is OK because parsing problem statements is business logic
private static final String API_MARKDOWN_FILE_PATH = String.format("%smarkdown/", ARTEMIS_FILE_PATH_PREFIX);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void splitAttachmentUnitIntoSingleSlides(PDDocument document, AttachmentU
Path savePath = fileService.saveFile(slideFile, FilePathService.getAttachmentUnitFilePath().resolve(attachmentUnit.getId().toString()).resolve("slide")
.resolve(String.valueOf(slideNumber)).resolve(filename));
Slide slideEntity = new Slide();
slideEntity.setSlideImagePath(FilePathService.publicPathForActualPath(savePath, (long) slideNumber).toString());
slideEntity.setSlideImagePath(FilePathService.publicPathForActualPathOrThrow(savePath, (long) slideNumber).toString());
slideEntity.setSlideNumber(slideNumber);
slideEntity.setAttachmentUnit(attachmentUnit);
slideRepository.save(slideEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ResponseEntity<Attachment> createAttachment(@RequestPart Attachment attac

Path basePath = FilePathService.getLectureAttachmentFilePath().resolve(attachment.getLecture().getId().toString());
Path savePath = fileService.saveFile(file, basePath, true);
attachment.setLink(FilePathService.publicPathForActualPath(savePath, attachment.getLecture().getId()).toString());
attachment.setLink(FilePathService.publicPathForActualPathOrThrow(savePath, attachment.getLecture().getId()).toString());

Attachment result = attachmentRepository.save(attachment);

Expand Down Expand Up @@ -124,7 +124,7 @@ public ResponseEntity<Attachment> updateAttachment(@PathVariable Long attachment
if (file != null) {
Path basePath = FilePathService.getLectureAttachmentFilePath().resolve(originalAttachment.getLecture().getId().toString());
Path savePath = fileService.saveFile(file, basePath, true);
attachment.setLink(FilePathService.publicPathForActualPath(savePath, originalAttachment.getLecture().getId()).toString());
attachment.setLink(FilePathService.publicPathForActualPathOrThrow(savePath, originalAttachment.getLecture().getId()).toString());
// Delete the old file
URI oldPath = URI.create(originalAttachment.getLink());
fileService.schedulePathForDeletion(FilePathService.actualPathForPublicPathOrThrow(oldPath), 0);
Expand Down
Loading
Loading