Skip to content

Commit

Permalink
SLVUU-129: Incorporate app layout and settings into single ObjectNode
Browse files Browse the repository at this point in the history
  • Loading branch information
pling-scottlogic committed Jan 9, 2024
1 parent c9f37c4 commit 2d79d80
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.finos.vuu.layoutserver.controller;

import com.fasterxml.jackson.databind.node.ObjectNode;
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.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -20,7 +19,6 @@
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
Expand All @@ -31,24 +29,22 @@ public class ApplicationLayoutController {
*/
@ResponseStatus(HttpStatus.OK)
@GetMapping
public ApplicationLayoutDto getApplicationLayout(@RequestHeader("username") String username) {
return mapper.map(service.getApplicationLayout(username), ApplicationLayoutDto.class);
public ObjectNode getApplicationLayout(@RequestHeader("username") String username) {
return service.getApplicationLayout(username).getApplicationLayout();
}

/**
* Creates or updates the unique application layout for the requesting user.
*
* @param applicationLayoutDto JSON representation of all relevant data about the application layout to be created,
* containing top-level nodes for the layout itself, and for associated settings
* @param applicationLayout JSON representation of all relevant data about the application layout to be created,
* containing top-level nodes for the layout itself, and (optionally) for associated settings
* @param username the user making the request
*/
@ResponseStatus(HttpStatus.CREATED)
@PutMapping
public void persistApplicationLayout(@RequestHeader("username") String username,
@RequestBody ApplicationLayoutDto applicationLayoutDto) {
service.persistApplicationLayout(username,
applicationLayoutDto.getApplicationLayout(),
applicationLayoutDto.getSettings());
@RequestBody ObjectNode applicationLayout) {
service.persistApplicationLayout(username, applicationLayout);
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@ public class ApplicationLayout {
@Convert(converter = ObjectNodeConverter.class)
@Column(columnDefinition = "JSON")
private ObjectNode applicationLayout;

@Convert(converter = ObjectNodeConverter.class)
@Column(columnDefinition = "JSON")
private ObjectNode settings;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class ApplicationLayoutService {
private final ApplicationLayoutRepository repository;
private final DefaultApplicationLayoutLoader defaultLoader;

public void persistApplicationLayout(String username, ObjectNode applicationLayout, ObjectNode settings) {
repository.save(new ApplicationLayout(username, applicationLayout, settings));
public void persistApplicationLayout(String username, ObjectNode applicationLayout) {
repository.save(new ApplicationLayout(username, applicationLayout));
}

public ApplicationLayout getApplicationLayout(String username) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ApplicationLayout getDefaultLayout() {

private void loadDefaultLayout() {
ObjectNode definition = loadDefaultLayoutJsonFile();
defaultLayout = new ApplicationLayout(null, definition, null);
defaultLayout = new ApplicationLayout(null, definition);
}

private ObjectNode loadDefaultLayoutJsonFile() {
Expand Down
52 changes: 27 additions & 25 deletions layout-server/src/main/resources/defaultApplicationLayout.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
{
"type": "Stack",
"id": "main-tabs",
"props": {
"className": "vuuShell-mainTabs",
"TabstripProps": {
"allowAddTab": true,
"allowCloseTab": true,
"allowRenameTab": true,
"animateSelectionThumb": false,
"location": "main-tab",
"tabClassName": "MainTab"
},
"preserve": true,
"active": 0
},
"children": [
{
"props": {
"id": "tab1",
"title": "Tab 1",
"className": "vuuShell-Placeholder"
"applicationLayout": {
"type": "Stack",
"id": "main-tabs",
"props": {
"className": "vuuShell-mainTabs",
"TabstripProps": {
"allowAddTab": true,
"allowCloseTab": true,
"allowRenameTab": true,
"animateSelectionThumb": false,
"location": "main-tab",
"tabClassName": "MainTab"
},
"type": "Placeholder"
}
]
}
"preserve": true,
"active": 0
},
"children": [
{
"props": {
"id": "tab1",
"title": "Tab 1",
"className": "vuuShell-Placeholder"
},
"type": "Placeholder"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.finos.vuu.layoutserver.controller;

import com.fasterxml.jackson.databind.node.ObjectNode;
import org.finos.vuu.layoutserver.dto.response.ApplicationLayoutDto;
import org.finos.vuu.layoutserver.model.ApplicationLayout;
import org.finos.vuu.layoutserver.service.ApplicationLayoutService;
import org.finos.vuu.layoutserver.utils.ObjectNodeConverter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.modelmapper.ModelMapper;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.times;
Expand All @@ -18,13 +16,12 @@
class ApplicationLayoutControllerTest {
private static ApplicationLayoutService mockService;
private static ApplicationLayoutController controller;
private static final ModelMapper modelMapper = new ModelMapper();
private static final ObjectNodeConverter objectNodeConverter = new ObjectNodeConverter();

@BeforeEach
public void setup() {
mockService = Mockito.mock(ApplicationLayoutService.class);
controller = new ApplicationLayoutController(mockService, modelMapper);
controller = new ApplicationLayoutController(mockService);
}

@Test
Expand All @@ -33,12 +30,11 @@ public void getApplicationLayout_anyUsername_returnsLayoutFromService() {
ObjectNode definition = objectNodeConverter.convertToEntityAttribute("{\"id\":\"main-tabs\"}");

when(mockService.getApplicationLayout(user))
.thenReturn(new ApplicationLayout(user, definition, null));
.thenReturn(new ApplicationLayout(user, definition));

ApplicationLayoutDto response = controller.getApplicationLayout(user);
ObjectNode response = controller.getApplicationLayout(user);

assertThat(response.getApplicationLayout()).isEqualTo(definition);
assertThat(response.getSettings()).isNull();
assertThat(response).isEqualTo(definition);

verify(mockService, times(1)).getApplicationLayout(user);
}
Expand All @@ -47,12 +43,10 @@ public void getApplicationLayout_anyUsername_returnsLayoutFromService() {
public void persistApplicationLayout_anyInput_callsService() {
String user = "user";
ObjectNode definition = objectNodeConverter.convertToEntityAttribute("{\"id\":\"main-tabs\"}");
ApplicationLayoutDto dto = new ApplicationLayoutDto();
dto.setApplicationLayout(definition);

controller.persistApplicationLayout(user, dto);
controller.persistApplicationLayout(user, definition);

verify(mockService, times(1)).persistApplicationLayout(user, definition, null);
verify(mockService, times(1)).persistApplicationLayout(user, definition);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void getApplicationLayout_noLayoutExists_returns200WithDefaultLayout() th
mockMvc.perform(get(BASE_URL).header("username", "new user"))
.andExpect(status().isOk())
// Expecting application layout as defined in /test/resources/defaultApplicationLayout.json
.andExpect(jsonPath("$.applicationLayout.defaultLayoutKey", is("default-layout-value")));
.andExpect(jsonPath("$.defaultLayoutKey", is("default-layout-value")));
}

@Test
Expand Down Expand Up @@ -88,7 +88,7 @@ public void getApplicationLayout_layoutExists_returns200WithPersistedLayout() th

mockMvc.perform(get(BASE_URL).header("username", user))
.andExpect(status().isOk())
.andExpect(jsonPath("$.applicationLayout", is(definition)));
.andExpect(jsonPath("$", is(definition)));
}

@Test
Expand All @@ -111,8 +111,7 @@ public void persistApplicationLayout_noLayoutExists_returns201AndPersistsLayout(
ApplicationLayout persistedLayout = repository.findById(user).orElseThrow();

assertThat(persistedLayout.getUsername()).isEqualTo(user);
assertThat(persistedLayout.getApplicationLayout()).isEqualTo(objectMapper.readTree(definition));
assertThat(persistedLayout.getSettings()).isEqualTo(objectMapper.readTree(settings));
assertThat(persistedLayout.getApplicationLayout()).isEqualTo(objectMapper.readTree(requestBody));
}

@Test
Expand Down Expand Up @@ -143,8 +142,7 @@ public void persistApplicationLayout_layoutExists_returns201AndOverwritesLayout(
ApplicationLayout retrievedLayout = repository.findById(user).orElseThrow();

assertThat(retrievedLayout.getUsername()).isEqualTo(user);
assertThat(retrievedLayout.getApplicationLayout()).isEqualTo(objectMapper.readTree(newDefinition));
assertThat(retrievedLayout.getSettings()).isEqualTo(objectMapper.readTree(settings));
assertThat(retrievedLayout.getApplicationLayout()).isEqualTo(objectMapper.readTree(requestBody));
}

@Test
Expand Down Expand Up @@ -192,6 +190,6 @@ public void deleteApplicationLayout_noUserInHeader_returns400() throws Exception
}

private void persistApplicationLayout(String user, Map<String, String> definition) {
repository.save(new ApplicationLayout(user, objectMapper.convertValue(definition, ObjectNode.class), null));
repository.save(new ApplicationLayout(user, objectMapper.convertValue(definition, ObjectNode.class)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ public void getApplicationLayout_noLayout_returnsDefault() {

assertThat(actualLayout.getUsername()).isNull();
assertThat(actualLayout.getApplicationLayout()).isEqualTo(expectedDefinition);
assertThat(actualLayout.getSettings()).isNull();
}

@Test
public void getApplicationLayout_layoutExists_returnsLayout() {
String user = "user";

ObjectNode expectedDefinition = objectNodeConverter.convertToEntityAttribute("{\"id\":\"main-tabs\"}");
ApplicationLayout expectedLayout = new ApplicationLayout(user, expectedDefinition, null);
ApplicationLayout expectedLayout = new ApplicationLayout(user, expectedDefinition);

when(mockRepo.findById(user)).thenReturn(Optional.of(expectedLayout));

Expand All @@ -67,10 +66,10 @@ public void createApplicationLayout_validDefinition_callsRepoSave() {
String user = "user";
ObjectNode definition = objectNodeConverter.convertToEntityAttribute("{\"id\":\"main-tabs\"}");

service.persistApplicationLayout(user, definition, null);
service.persistApplicationLayout(user, definition);

verify(mockRepo, times(1))
.save(new ApplicationLayout(user, definition, null));
.save(new ApplicationLayout(user, definition));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe("Application Layouts", () => {
expect(response.status).to.eq(200);

expect(response.body).to.have.property("applicationLayout");
expect(response.body).to.have.property("settings");

expect(JSON.stringify(response.body.applicationLayout)).to.equal(
JSON.stringify(Cypress.env(DEFAULT_APPLICATION_LAYOUT_ALIAS))
Expand Down

0 comments on commit 2d79d80

Please sign in to comment.