Adaptations for legacy database importation.

This commit is contained in:
Florian THIERRY
2024-03-21 18:07:33 +01:00
parent 30e5ffa2eb
commit 39663e914d
5 changed files with 12 additions and 11 deletions

View File

@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
@Component @Component
public class KeyGenerator { public class KeyGenerator {
private static final String ALLOWED_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; private static final String ALLOWED_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
private static final int KEY_LENGTH = 10; private static final int KEY_LENGTH = 14;
public String generateKey() { public String generateKey() {
SecureRandom random = new SecureRandom(); SecureRandom random = new SecureRandom();

View File

@@ -24,7 +24,8 @@ public class MultipartFileConverter {
try { try {
ALLOWED_MIME_TYPES = List.of( ALLOWED_MIME_TYPES = List.of(
mimeTypes.forName("image/png"), mimeTypes.forName("image/png"),
mimeTypes.forName("image/jpeg") mimeTypes.forName("image/jpeg"),
mimeTypes.forName("image/svg+xml")
); );
} catch (MimeTypeException exception) { } catch (MimeTypeException exception) {
throw new RuntimeException("An error occurred while loading allowed mime types.", exception); throw new RuntimeException("An error occurred while loading allowed mime types.", exception);
@@ -48,16 +49,15 @@ public class MultipartFileConverter {
} }
private String buildPicturePath(MultipartFile fileContent) { private String buildPicturePath(MultipartFile fileContent) {
MimeType fileContentType = extractMimeType(fileContent); checkMimeTypeIsAllowed(fileContent);
return String.format( return String.format(
"%s/%s%s", "%s/%s",
tempPicturesFolderPath, tempPicturesFolderPath,
UUID.randomUUID(), UUID.randomUUID()
fileContentType.getExtension()
); );
} }
private MimeType extractMimeType(MultipartFile fileContent) { private void checkMimeTypeIsAllowed(MultipartFile fileContent) {
MimeType result = null; MimeType result = null;
try { try {
result = MimeTypes.getDefaultMimeTypes() result = MimeTypes.getDefaultMimeTypes()
@@ -69,8 +69,6 @@ public class MultipartFileConverter {
if (isNull(result) || !isAllowedMimeType(result)) { if (isNull(result) || !isAllowedMimeType(result)) {
throw new PictureUploadException("Unable to upload the picture because its format is incorrect."); throw new PictureUploadException("Unable to upload the picture because its format is incorrect.");
} }
return result;
} }
private boolean isAllowedMimeType(MimeType mimeType) { private boolean isAllowedMimeType(MimeType mimeType) {

View File

@@ -46,7 +46,7 @@ CREATE INDEX user_photo_id_idx ON "user" (photo_id);
CREATE TABLE IF NOT EXISTS publication ( CREATE TABLE IF NOT EXISTS publication (
id UUID NOT NULL, id UUID NOT NULL,
key VARCHAR(10) NOT NULL, key VARCHAR(14) NOT NULL,
title VARCHAR NOT NULL, title VARCHAR NOT NULL,
text VARCHAR NOT NULL, text VARCHAR NOT NULL,
description VARCHAR NOT NULL, description VARCHAR NOT NULL,

View File

@@ -3,6 +3,9 @@ application:
path: /Users/florian_thierry/Documents/Developpement/codiki-hexa/pictures-folder/ path: /Users/florian_thierry/Documents/Developpement/codiki-hexa/pictures-folder/
temp-path : /Users/florian_thierry/Documents/Developpement/codiki-hexa/pictures-folder/temp/ temp-path : /Users/florian_thierry/Documents/Developpement/codiki-hexa/pictures-folder/temp/
server:
port: 8987
spring: spring:
jpa: jpa:
show-sql: true show-sql: true

View File

@@ -1,5 +1,5 @@
vars { vars {
url: http://localhost:8080 url: http://localhost:8987
publicationId: ec76602f-5501-4091-868e-b471611e63de publicationId: ec76602f-5501-4091-868e-b471611e63de
bearerToken: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1YWQ0NjJiOC04ZjllLTRhMjYtYmI4Ni1jNzRmZWY1ZDExYjYiLCJleHAiOjE3MTA4Mzc2ODQsInBzZXVkbyI6IlN0YW5kYXJkIHVzZXIiLCJlbWFpbCI6InN0YW5kYXJkLnVzZXJAY29kaWtpLm9yZyIsInJvbGVzIjoiU1RBTkRBUkQifQ.2HggC3T_4I14IpW02DZJiYfgYwc074kU8Y4AmuGf1mZzv0U8OUxpAw_xEhnKtn8NcaCozz_2vFv4o_CaBqS8Ag bearerToken: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1YWQ0NjJiOC04ZjllLTRhMjYtYmI4Ni1jNzRmZWY1ZDExYjYiLCJleHAiOjE3MTA4Mzc2ODQsInBzZXVkbyI6IlN0YW5kYXJkIHVzZXIiLCJlbWFpbCI6InN0YW5kYXJkLnVzZXJAY29kaWtpLm9yZyIsInJvbGVzIjoiU1RBTkRBUkQifQ.2HggC3T_4I14IpW02DZJiYfgYwc074kU8Y4AmuGf1mZzv0U8OUxpAw_xEhnKtn8NcaCozz_2vFv4o_CaBqS8Ag
categoryId: 172fa901-3f4b-4540-92f3-1c15820e8ec9 categoryId: 172fa901-3f4b-4540-92f3-1c15820e8ec9