[STYLE] fix style

This commit is contained in:
Edouard DUPIN 2024-09-14 10:20:07 +02:00
parent de08bcfab5
commit 3fa48fc839
6 changed files with 70 additions and 71 deletions

25
pom.xml
View File

@ -56,29 +56,28 @@
</dependency>
<!-- Decode webP images -->
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-webp</artifactId>
<version>3.11.0</version>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-webp</artifactId>
<version>3.11.0</version>
</dependency>
<!-- Decode JPEG image -->
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
<version>3.11.0</version>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
<version>3.11.0</version>
</dependency>
<!-- Encode file in webp -->
<dependency>
<groupId>com.github.gotson</groupId>
<artifactId>webp-imageio</artifactId>
<version>0.2.2</version>
<groupId>com.github.gotson</groupId>
<artifactId>webp-imageio</artifactId>
<version>0.2.2</version>
</dependency>
<!-- Detect type of a file with mime type -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.7.0</version>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.7.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-multipart -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>

View File

@ -64,18 +64,18 @@ public class DataResource {
private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks
/** Upload some datas */
private static long tmpFolderId = 1;
private static void createFolder(final String path) throws IOException {
if (!Files.exists(java.nio.file.Path.of(path))) {
// Log.print("Create folder: " + path);
Files.createDirectories(java.nio.file.Path.of(path));
}
}
public static long getTmpDataId() {
return tmpFolderId++;
}
public static String getTmpFileInData(final long tmpFolderId) {
final String filePath = ConfigBaseVariable.getTmpDataFolder() + File.separator + tmpFolderId;
try {
@ -85,7 +85,7 @@ public class DataResource {
}
return filePath;
}
public static String getFileDataOld(final long tmpFolderId) {
final String filePath = ConfigBaseVariable.getMediaDataFolder() + File.separator + tmpFolderId + File.separator
+ "data";
@ -96,7 +96,7 @@ public class DataResource {
}
return filePath;
}
public static String getFileData(final UUID uuid) {
final String stringUUID = uuid.toString();
final String part1 = stringUUID.substring(0, 2);
@ -113,11 +113,11 @@ public class DataResource {
filePath += part3;
return filePath;
}
public static String getFileMetaData(final UUID uuid) {
return getFileData(uuid) + ".json";
}
public static Data getWithSha512(final String sha512) {
LOGGER.info("find sha512 = {}", sha512);
try {
@ -128,7 +128,7 @@ public class DataResource {
}
return null;
}
public static Data getWithId(final long id) {
LOGGER.info("find id = {}", id);
try {
@ -139,7 +139,7 @@ public class DataResource {
}
return null;
}
public static Data createNewData(final long tmpUID, final String originalFileName, final String sha512)
throws IOException {
// determine mime type:
@ -159,7 +159,7 @@ public class DataResource {
injectedData.sha512 = sha512;
final String tmpPath = getTmpFileInData(tmpUID);
injectedData.size = Files.size(Paths.get(tmpPath));
try {
injectedData = DataAccess.insert(injectedData);
} catch (final Exception e) {
@ -173,7 +173,7 @@ public class DataResource {
LOGGER.info("Move done");
return injectedData;
}
public static void modeFileOldModelToNewModel(final long id, final UUID uuid) throws IOException {
String mediaCurentPath = getFileDataOld(id);
String mediaDestPath = getFileData(uuid);
@ -192,12 +192,12 @@ public class DataResource {
}
LOGGER.info("Move done");
}
public static String saveTemporaryFile(final InputStream uploadedInputStream, final long idData)
throws FailException {
return saveFile(uploadedInputStream, DataResource.getTmpFileInData(idData));
}
public static void removeTemporaryFile(final long idData) {
final String filepath = DataResource.getTmpFileInData(idData);
if (Files.exists(Paths.get(filepath))) {
@ -209,7 +209,7 @@ public class DataResource {
}
}
}
// save uploaded file to a defined location on the server
static String saveFile(final InputStream uploadedInputStream, final String serverLocation) throws FailException {
String out = "";
@ -243,7 +243,7 @@ public class DataResource {
}
return out;
}
public static String bytesToHex(final byte[] bytes) {
final StringBuilder sb = new StringBuilder();
for (final byte b : bytes) {
@ -251,7 +251,7 @@ public class DataResource {
}
return sb.toString();
}
public Data getSmall(final UUID id) {
try {
return DataAccess.get(Data.class, id);
@ -261,7 +261,7 @@ public class DataResource {
}
return null;
}
@POST
@Path("/upload/")
@Consumes({ MediaType.MULTIPART_FORM_DATA })
@ -286,7 +286,7 @@ public class DataResource {
}
saveFile(fileInputStream, filePath);
}
@GET
@Path("{uuid}")
@PermitTokenInURI
@ -313,7 +313,7 @@ public class DataResource {
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to build output stream", ex);
}
}
@GET
@Path("thumbnail/{uuid}")
@RolesAllowed("USER")
@ -400,7 +400,7 @@ public class DataResource {
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to build output stream", ex);
}
}
@GET
@Path("{uuid}/{name}")
@PermitTokenInURI
@ -424,7 +424,7 @@ public class DataResource {
return buildStream(getFileData(uuid), range,
value.mimeType == null ? "application/octet-stream" : value.mimeType);
}
/** Adapted from http://stackoverflow.com/questions/12768812/video-streaming-to-ipad-does-not-work-with-tapestry5/12829541#12829541
*
* @param range range header
@ -463,12 +463,12 @@ public class DataResource {
out.type(mimeType);
}
return out.build();
}
final String[] ranges = range.split("=")[1].split("-");
final long from = Long.parseLong(ranges[0]);
// logger.info("request range : {}", ranges.length);
// Chunk media if the range upper bound is unspecified. Chrome, Opera sends "bytes=0-"
long to = CHUNK_SIZE + from;
@ -481,7 +481,7 @@ public class DataResource {
// logger.info("responseRange: {}", responseRange);
try (final RandomAccessFile raf = new RandomAccessFile(file, "r")) {
raf.seek(from);
final long len = to - from + 1;
final MediaStreamer streamer = new MediaStreamer(len, raf);
final Response.ResponseBuilder out = Response.ok(streamer).status(Response.Status.PARTIAL_CONTENT)
@ -498,9 +498,9 @@ public class DataResource {
throw new FailException(Response.Status.INTERNAL_SERVER_ERROR, "Fail to access to the required file.", ex);
}
}
public static void undelete(final Long id) throws Exception {
DataAccess.unsetDelete(Data.class, id);
}
}

View File

@ -18,7 +18,7 @@ import jakarta.ws.rs.core.Response.Status;
//@Produces(MediaType.APPLICATION_JSON)
public class ProxyResource {
private static final Logger LOGGER = LoggerFactory.getLogger(ProxyResource.class);
@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getImageFromUrl(@QueryParam("url") final String url) {

View File

@ -27,7 +27,7 @@ public class RestErrorResponse {
@NotNull
@Column(length = 0)
final public String statusMessage;
public RestErrorResponse(final Response.Status status, final String time, final String error,
final String message) {
this.time = time;
@ -36,7 +36,7 @@ public class RestErrorResponse {
this.status = status.getStatusCode();
this.statusMessage = status.getReasonPhrase();
}
public RestErrorResponse(final Response.Status status, final String error, final String message) {
this.time = Instant.now().toString();
this.name = error;
@ -44,7 +44,7 @@ public class RestErrorResponse {
this.status = status.getStatusCode();
this.statusMessage = status.getReasonPhrase();
}
public RestErrorResponse(final Response.Status status) {
this.name = "generic";
this.message = "";
@ -52,5 +52,5 @@ public class RestErrorResponse {
this.status = status.getStatusCode();
this.statusMessage = status.getReasonPhrase();
}
}

View File

@ -30,7 +30,7 @@ import org.kar.archidata.externalRestApi.typescript.TsClassElementGroup;
public class TsGenerateApi {
/**
* Generate a full API tree for Typescript in a specific folder.
* This generate a folder containing a full API with "model" filder and "api" folder.
* This generate a folder containing a full API with "model" folder and "api" folder.
* The generation depend of Zod and can be strict compile.
* @param api Data model to generate the api
* @param pathPackage Path to store the api.

View File

@ -35,7 +35,7 @@ import com.nimbusds.jwt.SignedJWT;
class TestSigner implements JWSSigner {
public static String test_signature = "TEST_SIGNATURE_FOR_LOCAL_TEST_AND_TEST_E2E";
/** Signs the specified {@link JWSObject#getSigningInput input} of a {@link JWSObject JWS object}.
*
* @param header The JSON Web Signature (JWS) header. Must specify a supported JWS algorithm and must not be {@code null}.
@ -49,13 +49,13 @@ class TestSigner implements JWSSigner {
public Base64URL sign(final JWSHeader header, final byte[] signingInput) throws JOSEException {
return new Base64URL(test_signature);
}
@Override
public Set<JWSAlgorithm> supportedJWSAlgorithms() {
// TODO Auto-generated method stub
return Set.of(JWSAlgorithm.RS256);
}
@Override
public JCAContext getJCAContext() {
// TODO Auto-generated method stub
@ -65,20 +65,20 @@ class TestSigner implements JWSSigner {
public class JWTWrapper {
static final Logger LOGGER = LoggerFactory.getLogger(JWTWrapper.class);
private static RSAKey rsaJWK = null;
private static RSAKey rsaPublicJWK = null;
public static class PublicKey {
public String key;
public PublicKey(final String key) {
this.key = key;
}
public PublicKey() {}
}
public static void initLocalTokenRemote(final String ssoUri, final String application)
throws IOException, ParseException {
// check Token:
@ -95,11 +95,11 @@ public class JWTWrapper {
con.setRequestProperty(AuthenticationFilter.APIKEY, ssoToken);
}
final int responseCode = con.getResponseCode();
// LOGGER.debug("GET Response Code :: {}", responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) { // success
final BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
final StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
@ -115,7 +115,7 @@ public class JWTWrapper {
}
LOGGER.debug("GET JWT validator token not worked response code {} from {} ", responseCode, obj);
}
public static void initLocalToken(final String baseUUID) throws Exception {
// RSA signatures require a public and private RSA key pair, the public key
// must be made known to the JWS recipient in order to verify the signatures
@ -139,7 +139,7 @@ public class JWTWrapper {
rsaPublicJWK = null;
}
}
public static void initValidateToken(final String publicKey) {
try {
rsaPublicJWK = RSAKey.parse(publicKey);
@ -147,16 +147,16 @@ public class JWTWrapper {
e.printStackTrace();
LOGGER.debug("Can not retrieve public Key !!!!!!!! RSAKey='{}'", publicKey);
}
}
public static String getPublicKeyJson() {
if (rsaPublicJWK == null) {
return null;
}
return rsaPublicJWK.toJSONString();
}
public static java.security.interfaces.RSAPublicKey getPublicKeyJava() throws JOSEException {
if (rsaPublicJWK == null) {
return null;
@ -164,7 +164,7 @@ public class JWTWrapper {
// Convert back to std Java interface
return rsaPublicJWK.toRSAPublicKey();
}
/** Create a token with the provided elements
* @param userID UniqueId of the USER (global unique ID)
* @param userLogin Login of the user (never change)
@ -187,12 +187,12 @@ public class JWTWrapper {
try {
// Create RSA-signer with the private key
final JWSSigner signer = new RSASSASigner(rsaJWK);
LOGGER.warn("timeOutInMunites= {}", timeOutInMunites);
final Date now = new Date();
LOGGER.warn("now = {}", now);
final Date expiration = new Date(new Date().getTime() - 60 * timeOutInMunites * 1000 /* millisecond */);
LOGGER.warn("expiration= {}", expiration);
final JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder().subject(Long.toString(userID))
.claim("login", userLogin).claim("application", application).issuer(isuer).issueTime(now)
@ -205,7 +205,7 @@ public class JWTWrapper {
final JWTClaimsSet claimsSet = builder.build();
final SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).type(JOSEObjectType.JWT)
/* .keyID(rsaJWK.getKeyID()) */.build(), claimsSet);
// Compute the RSA signature
signedJWT.sign(signer);
// serialize the output...
@ -215,7 +215,7 @@ public class JWTWrapper {
}
return null;
}
public static JWTClaimsSet validateToken(final String signedToken, final String isuer, final String application) {
try {
// On the consumer side, parse the JWS and verify its RSA signature
@ -267,7 +267,7 @@ public class JWTWrapper {
}
return null;
}
public static String createJwtTestToken(
final long userID,
final String userLogin,
@ -280,10 +280,10 @@ public class JWTWrapper {
}
try {
final int timeOutInMunites = 3600;
final Date now = new Date();
final Date expiration = new Date(new Date().getTime() + timeOutInMunites * 1000 /* ms */);
final JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder().subject(Long.toString(userID))
.claim("login", userLogin).claim("application", application).issuer(isuer).issueTime(now)
.expirationTime(expiration); // Do not ask why we need a "-" here ... this have no meaning
@ -295,10 +295,10 @@ public class JWTWrapper {
final JWTClaimsSet claimsSet = builder.build();
final SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).type(JOSEObjectType.JWT)
/* .keyID(rsaJWK.getKeyID()) */.build(), claimsSet);
// Compute the RSA signature
signedJWT.sign(new TestSigner());
// serialize the output...
return signedJWT.serialize();
} catch (final Exception ex) {