Compare commits

...

5 Commits

Author SHA1 Message Date
4cb8c84312 [VERSION] create version 0.7.2 2024-03-29 22:37:54 +01:00
5acdbfb0c7 [DEV] update models 2024-03-29 22:37:54 +01:00
d35c83fcbf [DEV] generate a definable UUID 2024-03-19 23:14:11 +01:00
0fe769a203 [FORMAT] error while formating 2024-03-19 08:48:24 +01:00
dbe1b469f6 [DEV] update dev tag version 2024-03-19 08:43:14 +01:00
14 changed files with 117 additions and 72 deletions

View File

@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>kangaroo-and-rabbit</groupId>
<artifactId>archidata</artifactId>
<version>0.7.0</version>
<version>0.7.2</version>
<properties>
<maven.compiler.version>3.1</maven.compiler.version>
<maven.compiler.source>21</maven.compiler.source>

View File

@@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** In case of the update parameter with String input to detect null element. */
@Target({ElementType.PARAMETER, ElementType.METHOD})
@Target({ ElementType.PARAMETER, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface AsyncType {
Class<?> value();

View File

@@ -93,6 +93,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);
@@ -108,6 +109,7 @@ public class DataResource {
filePath += part3;
return filePath;
}
public static String getFileMetaData(final UUID uuid) {
return getFileData(uuid) + ".json";
}
@@ -317,8 +319,8 @@ public class DataResource {
return Response.status(404).entity("{\"error\":\"media Does not exist: " + id + "\"}").type("application/json").build();
}
if (value.mimeType.contentEquals("image/jpeg") || value.mimeType.contentEquals("image/png")
// || value.mimeType.contentEquals("image/webp")
) {
// || value.mimeType.contentEquals("image/webp")
) {
// reads input image
final BufferedImage inputImage = ImageIO.read(inputFile);
final int scaledWidth = 250;

View File

@@ -3,19 +3,21 @@ package org.kar.archidata.catcher;
import java.time.Instant;
import java.util.UUID;
import org.kar.archidata.tools.UuidUtils;
import jakarta.ws.rs.core.Response;
public class RestErrorResponse {
public UUID uuid = UUID.randomUUID();
public UUID uuid = UuidUtils.nextUUID();
public String name; // Mandatory for TS generic error
public String message; // Mandatory for TS generic error
public String time;
public String error;
public String message;
final public int status;
final public String statusMessage;
public RestErrorResponse(final Response.Status status, final String time, final String error, final String message) {
this.time = time;
this.error = error;
this.name = error;
this.message = message;
this.status = status.getStatusCode();
this.statusMessage = status.getReasonPhrase();
@@ -23,13 +25,15 @@ public class RestErrorResponse {
public RestErrorResponse(final Response.Status status, final String error, final String message) {
this.time = Instant.now().toString();
this.error = error;
this.name = error;
this.message = message;
this.status = status.getStatusCode();
this.statusMessage = status.getReasonPhrase();
}
public RestErrorResponse(final Response.Status status) {
this.name = "generic";
this.message = "";
this.time = Instant.now().toString();
this.status = status.getStatusCode();
this.statusMessage = status.getReasonPhrase();

View File

@@ -835,7 +835,8 @@ public class DataAccess {
UUID uuid = null;
if (generateUUID) {
firstField = false;
uuid = UUID.randomUUID();
// uuid = UUID.randomUUID();
uuid = UuidUtils.nextUUID();
addElement(ps, uuid, iii);
iii.inc();
}
@@ -889,13 +890,8 @@ public class DataAccess {
if (generatedKeys.next()) {
if (primaryKeyField.getType() == UUID.class) {
// uniqueSQLUUID = generatedKeys.getObject(1, UUID.class);
/*
final Object obj = generatedKeys.getObject(1);
final BigInteger bigint = (BigInteger) generatedKeys.getObject(1);
uniqueSQLUUID = UuidUtils.asUuid(bigint);
final UUID generatedUUID = (UUID) generatedKeys.getObject(1);
System.out.println("UUID généré: " + generatedUUID);
*/
/* final Object obj = generatedKeys.getObject(1); final BigInteger bigint = (BigInteger) generatedKeys.getObject(1); uniqueSQLUUID = UuidUtils.asUuid(bigint); final UUID
* generatedUUID = (UUID) generatedKeys.getObject(1); System.out.println("UUID généré: " + generatedUUID); */
final Object obj = generatedKeys.getObject(1);
final byte[] tmpid = generatedKeys.getBytes(1);
uniqueSQLUUID = UuidUtils.asUuid(tmpid);

View File

@@ -199,6 +199,7 @@ public class DataFactoryTsApi {
}
return ((AsyncType) annotation[0]).value();
}
public static Class<?> apiAnnotationGetAsyncType(final Method element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(AsyncType.class);
if (annotation.length == 0) {
@@ -265,7 +266,7 @@ public class DataFactoryTsApi {
returnTypeModel = method.getReturnType();
}
boolean isUnmanagedReturnType = false;
if (returnTypeModel == Response.class ) {
if (returnTypeModel == Response.class) {
isUnmanagedReturnType = true;
returnTypeModel = Void.class;
}
@@ -551,16 +552,14 @@ public class DataFactoryTsApi {
myWriter = new FileWriter(pathPackage + File.separator + "index.ts");
myWriter.write(index.toString());
myWriter.close();
final InputStream ioStream = DataFactoryTsApi.class
.getClassLoader()
.getResourceAsStream("rest-tools.ts");
final InputStream ioStream = DataFactoryTsApi.class.getClassLoader().getResourceAsStream("rest-tools.ts");
if (ioStream == null) {
throw new IllegalArgumentException("rest-tools.ts is not found");
}
final BufferedReader buffer = new BufferedReader(new InputStreamReader(ioStream));
myWriter = new FileWriter(pathPackage + File.separator + "rest-tools.ts");
String line;
while( (line = buffer.readLine()) != null) {
while ((line = buffer.readLine()) != null) {
myWriter.write(line);
myWriter.write("\n");
}

View File

@@ -97,7 +97,7 @@ public class DataFactoryZod {
out.append("zod.enum([");
for (final Object elem : arr) {
if (!first) {
out.append(", \n\t");
out.append(",\n\t");
} else {
out.append("\n\t");
first = false;
@@ -106,14 +106,18 @@ public class DataFactoryZod {
out.append(elem.toString());
out.append("'");
}
out.append("\n\t])");
if (first) {
out.append("]}");
} else {
out.append("\n\t])");
}
} else {
element.isEnum = true;
boolean first = true;
out.append("{");
for (final Object elem : arr) {
if (!first) {
out.append(", \n\t");
out.append(",\n\t");
} else {
out.append("\n\t");
first = false;
@@ -123,7 +127,11 @@ public class DataFactoryZod {
out.append(elem.toString());
out.append("'");
}
out.append("}");
if (first) {
out.append("}");
} else {
out.append(",\n\t}");
}
}
element.declaration = out.toString();
previous.addOrder(element);

View File

@@ -145,6 +145,7 @@ public class AddOnDataJson implements DataAccessAddOn {
final boolean createIfNotExist, final boolean createDrop, final int fieldId) throws Exception {
DataFactory.createTablesSpecificType(tableName, field, mainTableBuilder, preActionList, postActionList, createIfNotExist, createDrop, fieldId, JsonValue.class);
}
public static void addLink(final Class<?> clazz, final Long id, final String column, final Long remoteKey) throws Exception {
final String tableName = AnnotationTools.getTableName(clazz);
final TableCoversLongLong data = DataAccess.get(TableCoversLongLong.class, id, new OverrideTableName(tableName));
@@ -174,6 +175,7 @@ public class AddOnDataJson implements DataAccessAddOn {
data.covers.add(remoteKey);
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
}
public static void addLink(final Class<?> clazz, final UUID id, final String column, final UUID remoteKey) throws Exception {
final String tableName = AnnotationTools.getTableName(clazz);
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, id, new OverrideTableName(tableName));
@@ -188,6 +190,7 @@ public class AddOnDataJson implements DataAccessAddOn {
data.covers.add(remoteKey);
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
}
public static void addLink(final Class<?> clazz, final UUID id, final String column, final Long remoteKey) throws Exception {
final String tableName = AnnotationTools.getTableName(clazz);
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, id, new OverrideTableName(tableName));
@@ -202,6 +205,7 @@ public class AddOnDataJson implements DataAccessAddOn {
data.covers.add(remoteKey);
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
}
public static void removeLink(final Class<?> clazz, final UUID id, final String column, final Long remoteKey) throws Exception {
final String tableName = AnnotationTools.getTableName(clazz);
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, id, new OverrideTableName(tableName));
@@ -218,6 +222,7 @@ public class AddOnDataJson implements DataAccessAddOn {
data.covers = newList;
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
}
public static void removeLink(final Class<?> clazz, final UUID id, final String column, final UUID remoteKey) throws Exception {
final String tableName = AnnotationTools.getTableName(clazz);
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, id, new OverrideTableName(tableName));
@@ -234,6 +239,7 @@ public class AddOnDataJson implements DataAccessAddOn {
data.covers = newList;
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
}
public static void removeLink(final Class<?> clazz, final Long id, final String column, final Long remoteKey) throws Exception {
final String tableName = AnnotationTools.getTableName(clazz);
final TableCoversLongLong data = DataAccess.get(TableCoversLongLong.class, id, new OverrideTableName(tableName));
@@ -250,6 +256,7 @@ public class AddOnDataJson implements DataAccessAddOn {
data.covers = newList;
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
}
public static void removeLink(final Class<?> clazz, final Long id, final String column, final UUID remoteKey) throws Exception {
final String tableName = AnnotationTools.getTableName(clazz);
final TableCoversLongUUID data = DataAccess.get(TableCoversLongUUID.class, id, new OverrideTableName(tableName));
@@ -266,22 +273,9 @@ public class AddOnDataJson implements DataAccessAddOn {
data.covers = newList;
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
}
/*
public static <TYPE> void addLink(final Class<TYPE> clazz, final Object localKey, final String column, final Object remoteKey) throws Exception {
final String tableName = AnnotationTools.getTableName(clazz);
final TYPE data = DataAccess.get(clazz, localKey); // TODO: add filter of the "column"
// find the field column:
// add the remoteKey in the list:
// post new data in the DB
final String linkTableName = generateLinkTableName(this.tableName, this.column);
final LinkTable insertElement = new LinkTable(this.localKey, this.remoteKey);
DataAccess.insert(insertElement, new OverrideTableName(linkTableName));
}*/
/* public static <TYPE> void addLink(final Class<TYPE> clazz, final Object localKey, final String column, final Object remoteKey) throws Exception { final String tableName =
* AnnotationTools.getTableName(clazz); final TYPE data = DataAccess.get(clazz, localKey); // TODO: add filter of the "column" // find the field column: // add the remoteKey in the list: // post
* new data in the DB final String linkTableName = generateLinkTableName(this.tableName, this.column); final LinkTable insertElement = new LinkTable(this.localKey, this.remoteKey);
* DataAccess.insert(insertElement, new OverrideTableName(linkTableName)); } */
}

View File

@@ -5,7 +5,7 @@ import java.util.UUID;
public class RESTErrorResponseExeption extends Exception {
public UUID uuid;
public String time;
public String error;
public String name;
public String message;
public int status;
public String statusMessage;
@@ -13,16 +13,16 @@ public class RESTErrorResponseExeption extends Exception {
public RESTErrorResponseExeption() {
this.uuid = null;
this.time = null;
this.error = null;
this.name = null;
this.message = null;
this.status = 0;
this.statusMessage = null;
}
public RESTErrorResponseExeption(final UUID uuid, final String time, final String error, final String message, final int status, final String statusMessage) {
public RESTErrorResponseExeption(final UUID uuid, final String time, final String name, final String message, final int status, final String statusMessage) {
this.uuid = uuid;
this.time = time;
this.error = error;
this.name = name;
this.message = message;
this.status = status;
this.statusMessage = statusMessage;
@@ -30,7 +30,7 @@ public class RESTErrorResponseExeption extends Exception {
@Override
public String toString() {
return "RESTErrorResponseExeption [uuid=" + this.uuid + ", time=" + this.time + ", error=" + this.error + ", message=" + this.message + ", status=" + this.status + ", statusMessage="
return "RESTErrorResponseExeption [uuid=" + this.uuid + ", time=" + this.time + ", name=" + this.name + ", message=" + this.message + ", status=" + this.status + ", statusMessage="
+ this.statusMessage + "]";
}

View File

@@ -211,7 +211,8 @@ public class DataTools {
return data;
}
public static <CLASS_TYPE, ID_TYPE> Response uploadCover(final Class<CLASS_TYPE> clazz, final ID_TYPE id, String fileName, final InputStream fileInputStream, final FormDataContentDisposition fileMetaData) {
public static <CLASS_TYPE, ID_TYPE> Response uploadCover(final Class<CLASS_TYPE> clazz, final ID_TYPE id, String fileName, final InputStream fileInputStream,
final FormDataContentDisposition fileMetaData) {
try {
// correct input string stream :
fileName = multipartCorrection(fileName);

View File

@@ -47,7 +47,7 @@ public class RESTApi {
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
try {
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
throw new RESTErrorResponseExeption(out.uuid, out.time, out.error, out.message, out.status, out.statusMessage);
throw out;
} catch (final MismatchedInputException ex) {
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
}
@@ -123,7 +123,7 @@ public class RESTApi {
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
try {
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
throw new RESTErrorResponseExeption(out.uuid, out.time, out.error, out.message, out.status, out.statusMessage);
throw out;
} catch (final MismatchedInputException ex) {
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
} catch (final JsonParseException ex) {
@@ -156,7 +156,7 @@ public class RESTApi {
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
try {
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
throw new RESTErrorResponseExeption(out.uuid, out.time, out.error, out.message, out.status, out.statusMessage);
throw out;
} catch (final MismatchedInputException ex) {
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
}
@@ -178,7 +178,7 @@ public class RESTApi {
if (httpResponse.statusCode() < 200 || httpResponse.statusCode() >= 300) {
try {
final RESTErrorResponseExeption out = this.mapper.readValue(httpResponse.body(), RESTErrorResponseExeption.class);
throw new RESTErrorResponseExeption(out.uuid, out.time, out.error, out.message, out.status, out.statusMessage);
throw out;
} catch (final MismatchedInputException ex) {
throw new IOException("Fail to get the data [" + httpResponse.statusCode() + "] " + httpResponse.body());
}

View File

@@ -2,6 +2,10 @@ package org.kar.archidata.tools;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.UUID;
public class UuidUtils {
@@ -25,4 +29,41 @@ public class UuidUtils {
bb.putLong(uuid.getLeastSignificantBits());
return bb.array();
}
private static class Generator {
private long base;
private final long offset;
private long previous;
public Generator() {
this.offset = System.currentTimeMillis();
// The local method never generate new UUID in the past, then we use the creation function time to prevent 2038 error
final Instant startingUUID = LocalDate.of(2024, 03, 19).atStartOfDay(ZoneOffset.UTC).toInstant();
this.base = startingUUID.until(Instant.now(), ChronoUnit.SECONDS);
final String serveurBaseUUID = System.getenv("UUID_SERVER_ID");
if (serveurBaseUUID != null) {
long serverId = Long.valueOf(serveurBaseUUID);
serverId %= 0xFFFF;
this.base += (serverId << (64 - 16));
} else {
this.base += (1L << (64 - 16));
}
}
public synchronized UUID next() {
long tmp = System.currentTimeMillis();
if (this.previous >= tmp) {
tmp = this.previous + 1;
}
this.previous = tmp;
tmp -= this.offset;
return new UUID(Long.reverseBytes(tmp), this.base);
}
}
private static Generator generator = new Generator();
public static UUID nextUUID() {
return generator.next();
}
}

View File

@@ -150,12 +150,12 @@ export function RESTRequest({ restModel, restConfig, data, params, queries }: RE
const contentType = response.headers.get('Content-Type');
if (restModel.accept !== contentType) {
reject({
name: `REST check wrong type: ${restModel.accept} != ${contentType}`,
message: "rest-tools.ts Wrong type in the message return type",
time: Date().toString(),
status: 901,
error: `REST check wrong type: ${restModel.accept} != ${contentType}`,
statusMessage: "Fetch error",
message: "rest-tools.ts Wrong type in the message return type"
} as RestErrorResponse);
});
} else if (contentType === HTTPMimeType.JSON) {
response
.json()
@@ -165,32 +165,32 @@ export function RESTRequest({ restModel, restConfig, data, params, queries }: RE
})
.catch((reason: any) => {
reject({
name: `REST parse json fail: ${reason}`,
message: "rest-tools.ts Wrong message model to parse",
time: Date().toString(),
status: 902,
error: `REST parse json fail: ${reason}`,
statusMessage: "Fetch parse error",
message: "rest-tools.ts Wrong message model to parse"
} as RestErrorResponse);
});
});
} else {
resolve({ status: response.status, data: response.body });
}
} else {
reject({
name: `${response.body}`,
message: "rest-tools.ts Wrong return code",
time: Date().toString(),
status: response.status,
error: `${response.body}`,
statusMessage: "Fetch code error",
message: "rest-tools.ts Wrong return code"
} as RestErrorResponse);
});
}
}).catch((error: any) => {
reject({
name: error,
message: "http-wrapper.ts detect an error in the fetch request",
time: Date(),
status: 999,
error: error,
statusMessage: "Fetch catch error",
message: "http-wrapper.ts detect an error in the fetch request"
statusMessage: "Fetch catch error"
});
});
});
@@ -203,12 +203,12 @@ export function RESTRequestJson<TYPE>(request: RESTRequestType, checker: (data:
resolve(value.data);
} else {
reject({
name: "REST Fail to verify the data",
message: "api.ts Check type as fail",
time: Date().toString(),
status: 950,
error: "REST Fail to verify the data",
statusMessage: "API cast ERROR",
message: "api.ts Check type as fail"
} as RestErrorResponse);
});
}
}).catch((reason: RestErrorResponse) => {
reject(reason);
@@ -222,12 +222,12 @@ export function RESTRequestJsonArray<TYPE>(request: RESTRequestType, checker: (d
resolve(value.data);
} else {
reject({
name: "REST Fail to verify the data",
message: "api.ts Check type as fail",
time: Date().toString(),
status: 950,
error: "REST Fail to verify the data",
statusMessage: "API cast ERROR",
message: "api.ts Check type as fail"
} as RestErrorResponse);
});
}
}).catch((reason: RestErrorResponse) => {
reject(reason);

View File

@@ -1 +1 @@
0.7.0
0.7.2