Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add case format to POST explore/studies/STUDY1/cases/ endpoint #73

Merged
merged 6 commits into from
Feb 16, 2024
Merged
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 @@ -50,12 +50,14 @@ public ExploreController(ExploreService exploreService, DirectoryService directo
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Study creation request delegated to study server")})
public ResponseEntity<Void> createStudy(@PathVariable("studyName") String studyName,
@PathVariable("caseUuid") UUID caseUuid,
@RequestParam(name = "caseFormat") String caseFormat,
@RequestParam(name = "duplicateCase", required = false, defaultValue = "false") Boolean duplicateCase,
@RequestParam("description") String description,
@RequestParam(QUERY_PARAM_PARENT_DIRECTORY_ID) UUID parentDirectoryUuid,
@RequestHeader("userId") String userId,
@RequestBody(required = false) Map<String, Object> importParams) {
exploreService.createStudy(studyName, caseUuid, description, userId, parentDirectoryUuid, importParams, duplicateCase);
CaseInfo caseInfo = new CaseInfo(caseUuid, caseFormat);
exploreService.createStudy(studyName, caseInfo, description, userId, parentDirectoryUuid, importParams, duplicateCase);
return ResponseEntity.ok().build();
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/gridsuite/explore/server/dto/CaseInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.gridsuite.explore.server.dto;

import java.util.UUID;
/**
* @author Jamal KHEYYAD <jamal.kheyyad at rte-france.com>
*/

public record CaseInfo(UUID caseUuid, String caseFormat) { }
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public ExploreService(
this.parametersService = parametersService;
}

public void createStudy(String studyName, UUID caseUuid, String description, String userId, UUID parentDirectoryUuid, Map<String, Object> importParams, Boolean duplicateCase) {
public void createStudy(String studyName, CaseInfo caseInfo, String description, String userId, UUID parentDirectoryUuid, Map<String, Object> importParams, Boolean duplicateCase) {
ElementAttributes elementAttributes = new ElementAttributes(UUID.randomUUID(), studyName, STUDY, null, userId, 0L, description);
studyService.insertStudyWithExistingCaseFile(elementAttributes.getElementUuid(), userId, caseUuid, importParams, duplicateCase);
studyService.insertStudyWithExistingCaseFile(elementAttributes.getElementUuid(), userId, caseInfo.caseUuid(), caseInfo.caseFormat(), importParams, duplicateCase);
directoryService.createElement(elementAttributes, parentDirectoryUuid, userId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ public void setStudyServerBaseUri(String studyServerBaseUri) {
this.studyServerBaseUri = studyServerBaseUri;
}

public void insertStudyWithExistingCaseFile(UUID studyUuid, String userId, UUID caseUuid,
public void insertStudyWithExistingCaseFile(UUID studyUuid, String userId, UUID caseUuid, String caseFormat,
Map<String, Object> importParams, Boolean duplicateCase) {
String path = UriComponentsBuilder.fromPath(DELIMITER + STUDY_SERVER_API_VERSION +
"/studies/cases/{caseUuid}")
.queryParam("studyUuid", studyUuid)
.queryParam("duplicateCase", duplicateCase)
.queryParam("caseFormat", caseFormat)
.buildAndExpand(caseUuid)
.toUriString();
HttpHeaders headers = new HttpHeaders();
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/gridsuite/explore/server/ExploreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ public void testCreateStudyFromExistingCase() throws Exception {
mockMvc.perform(post("/v1/explore/studies/" + STUDY1 + "/cases/" + CASE_UUID + "?description=desc&parentDirectoryUuid=" + PARENT_DIRECTORY_UUID)
.param("duplicateCase", "false")
.header("userId", "userId")
.param("caseFormat", "XIIDM")
.contentType(MediaType.APPLICATION_JSON)
).andExpect(status().isOk());
}
Expand All @@ -306,6 +307,7 @@ public void testCreateStudyFromExistingCase() throws Exception {
public void testCreateStudyFromExistingCaseError() throws Exception {
mockMvc.perform(post("/v1/explore/studies/" + STUDY1 + "/cases/" + NON_EXISTING_CASE_UUID + "?description=desc&parentDirectoryUuid=" + PARENT_DIRECTORY_UUID)
.header("userId", USER1)
.param("caseFormat", "XIIDM")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isNotFound());
}
Expand Down
Loading