Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 5c620f8

Browse files
FF-251 Delete FileSystemItem API Endpoint (#62)
* FF-251 Added basic structure and exception + handler. * Cleanup. Reworked custom Exceptions. * Cleanup. Implemented Change in UnitTests. * Cleanup. Implemented necessary changes to cucumber steps * added the .feature file for deleting * FileSystemItem now includes the User * fixed copy pesto, added step function * removed the empty lines * minor fixes, recusive scenarion for permissions * Cleanup. Refactored getContentsOfFolder. * Commented out feature. * Implemented TODO, updated tests. * WIP. basic structure, added wip comments * WIP. added checks for invisible entities. * WIP. started implementing. Added more comments. * Fixed Tests. * FF-251 finished adding logic. * Added UnitTests (1/2) * added some comments to understand the recursion * Fixing, refactoring. * Added UnitTests (1,95/2) * Fixing spelling, and minor bugs in feature files. * Implemented requested changes by @qvalentin * Some more cleanup. * Implemented return value, and Cucumber Steps. * It seems that deleteAll doesnt work, so we need to do that. * WIP: update tests. * Fixed broken merge. * Fixed Tests, finished implementing. * Added one more scenario * Bumped Version to v0.0.7 * Implemented changes by @qvalentin Co-authored-by: qvalentin <[email protected]>
1 parent e9a1fbf commit 5c620f8

File tree

50 files changed

+1126
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1126
-231
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>de.filefighter</groupId>
1212
<artifactId>rest</artifactId>
13-
<version>0.0.6</version>
13+
<version>0.0.7</version>
1414
<name>RestApi</name>
1515
<description>RestApi for FileFighter</description>
1616

src/main/java/de/filefighter/rest/configuration/CorsConfig.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,35 @@
1212
@Configuration
1313
public class CorsConfig {
1414

15-
@Bean
16-
@Profile("dev")
17-
public CorsFilter corsFilter() {
18-
final CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues();
19-
ArrayList<String> allowedOrigins = new ArrayList<>();
20-
allowedOrigins.add("*");
21-
config.setAllowedOrigins(allowedOrigins);
15+
private final ArrayList<String> allowedMethods;
2216

23-
ArrayList<String> allowedMethods = new ArrayList<>();
17+
public CorsConfig() {
18+
this.allowedMethods = new ArrayList<>();
2419
allowedMethods.add("HEAD");
2520
allowedMethods.add("GET");
2621
allowedMethods.add("POST");
2722
allowedMethods.add("PUT");
2823
allowedMethods.add("DELETE");
2924
allowedMethods.add("OPTIONS");
25+
}
26+
27+
@Bean
28+
@Profile("dev")
29+
public CorsFilter corsFilterDev() {
30+
final CorsConfiguration config = new CorsConfiguration().applyPermitDefaultValues();
31+
ArrayList<String> allowedOrigins = new ArrayList<>();
32+
allowedOrigins.add("*");
33+
config.setAllowedOrigins(allowedOrigins);
34+
35+
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
36+
source.registerCorsConfiguration("/**", config);
37+
return new CorsFilter(source);
38+
}
39+
40+
@Bean
41+
@Profile({"prod","test"})
42+
public CorsFilter corsFilterProd() {
43+
final CorsConfiguration config = new CorsConfiguration();
3044
config.setAllowedMethods(allowedMethods);
3145

3246
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

src/main/java/de/filefighter/rest/configuration/PrepareDataBase.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ CommandLineRunner cleanDataBase(UserRepository userRepository, FileSystemReposit
7777
CommandLineRunner createRuntimeUser(UserRepository userRepository) {
7878
return args -> log.info("Preloading system runtime user. {}", userRepository.save(UserEntity
7979
.builder()
80-
.userId(0L)
80+
.userId(RestConfiguration.RUNTIME_USER_ID)
8181
.username("FileFighter")
8282
.lowercaseUsername("filefighter")
8383
.password(null)
@@ -102,7 +102,7 @@ CommandLineRunner initDataBaseProd(UserRepository userRepository, FileSystemRepo
102102

103103
log.info("Preloading default fsStructure: {} {}.", fileSystemRepository.save(FileSystemEntity
104104
.builder()
105-
.createdByUserId(0)
105+
.createdByUserId(RestConfiguration.RUNTIME_USER_ID)
106106
.fileSystemId(0)
107107
.isFile(false)
108108
.path("/")
@@ -171,7 +171,7 @@ CommandLineRunner initDataBaseDev(UserRepository userRepository, AccessTokenRepo
171171

172172
log.info("Preloading default fsItems: {} {} {}.",
173173
fileSystemRepository.save(FileSystemEntity.builder()
174-
.createdByUserId(0)
174+
.createdByUserId(RestConfiguration.RUNTIME_USER_ID)
175175
.fileSystemId(0)
176176
.isFile(false)
177177
.path("/")
@@ -183,7 +183,7 @@ CommandLineRunner initDataBaseDev(UserRepository userRepository, AccessTokenRepo
183183
.visibleForGroupIds(new long[]{FAMILY.getGroupId(), ADMIN.getGroupId()})
184184
.build()),
185185
fileSystemRepository.save(FileSystemEntity.builder()
186-
.createdByUserId(0)
186+
.createdByUserId(RestConfiguration.RUNTIME_USER_ID)
187187
.fileSystemId(1)
188188
.isFile(false)
189189
.path("/")

src/main/java/de/filefighter/rest/configuration/RestConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class RestConfiguration {
1010
public static final String FS_PATH_HEADER = "X-FF-PATH";
1111
public static final String USER_BASE_URI = "/users/";
1212
public static final String DEFAULT_ERROR_URI = "/error";
13+
public static final long RUNTIME_USER_ID = 0;
1314

1415
private RestConfiguration(){
1516
// Cannot be instantiated.

src/main/java/de/filefighter/rest/rest/exceptions/DataBaseExceptionAdvise.java renamed to src/main/java/de/filefighter/rest/domain/common/exceptions/DataBaseExceptionAdvise.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package de.filefighter.rest.rest.exceptions;
1+
package de.filefighter.rest.domain.common.exceptions;
22

33
import de.filefighter.rest.domain.health.business.SystemHealthBusinessService;
44
import de.filefighter.rest.domain.health.data.SystemHealth;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package de.filefighter.rest.domain.common.exceptions;
2+
3+
import org.springframework.dao.DataAccessException;
4+
5+
public class FileFighterDataException extends DataAccessException implements FileFighterException {
6+
7+
private static final String ERROR_MESSAGE_PREFIX = "Internal Error occurred.";
8+
9+
public FileFighterDataException(String msg) {
10+
super(ERROR_MESSAGE_PREFIX + " " + msg);
11+
}
12+
13+
public static String getErrorMessagePrefix() {
14+
return ERROR_MESSAGE_PREFIX;
15+
}
16+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package de.filefighter.rest.domain.common.exceptions;
2+
3+
public interface FileFighterException {
4+
static String getErrorMessagePrefix() {
5+
throw new IllegalArgumentException("Custom exception should overwrite this message.");
6+
}
7+
}

src/main/java/de/filefighter/rest/domain/common/InputSanitizerService.java renamed to src/main/java/de/filefighter/rest/domain/common/exceptions/InputSanitizerService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package de.filefighter.rest.domain.common;
1+
package de.filefighter.rest.domain.common.exceptions;
22

3-
import de.filefighter.rest.rest.exceptions.RequestDidntMeetFormalRequirementsException;
43
import org.springframework.stereotype.Service;
54

65
@Service

src/main/java/de/filefighter/rest/rest/exceptions/RequestDidntMeetFormalRequirementsAdvise.java renamed to src/main/java/de/filefighter/rest/domain/common/exceptions/RequestDidntMeetFormalRequirementsAdvise.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package de.filefighter.rest.rest.exceptions;
1+
package de.filefighter.rest.domain.common.exceptions;
22

33
import de.filefighter.rest.rest.ServerResponse;
44
import lombok.extern.log4j.Log4j2;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package de.filefighter.rest.domain.common.exceptions;
2+
3+
public class RequestDidntMeetFormalRequirementsException extends RuntimeException implements FileFighterException {
4+
5+
private static final String ERROR_MESSAGE_PREFIX = "Request didnt meet formal requirements.";
6+
7+
public RequestDidntMeetFormalRequirementsException() {
8+
super(ERROR_MESSAGE_PREFIX);
9+
}
10+
11+
public RequestDidntMeetFormalRequirementsException(String reason) {
12+
super(ERROR_MESSAGE_PREFIX + " " + reason);
13+
}
14+
15+
public static String getErrorMessagePrefix() {
16+
return ERROR_MESSAGE_PREFIX;
17+
}
18+
}

0 commit comments

Comments
 (0)