[STYLE] format code

This commit is contained in:
Edouard DUPIN 2024-05-21 23:22:32 +02:00
parent 0597ba0df3
commit c33a73a567
14 changed files with 107 additions and 107 deletions

View File

@ -13,7 +13,7 @@ public class AnalyzeApi {
static final Logger LOGGER = LoggerFactory.getLogger(AnalyzeApi.class);
protected final List<ApiGroupModel> apiModels = new ArrayList<>();
protected final ModelGroup modelGroup = new ModelGroup();
public void addAllModel(final List<Class<?>> classes) throws Exception {
this.modelGroup.addAll(classes);
analyzeModels();
@ -35,15 +35,15 @@ public class AnalyzeApi {
}
analyzeModels();
}
public List<ApiGroupModel> getAllApi() {
return this.apiModels;
}
public List<ClassModel> getAllModel() {
return this.modelGroup.getModels();
}
private void analyzeModels() throws Exception {
final List<ClassModel> dones = new ArrayList<>();
while (dones.size() < getAllModel().size()) {

View File

@ -1,8 +1,8 @@
package org.kar.archidata.externalRestApi;
public class PythonGenerateApi {
public static void generateApi(final AnalyzeApi api) {
}
}

View File

@ -27,7 +27,7 @@ import jakarta.ws.rs.core.MediaType;
public class TsApiGeneration {
static final Logger LOGGER = LoggerFactory.getLogger(TsApiGeneration.class);
public static String getBaseHeader() {
return """
/**
@ -130,14 +130,14 @@ public class TsApiGeneration {
}
return out.toString();
}
public static String capitalizeFirstLetter(final String str) {
if (str == null || str.isEmpty()) {
return str;
}
return str.substring(0, 1).toUpperCase() + str.substring(1);
}
public static void generateApiFile(
final ApiGroupModel element,
final String pathPackage,
@ -429,5 +429,5 @@ public class TsApiGeneration {
myWriter.write(out.toString());
myWriter.close();
}
}

View File

@ -20,13 +20,13 @@ import org.slf4j.LoggerFactory;
public class TsClassElement {
static final Logger LOGGER = LoggerFactory.getLogger(TsClassElement.class);
public enum DefinedPosition {
NATIVE, // Native element of TS language.
BASIC, // basic wrapping for JAVA type.
NORMAL // Normal Object to interpret.
}
public List<ClassModel> models;
public String zodName;
public String tsTypeName;
@ -35,7 +35,7 @@ public class TsClassElement {
public String fileName = null;
public String comment = null;
public DefinedPosition nativeType = DefinedPosition.NORMAL;
public static String determineFileName(final String className) {
return className.replaceAll("([a-z])([A-Z])", "$1-$2").replaceAll("([A-Z])([A-Z][a-z])", "$1-$2").toLowerCase();
}
@ -50,7 +50,7 @@ public class TsClassElement {
this.nativeType = nativeType;
this.fileName = determineFileName(tsTypeName);
}
public TsClassElement(final ClassModel model) {
this.models = List.of(model);
this.zodName = "Zod" + model.getOriginClasses().getSimpleName();
@ -59,27 +59,27 @@ public class TsClassElement {
this.declaration = null;
this.fileName = determineFileName(this.tsTypeName);
}
public boolean isCompatible(final ClassModel model) {
return this.models.contains(model);
}
public String getBaseHeader() {
return """
/**
* Interface of the server (auto-generated code)
*/
import { z as zod } from "zod";
""";
}
public String generateEnum(final ClassEnumModel model, final TsClassElementGroup tsGroup) throws IOException {
final StringBuilder out = new StringBuilder();
out.append(getBaseHeader());
out.append("\n");
//out.append(generateComment(model));
if (System.getenv("ARCHIDATA_GENERATE_ZOD_ENUM") != null) {
boolean first = true;
out.append("export const ");
@ -141,7 +141,7 @@ public class TsClassElement {
out.append(generateExportCheckFunctionWrite(""));
return out.toString();
}
private static String generateExportCheckFunction(
final String tsCheckType,
final String tsTypeName,
@ -167,12 +167,12 @@ public class TsClassElement {
""");
return out.toString();
}
private String generateExportCheckFunctionWrite(final String writeString) {
return generateExportCheckFunction(this.tsCheckType + writeString, this.tsTypeName + writeString,
this.zodName + writeString);
}
public String generateImports(final List<ClassModel> depModels, final TsClassElementGroup tsGroup)
throws IOException {
final StringBuilder out = new StringBuilder();
@ -188,7 +188,7 @@ public class TsClassElement {
}
return out.toString();
}
private Object generateComment(final ClassObjectModel model) {
final StringBuilder out = new StringBuilder();
if (model.getDescription() != null || model.getExample() != null) {
@ -214,7 +214,7 @@ public class TsClassElement {
}
return out.toString();
}
public String optionalTypeZod(final FieldProperty field) {
if (field.model().getOriginClasses() == null || field.model().getOriginClasses().isPrimitive()) {
return "";
@ -242,12 +242,12 @@ public class TsClassElement {
}
return "";
}
public String generateBaseObject() {
final StringBuilder out = new StringBuilder();
out.append(getBaseHeader());
out.append("\n");
out.append("export const ");
out.append(this.zodName);
out.append(" = ");
@ -262,12 +262,12 @@ public class TsClassElement {
out.append(getBaseHeader());
out.append(generateImports(model.getDependencyModels(), tsGroup));
out.append("\n");
out.append(generateComment(model));
out.append("export const ");
out.append(this.zodName);
out.append(" = ");
if (model.getExtendsClass() != null) {
final ClassModel parentClass = model.getExtendsClass();
final TsClassElement tsParentModel = tsGroup.find(parentClass);
@ -307,7 +307,7 @@ public class TsClassElement {
out.append("\n});\n");
out.append(generateZodInfer(this.tsTypeName, this.zodName));
out.append(generateExportCheckFunctionWrite(""));
// Generate the Write Type associated.
out.append("\nexport const ");
out.append(this.zodName);
@ -324,10 +324,10 @@ public class TsClassElement {
}
out.append(".partial();\n");
out.append(generateZodInfer(this.tsTypeName + "Write", this.zodName + "Write"));
// Check only the input value ==> no need of the output
out.append(generateExportCheckFunctionWrite("Write"));
return out.toString();
}
@ -374,17 +374,17 @@ public class TsClassElement {
out.append(")");
return out.toString();
}
private static String generateTsEnum(final ClassEnumModel model, final TsClassElementGroup tsGroup) {
final TsClassElement tsParentModel = tsGroup.find(model);
return tsParentModel.zodName;
}
private static String generateTsObject(final ClassObjectModel model, final TsClassElementGroup tsGroup) {
final TsClassElement tsParentModel = tsGroup.find(model);
return tsParentModel.zodName;
}
private static String generateTsList(final ClassListModel model, final TsClassElementGroup tsGroup) {
final StringBuilder out = new StringBuilder();
out.append("zod.array(");
@ -401,7 +401,7 @@ public class TsClassElement {
out.append(")");
return out.toString();
}
public void generateFile(final String pathPackage, final TsClassElementGroup tsGroup) throws IOException {
if (this.nativeType == DefinedPosition.NATIVE) {
return;
@ -475,5 +475,5 @@ public class TsClassElement {
out.append(generateExportCheckFunction("is" + ModelName, ModelName, "Zod" + ModelName));
return out.toString();
}
}

View File

@ -23,7 +23,7 @@ import org.kar.archidata.externalRestApi.model.ApiGroupModel;
import org.kar.archidata.externalRestApi.model.ClassModel;
public class TsGenerateApi {
public static void generateApi(final AnalyzeApi api, final String pathPackage) throws Exception {
final List<TsClassElement> localModel = generateApiModel(api);
final TsClassElementGroup tsGroup = new TsClassElementGroup(localModel);
@ -51,13 +51,13 @@ public class TsGenerateApi {
export * from \"./model\";
export * from \"./api\";
export * from \"./rest-tools\";
""";
final FileWriter myWriter = new FileWriter(pathPackage + File.separator + "index.ts");
myWriter.write(out);
myWriter.close();
}
private static void createResourceIndex(final String pathPackage, final List<ApiGroupModel> apiModels)
throws IOException {
final StringBuilder out = new StringBuilder("""
@ -211,7 +211,7 @@ public class TsGenerateApi {
return tsModels;
}
public static void copyResourceFile(final String name, final String destinationPath) throws IOException {
final InputStream ioStream = TsGenerateApi.class.getClassLoader().getResourceAsStream(name);
if (ioStream == null) {

View File

@ -14,10 +14,10 @@ import org.slf4j.LoggerFactory;
public class ApiModel {
static final Logger LOGGER = LoggerFactory.getLogger(ApiModel.class);
Class<?> originClass;
Method orignMethod;
// Name of the REST end-point name
public String restEndPoint;
// Type of the request:
@ -26,7 +26,7 @@ public class ApiModel {
public String description;
// need to generate the progression of stream (if possible)
public boolean needGenerateProgress;
// List of types returned by the API
public List<ClassModel> returnTypes = new ArrayList<>();;
// Name of the API (function name)
@ -39,12 +39,12 @@ public class ApiModel {
public final Map<String, List<ClassModel>> multiPartParameters = new HashMap<>();
// model of data available
public final List<ClassModel> unnamedElement = new ArrayList<>();
// Possible input type of the REST API
public List<String> consumes = new ArrayList<>();
// Possible output type of the REST API
public List<String> produces = new ArrayList<>();
private void updateReturnTypes(final Method method, final ModelGroup previousModel) throws Exception {
// get return type from the user specification:
final Class<?>[] returnTypeModel = ApiTool.apiAnnotationGetAsyncType(method);
@ -66,7 +66,7 @@ public class ApiModel {
}
return;
}
final Class<?> returnTypeModelRaw = method.getReturnType();
LOGGER.info("Get return Type RAW = {}", returnTypeModelRaw.getCanonicalName());
if (returnTypeModelRaw == Map.class) {
@ -92,12 +92,12 @@ public class ApiModel {
LOGGER.warn(" - {}", elem);
}
}
public ApiModel(final Class<?> clazz, final Method method, final String baseRestEndPoint,
final List<String> consume, final List<String> produce, final ModelGroup previousModel) throws Exception {
this.originClass = clazz;
this.orignMethod = method;
String tmpPath = ApiTool.apiAnnotationGetPath(method);
if (tmpPath == null) {
tmpPath = "";
@ -105,19 +105,19 @@ public class ApiModel {
this.restEndPoint = baseRestEndPoint + "/" + tmpPath;
this.restTypeRequest = ApiTool.apiAnnotationGetTypeRequest2(method);
this.name = method.getName();
this.description = ApiTool.apiAnnotationGetOperationDescription(method);
this.consumes = ApiTool.apiAnnotationGetConsumes2(consume, method);
this.produces = ApiTool.apiAnnotationProduces2(produce, method);
LOGGER.trace(" [{}] {} => {}/{}", baseRestEndPoint, this.name, this.restEndPoint);
this.needGenerateProgress = ApiTool.apiAnnotationTypeScriptProgress(method);
updateReturnTypes(method, previousModel);
LOGGER.trace(" return: {}", this.returnTypes.size());
for (final ClassModel elem : this.returnTypes) {
LOGGER.trace(" - {}", elem);
}
// LOGGER.info(" Parameters:");
for (final Parameter parameter : method.getParameters()) {
// Security context are internal parameter (not available from API)
@ -142,7 +142,7 @@ public class ApiModel {
} else {
parameterModel.add(previousModel.add(parameterType));
}
final String pathParam = ApiTool.apiAnnotationGetPathParam(parameter);
final String queryParam = ApiTool.apiAnnotationGetQueryParam(parameter);
final String formDataParam = ApiTool.apiAnnotationGetFormDataParam(parameter);
@ -159,6 +159,6 @@ public class ApiModel {
if (this.unnamedElement.size() > 1) {
throw new IOException("Can not parse the API, enmpty element is more than 1 in " + this.name);
}
}
}

View File

@ -7,11 +7,11 @@ import java.util.Map;
import java.util.Set;
public class ClassEnumModel extends ClassModel {
protected ClassEnumModel(final Class<?> clazz) {
this.originClasses = clazz;
}
@Override
public String toString() {
final StringBuilder out = new StringBuilder();
@ -20,9 +20,9 @@ public class ClassEnumModel extends ClassModel {
out.append("]");
return out.toString();
}
final Map<String, Object> listOfValues = new HashMap<>();
@Override
public void analyze(final ModelGroup group) throws IOException {
if (this.analyzeDone) {
@ -49,16 +49,16 @@ public class ClassEnumModel extends ClassModel {
this.listOfValues.put(elem.toString(), elem.toString());
}
}
public Map<String, Object> getListOfValues() {
return this.listOfValues;
}
@Override
public Set<ClassModel> getAlls() {
return Set.of(this);
}
@Override
public Set<ClassModel> getDependencyGroupModels() {
return Set.of(this);

View File

@ -7,39 +7,39 @@ import java.util.Set;
public class ClassListModel extends ClassModel {
public ClassModel valueModel;
public ClassListModel(final ClassModel valueModel) {
this.valueModel = valueModel;
}
public ClassListModel(final Class<?> clazz, final ModelGroup previousModel) throws IOException {
this.valueModel = getModel(clazz, previousModel);
}
public ClassListModel(final Type model, final ModelGroup previousModel) throws IOException {
this.valueModel = getModel(model, previousModel);
}
public ClassListModel(final ParameterizedType listType, final ModelGroup previousModel) throws IOException {
final Type model = listType.getActualTypeArguments()[0];
this.valueModel = getModel(model, previousModel);
}
@Override
public String toString() {
return "ClassListModel [valueModel=" + this.valueModel + "]";
}
@Override
public void analyze(final ModelGroup group) throws IOException {
throw new IOException("Analyze can not be done at this phase for List...");
}
@Override
public Set<ClassModel> getAlls() {
return this.valueModel.getAlls();
}
@Override
public Set<ClassModel> getDependencyGroupModels() {
return this.valueModel.getDependencyGroupModels();

View File

@ -9,40 +9,40 @@ import java.util.Set;
public class ClassMapModel extends ClassModel {
public ClassModel keyModel;
public ClassModel valueModel;
public ClassMapModel(final ClassModel keyModel, final ClassModel valueModel) {
this.keyModel = keyModel;
this.valueModel = valueModel;
}
public ClassMapModel(final Type listTypeKey, final Type listTypeValue, final ModelGroup previousModel)
throws IOException {
this.keyModel = getModel(listTypeKey, previousModel);
this.valueModel = getModel(listTypeValue, previousModel);
}
public ClassMapModel(final ParameterizedType listType, final ModelGroup previousModel) throws IOException {
this.keyModel = getModel(listType.getActualTypeArguments()[0], previousModel);
this.valueModel = getModel(listType.getActualTypeArguments()[1], previousModel);
}
@Override
public String toString() {
return "ClassMapModel [keyModel=" + this.keyModel + ", valueModel=" + this.valueModel + "]";
}
@Override
public void analyze(final ModelGroup group) throws IOException {
throw new IOException("Analyze can not be done at this phase for Map...");
}
@Override
public Set<ClassModel> getAlls() {
final Set<ClassModel> out = new HashSet<>(this.keyModel.getAlls());
out.addAll(this.valueModel.getAlls());
return out;
}
@Override
public Set<ClassModel> getDependencyGroupModels() {
final Set<ClassModel> out = new HashSet<>(this.valueModel.getDependencyGroupModels());

View File

@ -24,7 +24,7 @@ public abstract class ClassModel {
public List<ClassModel> getDependencyModels() {
return this.dependencyModels;
}
public abstract Set<ClassModel> getDependencyGroupModels();
public static ClassModel getModel(final Type type, final ModelGroup previousModel) throws IOException {
@ -70,7 +70,7 @@ public abstract class ClassModel {
public abstract void analyze(final ModelGroup group) throws Exception;
public abstract Set<ClassModel> getAlls();
public List<String> getReadOnlyField() {
return List.of();
}

View File

@ -15,11 +15,11 @@ import org.slf4j.LoggerFactory;
public class ClassObjectModel extends ClassModel {
static final Logger LOGGER = LoggerFactory.getLogger(ClassObjectModel.class);
public ClassObjectModel(final Class<?> clazz) {
this.originClasses = clazz;
}
@Override
public String toString() {
final StringBuilder out = new StringBuilder();
@ -28,7 +28,7 @@ public class ClassObjectModel extends ClassModel {
out.append("]");
return out.toString();
}
private static boolean isFieldFromSuperClass(final Class<?> model, final String filedName) {
final Class<?> superClass = model.getSuperclass();
if (superClass == null) {
@ -48,7 +48,7 @@ public class ClassObjectModel extends ClassModel {
}
return false;
}
public record FieldProperty(
String name,
ClassModel model,
@ -57,7 +57,7 @@ public class ClassObjectModel extends ClassModel {
boolean readOnly,
boolean notNull,
boolean nullable) {
public FieldProperty(final String name, final ClassModel model, final String comment, final int limitSize,
final boolean readOnly, final boolean notNull, final boolean nullable) {
this.name = name;
@ -67,9 +67,9 @@ public class ClassObjectModel extends ClassModel {
this.readOnly = readOnly;
this.notNull = notNull;
this.nullable = nullable;
}
public FieldProperty(final Field field, final ModelGroup previous) throws Exception {
this(field.getName(), //
ClassModel.getModel(field.getGenericType(), previous), //
@ -79,40 +79,40 @@ public class ClassObjectModel extends ClassModel {
AnnotationTools.getConstraintsNotNull(field), //
AnnotationTools.getColumnNotNull(field));
}
}
String name = "";
boolean isPrimitive = false;
String description = null;
String example = null;
ClassModel extendsClass = null;
List<FieldProperty> fields = new ArrayList<>();
public String getName() {
return this.name;
}
public boolean isPrimitive() {
return this.isPrimitive;
}
public String getDescription() {
return this.description;
}
public String getExample() {
return this.example;
}
public ClassModel getExtendsClass() {
return this.extendsClass;
}
public List<FieldProperty> getFields() {
return this.fields;
}
@Override
public void analyze(final ModelGroup previous) throws Exception {
if (this.analyzeDone) {
@ -174,17 +174,17 @@ public class ClassObjectModel extends ClassModel {
this.dependencyModels.add(this.extendsClass);
}
}
@Override
public Set<ClassModel> getDependencyGroupModels() {
return Set.of(this);
}
@Override
public Set<ClassModel> getAlls() {
return Set.of(this);
}
@Override
public List<String> getReadOnlyField() {
final List<String> out = new ArrayList<>();
@ -198,5 +198,5 @@ public class ClassObjectModel extends ClassModel {
}
return out;
}
}

View File

@ -13,13 +13,13 @@ public class ModelGroup {
public List<ClassModel> models = new ArrayList<>();
public ModelGroup() {}
public void addAll(final List<Class<?>> classes) {
for (final Class<?> clazz : classes) {
add(clazz);
}
}
public ClassModel add(Class<?> clazz) {
if (clazz == Response.class) {
clazz = Object.class;

View File

@ -8,13 +8,13 @@ import jakarta.persistence.Column;
public class GetToken {
@Column(length = -1, nullable = false)
public String jwt;
public GetToken() {
}
public GetToken(final String jwt) {
this.jwt = jwt;
}
}

View File

@ -9,9 +9,9 @@ public class Token {
public String token;
public String createTime;
public String endValidityTime;
public Token() {}
public Token(final long id, final long userId, final String token, final String createTime,
final String endValidityTime) {
this.id = id;
@ -20,7 +20,7 @@ public class Token {
this.createTime = createTime;
this.endValidityTime = endValidityTime;
}
public Token(final ResultSet rs) {
int iii = 1;
try {
@ -33,7 +33,7 @@ public class Token {
ex.printStackTrace();
}
}
@Override
public String toString() {
return "Token{" + "id=" + this.id + ", userId=" + this.userId + ", token='" + this.token + '\''