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-89-fix-layoutID
- Loading branch information
Showing
480 changed files
with
9,152 additions
and
5,190 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
15 changes: 15 additions & 0 deletions
15
layout-server/src/main/java/org/finos/vuu/layoutserver/CorsConfig.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,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"); | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
...rver/src/main/java/org/finos/vuu/layoutserver/controller/ApplicationLayoutController.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,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); | ||
} | ||
} |
44 changes: 0 additions & 44 deletions
44
...ut-server/src/main/java/org/finos/vuu/layoutserver/controller/GlobalExceptionHandler.java
This file was deleted.
Oops, something went wrong.
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
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
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
10 changes: 10 additions & 0 deletions
10
...ut-server/src/main/java/org/finos/vuu/layoutserver/dto/response/ApplicationLayoutDto.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,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; | ||
} |
24 changes: 24 additions & 0 deletions
24
layout-server/src/main/java/org/finos/vuu/layoutserver/dto/response/ErrorResponse.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,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; | ||
} | ||
} |
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
11 changes: 6 additions & 5 deletions
11
...ver/dto/response/MetadataResponseDTO.java → ...ver/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 |
---|---|---|
@@ -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; | ||
} |
50 changes: 50 additions & 0 deletions
50
...ut-server/src/main/java/org/finos/vuu/layoutserver/exceptions/GlobalExceptionHandler.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,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); | ||
|
||
} | ||
} |
Oops, something went wrong.