-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fda74d1
commit 7e6705e
Showing
13 changed files
with
238 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/de/caritas/cob/upload/api/exception/httpresponses/BadRequestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package de.caritas.cob.upload.api.exception.httpresponses; | ||
|
||
import de.caritas.cob.uploadservice.api.service.LogService; | ||
import java.io.Serial; | ||
|
||
public class BadRequestException extends CustomHttpStatusException { | ||
|
||
@Serial private static final long serialVersionUID = -8047408802295905803L; | ||
|
||
/** | ||
* BadRequest exception. | ||
* | ||
* @param message an additional message | ||
*/ | ||
public BadRequestException(String message) { | ||
super(message, LogService::logWarning); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ain/java/de/caritas/cob/upload/api/exception/httpresponses/CustomHttpStatusException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package de.caritas.cob.upload.api.exception.httpresponses; | ||
|
||
import static java.util.Objects.nonNull; | ||
|
||
import java.io.Serial; | ||
import java.util.function.Consumer; | ||
|
||
/** Custom HTTP status exception. */ | ||
public abstract class CustomHttpStatusException extends RuntimeException { | ||
|
||
@Serial private static final long serialVersionUID = -3545035432045919306L; | ||
private final Consumer<Exception> loggingMethod; | ||
|
||
CustomHttpStatusException(String message, Consumer<Exception> loggingMethod) { | ||
super(message); | ||
this.loggingMethod = loggingMethod; | ||
} | ||
|
||
CustomHttpStatusException(String message, Exception ex, Consumer<Exception> loggingMethod) { | ||
super(message, ex); | ||
this.loggingMethod = loggingMethod; | ||
} | ||
|
||
/** Executes the non null logging method. */ | ||
public void executeLogging() { | ||
if (nonNull(this.loggingMethod)) { | ||
this.loggingMethod.accept(this); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
.../java/de/caritas/cob/upload/api/exception/httpresponses/InternalServerErrorException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package de.caritas.cob.upload.api.exception.httpresponses; | ||
|
||
import de.caritas.cob.uploadservice.api.service.LogService; | ||
import java.io.Serial; | ||
import java.util.function.Consumer; | ||
|
||
/** Represents the exception for an internal server error - status code 500. */ | ||
public class InternalServerErrorException extends CustomHttpStatusException { | ||
|
||
@Serial private static final long serialVersionUID = 6051508644381775936L; | ||
|
||
/** | ||
* InternalServerErrorException exception. | ||
* | ||
* @param message the message to be logged | ||
*/ | ||
public InternalServerErrorException(String message) { | ||
super(message, LogService::logInternalServerError); | ||
} | ||
|
||
/** | ||
* InternalServerErrorException exception. | ||
* | ||
* @param loggingMethod the method to be used for logging | ||
* @param message the message to be logged | ||
*/ | ||
public InternalServerErrorException(Consumer<Exception> loggingMethod, String message) { | ||
super(message, loggingMethod); | ||
} | ||
|
||
/** | ||
* InternalServerError exception. | ||
* | ||
* @param message the exception message | ||
* @param ex the exception | ||
*/ | ||
public InternalServerErrorException(String message, Exception ex) { | ||
super(message, ex, LogService::logInternalServerError); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/de/caritas/cob/upload/api/exception/httpresponses/NotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.caritas.cob.upload.api.exception.httpresponses; | ||
|
||
import lombok.NoArgsConstructor; | ||
|
||
/** 404 - Not found http exception */ | ||
@NoArgsConstructor | ||
public class NotFoundException extends RuntimeException {} |
15 changes: 15 additions & 0 deletions
15
...n/java/de/caritas/cob/upload/api/exception/httpresponses/StatisticsDisabledException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package de.caritas.cob.upload.api.exception.httpresponses; | ||
|
||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.security.access.AccessDeniedException; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@Getter | ||
@ResponseStatus(value = HttpStatus.FORBIDDEN, reason = "statistics disabled") | ||
public class StatisticsDisabledException extends AccessDeniedException { | ||
|
||
public StatisticsDisabledException(String msg) { | ||
super(msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 28 additions & 3 deletions
31
src/main/java/de/caritas/cob/uploadservice/api/service/TenantService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,46 @@ | ||
package de.caritas.cob.uploadservice.api.service; | ||
|
||
import de.caritas.cob.uploadservice.config.CacheManagerConfig; | ||
import de.caritas.cob.uploadservice.tenantservice.generated.web.TenantControllerApi; | ||
import de.caritas.cob.uploadservice.config.TenantServiceApiControllerFactory; | ||
import de.caritas.cob.uploadservice.tenantservice.generated.web.model.RestrictedTenantDTO; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class TenantService { | ||
|
||
private final @NonNull TenantControllerApi tenantControllerApi; | ||
private final @NonNull TenantServiceApiControllerFactory tenantServiceApiControllerFactory; | ||
|
||
@Cacheable(cacheNames = CacheManagerConfig.TENANT_CACHE, key = "#subdomain") | ||
public RestrictedTenantDTO getRestrictedTenantDataBySubdomain(String subdomain) { | ||
return tenantControllerApi.getRestrictedTenantDataBySubdomainWithHttpInfo(subdomain).getBody(); | ||
return getRestrictedTenantDTO(subdomain); | ||
} | ||
|
||
public RestrictedTenantDTO getRestrictedTenantDataBySubdomainNonCached(String subdomain) { | ||
return getRestrictedTenantDTO(subdomain); | ||
} | ||
|
||
private RestrictedTenantDTO getRestrictedTenantDTO(String subdomain) { | ||
log.debug("Calling tenant service to get tenant data for subdomain {}", subdomain); | ||
return tenantServiceApiControllerFactory | ||
.createControllerApi() | ||
.getRestrictedTenantDataBySubdomainWithHttpInfo(subdomain, null) | ||
.getBody(); | ||
} | ||
|
||
private RestrictedTenantDTO getRestrictedTenantDTO(Long tenantId) { | ||
log.debug("Calling tenant service to get tenant data for tenantId {}", tenantId); | ||
return tenantServiceApiControllerFactory | ||
.createControllerApi() | ||
.getRestrictedTenantDataByTenantId(tenantId); | ||
} | ||
|
||
public RestrictedTenantDTO getRestrictedTenantDataNonCached(Long tenantId) { | ||
return getRestrictedTenantDTO(tenantId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.