[DEV] update with openAPI
This commit is contained in:
parent
1c82fb1a86
commit
dfc7c77f47
@ -25,7 +25,7 @@
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
|
6
pom.xml
6
pom.xml
@ -142,6 +142,12 @@
|
||||
<artifactId>jakarta.persistence-api</artifactId>
|
||||
<version>3.2.0-M1</version>
|
||||
</dependency>
|
||||
<!-- Swagger dependencies -->
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-jaxrs2-jakarta</artifactId>
|
||||
<version>2.1.10</version>
|
||||
</dependency>
|
||||
<!--
|
||||
************************************************************
|
||||
** TEST dependency **
|
||||
|
@ -10,6 +10,7 @@ import org.kar.archidata.dataAccess.options.OverrideTableName;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
@ -51,10 +52,21 @@ public class AnnotationTools {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public static String getSchemedescription(final Field element) throws Exception {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Schema.class);
|
||||
if (annotation.length == 0) {
|
||||
return null;
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new Exception("Must not have more than 1 element @Schema on " + element.getClass().getCanonicalName());
|
||||
}
|
||||
return ((Schema) annotation[0]).description();
|
||||
}
|
||||
|
||||
public static String getComment(final Field element) throws Exception {
|
||||
final Annotation[] annotation = element.getDeclaredAnnotationsByType(DataComment.class);
|
||||
if (annotation.length == 0) {
|
||||
return null;
|
||||
return getSchemedescription(element);
|
||||
}
|
||||
if (annotation.length > 1) {
|
||||
throw new Exception("Must not have more than 1 element @DataComment on " + element.getClass().getCanonicalName());
|
||||
|
@ -7,8 +7,7 @@ import java.lang.annotation.Target;
|
||||
|
||||
@Target({ ElementType.TYPE, ElementType.FIELD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Deprecated(since = "0.5.2")
|
||||
public @interface DataComment {
|
||||
|
||||
String value();
|
||||
|
||||
}
|
||||
|
34
src/org/kar/archidata/api/openApiResource.java
Normal file
34
src/org/kar/archidata/api/openApiResource.java
Normal file
@ -0,0 +1,34 @@
|
||||
package org.kar.archidata.api;
|
||||
|
||||
import io.swagger.v3.jaxrs2.integration.resources.BaseOpenApiResource;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.servlet.ServletConfig;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.core.Application;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
|
||||
@Path("/openapi")
|
||||
public class openApiResource extends BaseOpenApiResource {
|
||||
@Context
|
||||
ServletConfig config;
|
||||
|
||||
@Context
|
||||
Application app;
|
||||
|
||||
@GET
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(hidden = true)
|
||||
@PermitAll
|
||||
public Response getDescription(@Context final HttpHeaders headers, @Context final UriInfo uriInfo) throws Exception {
|
||||
|
||||
return getOpenApi(headers, this.config, this.app, uriInfo, "json");
|
||||
}
|
||||
|
||||
}
|
@ -471,12 +471,12 @@ public class DataAccess {
|
||||
|
||||
public static <T> T insert(final T data, final QueryOption... option) throws Exception {
|
||||
final Class<?> clazz = data.getClass();
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
|
||||
// External checker of data:
|
||||
final CheckFunction check = options.get(CheckFunction.class);
|
||||
if (check != null) {
|
||||
check.getChecker().check(data, AnnotationTools.getFieldsNames(clazz));
|
||||
check.getChecker().check("", data, AnnotationTools.getFieldsNames(clazz));
|
||||
}
|
||||
|
||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
@ -638,7 +638,7 @@ public class DataAccess {
|
||||
}
|
||||
// check the compatibility of the id and the declared ID
|
||||
final Class<?> typeClass = idField.getType();
|
||||
if (idKey.getClass() == typeClass) {
|
||||
if (idKey.getClass() != typeClass) {
|
||||
throw new DataAccessException("Request update with the wrong type ...");
|
||||
}
|
||||
return new QueryCondition(AnnotationTools.getFieldName(idField), "=", idKey);
|
||||
@ -654,8 +654,8 @@ public class DataAccess {
|
||||
* @return the number of object updated
|
||||
* @throws Exception */
|
||||
public static <T, ID_TYPE> int updateWithJson(final Class<T> clazz, final ID_TYPE id, final String jsonData, final QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
Condition condition = options.get(Condition.class);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
final Condition condition = options.get(Condition.class);
|
||||
if (condition != null) {
|
||||
throw new DataAccessException("request a updateWithJson with a condition");
|
||||
}
|
||||
@ -664,8 +664,8 @@ public class DataAccess {
|
||||
}
|
||||
|
||||
public static <T> int updateWhereWithJson(final Class<T> clazz, final String jsonData, final QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
Condition condition = options.get(Condition.class);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
final Condition condition = options.get(Condition.class);
|
||||
if (condition == null) {
|
||||
throw new DataAccessException("request a updateWhereWithJson without any condition");
|
||||
}
|
||||
@ -692,19 +692,19 @@ public class DataAccess {
|
||||
* @return the affected rows.
|
||||
* @throws Exception */
|
||||
public static <T, ID_TYPE> int update(final T data, final ID_TYPE id, final List<String> updateColomn) throws Exception {
|
||||
QueryOptions options = new QueryOptions(new Condition(getTableIdCondition(data.getClass(), id)), new FilterValue(updateColomn));
|
||||
final QueryOptions options = new QueryOptions(new Condition(getTableIdCondition(data.getClass(), id)), new FilterValue(updateColomn));
|
||||
return updateWhere(data, options.getAllArray());
|
||||
}
|
||||
|
||||
// il y avait: final List<String> filterValue
|
||||
public static <T> int updateWhere(final T data, final QueryOption... option) throws Exception {
|
||||
final Class<?> clazz = data.getClass();
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
Condition condition = options.get(Condition.class);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
final Condition condition = options.get(Condition.class);
|
||||
if (condition == null) {
|
||||
throw new DataAccessException("request a gets without any condition");
|
||||
}
|
||||
FilterValue filter = options.get(FilterValue.class);
|
||||
final FilterValue filter = options.get(FilterValue.class);
|
||||
if (filter == null) {
|
||||
throw new DataAccessException("request a gets without any filter values");
|
||||
}
|
||||
@ -715,7 +715,7 @@ public class DataAccess {
|
||||
if (options != null) {
|
||||
final CheckFunction check = options.get(CheckFunction.class);
|
||||
if (check != null) {
|
||||
check.getChecker().check(data, filter.getValues());
|
||||
check.getChecker().check("", data, filter.getValues());
|
||||
}
|
||||
}
|
||||
|
||||
@ -877,8 +877,8 @@ public class DataAccess {
|
||||
return executeQuerry(query, false);
|
||||
}
|
||||
|
||||
public static <T> T getWhere(final Class<T> clazz, QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
public static <T> T getWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Limit(1));
|
||||
final List<T> values = getsWhere(clazz, options);
|
||||
if (values.size() == 0) {
|
||||
@ -926,13 +926,13 @@ public class DataAccess {
|
||||
}
|
||||
|
||||
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
return getsWhere(clazz, options);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryOptions options) throws Exception {
|
||||
Condition condition = options.get(Condition.class);
|
||||
final Condition condition = options.get(Condition.class);
|
||||
final List<LazyGetter> lazyCall = new ArrayList<>();
|
||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
@ -1029,14 +1029,14 @@ public class DataAccess {
|
||||
}
|
||||
|
||||
public static long countWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
Condition condition = options.get(Condition.class);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
final Condition condition = options.get(Condition.class);
|
||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
long count = 0;
|
||||
// real add in the BDD:
|
||||
try {
|
||||
StringBuilder query = new StringBuilder();
|
||||
final StringBuilder query = new StringBuilder();
|
||||
final String tableName = AnnotationTools.getTableName(clazz, options);
|
||||
query.append("SELECT COUNT(*) FROM `");
|
||||
query.append(tableName);
|
||||
@ -1076,7 +1076,7 @@ public class DataAccess {
|
||||
}
|
||||
|
||||
public static <T, ID_TYPE> T get(final Class<T> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||
return DataAccess.getWhere(clazz, options.getAllArray());
|
||||
}
|
||||
@ -1128,14 +1128,14 @@ public class DataAccess {
|
||||
}
|
||||
|
||||
public static <ID_TYPE> int deleteHard(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||
return deleteHardWhere(clazz, options.getAllArray());
|
||||
}
|
||||
|
||||
public static int deleteHardWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
Condition condition = options.get(Condition.class);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
final Condition condition = options.get(Condition.class);
|
||||
if (condition == null) {
|
||||
throw new DataAccessException("request a gets without any condition");
|
||||
}
|
||||
@ -1162,14 +1162,14 @@ public class DataAccess {
|
||||
}
|
||||
|
||||
private static <ID_TYPE> int deleteSoft(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||
return deleteSoftWhere(clazz, options.getAllArray());
|
||||
}
|
||||
|
||||
public static int deleteSoftWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
Condition condition = options.get(Condition.class);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
final Condition condition = options.get(Condition.class);
|
||||
if (condition == null) {
|
||||
throw new DataAccessException("request a gets without any condition");
|
||||
}
|
||||
@ -1205,14 +1205,14 @@ public class DataAccess {
|
||||
}
|
||||
|
||||
public static <ID_TYPE> int unsetDelete(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||
return unsetDeleteWhere(clazz, options.getAllArray());
|
||||
}
|
||||
|
||||
public static int unsetDeleteWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||
QueryOptions options = new QueryOptions(option);
|
||||
Condition condition = options.get(Condition.class);
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
final Condition condition = options.get(Condition.class);
|
||||
if (condition == null) {
|
||||
throw new DataAccessException("request a gets without any condition");
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package org.kar.archidata.model;
|
||||
|
||||
import org.kar.archidata.annotation.DataComment;
|
||||
import org.kar.archidata.annotation.DataIfNotExists;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@ -14,12 +14,12 @@ import jakarta.persistence.Table;
|
||||
public class Data extends GenericDataSoftDelete {
|
||||
|
||||
@Column(length = 128, nullable = false)
|
||||
@DataComment("Sha512 of the data")
|
||||
@Schema(description = "Sha512 of the data")
|
||||
public String sha512;
|
||||
@Column(length = 128, nullable = false)
|
||||
@DataComment("Mime -type of the media")
|
||||
@Schema(description = "Mime -type of the media")
|
||||
public String mimeType;
|
||||
@Column(nullable = false)
|
||||
@DataComment("Size in Byte of the data")
|
||||
@Schema(description = "Size in Byte of the data")
|
||||
public Long size;
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ package org.kar.archidata.model;
|
||||
import java.util.Date;
|
||||
|
||||
import org.kar.archidata.annotation.CreationTimestamp;
|
||||
import org.kar.archidata.annotation.DataComment;
|
||||
import org.kar.archidata.annotation.DataNotRead;
|
||||
import org.kar.archidata.annotation.UpdateTimestamp;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
@ -19,20 +19,20 @@ public class GenericData {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(nullable = false, unique = true)
|
||||
@DataComment("Primary key of the base")
|
||||
@Schema(description = "Unique Id of the object", required = false, readOnly = true)
|
||||
public Long id = null;
|
||||
@DataNotRead
|
||||
@CreationTimestamp
|
||||
@Column(nullable = false)
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@DataComment("Create time of the object")
|
||||
@NotNull
|
||||
@Schema(description = "Create time of the object", required = false, example = "2000-01-23T01:23:45.678+01:00", readOnly = true)
|
||||
public Date createdAt = null;
|
||||
@DataNotRead
|
||||
@UpdateTimestamp
|
||||
@Column(nullable = false)
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@DataComment("When update the object")
|
||||
@NotNull
|
||||
@Schema(description = "When update the object", required = false, example = "2000-01-23T00:23:45.678Z", readOnly = true)
|
||||
public Date updatedAt = null;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package org.kar.archidata.model;
|
||||
|
||||
import org.kar.archidata.annotation.DataComment;
|
||||
import org.kar.archidata.annotation.DataDefault;
|
||||
import org.kar.archidata.annotation.DataDeleted;
|
||||
import org.kar.archidata.annotation.DataNotRead;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
@ -13,7 +13,7 @@ public class GenericDataSoftDelete extends GenericData {
|
||||
@Column(nullable = false)
|
||||
@DataDefault("'0'")
|
||||
@DataDeleted
|
||||
@DataComment("When delete, they are not removed, they are just set in a deleted state")
|
||||
@NotNull
|
||||
@Schema(description = "Deleted state", hidden = true, required = false, readOnly = true)
|
||||
public Boolean deleted = null;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user