-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add images controller * feat: increase image size * feat: add RefTypePathParamMapper * feat: fix test failure keycloak
- Loading branch information
Showing
12 changed files
with
1,791 additions
and
1,113 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
88 changes: 88 additions & 0 deletions
88
src/main/java/org/tkit/onecx/product/store/bff/rs/controllers/ImagesRestController.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,88 @@ | ||
package org.tkit.onecx.product.store.bff.rs.controllers; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.transaction.Transactional; | ||
import jakarta.validation.ConstraintViolationException; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.HttpHeaders; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
import org.jboss.resteasy.reactive.RestResponse; | ||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper; | ||
import org.tkit.onecx.product.store.bff.rs.mappers.ExceptionMapper; | ||
import org.tkit.onecx.product.store.bff.rs.mappers.ImagesMapper; | ||
import org.tkit.quarkus.log.cdi.LogService; | ||
|
||
import gen.org.tkit.onecx.product.store.bff.rs.internal.ImagesInternalApiService; | ||
import gen.org.tkit.onecx.product.store.bff.rs.internal.model.ImageInfoDTO; | ||
import gen.org.tkit.onecx.product.store.bff.rs.internal.model.ProblemDetailResponseDTO; | ||
import gen.org.tkit.onecx.product.store.bff.rs.internal.model.RefTypeDTO; | ||
import gen.org.tkit.onecx.product.store.client.api.ImagesInternalApi; | ||
import gen.org.tkit.onecx.product.store.client.model.ImageInfo; | ||
|
||
@ApplicationScoped | ||
@Transactional(value = Transactional.TxType.NOT_SUPPORTED) | ||
@LogService | ||
public class ImagesRestController implements ImagesInternalApiService { | ||
|
||
@Inject | ||
@RestClient | ||
ImagesInternalApi imageApi; | ||
|
||
@Inject | ||
ImagesMapper imageMapper; | ||
|
||
@Inject | ||
ExceptionMapper exceptionMapper; | ||
|
||
@Override | ||
public Response getImage(String refId, RefTypeDTO refType) { | ||
try (Response response = imageApi.getImage(refId, imageMapper.map(refType))) { | ||
var contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE); | ||
var contentLength = response.getHeaderString(HttpHeaders.CONTENT_LENGTH); | ||
var body = response.readEntity(byte[].class); | ||
if (contentType != null && contentLength != null && body != null && body.length != 0) { | ||
return Response.status(response.getStatus()) | ||
.header(HttpHeaders.CONTENT_TYPE, contentType) | ||
.header(HttpHeaders.CONTENT_LENGTH, contentLength) | ||
.entity(body) | ||
.build(); | ||
} else { | ||
return Response.status(Response.Status.BAD_REQUEST).build(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Response updateImage(String refId, RefTypeDTO refType, byte[] body, Integer contentLength) { | ||
|
||
try (Response response = imageApi.updateImage(refId, imageMapper.map(refType), body, | ||
contentLength)) { | ||
|
||
ImageInfoDTO imageInfoDTO = imageMapper.map(response.readEntity(ImageInfo.class)); | ||
return Response.status(response.getStatus()).entity(imageInfoDTO).build(); | ||
} | ||
} | ||
|
||
@Override | ||
public Response uploadImage(Integer contentLength, String refId, RefTypeDTO refType, byte[] body) { | ||
|
||
try (Response response = imageApi.uploadImage(contentLength, refId, imageMapper.map(refType), | ||
body)) { | ||
ImageInfoDTO imageInfoDTO = imageMapper.map(response.readEntity(ImageInfo.class)); | ||
return Response.status(response.getStatus()).entity(imageInfoDTO).build(); | ||
} | ||
} | ||
|
||
@ServerExceptionMapper | ||
public RestResponse<ProblemDetailResponseDTO> constraint(ConstraintViolationException ex) { | ||
return exceptionMapper.constraint(ex); | ||
} | ||
|
||
@ServerExceptionMapper | ||
public Response restException(WebApplicationException ex) { | ||
return Response.status(ex.getResponse().getStatus()).build(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/org/tkit/onecx/product/store/bff/rs/mappers/ImagesMapper.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,20 @@ | ||
package org.tkit.onecx.product.store.bff.rs.mappers; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; | ||
|
||
import gen.org.tkit.onecx.product.store.bff.rs.internal.model.ImageInfoDTO; | ||
import gen.org.tkit.onecx.product.store.bff.rs.internal.model.RefTypeDTO; | ||
import gen.org.tkit.onecx.product.store.client.model.ImageInfo; | ||
import gen.org.tkit.onecx.product.store.client.model.RefType; | ||
|
||
@Mapper(uses = { OffsetDateTimeMapper.class }) | ||
public interface ImagesMapper { | ||
|
||
ImageInfoDTO map(ImageInfo image); | ||
|
||
ImageInfo map(ImageInfoDTO image); | ||
|
||
RefType map(RefTypeDTO refType); | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/tkit/onecx/product/store/bff/rs/mappers/RefTypePathParamMapper.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,39 @@ | ||
package org.tkit.onecx.product.store.bff.rs.mappers; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
|
||
import jakarta.inject.Singleton; | ||
import jakarta.ws.rs.ext.ParamConverter; | ||
import jakarta.ws.rs.ext.ParamConverterProvider; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
import gen.org.tkit.onecx.product.store.client.model.RefType; | ||
|
||
@Provider | ||
@Singleton | ||
public class RefTypePathParamMapper implements ParamConverterProvider { | ||
public RefTypePathParamMapper() { | ||
|
||
} | ||
|
||
@Override | ||
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) { | ||
|
||
return rawType.isAssignableFrom(RefType.class) ? (ParamConverter<T>) new RefTypeParamConverter() : null; | ||
} | ||
|
||
public static class RefTypeParamConverter implements ParamConverter<RefType> { | ||
public RefTypeParamConverter() { | ||
} | ||
|
||
public RefType fromString(String value) { | ||
return value != null && !value.isBlank() ? RefType.fromString(value) : null; | ||
} | ||
|
||
public String toString(RefType value) { | ||
return value == null ? null : value.toString(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.