Skip to content

Commit

Permalink
add case format to POST explore/studies/STUDY1/cases/ endpoint (#73)
Browse files Browse the repository at this point in the history
* add caseFormat parametter to POST explore/studies/STUDY1/cases/ endpoint
  • Loading branch information
jamal-khey authored Feb 16, 2024
1 parent 2052301 commit 3b9d35a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
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 @@ -66,9 +66,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 @@ -311,6 +311,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 @@ -319,6 +320,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

0 comments on commit 3b9d35a

Please sign in to comment.