Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -9,11 +9,11 @@
import java.util.UUID;

/**
* One occurrence of a network modification referencing a shared composite modification
* One occurrence of a network modification referencing a shared composite modification.
*
* @param modificationUuid uuid of the modification-reference itself
* @param referenceId uuid of the referenced shared composite
* @param referencedId uuid of the referenced shared composite
* @param containerId uuid of the composite containing the reference, null if the modification-reference is at the root level
*/
public record ReferenceData(UUID modificationUuid, UUID referenceId, UUID containerId) {
public record ModificationReference(UUID modificationUuid, UUID referencedId, UUID containerId) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,35 @@
*/
package org.gridsuite.study.server.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import lombok.NonNull;

import java.util.UUID;

/**
* @author Mathieu Deharbe <mathieu.deharbe at rte-france.com>
* attributes of the references to the shared composites stored in directory server
* @author Maissa Souissi <maissa.souissi at rte-france.com>
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ReferenceAttributes {
public enum ReferenceType {
STUDY_NODE,
NETWORK_MODIFICATION,
DIRECTORY_ELEMENT
STUDY_NODE_NETWORK_MODIFICATION,
DIRECTORY_NETWORK_MODIFICATION,
}

// id of the reference modification
@NonNull
private UUID referenceId;
// Container where the reference is used (see ReferenceType for the meaning of its ids)
@NonNull
private ReferenceContainer referenceContainer;
@NonNull
private ReferenceType referenceType;

public static ReferenceAttributes createReferenceAttributes(UUID referenceId, UUID rootContainerId, UUID containerId, ReferenceType referenceType) {
return new ReferenceAttributes(referenceId, ReferenceContainer.builder().rootContainerId(rootContainerId).containerId(containerId).build(), referenceType);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
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.study.server.dto;

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

import java.util.UUID;

/**
* 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
*
* @author Maissa Souissi <maissa.souissi at rte-france.com>
*/
@Getter
@Setter
@NoArgsConstructor
@SuperBuilder
public class ReferenceContainer {
@NonNull private UUID rootContainerId;
@NonNull private UUID containerId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@
public record ModificationContainerInfos(
@Schema(description = "container UUID; omitted only for GROUP, where node's group is used") UUID id,
@Schema(description = "container type") ModificationContainerType type) {

public boolean isGroup() {
return ModificationContainerType.GROUP.equals(type);
}

public boolean isComposite() {
return ModificationContainerType.COMPOSITE.equals(type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public class DirectoryService {
public static final String PARAM_ACCESS_TYPE = "accessType";
public static final String PARAM_TARGET_DIRECTORY_UUID = "targetDirectoryUuid";
public static final String PARAM_RECURSIVE_CHECK = "recursiveCheck";
public static final String PARAM_ORIGIN_REFERENCE_UUID = "originReferenceUuid";
public static final String PARAM_TARGET_REFERENCE_UUID = "targetReferenceUuid";
public static final String PARAM_TARGET_REFERENCE_TYPE = "targetReferenceType";
private final RestTemplate restTemplate;

@Setter
Expand Down Expand Up @@ -111,30 +108,19 @@ public boolean elementExists(UUID directoryUuid, String elementName, String type
return response.getStatusCode() == HttpStatus.OK;
}

/**
* creates references and add them to shared composite modifications stored in directory server
* @param elementsUuids element uuids of the shared composites in directory server
* @param userId id of the user who creates the references
* @param targetReferenceUuid where the new references will point
*/
public void createsReferencesToSharedComposites(@NonNull List<UUID> elementsUuids, String userId, UUID targetReferenceUuid, ReferenceAttributes.ReferenceType targetReferenceType) {
// TODO : instead of multiple calls, an endpoint in directory server should be created to handle multiple references creation
// OR if not, turn this into simultaneous asynchronous calls
elementsUuids.forEach(elementUuid -> {
var path = UriComponentsBuilder.fromPath(
DELIMITER + DIRECTORY_API_VERSION + DELIMITER + "elements/{elementUuid}/references")
.buildAndExpand(elementUuid)
.toUriString();

HttpHeaders headers = new HttpHeaders();
headers.set(HEADER_USER_ID, userId);
headers.setContentType(MediaType.APPLICATION_JSON);

ReferenceAttributes referenceAttributes = new ReferenceAttributes(targetReferenceUuid, targetReferenceType);

HttpEntity<ReferenceAttributes> requestEntity = new HttpEntity<>(referenceAttributes, headers);
restTemplate.exchange(getDirectoryServerServerBaseUri() + path, HttpMethod.POST, requestEntity, ElementAttributes.class);
});
public void createElementReference(@NonNull UUID elementUuid, @NonNull ReferenceAttributes referenceAttributes, String userId) {
HttpHeaders headers = new HttpHeaders();
headers.set(HEADER_USER_ID, userId);
headers.setContentType(MediaType.APPLICATION_JSON);

HttpEntity<ReferenceAttributes> requestEntity = new HttpEntity<>(referenceAttributes, headers);

var path = UriComponentsBuilder.fromPath(
DELIMITER + DIRECTORY_API_VERSION + DELIMITER + "elements/{elementUuid}/references")
.buildAndExpand(elementUuid)
.toUriString();

restTemplate.exchange(getDirectoryServerServerBaseUri() + path, HttpMethod.POST, requestEntity, ElementAttributes.class);
}

/**
Expand All @@ -143,7 +129,7 @@ public void createsReferencesToSharedComposites(@NonNull List<UUID> elementsUuid
* @param userId id of the user who caused the unreferencing
* @param sharedElementUuid uuid of the referenced shared element in the directory-server
*/
public void removeReference(UUID referenceUuid, String userId, UUID sharedElementUuid) {
public void removeElementReference(UUID referenceUuid, UUID sharedElementUuid, String userId) {
Objects.requireNonNull(referenceUuid);
Objects.requireNonNull(sharedElementUuid);

Expand Down Expand Up @@ -189,34 +175,25 @@ public void checkPermission(List<UUID> elementUuids, UUID targetDirectoryUuid, S
}

/**
* update references of shared composite modifications in directory server
* @param elementsUuids element uuids of the shared composites
* @param userId id of the user who moves the references
* @param originReferenceUuid uuid of the container whose references are updated
* @param targetReferenceUuid where the references will point after the update
* @param targetReferenceType type where the references will point after the update
* update a modification-reference in directory server so it points to a new container after a move.
* the row to update is identified by {@code elementUuid} (the referenced shared element) and
* {@code referenceUuid} (the modification-reference itself); {@code referenceAttributes} carries the new location.
* @param elementUuid uuid of the referenced shared element in the directory-server
* @param referenceAttributes new attributes of the modification-reference
* @param userId id of the user who moves the reference
*/
public void updateReferencesToSharedComposites(@NonNull List<UUID> elementsUuids, String userId, @NonNull UUID originReferenceUuid,
UUID targetReferenceUuid, ReferenceAttributes.ReferenceType targetReferenceType) {
Objects.requireNonNull(originReferenceUuid);

if (elementsUuids.isEmpty()) {
return;
}

String path = UriComponentsBuilder.fromPath(DELIMITER + DIRECTORY_API_VERSION + DELIMITER + "elements/references")
.queryParam(PARAM_IDS, elementsUuids)
.queryParam(PARAM_ORIGIN_REFERENCE_UUID, originReferenceUuid)
.queryParam(PARAM_TARGET_REFERENCE_UUID, targetReferenceUuid)
.queryParam(PARAM_TARGET_REFERENCE_TYPE, targetReferenceType)
.buildAndExpand()
.toUriString();

public void updateElementReference(@NonNull UUID elementUuid, @NonNull ReferenceAttributes referenceAttributes, String userId) {
HttpHeaders headers = new HttpHeaders();
headers.set(HEADER_USER_ID, userId);
headers.setContentType(MediaType.APPLICATION_JSON);

HttpEntity<Void> requestEntity = new HttpEntity<>(headers);
HttpEntity<ReferenceAttributes> requestEntity = new HttpEntity<>(referenceAttributes, headers);

var path = UriComponentsBuilder.fromPath(
DELIMITER + DIRECTORY_API_VERSION + DELIMITER + "elements/{elementUuid}/references/{referenceUuid}")
.buildAndExpand(elementUuid, referenceAttributes.getReferenceId())
.toUriString();

restTemplate.exchange(getDirectoryServerServerBaseUri() + path, HttpMethod.PUT, requestEntity, Void.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.gridsuite.study.server.RemoteServicesProperties;
import org.gridsuite.study.server.StudyConstants;
import org.gridsuite.study.server.dto.BuildInfos;
import org.gridsuite.study.server.dto.ModificationReference;
import org.gridsuite.study.server.dto.NodeReceiver;
import org.gridsuite.study.server.dto.ReferenceData;
import org.gridsuite.study.server.dto.modification.*;
import org.gridsuite.study.server.dto.workflow.AbstractWorkflowInfos;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -289,7 +289,7 @@ public void restoreModifications(UUID groupUUid, List<UUID> modificationsUuids)
/**
* @return references data of the modificationsUuids found among modificationsUuids
*/
public List<ReferenceData> getReferences(List<UUID> modificationsUuids) {
public List<ModificationReference> getModificationReferences(List<UUID> modificationsUuids) {
Objects.requireNonNull(modificationsUuids);
var path = UriComponentsBuilder
.fromUriString(getNetworkModificationServerURI(false) + "references")
Expand All @@ -306,7 +306,7 @@ public List<ReferenceData> getReferences(List<UUID> modificationsUuids) {
path,
HttpMethod.GET,
httpEntity,
new ParameterizedTypeReference<List<ReferenceData>>() { }
new ParameterizedTypeReference<List<ModificationReference>>() { }
).getBody();
}

Expand Down Expand Up @@ -340,20 +340,20 @@ public Map<UUID, UUID> findParentComposites(List<UUID> modificationsUuids) {
* - element uuid in directory server
* - uuid of its mother composite (null if the modification is at the root level)
*/
public List<ReferenceData> getReferencesFromGroup(UUID groupUuid) {
public List<ModificationReference> getModificationReferences(UUID groupUuid) {
Objects.requireNonNull(groupUuid);
var path = UriComponentsBuilder.fromPath(GROUP_PATH + DELIMITER + "references");

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

HttpEntity<List<ReferenceData>> httpEntity = new HttpEntity<>(headers);
HttpEntity<List<ModificationReference>> httpEntity = new HttpEntity<>(headers);

return restTemplate.exchange(
getNetworkModificationServerURI(false) + path.buildAndExpand(groupUuid).toUriString(),
HttpMethod.GET,
httpEntity,
new ParameterizedTypeReference<List<ReferenceData>>() { }
new ParameterizedTypeReference<List<ModificationReference>>() { }
).getBody();
}

Expand Down
Loading
Loading