-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for spreadsheet config collections (#111)
Signed-off-by: Ayoub LABIDI <[email protected]>
- Loading branch information
Showing
5 changed files
with
365 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/main/java/org/gridsuite/explore/server/services/SpreadsheetConfigCollectionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* 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.services; | ||
|
||
import lombok.Setter; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
/** | ||
* @author Ayoub LABIDI <ayoub.labidi at rte-france.com> | ||
*/ | ||
@Service | ||
public class SpreadsheetConfigCollectionService implements IDirectoryElementsService { | ||
|
||
private static final String SPREADSHEET_CONFIG_API_VERSION = "v1"; | ||
private static final String DELIMITER = "/"; | ||
private static final String SPREADSHEET_CONFIG_COLLECTIONS_PATH = DELIMITER + SPREADSHEET_CONFIG_API_VERSION + DELIMITER + "spreadsheet-config-collections"; | ||
private static final String DUPLICATE_FROM_PARAMETER = "duplicateFrom"; | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
@Setter | ||
private String spreadsheetConfigServerBaseUri; | ||
|
||
@Autowired | ||
public SpreadsheetConfigCollectionService(RestTemplate restTemplate, RemoteServicesProperties remoteServicesProperties) { | ||
this.spreadsheetConfigServerBaseUri = remoteServicesProperties.getServiceUri("spreadsheet-config-server"); | ||
this.restTemplate = restTemplate; | ||
} | ||
|
||
public UUID createSpreadsheetConfigCollection(String collection) { | ||
Objects.requireNonNull(collection); | ||
|
||
var path = UriComponentsBuilder | ||
.fromPath(SPREADSHEET_CONFIG_COLLECTIONS_PATH) | ||
.buildAndExpand() | ||
.toUriString(); | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
|
||
HttpEntity<String> httpEntity = new HttpEntity<>(collection, headers); | ||
|
||
return restTemplate.exchange(spreadsheetConfigServerBaseUri + path, HttpMethod.POST, httpEntity, UUID.class).getBody(); | ||
} | ||
|
||
public UUID duplicateSpreadsheetConfigCollection(UUID collectionId) { | ||
Objects.requireNonNull(collectionId); | ||
|
||
var path = UriComponentsBuilder | ||
.fromPath(SPREADSHEET_CONFIG_COLLECTIONS_PATH + DELIMITER + "duplicate") | ||
.queryParam(DUPLICATE_FROM_PARAMETER, collectionId) | ||
.buildAndExpand() | ||
.toUriString(); | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
|
||
HttpEntity<String> httpEntity = new HttpEntity<>(headers); | ||
|
||
return restTemplate.exchange(spreadsheetConfigServerBaseUri + path, HttpMethod.POST, httpEntity, UUID.class).getBody(); | ||
} | ||
|
||
public void updateSpreadsheetConfigCollection(UUID collectionId, String collection) { | ||
Objects.requireNonNull(collectionId); | ||
Objects.requireNonNull(collection); | ||
|
||
var path = UriComponentsBuilder | ||
.fromPath(SPREADSHEET_CONFIG_COLLECTIONS_PATH + DELIMITER + collectionId) | ||
.buildAndExpand() | ||
.toUriString(); | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
|
||
HttpEntity<String> httpEntity = new HttpEntity<>(collection, headers); | ||
|
||
restTemplate.exchange(spreadsheetConfigServerBaseUri + path, HttpMethod.PUT, httpEntity, Void.class); | ||
} | ||
|
||
@Override | ||
public void delete(UUID configUuid, String userId) { | ||
Objects.requireNonNull(configUuid); | ||
|
||
var path = UriComponentsBuilder | ||
.fromPath(SPREADSHEET_CONFIG_COLLECTIONS_PATH + DELIMITER + configUuid) | ||
.buildAndExpand() | ||
.toUriString(); | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add(HEADER_USER_ID, userId); | ||
|
||
restTemplate.exchange(spreadsheetConfigServerBaseUri + path, HttpMethod.DELETE, new HttpEntity<>(headers), Void.class); | ||
} | ||
} |
Oops, something went wrong.