Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/root-network-creation' into root…
Browse files Browse the repository at this point in the history
…-network-delete
  • Loading branch information
LE SAULNIER Kevin committed Dec 10, 2024
2 parents 379b6ec + 9edc642 commit ea0d2b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ public ResponseEntity<Void> checkNetworkExistence(@PathVariable("studyUuid") UUI
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Study network recreation has started"),
@ApiResponse(responseCode = "424", description = "The case doesn't exist")})
public ResponseEntity<BasicStudyInfos> recreateStudyNetworkFromCase(@PathVariable("studyUuid") UUID studyUuid,
public ResponseEntity<BasicStudyInfos> recreateNetworkFromCase(@PathVariable("studyUuid") UUID studyUuid,
@RequestBody(required = false) Map<String, Object> importParameters,
@RequestParam(value = "caseUuid") UUID caseUuid,
@Parameter(description = "case format") @RequestParam(name = "caseFormat", required = false) String caseFormat,
@RequestHeader(HEADER_USER_ID) String userId) {
studyService.recreateStudyRootNetwork(caseUuid, userId, studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid), caseFormat, importParameters);
studyService.recreateNetwork(caseUuid, userId, studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid), caseFormat, importParameters);
return ResponseEntity.ok().build();
}

Expand All @@ -268,7 +268,7 @@ public ResponseEntity<BasicStudyInfos> recreateStudyNetwork(@PathVariable("study
@RequestHeader(HEADER_USER_ID) String userId,
@Parameter(description = "case format") @RequestParam(name = "caseFormat", required = false) String caseFormat
) {
studyService.recreateStudyRootNetwork(userId, studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid), caseFormat);
studyService.recreateNetwork(userId, studyUuid, studyService.getStudyFirstRootNetworkUuid(studyUuid), caseFormat);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public NetworkConversionService(@Value("${powsybl.services.network-conversion-se
* - one variant for root node - INITIAL_VARIANT
* - one variant cloned from the previous one for the 1st node - *variantId*
*/
public void persistentStore(UUID caseUuid, UUID studyUuid, UUID rootNetworkUuid, String variantId, String userId, UUID importReportUuid, String caseFormat, Map<String, Object> importParameters, CaseImportAction caseImportAction) {
public void persistNetwork(UUID caseUuid, UUID studyUuid, UUID rootNetworkUuid, String variantId, String userId, UUID importReportUuid, String caseFormat, Map<String, Object> importParameters, CaseImportAction caseImportAction) {
String receiver;
try {
receiver = URLEncoder.encode(objectMapper.writeValueAsString(
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/gridsuite/study/server/service/StudyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public BasicStudyInfos createStudy(UUID caseUuid, String userId, UUID studyUuid,
if (duplicateCase) {
caseUuidToUse = caseService.duplicateCase(caseUuid, true);
}
persistentStore(caseUuidToUse, basicStudyInfos.getId(), null, NetworkModificationTreeService.FIRST_VARIANT_ID, userId, importReportUuid, caseFormat, importParameters, CaseImportAction.STUDY_CREATION);
persistNetwork(caseUuidToUse, basicStudyInfos.getId(), null, NetworkModificationTreeService.FIRST_VARIANT_ID, userId, importReportUuid, caseFormat, importParameters, CaseImportAction.STUDY_CREATION);
} catch (Exception e) {
self.deleteStudyIfNotCreationInProgress(basicStudyInfos.getId(), userId);
throw e;
Expand All @@ -293,7 +293,7 @@ public RootNetworkCreationRequestInfos createRootNetwork(UUID studyUuid, UUID ca
UUID rootNetworkUuid = UUID.randomUUID();
RootNetworkCreationRequestEntity rootNetworkCreationRequestEntity = rootNetworkService.insertCreationRequest(rootNetworkUuid, studyEntity, userId);
try {
networkConversionService.persistentStore(caseUuid, studyUuid, rootNetworkUuid, null, userId, importReportUuid, caseFormat, importParameters, CaseImportAction.ROOT_NETWORK_CREATION);
networkConversionService.persistNetwork(caseUuid, studyUuid, rootNetworkUuid, null, userId, importReportUuid, caseFormat, importParameters, CaseImportAction.ROOT_NETWORK_CREATION);
} catch (Exception e) {
//TODO: don't throw another error if deletion fails ?
rootNetworkService.delete(rootNetworkUuid);
Expand Down Expand Up @@ -323,28 +323,28 @@ public void createRootNetwork(@NonNull UUID studyUuid, @NonNull RootNetworkInfos
* @param studyUuid
* @param importParameters
*/
public void recreateStudyRootNetwork(UUID caseUuid, String userId, UUID studyUuid, UUID rootNetworkUuid, String caseFormat, Map<String, Object> importParameters) {
recreateStudyRootNetwork(caseUuid, userId, studyUuid, rootNetworkUuid, caseFormat, importParameters, false);
public void recreateNetwork(UUID caseUuid, String userId, UUID studyUuid, UUID rootNetworkUuid, String caseFormat, Map<String, Object> importParameters) {
recreateNetwork(caseUuid, userId, studyUuid, rootNetworkUuid, caseFormat, importParameters, false);
}

/**
* Recreates study network from existing case and import parameters
* @param userId
* @param studyUuid
*/
public void recreateStudyRootNetwork(String userId, UUID studyUuid, UUID rootNetworkUuid, String caseFormat) {
public void recreateNetwork(String userId, UUID studyUuid, UUID rootNetworkUuid, String caseFormat) {
UUID caseUuid = rootNetworkService.getRootNetwork(rootNetworkUuid).orElseThrow(() -> new StudyException(ROOTNETWORK_NOT_FOUND)).getCaseUuid();
recreateStudyRootNetwork(caseUuid, userId, studyUuid, rootNetworkUuid, caseFormat, null, true);
recreateNetwork(caseUuid, userId, studyUuid, rootNetworkUuid, caseFormat, null, true);
}

private void recreateStudyRootNetwork(UUID caseUuid, String userId, UUID studyUuid, UUID rootNetworkUuid, String caseFormat, Map<String, Object> importParameters, boolean shouldLoadPreviousImportParameters) {
private void recreateNetwork(UUID caseUuid, String userId, UUID studyUuid, UUID rootNetworkUuid, String caseFormat, Map<String, Object> importParameters, boolean shouldLoadPreviousImportParameters) {
caseService.assertCaseExists(caseUuid);
UUID importReportUuid = UUID.randomUUID();
Map<String, Object> importParametersToUse = shouldLoadPreviousImportParameters
? new HashMap<>(rootNetworkService.getImportParameters(rootNetworkUuid))
: importParameters;

persistentStore(caseUuid, studyUuid, rootNetworkUuid, null, userId, importReportUuid, caseFormat, importParametersToUse, CaseImportAction.NETWORK_RECREATION);
persistNetwork(caseUuid, studyUuid, rootNetworkUuid, null, userId, importReportUuid, caseFormat, importParametersToUse, CaseImportAction.NETWORK_RECREATION);
}

public UUID duplicateStudy(UUID sourceStudyUuid, String userId) {
Expand Down Expand Up @@ -610,9 +610,9 @@ public String getVoltageLevelSvgAndMetadata(String voltageLevelId, DiagramParame
}
}

private void persistentStore(UUID caseUuid, UUID studyUuid, UUID rootNetworkUuid, String variantId, String userId, UUID importReportUuid, String caseFormat, Map<String, Object> importParameters, CaseImportAction caseImportAction) {
private void persistNetwork(UUID caseUuid, UUID studyUuid, UUID rootNetworkUuid, String variantId, String userId, UUID importReportUuid, String caseFormat, Map<String, Object> importParameters, CaseImportAction caseImportAction) {
try {
networkConversionService.persistentStore(caseUuid, studyUuid, rootNetworkUuid, variantId, userId, importReportUuid, caseFormat, importParameters, caseImportAction);
networkConversionService.persistNetwork(caseUuid, studyUuid, rootNetworkUuid, variantId, userId, importReportUuid, caseFormat, importParameters, caseImportAction);
} catch (HttpStatusCodeException e) {
throw handleHttpError(e, STUDY_CREATION_FAILED);
}
Expand Down

0 comments on commit ea0d2b9

Please sign in to comment.