Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.gridsuite.studyconfig.server.StudyConfigApi;
import org.gridsuite.studyconfig.server.dto.diagramgridlayout.DiagramGridLayout;
import org.gridsuite.studyconfig.server.service.DiagramGridLayoutService;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -29,6 +30,8 @@
public class DiagramGridLayoutController {
private final DiagramGridLayoutService diagramGridLayoutService;

public static final String DUPLICATE_FROM = "duplicateFrom";

@PostMapping(consumes = APPLICATION_JSON_VALUE)
@Operation(summary = "Save diagram grid layout")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The newly created diagram grid layout UUID returned")})
Expand Down Expand Up @@ -61,4 +64,13 @@ public ResponseEntity<DiagramGridLayout> deleteDiagramGridLayout(
diagramGridLayoutService.deleteDiagramGridLayout(diagramGridLayoutUuid);
return ResponseEntity.ok().build();
}

@PostMapping(params = { DUPLICATE_FROM })
@Operation(summary = "Duplicate diagram grid layout")
@ApiResponses(value = {@ApiResponse(responseCode = "201", description = "The diagram grid layout is duplicated")})
public ResponseEntity<UUID> duplicateDiagramGridLayout(@RequestParam(name = DUPLICATE_FROM) UUID diagramGridLayoutUuid) {
UUID newId = diagramGridLayoutService.duplicateDiagramGridLayout(diagramGridLayoutUuid);
return ResponseEntity.status(HttpStatus.CREATED).body(newId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ public void updateDiagramGridLayout(UUID diagramGridLayoutUuid, DiagramGridLayou

diagramGridLayoutRepository.save(diagramGridLayoutEntity);
}

@Transactional
public UUID duplicateDiagramGridLayout(UUID diagramGridLayoutUuid) {
DiagramGridLayoutEntity entity = diagramGridLayoutRepository.findById(diagramGridLayoutUuid)
.orElseThrow(() -> new EntityNotFoundException("Diagram grid layout not found with id: " + diagramGridLayoutUuid));

DiagramGridLayoutEntity duplicate = DiagramGridLayoutMapper.toEntity(DiagramGridLayoutMapper.toDto(entity));
return diagramGridLayoutRepository.save(duplicate).getUuid();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ void testSaveDiagramGridLayout() throws Exception {
assertThat(diagramGridLayoutToCheck).usingRecursiveComparison().isEqualTo(diagramGridLayoutToSave);
}

@Test
void testDuplicateDiagramGridLayout() throws Exception {
DiagramGridLayoutEntity existing = diagramGridLayoutRepository.save(DiagramGridLayoutMapper.toEntity(createDiagramGridLayout()));

MvcResult mockMvcResult = mockMvc.perform(post("/v1/diagram-grid-layout")
.queryParam("duplicateFrom", existing.getUuid().toString()))
.andExpect(status().isCreated())
.andReturn();

UUID duplicatedUuid = objectMapper.readValue(mockMvcResult.getResponse().getContentAsString(), UUID.class);
DiagramGridLayout duplicated = diagramGridLayoutService.getByDiagramGridLayoutUuid(duplicatedUuid);
assertThat(duplicated).usingRecursiveComparison().isEqualTo(DiagramGridLayoutMapper.toDto(existing));
}

@Test
void testSaveMapGridLayout() throws Exception {
DiagramGridLayout mapLayoutToSave = createMapGridLayout();
Expand Down