Add ObjectType
Add ObjectAttribute Add rest ObjectTypeResource Add sample ObjectAttribute String implementation Add jackson dependency
This commit is contained in:
@ -15,6 +15,7 @@ dependencies {
|
||||
implementation 'io.quarkus:quarkus-arc'
|
||||
testImplementation 'io.quarkus:quarkus-junit5'
|
||||
testImplementation 'io.rest-assured:rest-assured'
|
||||
implementation 'io.quarkus:quarkus-rest-jackson:3.11.2'
|
||||
compileOnly 'org.projectlombok:lombok:1.18.32'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.32'
|
||||
implementation ('com.rethinkdb:rethinkdb-driver:2.4.4') {
|
||||
|
30
src/main/java/de/w665/fluidcms/model/ObjectAttribute.java
Normal file
30
src/main/java/de/w665/fluidcms/model/ObjectAttribute.java
Normal file
@ -0,0 +1,30 @@
|
||||
package de.w665.fluidcms.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import de.w665.fluidcms.model.objectattributes.StringObjectAttribute;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@JsonTypeInfo(
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
property = "type")
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = StringObjectAttribute.class, name = "String"),
|
||||
})
|
||||
public abstract class ObjectAttribute <T> {
|
||||
private String name;
|
||||
private String description;
|
||||
private boolean required;
|
||||
private T defaultValue;
|
||||
|
||||
public abstract String getValueAsString();
|
||||
public abstract T getValue();
|
||||
public abstract void setValue(T value);
|
||||
}
|
19
src/main/java/de/w665/fluidcms/model/ObjectType.java
Normal file
19
src/main/java/de/w665/fluidcms/model/ObjectType.java
Normal file
@ -0,0 +1,19 @@
|
||||
package de.w665.fluidcms.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class ObjectType {
|
||||
private String id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String icon;
|
||||
private String color;
|
||||
private Map<String, ObjectAttribute> attributes;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package de.w665.fluidcms.model.objectattributes;
|
||||
|
||||
import de.w665.fluidcms.model.ObjectAttribute;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class StringObjectAttribute extends ObjectAttribute<String> {
|
||||
private String value;
|
||||
|
||||
@Override
|
||||
public String getValueAsString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package de.w665.fluidcms.rest.mapping;
|
||||
|
||||
import de.w665.fluidcms.model.ObjectAttribute;
|
||||
import de.w665.fluidcms.model.ObjectType;
|
||||
import de.w665.fluidcms.model.objectattributes.StringObjectAttribute;
|
||||
import jakarta.ws.rs.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jboss.resteasy.reactive.RestResponse;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Path("/objectType")
|
||||
public class ObjectTypeResource {
|
||||
|
||||
@POST
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public RestResponse<ObjectType> createObjectType(ObjectType objectType) {
|
||||
log.debug(objectType.toString());
|
||||
return RestResponse.ok(objectType);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Produces("application/json")
|
||||
public RestResponse<ObjectType> getObjectType() {
|
||||
StringObjectAttribute attr1 = new StringObjectAttribute();
|
||||
String number = String.valueOf((int) (Math.random() * 100));
|
||||
attr1.setName("Attribute " + number);
|
||||
attr1.setDescription("This is attribute " + number);
|
||||
attr1.setRequired(true);
|
||||
attr1.setDefaultValue("Default Value " + number);
|
||||
attr1.setValue("Attribute " + number + " Value");
|
||||
|
||||
number = String.valueOf((int) (Math.random() * 100));
|
||||
StringObjectAttribute attr2 = new StringObjectAttribute();
|
||||
attr2.setName("Attribute " + number);
|
||||
attr2.setDescription("This is attribute " + number);
|
||||
attr2.setRequired(false);
|
||||
attr2.setDefaultValue("Default Value " + number);
|
||||
attr2.setValue("Attribute " + number + " Value");
|
||||
|
||||
// Add the StringObjectAttribute objects to a Map
|
||||
Map<String, ObjectAttribute> attributes = new HashMap<>();
|
||||
attributes.put("attr1", attr1);
|
||||
attributes.put("attr2", attr2);
|
||||
|
||||
// Create an ObjectType object and set the attributes
|
||||
ObjectType objectType = new ObjectType();
|
||||
objectType.setId("123");
|
||||
|
||||
number = String.valueOf((int) (Math.random() * 100));
|
||||
objectType.setName("Object Type " + number);
|
||||
objectType.setDescription("This is object type " + number);
|
||||
|
||||
// random number
|
||||
|
||||
objectType.setIcon("icon.png");
|
||||
objectType.setColor("blue");
|
||||
objectType.setAttributes(attributes);
|
||||
|
||||
return RestResponse.ok(objectType);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user