-
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.
Merge branch 'main' of https://github.com/gridsuite/explore-server in…
…to Delete-reference-to-a-specific-type # Conflicts: # src/main/java/org/gridsuite/explore/server/services/ExploreService.java
- Loading branch information
Showing
14 changed files
with
401 additions
and
107 deletions.
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
65 changes: 37 additions & 28 deletions
65
src/main/java/org/gridsuite/explore/server/ExploreController.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
52 changes: 52 additions & 0 deletions
52
src/main/java/org/gridsuite/explore/server/services/UserAdminService.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,52 @@ | ||
/** | ||
* 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.stereotype.Service; | ||
import org.springframework.web.client.HttpStatusCodeException; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import static org.gridsuite.explore.server.utils.ExploreUtils.wrapRemoteError; | ||
|
||
/** | ||
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com> | ||
*/ | ||
@Service | ||
public class UserAdminService { | ||
|
||
private static final String USER_ADMIN_API_VERSION = "v1"; | ||
private static final String USERS_MAX_ALLOWED_CASES_URI = "/users/{sub}/profile/max-cases"; | ||
|
||
private static final String DELIMITER = "/"; | ||
private final RestTemplate restTemplate; | ||
@Setter | ||
private String userAdminServerBaseUri; | ||
|
||
@Autowired | ||
public UserAdminService(RestTemplate restTemplate, RemoteServicesProperties remoteServicesProperties) { | ||
this.userAdminServerBaseUri = remoteServicesProperties.getServiceUri("user-admin-server"); | ||
this.restTemplate = restTemplate; | ||
} | ||
|
||
public Integer getUserMaxAllowedCases(String sub) { | ||
String path = UriComponentsBuilder.fromPath(DELIMITER + USER_ADMIN_API_VERSION + USERS_MAX_ALLOWED_CASES_URI) | ||
.buildAndExpand(sub).toUriString(); | ||
try { | ||
return restTemplate.getForObject(userAdminServerBaseUri + path, Integer.class); | ||
} catch (HttpStatusCodeException e) { | ||
if (e.getStatusCode().value() == 404) { | ||
return null; // no profile == unlimited import | ||
} | ||
throw wrapRemoteError(e.getMessage(), e.getStatusCode()); | ||
|
||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/gridsuite/explore/server/utils/ExploreUtils.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,29 @@ | ||
/* | ||
* 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.utils; | ||
|
||
import org.gridsuite.explore.server.ExploreException; | ||
import org.springframework.http.HttpStatusCode; | ||
|
||
/** | ||
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com | ||
*/ | ||
public final class ExploreUtils { | ||
|
||
private ExploreUtils() { | ||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); | ||
} | ||
|
||
public static ExploreException wrapRemoteError(String response, HttpStatusCode statusCode) { | ||
if (!"".equals(response)) { | ||
throw new ExploreException(ExploreException.Type.REMOTE_ERROR, response); | ||
} else { | ||
throw new ExploreException(ExploreException.Type.REMOTE_ERROR, "{\"message\": " + statusCode + "\"}"); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.