Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ScottLogic/finos-vuu into V…
Browse files Browse the repository at this point in the history
…UU-27-remote-layout-management
  • Loading branch information
vferraro-scottlogic committed Oct 24, 2023
1 parent cb49a88 commit b115e53
Show file tree
Hide file tree
Showing 261 changed files with 3,848 additions and 2,437 deletions.
68 changes: 68 additions & 0 deletions layout-server/pom.xml
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>
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);
}

}
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;
}
}
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);
}
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;

}
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);
}
Loading

0 comments on commit b115e53

Please sign in to comment.