Skip to content

Commit

Permalink
resolve conflicts and merge main into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ghazwarhili committed Jun 7, 2024
2 parents 44a351b + 239906a commit e69c2f5
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 85 deletions.
13 changes: 9 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</developers>

<properties>
<powsybl-ws-dependencies.version>2.9.0</powsybl-ws-dependencies.version>
<gridsuite-dependencies.version>29</gridsuite-dependencies.version>
</properties>

<build>
Expand Down Expand Up @@ -83,9 +83,9 @@
<dependencies>
<!-- imports -->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ws-dependencies</artifactId>
<version>${powsybl-ws-dependencies.version}</version>
<groupId>org.gridsuite</groupId>
<artifactId>gridsuite-dependencies</artifactId>
<version>${gridsuite-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -128,6 +128,11 @@
<artifactId>spring-boot-starter-actuator</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/gridsuite/explore/server/ExploreController.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ public ResponseEntity<Void> replaceFilterWithScript(@PathVariable("id") UUID id,

@DeleteMapping(value = "/explore/elements/{elementUuid}")
@Operation(summary = "Remove directory/element")
@ApiResponses(@ApiResponse(responseCode = "200", description = "Directory/element was successfully removed"))
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Directory/element was successfully removed"),
@ApiResponse(responseCode = "404", description = "Directory/element was not found"),
@ApiResponse(responseCode = "403", description = "Access forbidden for the directory/element")
})
public ResponseEntity<Void> deleteElement(@PathVariable("elementUuid") UUID elementUuid,
@RequestHeader(QUERY_PARAM_USER_ID) String userId) {
exploreService.deleteElement(elementUuid, userId);
Expand All @@ -219,7 +223,11 @@ public ResponseEntity<Void> deleteElement(@PathVariable("elementUuid") UUID elem

@DeleteMapping(value = "/explore/elements/{directoryUuid}", params = "ids")
@Operation(summary = "Remove directories/elements")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "directories/elements was successfully removed")})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "directories/elements was successfully removed"),
@ApiResponse(responseCode = "404", description = "At least one directory/element was not found"),
@ApiResponse(responseCode = "403", description = "Access forbidden for at least one directory/element")
})
public ResponseEntity<Void> deleteElements(@RequestParam("ids") List<UUID> elementsUuid,
@RequestHeader(QUERY_PARAM_USER_ID) String userId,
@PathVariable UUID directoryUuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class ExploreException extends RuntimeException {

public enum Type {
NOT_FOUND,
NOT_ALLOWED,
UNKNOWN_ELEMENT_TYPE,
REMOTE_ERROR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ protected ResponseEntity<Object> handleExploreException(ExploreException excepti
}
ExploreException exploreException = exception;
switch (exploreException.getType()) {
case NOT_FOUND:
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
case NOT_ALLOWED:
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(NOT_ALLOWED);
case REMOTE_ERROR:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class ElementAttributes {

private String type;

private AccessRightsAttributes accessRights;

private String owner;

private Long subdirectoriesCount;
Expand All @@ -36,7 +34,7 @@ public class ElementAttributes {

private Map<String, Object> specificMetadata = new HashMap<>();

public ElementAttributes(UUID elementUuid, String elementName, String type, AccessRightsAttributes accessRights, String owner, long subdirectoriesCount, String description) {
this(elementUuid, elementName, type, accessRights, owner, subdirectoriesCount, description, null);
public ElementAttributes(UUID elementUuid, String elementName, String type, String owner, long subdirectoriesCount, String description) {
this(elementUuid, elementName, type, owner, subdirectoriesCount, description, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
import org.gridsuite.explore.server.utils.ParametersType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

Expand All @@ -42,6 +40,9 @@ public class DirectoryService implements IDirectoryElementsService {
private static final String ELEMENTS_SERVER_ROOT_PATH = DELIMITER + DIRECTORY_SERVER_API_VERSION + DELIMITER
+ "elements";

private static final String PARAM_IDS = "ids";
private static final String PARAM_FOR_DELETION = "forDeletion";

private final Map<String, IDirectoryElementsService> genericServices;
private final RestTemplate restTemplate;
private String directoryServerBaseUri;
Expand Down Expand Up @@ -115,11 +116,42 @@ public void deleteDirectoryElement(UUID elementUuid, String userId) {
restTemplate.exchange(directoryServerBaseUri + path, HttpMethod.DELETE, new HttpEntity<>(headers), Void.class);
}

public void areDirectoryElementsDeletable(List<UUID> elementUuids, String userId) {
var ids = elementUuids.stream().map(UUID::toString).collect(Collectors.joining(","));

HttpHeaders headers = new HttpHeaders();
headers.add(HEADER_USER_ID, userId);
String path = UriComponentsBuilder
.fromPath(ELEMENTS_SERVER_ROOT_PATH)
.queryParam(PARAM_FOR_DELETION, true)
.queryParam(PARAM_IDS, ids)
.buildAndExpand()
.toUriString();

ResponseEntity<Void> response;
try {
response = restTemplate.exchange(directoryServerBaseUri + path, HttpMethod.HEAD, new HttpEntity<>(headers), Void.class);

} catch (HttpStatusCodeException e) {
if (HttpStatus.FORBIDDEN.equals(e.getStatusCode())) {
throw new ExploreException(NOT_ALLOWED);
} else if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) {
throw new ExploreException(NOT_FOUND);
} else {
throw e;
}
}

if (HttpStatus.NO_CONTENT.equals(response.getStatusCode())) {
throw new ExploreException(NOT_ALLOWED);
}
}

public void deleteElementsFromDirectory(List<UUID> elementUuids, UUID parentDirectoryUuid, String userId) {
var ids = elementUuids.stream().map(UUID::toString).collect(Collectors.joining(","));
String path = UriComponentsBuilder
.fromPath(ELEMENTS_SERVER_ROOT_PATH)
.queryParam("ids", ids)
.queryParam(PARAM_IDS, ids)
.queryParam("parentDirectoryUuid", parentDirectoryUuid)
.buildAndExpand()
.toUriString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public class ExploreService {
static final String MODIFICATION = "MODIFICATION";
static final String DIRECTORY = "DIRECTORY";

private DirectoryService directoryService;
private StudyService studyService;
private ContingencyListService contingencyListService;
private NetworkModificationService networkModificationService;
private FilterService filterService;
private CaseService caseService;
private ParametersService parametersService;
private final DirectoryService directoryService;
private final StudyService studyService;
private final ContingencyListService contingencyListService;
private final NetworkModificationService networkModificationService;
private final FilterService filterService;
private final CaseService caseService;
private final ParametersService parametersService;

private static final Logger LOGGER = LoggerFactory.getLogger(ExploreService.class);

Expand All @@ -67,7 +67,7 @@ public ExploreService(
}

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);
ElementAttributes elementAttributes = new ElementAttributes(UUID.randomUUID(), studyName, STUDY, userId, 0L, description);
studyService.insertStudyWithExistingCaseFile(elementAttributes.getElementUuid(), userId, caseInfo.caseUuid(), caseInfo.caseFormat(), importParams, duplicateCase);
directoryService.createElement(elementAttributes, parentDirectoryUuid, userId);
}
Expand All @@ -79,7 +79,7 @@ public void duplicateStudy(UUID sourceStudyUuid, UUID targetDirectoryId, String

public void createCase(String caseName, MultipartFile caseFile, String description, String userId, UUID parentDirectoryUuid) {
UUID uuid = caseService.importCase(caseFile);
directoryService.createElement(new ElementAttributes(uuid, caseName, CASE, null, userId, 0L, description),
directoryService.createElement(new ElementAttributes(uuid, caseName, CASE, userId, 0L, description),
parentDirectoryUuid, userId);
}

Expand All @@ -89,8 +89,7 @@ public void duplicateCase(UUID sourceCaseUuid, UUID targetDirectoryId, String us
}

public void createScriptContingencyList(String listName, String content, String description, String userId, UUID parentDirectoryUuid) {
ElementAttributes elementAttributes = new ElementAttributes(UUID.randomUUID(), listName, CONTINGENCY_LIST,
null, userId, 0L, description);
ElementAttributes elementAttributes = new ElementAttributes(UUID.randomUUID(), listName, CONTINGENCY_LIST, userId, 0L, description);
contingencyListService.insertScriptContingencyList(elementAttributes.getElementUuid(), content);
directoryService.createElement(elementAttributes, parentDirectoryUuid, userId);
}
Expand All @@ -105,8 +104,7 @@ public void duplicateContingencyList(UUID contingencyListsId, UUID targetDirecto
}

public void createFormContingencyList(String listName, String content, String description, String userId, UUID parentDirectoryUuid) {
ElementAttributes elementAttributes = new ElementAttributes(UUID.randomUUID(), listName, CONTINGENCY_LIST,
null, userId, 0L, description);
ElementAttributes elementAttributes = new ElementAttributes(UUID.randomUUID(), listName, CONTINGENCY_LIST, userId, 0L, description);
contingencyListService.insertFormContingencyList(elementAttributes.getElementUuid(), content);
directoryService.createElement(elementAttributes, parentDirectoryUuid, userId);
}
Expand All @@ -117,7 +115,7 @@ public void newScriptFromFormContingencyList(UUID id, String scriptName, String
throw new ExploreException(NOT_ALLOWED);
}
ElementAttributes newElementAttributes = new ElementAttributes(UUID.randomUUID(), scriptName,
CONTINGENCY_LIST, new AccessRightsAttributes(elementAttribute.getAccessRights().isPrivate()), userId, 0L, null);
CONTINGENCY_LIST, userId, 0L, null);
contingencyListService.newScriptFromFormContingencyList(id, newElementAttributes.getElementUuid());
directoryService.createElement(newElementAttributes, parentDirectoryUuid, userId);
}
Expand All @@ -135,15 +133,13 @@ public void replaceFormContingencyListWithScript(UUID id, String userId) {
}

public void createIdentifierContingencyList(String listName, String content, String description, String userId, UUID parentDirectoryUuid) {
ElementAttributes elementAttributes = new ElementAttributes(UUID.randomUUID(), listName, CONTINGENCY_LIST,
null, userId, 0L, description);
ElementAttributes elementAttributes = new ElementAttributes(UUID.randomUUID(), listName, CONTINGENCY_LIST, userId, 0L, description);
contingencyListService.insertIdentifierContingencyList(elementAttributes.getElementUuid(), content);
directoryService.createElement(elementAttributes, parentDirectoryUuid, userId);
}

public void createFilter(String filter, String filterName, String description, UUID parentDirectoryUuid, String userId) {
ElementAttributes elementAttributes = new ElementAttributes(UUID.randomUUID(), filterName, FILTER,
null, userId, 0, description);
ElementAttributes elementAttributes = new ElementAttributes(UUID.randomUUID(), filterName, FILTER, userId, 0, description);
filterService.insertFilter(filter, elementAttributes.getElementUuid(), userId);
directoryService.createElement(elementAttributes, parentDirectoryUuid, userId);
}
Expand All @@ -159,7 +155,7 @@ public void newScriptFromFilter(UUID filterId, String scriptName, String userId,
throw new ExploreException(NOT_ALLOWED);
}
ElementAttributes newElementAttributes = new ElementAttributes(UUID.randomUUID(), scriptName,
FILTER, new AccessRightsAttributes(elementAttribute.getAccessRights().isPrivate()), userId, 0, null);
FILTER, userId, 0, null);
filterService.insertNewScriptFromFilter(filterId, newElementAttributes.getElementUuid());
directoryService.createElement(newElementAttributes, parentDirectoryUuid, userId);
}
Expand All @@ -177,6 +173,9 @@ public void replaceFilterWithScript(UUID id, String userId) {
}

public void deleteElement(UUID id, String userId) {
// Verify if the user is allowed to delete the element.
// FIXME: to be deleted when it's properly handled by the gateway
directoryService.areDirectoryElementsDeletable(List.of(id), userId);
try {
directoryService.deleteElement(id, userId);
directoryService.deleteDirectoryElement(id, userId);
Expand All @@ -188,6 +187,10 @@ public void deleteElement(UUID id, String userId) {
}

public void deleteElementsFromDirectory(List<UUID> uuids, UUID parentDirectoryUuids, String userId) {

// Verify if the user is allowed to delete the elements.
// FIXME: to be deleted when it's properly handled by the gateway
directoryService.areDirectoryElementsDeletable(uuids, userId);
try {
uuids.forEach(id -> directoryService.deleteElement(id, userId));
// FIXME dirty fix to ignore errors and still delete the elements in the directory-server. To delete when handled properly.
Expand Down Expand Up @@ -232,8 +235,7 @@ private String getProperPath(ContingencyListType contingencyListType) {

public void createParameters(String parameters, ParametersType parametersType, String parametersName, UUID parentDirectoryUuid, String userId) {
UUID parametersUuid = parametersService.createParameters(parameters, parametersType);
ElementAttributes elementAttributes = new ElementAttributes(parametersUuid, parametersName, parametersType.name(),
null, userId, 0, null);
ElementAttributes elementAttributes = new ElementAttributes(parametersUuid, parametersName, parametersType.name(), userId, 0, null);
directoryService.createElement(elementAttributes, parentDirectoryUuid, userId);
}

Expand All @@ -253,7 +255,7 @@ public void createNetworkModifications(String modificationAttributesList, String
// create modifications group
UUID newModificationsUuids = networkModificationService.createNetworkModifications(modificationAttributesList);
ElementAttributes elementAttributes = new ElementAttributes(newModificationsUuids, name, MODIFICATION,
null, userId, 0L, description);
userId, 0L, description);
directoryService.createElementWithNewName(elementAttributes, parentDirectoryUuid, userId, true);
}

Expand Down
Loading

0 comments on commit e69c2f5

Please sign in to comment.