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-89-fix-layoutID
  • Loading branch information
vferraro-scottlogic committed Nov 8, 2023
2 parents 76b2280 + 64e0dcf commit c3fb3ca
Show file tree
Hide file tree
Showing 480 changed files with 9,152 additions and 5,190 deletions.
1 change: 1 addition & 0 deletions .semgrepignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ vuu/src/main/resources/www/ws-example.html
vuu/src/main/scala/org/finos/vuu/provider/simulation/SimulatedBigInstrumentsProvider.scala
vuu-ui/packages/vuu-data/src/array-data-source/group-utils.ts
vuu-ui/packages/vuu-datagrid-extras/src/column-expression-input/column-language-parser/walkExpressionTree.ts
vuu-ui/packages/vuu-layout/src/layout-persistence/RemoteLayoutPersistenceManager.ts
vuu-ui/packages/vuu-popups/src/menu/useContextMenu.tsx
vuu-ui/packages/vuu-table-extras/src/cell-edit-validators/PatternValidator.ts
vuu-ui/packages/vuu-ui-controls/src/list/Highlighter.tsx
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.finos.vuu.layoutserver;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://127.0.0.1:5173")
.allowedMethods("GET", "POST", "PUT", "DELETE");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.finos.vuu.layoutserver.config;

import lombok.RequiredArgsConstructor;
import org.finos.vuu.layoutserver.dto.request.LayoutRequestDTO;
import org.finos.vuu.layoutserver.dto.request.LayoutRequestDto;
import org.finos.vuu.layoutserver.model.Layout;
import org.modelmapper.ModelMapper;
import org.springframework.context.annotation.Bean;
Expand All @@ -15,9 +15,9 @@ public class MappingConfig {
public ModelMapper modelMapper() {
ModelMapper mapper = new ModelMapper();

mapper.typeMap(LayoutRequestDTO.class, Layout.class)
mapper.typeMap(LayoutRequestDto.class, Layout.class)
.addMappings(m -> m.skip(Layout::setId));

return mapper;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.finos.vuu.layoutserver.controller;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import org.finos.vuu.layoutserver.dto.response.ApplicationLayoutDto;
import org.finos.vuu.layoutserver.service.ApplicationLayoutService;
import org.modelmapper.ModelMapper;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RestController
@RequestMapping("/application-layouts")
public class ApplicationLayoutController {

private final ApplicationLayoutService service;
private final ModelMapper mapper;

/**
* Gets the persisted application layout for the requesting user. If the requesting user does not have an
* application layout persisted, a default layout with a null username is returned instead. No more than one
* application layout can be persisted for a given user.
*
* @return the application layout
*/
@ResponseStatus(HttpStatus.OK)
@GetMapping
public ApplicationLayoutDto getApplicationLayout(@RequestHeader("username") String username) {
return mapper.map(service.getApplicationLayout(username), ApplicationLayoutDto.class);
}

/**
* Creates or updates the unique application layout for the requesting user.
*
* @param layoutDefinition JSON representation of the application layout to be created
* @param username the user making the request
*/
@ResponseStatus(HttpStatus.CREATED)
@PutMapping
public void persistApplicationLayout(@RequestHeader("username") String username, @RequestBody JsonNode layoutDefinition) {
service.persistApplicationLayout(username, layoutDefinition);
}

/**
* Deletes the application layout for the requesting user. A 404 will be returned if there is no existing
* application layout.
*
* @param username the user making the request
*/
@ResponseStatus(HttpStatus.NO_CONTENT)
@DeleteMapping
public void deleteApplicationLayout(@RequestHeader("username") String username) {
service.deleteApplicationLayout(username);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
package org.finos.vuu.layoutserver.controller;

import java.util.List;
import java.util.UUID;
import javax.validation.Valid;
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.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.validation.annotation.Validated;
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 org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.UUID;

@RequiredArgsConstructor
@RestController
Expand All @@ -41,8 +34,8 @@ public class LayoutController {
*/
@ResponseStatus(HttpStatus.OK)
@GetMapping("/{id}")
public LayoutResponseDTO getLayout(@PathVariable UUID id) {
return mapper.map(layoutService.getLayout(id), LayoutResponseDTO.class);
public LayoutResponseDto getLayout(@PathVariable UUID id) {
return mapper.map(layoutService.getLayout(id), LayoutResponseDto.class);
}

/**
Expand All @@ -52,12 +45,12 @@ public LayoutResponseDTO getLayout(@PathVariable UUID id) {
*/
@ResponseStatus(HttpStatus.OK)
@GetMapping("/metadata")
public List<MetadataResponseDTO> getMetadata() {
public List<MetadataResponseDto> getMetadata() {

return metadataService.getMetadata()
.stream()
.map(metadata -> mapper.map(metadata, MetadataResponseDTO.class))
.collect(java.util.stream.Collectors.toList());
.stream()
.map(metadata -> mapper.map(metadata, MetadataResponseDto.class))
.collect(java.util.stream.Collectors.toList());
}

/**
Expand All @@ -68,21 +61,21 @@ public List<MetadataResponseDTO> getMetadata() {
*/
@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public LayoutResponseDTO createLayout(@Valid @RequestBody LayoutRequestDTO layoutToCreate) {
public LayoutResponseDto createLayout(@RequestBody @Valid LayoutRequestDto layoutToCreate) {
Layout layout = mapper.map(layoutToCreate, Layout.class);

return mapper.map(layoutService.createLayout(layout), LayoutResponseDTO.class);
return mapper.map(layoutService.createLayout(layout), LayoutResponseDto.class);
}

/**
* Updates the specified layout
*
* @param id ID of the layout to update
* @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, @Valid @RequestBody LayoutRequestDTO layout) {
public void updateLayout(@PathVariable UUID id, @RequestBody @Valid LayoutRequestDto layout) {
Layout newLayout = mapper.map(layout, Layout.class);

layoutService.updateLayout(id, newLayout);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.finos.vuu.layoutserver.dto.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Data;

@Data
public class LayoutRequestDTO {
public class LayoutRequestDto {

/**
* The definition of the layout as a string (e.g. stringified JSON structure containing
Expand All @@ -18,5 +19,5 @@ public class LayoutRequestDTO {

@JsonProperty(value = "metadata", required = true)
@NotNull(message = "Metadata must not be null")
private MetadataRequestDTO metadata;
private MetadataRequestDto metadata;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.finos.vuu.layoutserver.model.BaseMetadata;

@Data
public class MetadataRequestDTO {
public class MetadataRequestDto {

@JsonUnwrapped
BaseMetadata baseMetadata;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.finos.vuu.layoutserver.dto.response;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;

@Data
public class ApplicationLayoutDto {
private String username;
private JsonNode definition;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.finos.vuu.layoutserver.dto.response;

import lombok.Data;
import org.springframework.http.HttpStatus;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Data
public class ErrorResponse {
private Date timestamp = new Date();
private int status;
private String error;
private List<String> messages;
private String path;

public ErrorResponse(HttpServletRequest request, List<String> messages, HttpStatus status) {
this.status = status.value();
this.error = status.getReasonPhrase();
this.path = request.getRequestURI();
this.messages = messages;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.UUID;

@Data
public class LayoutResponseDTO {
public class LayoutResponseDto {

private UUID id;

Expand All @@ -15,5 +15,5 @@ public class LayoutResponseDTO {
*/
private String definition;

private MetadataResponseDTO metadata;
private MetadataResponseDto metadata;
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
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;

import java.time.LocalDate;
import java.util.UUID;

@Data
public class MetadataResponseDTO {
public class MetadataResponseDto {

private UUID id;

@JsonUnwrapped
BaseMetadata baseMetadata;

private Date created;
private Date updated;
private LocalDate created;
private LocalDate updated;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.finos.vuu.layoutserver.exceptions;

import org.finos.vuu.layoutserver.dto.response.ErrorResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;

@ControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(NoSuchElementException.class)
public ResponseEntity<ErrorResponse> handleNotFound(HttpServletRequest request, Exception ex) {
HttpStatus status = HttpStatus.NOT_FOUND;
return new ResponseEntity<>(new ErrorResponse(request, List.of(ex.getMessage()), status), status);
}

@ExceptionHandler({
HttpMessageNotReadableException.class,
MethodArgumentTypeMismatchException.class})
public ResponseEntity<ErrorResponse> handleBadRequest(HttpServletRequest request, Exception ex) {
HttpStatus status = HttpStatus.BAD_REQUEST;
return new ResponseEntity<>(new ErrorResponse(request, List.of(ex.getMessage()), status), status);
}

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ErrorResponse> handleMethodArgumentNotValid(HttpServletRequest request, MethodArgumentNotValidException ex) {
HttpStatus status = HttpStatus.BAD_REQUEST;
List<String> errors = ex.getFieldErrors()
.stream()
.map(fieldError -> fieldError.getField() + ": " + fieldError.getDefaultMessage())
.collect(Collectors.toList());
return new ResponseEntity<>(new ErrorResponse(request, errors, status), status);
}

@ExceptionHandler(InternalServerErrorException.class)
public ResponseEntity<ErrorResponse> handleInternalServerError(HttpServletRequest request, Exception ex) {
HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
return new ResponseEntity<>(new ErrorResponse(request, List.of(ex.getMessage()), status), status);

}
}
Loading

0 comments on commit c3fb3ca

Please sign in to comment.