Skip to content

Commit

Permalink
get case base name from caseName with extension (#55)
Browse files Browse the repository at this point in the history
* Add function to get case base name from caseName (with extension)

Signed-off-by: basseche <[email protected]>
  • Loading branch information
basseche authored Dec 20, 2024
1 parent 4de78a9 commit 0bc7c88
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/powsybl/caseserver/CaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.caseserver.elasticsearch.CaseInfosService;
import com.powsybl.caseserver.service.CaseService;
import com.powsybl.caseserver.service.MetadataService;
import com.powsybl.commons.datasource.DataSourceUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -224,4 +225,13 @@ public ResponseEntity<List<CaseInfos>> getMetadata(@RequestParam("ids") List<UUI
LOGGER.debug("get Cases metadata");
return ResponseEntity.ok().body(caseService.getMetadata(ids));
}

@GetMapping("/cases/caseBaseName")
@Operation(summary = "Get case base name")
@ApiResponse(responseCode = "200", description = "case base name retrieved")
public ResponseEntity<String> getCaseBaseName(@RequestParam("caseName") String caseName) {
LOGGER.debug("getting base name from case file name");
String baseName = DataSourceUtil.getBaseName(caseName);
return ResponseEntity.ok(baseName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -739,4 +739,31 @@ void invalidFileInCaseDirectoryShouldBeIgnored() throws Exception {
.andExpect(status().isOk());
assertNotNull(outputDestination.receive(1000, caseImportDestination));
}

@Test
void testGetCaseBaseName() throws Exception {
MvcResult mvcResult = mvc.perform(get("/v1/cases/caseBaseName?caseName=case.xml"))
.andExpect(status().isOk())
.andReturn();
String response = mvcResult.getResponse().getContentAsString();
assertEquals("case", response);

mvcResult = mvc.perform(get("/v1/cases/caseBaseName?caseName=case.xml.gz"))
.andExpect(status().isOk())
.andReturn();
response = mvcResult.getResponse().getContentAsString();
assertEquals("case", response);

mvcResult = mvc.perform(get("/v1/cases/caseBaseName?caseName=case.v1.xml"))
.andExpect(status().isOk())
.andReturn();
response = mvcResult.getResponse().getContentAsString();
assertEquals("case.v1", response);

mvcResult = mvc.perform(get("/v1/cases/caseBaseName?caseName=case.v1.xml.gz"))
.andExpect(status().isOk())
.andReturn();
response = mvcResult.getResponse().getContentAsString();
assertEquals("case.v1", response);
}
}

0 comments on commit 0bc7c88

Please sign in to comment.