forked from finos/vuu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/ScottLogic/finos-vuu into V…
…UU-27-remote-layout-management
- Loading branch information
1 parent
cb49a88
commit b115e53
Showing
261 changed files
with
3,848 additions
and
2,437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.7.16</version> | ||
<relativePath/> <!-- lookup parent fromEntity repository --> | ||
</parent> | ||
<groupId>org.finos.vuu</groupId> | ||
<artifactId>layout-server</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>layout-server</name> | ||
<description>A remote server to persist layouts for the Vuu client</description> | ||
<properties> | ||
<java.version>11</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springdoc</groupId> | ||
<artifactId>springdoc-openapi-ui</artifactId> | ||
<version>1.6.12</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.modelmapper</groupId> | ||
<artifactId>modelmapper</artifactId> | ||
<version>3.1.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
layout-server/src/main/java/org/finos/vuu/layoutserver/LayoutServerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.finos.vuu.layoutserver; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class LayoutServerApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(LayoutServerApplication.class, args); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
layout-server/src/main/java/org/finos/vuu/layoutserver/config/MappingConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.finos.vuu.layoutserver.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.finos.vuu.layoutserver.dto.request.LayoutRequestDTO; | ||
import org.finos.vuu.layoutserver.dto.request.MetadataRequestDTO; | ||
import org.finos.vuu.layoutserver.dto.response.MetadataResponseDTO; | ||
import org.finos.vuu.layoutserver.model.Layout; | ||
import org.finos.vuu.layoutserver.model.Metadata; | ||
import org.finos.vuu.layoutserver.service.LayoutService; | ||
import org.modelmapper.ModelMapper; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
public class MappingConfig { | ||
|
||
private final LayoutService layoutService; | ||
|
||
@Bean | ||
public ModelMapper modelMapper() { | ||
ModelMapper mapper = new ModelMapper(); | ||
|
||
mapper.typeMap(LayoutRequestDTO.class, Layout.class) | ||
.addMappings(m -> m.skip(Layout::setId)); | ||
|
||
mapper.typeMap(Metadata.class, MetadataResponseDTO.class) | ||
.addMappings(m -> m.map( | ||
metadata -> layoutService.getLayoutByMetadataId(metadata.getId()), | ||
MetadataResponseDTO::setLayoutId)); | ||
|
||
mapper.typeMap(MetadataRequestDTO.class, Metadata.class) | ||
.addMappings(m -> m.map( | ||
MetadataRequestDTO::getBaseMetadata, | ||
Metadata::setBaseMetadata)); | ||
|
||
mapper.typeMap(Metadata.class, MetadataResponseDTO.class) | ||
.addMappings(m -> m.map( | ||
Metadata::getBaseMetadata, | ||
MetadataResponseDTO::setBaseMetadata)); | ||
|
||
return mapper; | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
layout-server/src/main/java/org/finos/vuu/layoutserver/controller/LayoutController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package org.finos.vuu.layoutserver.controller; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import org.finos.vuu.layoutserver.dto.request.LayoutRequestDTO; | ||
import org.finos.vuu.layoutserver.dto.response.LayoutResponseDTO; | ||
import org.finos.vuu.layoutserver.dto.response.MetadataResponseDTO; | ||
import org.finos.vuu.layoutserver.model.Layout; | ||
import org.finos.vuu.layoutserver.service.LayoutService; | ||
import org.finos.vuu.layoutserver.service.MetadataService; | ||
import org.modelmapper.ModelMapper; | ||
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; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/layouts") | ||
public class LayoutController { | ||
|
||
private final LayoutService layoutService; | ||
private final MetadataService metadataService; | ||
private final ModelMapper mapper; | ||
|
||
/** | ||
* Gets the specified layout | ||
* | ||
* @param id ID of the layout to get | ||
* @return the layout | ||
*/ | ||
@ResponseStatus(HttpStatus.OK) | ||
@GetMapping("/{id}") | ||
public LayoutResponseDTO getLayout(@PathVariable UUID id) { | ||
return mapper.map(layoutService.getLayout(id), LayoutResponseDTO.class); | ||
} | ||
|
||
/** | ||
* Gets metadata for all layouts | ||
* | ||
* @return the metadata | ||
*/ | ||
@ResponseStatus(HttpStatus.OK) | ||
@GetMapping("/metadata") | ||
public List<MetadataResponseDTO> getMetadata() { | ||
|
||
return metadataService.getMetadata() | ||
.stream() | ||
.map(metadata -> mapper.map(metadata, MetadataResponseDTO.class)) | ||
.collect(java.util.stream.Collectors.toList()); | ||
} | ||
|
||
/** | ||
* Creates a new layout | ||
* | ||
* @param layoutToCreate the layout to be created | ||
* @return the layout that has been created, with the autogenerated ID and created date | ||
*/ | ||
@ResponseStatus(HttpStatus.CREATED) | ||
@PostMapping | ||
public LayoutResponseDTO createLayout(@RequestBody LayoutRequestDTO layoutToCreate) { | ||
Layout layout = mapper.map(layoutToCreate, Layout.class); | ||
|
||
Layout createdLayout = layoutService.getLayout(layoutService.createLayout(layout)); | ||
|
||
return mapper.map(createdLayout, LayoutResponseDTO.class); | ||
} | ||
|
||
/** | ||
* Updates the specified layout | ||
* | ||
* @param id ID of the layout to update | ||
* @param layout the new layout | ||
*/ | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
@PutMapping("/{id}") | ||
public void updateLayout(@PathVariable UUID id, @RequestBody LayoutRequestDTO layout) { | ||
Layout newLayout = mapper.map(layout, Layout.class); | ||
|
||
layoutService.updateLayout(id, newLayout); | ||
} | ||
|
||
/** | ||
* Deletes the specified layout | ||
* | ||
* @param id ID of the layout to delete | ||
*/ | ||
@ResponseStatus(HttpStatus.NO_CONTENT) | ||
@DeleteMapping("/{id}") | ||
public void deleteLayout(@PathVariable UUID id) { | ||
layoutService.deleteLayout(id); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
layout-server/src/main/java/org/finos/vuu/layoutserver/dto/request/LayoutRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.finos.vuu.layoutserver.dto.request; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class LayoutRequestDTO { | ||
|
||
/** | ||
* The definition of the layout as a string (i.e. stringified JSON structure containing components) | ||
*/ | ||
private String definition; | ||
|
||
private MetadataRequestDTO metadata; | ||
} |
12 changes: 12 additions & 0 deletions
12
layout-server/src/main/java/org/finos/vuu/layoutserver/dto/request/MetadataRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.finos.vuu.layoutserver.dto.request; | ||
|
||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import lombok.Data; | ||
import org.finos.vuu.layoutserver.model.BaseMetadata; | ||
|
||
@Data | ||
public class MetadataRequestDTO { | ||
|
||
@JsonUnwrapped | ||
BaseMetadata baseMetadata; | ||
} |
19 changes: 19 additions & 0 deletions
19
layout-server/src/main/java/org/finos/vuu/layoutserver/dto/response/LayoutResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.finos.vuu.layoutserver.dto.response; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.UUID; | ||
|
||
@Data | ||
public class LayoutResponseDTO { | ||
|
||
private UUID id; | ||
|
||
/** | ||
* The definition of the layout as a string (e.g. stringified JSON structure containing | ||
* components) | ||
*/ | ||
private String definition; | ||
|
||
private MetadataResponseDTO metadata; | ||
} |
19 changes: 19 additions & 0 deletions
19
layout-server/src/main/java/org/finos/vuu/layoutserver/dto/response/MetadataResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.finos.vuu.layoutserver.dto.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import java.util.Date; | ||
import java.util.UUID; | ||
import lombok.Data; | ||
import org.finos.vuu.layoutserver.model.BaseMetadata; | ||
|
||
@Data | ||
public class MetadataResponseDTO { | ||
|
||
private UUID layoutId; | ||
|
||
@JsonUnwrapped | ||
BaseMetadata baseMetadata; | ||
|
||
private Date created; | ||
private Date updated; | ||
} |
18 changes: 18 additions & 0 deletions
18
layout-server/src/main/java/org/finos/vuu/layoutserver/model/BaseMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.finos.vuu.layoutserver.model; | ||
|
||
import javax.persistence.Embeddable; | ||
import javax.persistence.Lob; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Embeddable | ||
public class BaseMetadata { | ||
|
||
private String name; | ||
private String group; | ||
|
||
@Lob | ||
private String screenshot; | ||
|
||
private String user; | ||
} |
28 changes: 28 additions & 0 deletions
28
layout-server/src/main/java/org/finos/vuu/layoutserver/model/Layout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.finos.vuu.layoutserver.model; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.OneToOne; | ||
import lombok.Data; | ||
import java.util.UUID; | ||
|
||
@Data | ||
@Entity | ||
public class Layout { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(columnDefinition = "BINARY(16)") | ||
private UUID id; | ||
|
||
private String definition; | ||
|
||
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true) | ||
@JoinColumn(name = "metadata_id", referencedColumnName = "id") | ||
private Metadata metadata; | ||
} |
35 changes: 35 additions & 0 deletions
35
layout-server/src/main/java/org/finos/vuu/layoutserver/model/Metadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.finos.vuu.layoutserver.model; | ||
|
||
import java.util.Date; | ||
import java.util.UUID; | ||
import javax.persistence.Column; | ||
import javax.persistence.Embedded; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
public class Metadata { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(columnDefinition = "BINARY(16)") | ||
private UUID id; | ||
|
||
@Embedded | ||
private BaseMetadata baseMetadata; | ||
|
||
private Date created = new Date(); | ||
|
||
private Date updated; | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
layout-server/src/main/java/org/finos/vuu/layoutserver/repository/LayoutRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.finos.vuu.layoutserver.repository; | ||
|
||
import org.finos.vuu.layoutserver.model.Layout; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.UUID; | ||
|
||
@Repository | ||
public interface LayoutRepository extends CrudRepository<Layout, UUID> { | ||
|
||
Layout findLayoutByMetadataId(UUID id); | ||
} |
Oops, something went wrong.