diff --git a/layout-server/pom.xml b/layout-server/pom.xml
index f1ab238a2..5b4cb720c 100644
--- a/layout-server/pom.xml
+++ b/layout-server/pom.xml
@@ -40,16 +40,15 @@
h2
runtime
-
- org.projectlombok
- lombok
- true
-
org.springdoc
springdoc-openapi-starter-webmvc-ui
2.1.0
+
+ org.projectlombok
+ lombok
+
@@ -57,14 +56,6 @@
org.springframework.boot
spring-boot-maven-plugin
-
-
-
- org.projectlombok
- lombok
-
-
-
diff --git a/layout-server/src/main/java/org/finos/vuu/layoutserver/controller/LayoutController.java b/layout-server/src/main/java/org/finos/vuu/layoutserver/controller/LayoutController.java
index 9583c10e4..50dca326a 100644
--- a/layout-server/src/main/java/org/finos/vuu/layoutserver/controller/LayoutController.java
+++ b/layout-server/src/main/java/org/finos/vuu/layoutserver/controller/LayoutController.java
@@ -1,24 +1,42 @@
package org.finos.vuu.layoutserver.controller;
+import org.finos.vuu.layoutserver.dto.response.LayoutDTO;
+import org.finos.vuu.layoutserver.dto.response.MetadataDTO;
import org.finos.vuu.layoutserver.model.Layout;
import org.finos.vuu.layoutserver.model.Metadata;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
-import java.util.ArrayList;
import java.util.List;
-@RestController("/layout")
+@RestController
+@RequestMapping("/layout")
public class LayoutController {
- /**
- * Gets all layouts if no IDs are specified, otherwise gets the specified layouts
- *
- * @param ids IDs of the layouts to get
- * @return the layouts
- */
- @GetMapping
- public List getLayouts(@RequestBody(required = false) String[] ids) {
- return new ArrayList<>();
+ public static final String LAYOUT_ID = "testLayoutId";
+
+ // TODO: Delete dummy data
+ private Layout createDummyLayout(String id) {
+ Layout layout = new Layout();
+ layout.setId(id);
+ layout.setDefinition("testDefinition");
+ Metadata metadata = new Metadata();
+ metadata.setId("testMetadataId");
+ metadata.setLayout(layout);
+ metadata.setName("testName");
+ metadata.setGroup("testGroup");
+ metadata.setScreenshot("testScreenshot");
+ metadata.setUser("testUser");
+ layout.setMetadata(metadata);
+ return layout;
}
/**
@@ -28,50 +46,51 @@ public List getLayouts(@RequestBody(required = false) String[] ids) {
* @return the layout
*/
@GetMapping("/{id}")
- public Layout getLayout(@PathVariable String id) {
- return Layout.builder().build();
+ public LayoutDTO getLayout(@PathVariable String id) {
+ Layout layout = createDummyLayout(id);
+ return LayoutDTO.fromEntity(layout);
}
/**
- * Gets metadata for all layouts if no IDs are specified, otherwise gets the metadata for specified layouts
+ * Gets metadata for all layouts
*
- * @param ids IDs of the layouts to get metadata for
* @return the metadata
*/
@GetMapping("/metadata")
- public List getMetadata(@RequestBody(required = false) String[] ids) {
- return new ArrayList<>();
+ public List getMetadata() {
+ Layout layout = createDummyLayout(LAYOUT_ID);
+ return List.of(MetadataDTO.fromEntity(layout.getMetadata()));
}
/**
* Creates a new layout
*
- * @return the ID of the new layout`
+ * @return the ID of the new layout
*/
+ @ResponseStatus(HttpStatus.CREATED)
@PostMapping
- public String createLayout() {
- return "Hello World";
+ public String createLayout(@RequestBody LayoutDTO layoutDTO) {
+ return createDummyLayout(LAYOUT_ID).getId();
}
/**
* Updates the specified layout
*
- * @param id ID of the layout to update
- * @return the ID of the updated layout
+ * @param id ID of the layout to update
+ * @param layoutDTO the new data to overwrite the layout with
*/
+ @ResponseStatus(HttpStatus.ACCEPTED)
@PutMapping("/{id}")
- public String updateLayout(@PathVariable String id) {
- return "Hello World";
+ public void updateLayout(@PathVariable String id, @RequestBody LayoutDTO layoutDTO) {
+ createDummyLayout(LAYOUT_ID);
}
/**
* Deletes the specified layout
*
* @param id ID of the layout to delete
- * @return the ID of the deleted layout
*/
+ @ResponseStatus(HttpStatus.ACCEPTED)
@DeleteMapping("/{id}")
- public String deleteLayout(@PathVariable String id) {
- return "Hello World";
- }
+ public void deleteLayout(@PathVariable String id) {}
}
diff --git a/layout-server/src/main/java/org/finos/vuu/layoutserver/dto/response/LayoutDTO.java b/layout-server/src/main/java/org/finos/vuu/layoutserver/dto/response/LayoutDTO.java
new file mode 100644
index 000000000..d7c64edb5
--- /dev/null
+++ b/layout-server/src/main/java/org/finos/vuu/layoutserver/dto/response/LayoutDTO.java
@@ -0,0 +1,24 @@
+package org.finos.vuu.layoutserver.dto.response;
+
+import lombok.Builder;
+import lombok.Data;
+import org.finos.vuu.layoutserver.model.Layout;
+
+import java.io.Serializable;
+
+@Data
+@Builder
+public class LayoutDTO implements Serializable {
+
+ private String id;
+ private String definition;
+ private MetadataDTO metadata;
+
+ public static LayoutDTO fromEntity(Layout layout) {
+ return LayoutDTO.builder()
+ .id(layout.getId())
+ .definition(layout.getDefinition())
+ .metadata(MetadataDTO.fromEntity(layout.getMetadata()))
+ .build();
+ }
+}
diff --git a/layout-server/src/main/java/org/finos/vuu/layoutserver/dto/response/MetadataDTO.java b/layout-server/src/main/java/org/finos/vuu/layoutserver/dto/response/MetadataDTO.java
new file mode 100644
index 000000000..bd253a86a
--- /dev/null
+++ b/layout-server/src/main/java/org/finos/vuu/layoutserver/dto/response/MetadataDTO.java
@@ -0,0 +1,31 @@
+package org.finos.vuu.layoutserver.dto.response;
+
+import lombok.Builder;
+import lombok.Data;
+import org.finos.vuu.layoutserver.model.Metadata;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+@Builder
+public class MetadataDTO implements Serializable {
+
+ private String layoutId;
+ private String name;
+ private String group;
+ private String screenshot;
+ private String user;
+ private Date date;
+
+ public static MetadataDTO fromEntity(Metadata metadata) {
+ return MetadataDTO.builder()
+ .layoutId(metadata.getLayout().getId())
+ .name(metadata.getName())
+ .group(metadata.getGroup())
+ .screenshot(metadata.getScreenshot())
+ .user(metadata.getUser())
+ .date(metadata.getDate())
+ .build();
+ }
+}
diff --git a/layout-server/src/main/java/org/finos/vuu/layoutserver/model/Layout.java b/layout-server/src/main/java/org/finos/vuu/layoutserver/model/Layout.java
index cb5aebe62..9f1efef61 100644
--- a/layout-server/src/main/java/org/finos/vuu/layoutserver/model/Layout.java
+++ b/layout-server/src/main/java/org/finos/vuu/layoutserver/model/Layout.java
@@ -1,21 +1,23 @@
package org.finos.vuu.layoutserver.model;
import jakarta.persistence.*;
-import lombok.Builder;
import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
-@Entity
@Data
-@Builder
+@Entity
+@NoArgsConstructor
public class Layout {
@Id
- @GeneratedValue(strategy= GenerationType.AUTO)
+ @GeneratedValue(strategy = GenerationType.AUTO)
private String id;
+ @NonNull
private String definition;
@OneToOne(cascade = CascadeType.ALL)
+ @JoinColumn(name = "metadata_id", referencedColumnName = "id")
+ @NonNull
private Metadata metadata;
-
- protected Layout() {}
}
diff --git a/layout-server/src/main/java/org/finos/vuu/layoutserver/model/Metadata.java b/layout-server/src/main/java/org/finos/vuu/layoutserver/model/Metadata.java
index 7df0c2fa0..2a0eec777 100644
--- a/layout-server/src/main/java/org/finos/vuu/layoutserver/model/Metadata.java
+++ b/layout-server/src/main/java/org/finos/vuu/layoutserver/model/Metadata.java
@@ -1,28 +1,28 @@
package org.finos.vuu.layoutserver.model;
-import jakarta.persistence.Entity;
-import jakarta.persistence.GeneratedValue;
-import jakarta.persistence.Id;
-import lombok.Builder;
+import jakarta.persistence.*;
import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
import java.util.Date;
-@Entity
@Data
-@Builder
+@NoArgsConstructor
+@Entity
public class Metadata {
@Id
- @GeneratedValue
- private Long id;
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private String id;
+
+ @OneToOne(mappedBy = "metadata")
+ @NonNull
+ private Layout layout;
private String name;
private String group;
private String screenshot;
private String user;
- private Date date;
-
- protected Metadata() {
- }
+ private Date date = new Date();
}
diff --git a/layout-server/src/main/resources/application.properties b/layout-server/src/main/resources/application.properties
index f95f5b025..fb9c7e613 100644
--- a/layout-server/src/main/resources/application.properties
+++ b/layout-server/src/main/resources/application.properties
@@ -1,3 +1,4 @@
+server.servlet.contextPath=/api
spring.datasource.url=jdbc:h2:file:/data/layout
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa