Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@
*/
package org.gridsuite.explore.server.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.NonNull;
import lombok.experimental.SuperBuilder;

import java.util.UUID;

/**
* @author Florent MILLOT {@literal <florent.millot_externe at rte-france.com>}
* @author Maissa Souissi <maissa.souissi at rte-france.com>
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
public class ReferenceAttributes {
public enum ReferenceType {
STUDY_NODE,
NETWORK_MODIFICATION,
DIRECTORY_ELEMENT
STUDY_NODE_NETWORK_MODIFICATION,
DIRECTORY_NETWORK_MODIFICATION,
}

@NonNull
private UUID referenceId;
private ReferenceType referenceType;
@NonNull private ReferenceContainer referenceContainer;
@NonNull private ReferenceType referenceType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright (c) 2026, 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.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.experimental.SuperBuilder;

import java.util.UUID;

/**
* @author Maissa Souissi <maissa.souissi at rte-france.com>
*/
@Getter
@NoArgsConstructor
@SuperBuilder
/**
* ReferenceContainer represents the information that makes it easy to locate the reference where it is used.
* It depends on the type of reference:
* STUDY_NODE: rootContainerId: studyId; containerId: nodeId
* STUDY_NODE_NETWORK_MODIFICATION: rootContainerId: nodeId; containerId: parentCompositeId
* DIRECTORY_NETWORK_MODIFICATION: rootContainerId: directoryId; containerId: parentCompositeId
*/
public class ReferenceContainer {
@NonNull private UUID rootContainerId;
@NonNull private UUID containerId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ public List<ReferencingElementInfos> getReferencingElementInfos(UUID elementUuid
// for now only STUDY_NODE references
List<UUID> referencedNodeUuids = directoryService.getElementInfos(elementUuid).getReferences().stream()
.filter(reference -> reference.getReferenceType() == ReferenceAttributes.ReferenceType.STUDY_NODE)
.map(ReferenceAttributes::getReferenceId)
// STUDY_NODE: the referenced node is the container's containerId
.map(reference -> reference.getReferenceContainer().getContainerId())
.toList();
if (referencedNodeUuids.isEmpty()) {
return List.of();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.gridsuite.explore.server.dto.ElementAttributes;
import org.gridsuite.explore.server.dto.NodeInfos;
import org.gridsuite.explore.server.dto.ReferenceAttributes;
import org.gridsuite.explore.server.dto.ReferenceContainer;
import org.gridsuite.explore.server.dto.ReferencingElementInfos;
import org.gridsuite.explore.server.services.DirectoryService;
import org.gridsuite.explore.server.services.StudyService;
Expand Down Expand Up @@ -113,11 +114,22 @@ private void stubUsersIdentities() {
""")));
}

private void stubSharedElementReferences(UUID... referencedNodeUuids) throws Exception {
/** A STUDY_NODE reference: containerId is the node, rootContainerId is the study that holds it. */
private static ReferenceAttributes studyNodeReference(UUID nodeUuid, UUID studyUuid) {
return ReferenceAttributes.builder()
// id of the modification reference pointing to the composite, not the composite itself
.referenceId(UUID.randomUUID())
.referenceType(ReferenceAttributes.ReferenceType.STUDY_NODE)
.referenceContainer(ReferenceContainer.builder()
.rootContainerId(studyUuid)
.containerId(nodeUuid)
.build())
.build();
}

private void stubSharedElementReferences(ReferenceAttributes... references) throws Exception {
ElementAttributes sharedElement = new ElementAttributes(SHARED_ELEMENT_UUID, "sharedModification", "MODIFICATION", OWNER_SUB, 0L, null);
sharedElement.setReferences(Arrays.stream(referencedNodeUuids)
.map(nodeUuid -> new ReferenceAttributes(nodeUuid, ReferenceAttributes.ReferenceType.STUDY_NODE))
.toList());
sharedElement.setReferences(List.of(references));
wireMockServer.stubFor(WireMock.get(WireMock.urlPathEqualTo(SHARED_ELEMENT_PATH))
.willReturn(jsonResponse(sharedElement)));
}
Expand Down Expand Up @@ -163,7 +175,7 @@ private List<ReferencingElementInfos> getReferencingElementInfos() throws Except

@Test
void testTwoNodesInDistinctStudies() throws Exception {
stubSharedElementReferences(NODE_1_UUID, NODE_2_UUID);
stubSharedElementReferences(studyNodeReference(NODE_1_UUID, STUDY_1_UUID), studyNodeReference(NODE_2_UUID, STUDY_2_UUID));
stubNodesInfos(
new NodeInfos(NODE_1_UUID, "node1", STUDY_1_UUID),
new NodeInfos(NODE_2_UUID, "node2", STUDY_2_UUID));
Expand Down Expand Up @@ -204,7 +216,7 @@ STUDY_1_UUID, pathStub(STUDY_1_UUID, "study1", "root", "folder"),

@Test
void testTwoNodesInSameStudy() throws Exception {
stubSharedElementReferences(NODE_1_UUID, NODE_2_UUID);
stubSharedElementReferences(studyNodeReference(NODE_1_UUID, STUDY_1_UUID), studyNodeReference(NODE_2_UUID, STUDY_1_UUID));
stubNodesInfos(
new NodeInfos(NODE_1_UUID, "node1", STUDY_1_UUID),
new NodeInfos(NODE_2_UUID, "node2", STUDY_1_UUID));
Expand All @@ -225,7 +237,7 @@ void testTwoNodesInSameStudy() throws Exception {

@Test
void testSameNodeReferencedTwice() throws Exception {
stubSharedElementReferences(NODE_1_UUID, NODE_1_UUID);
stubSharedElementReferences(studyNodeReference(NODE_1_UUID, STUDY_1_UUID), studyNodeReference(NODE_1_UUID, STUDY_1_UUID));
stubNodesInfos(new NodeInfos(NODE_1_UUID, "node1", STUDY_1_UUID));
stubStudies(studyStub(STUDY_1_UUID, "study1"));
stubStudiesPaths(Map.of(STUDY_1_UUID, pathStub(STUDY_1_UUID, "study1", "root")));
Expand All @@ -242,7 +254,7 @@ void testSameNodeReferencedTwice() throws Exception {

@Test
void testStudyNotReadableIsOmitted() throws Exception {
stubSharedElementReferences(NODE_1_UUID, NODE_2_UUID);
stubSharedElementReferences(studyNodeReference(NODE_1_UUID, STUDY_1_UUID), studyNodeReference(NODE_2_UUID, STUDY_2_UUID));
stubNodesInfos(
new NodeInfos(NODE_1_UUID, "node1", STUDY_1_UUID),
new NodeInfos(NODE_2_UUID, "node2", STUDY_2_UUID));
Expand All @@ -269,7 +281,7 @@ void testStudyNotReadableIsOmitted() throws Exception {

@Test
void testUnknownNodesLeaveNothingToDescribe() throws Exception {
stubSharedElementReferences(NODE_1_UUID, NODE_2_UUID);
stubSharedElementReferences(studyNodeReference(NODE_1_UUID, STUDY_1_UUID), studyNodeReference(NODE_2_UUID, STUDY_2_UUID));
// the study-server knows none of the referenced nodes anymore
stubNodesInfos();

Expand Down
Loading