Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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,33 +6,32 @@
*/
package org.gridsuite.study.server.dto;

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

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,
}

private UUID referenceId;
private ReferenceType referenceType;
// id of the referenced shared composite modification
@NonNull private UUID referenceId;
// where the reference is used (see ReferenceType for the meaning of its ids)
@NonNull private ReferenceContainer referenceContainer;
@NonNull private ReferenceType 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 @@ -12,6 +12,7 @@
import org.gridsuite.study.server.RemoteServicesProperties;
import org.gridsuite.study.server.dto.ElementAttributes;
import org.gridsuite.study.server.dto.ReferenceAttributes;
import org.gridsuite.study.server.dto.ReferenceContainer;
import org.gridsuite.study.server.dto.networkexport.PermissionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
Expand All @@ -36,8 +37,10 @@ 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_ORIGIN_ROOT_CONTAINER_ID = "originRootContainerId";
public static final String PARAM_ORIGIN_CONTAINER_ID = "originContainerId";
public static final String PARAM_TARGET_ROOT_CONTAINER_ID = "targetRootContainerId";
public static final String PARAM_TARGET_CONTAINER_ID = "targetContainerId";
public static final String PARAM_TARGET_REFERENCE_TYPE = "targetReferenceType";
private final RestTemplate restTemplate;

Expand Down Expand Up @@ -113,28 +116,23 @@ public boolean elementExists(UUID directoryUuid, String elementName, String type

/**
* 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) {
public void createElementReference(@NonNull UUID elementUuid, @NonNull ReferenceAttributes referenceAttributes, String userId) {
// 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);
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);

HttpEntity<ReferenceAttributes> requestEntity = new HttpEntity<>(referenceAttributes, headers);
restTemplate.exchange(getDirectoryServerServerBaseUri() + path, HttpMethod.POST, requestEntity, ElementAttributes.class);
});
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 +141,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 @@ -192,22 +190,28 @@ 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 originRootContainerId root container of the reference location whose references are updated (see {@link ReferenceAttributes.ReferenceType})
* @param originContainerId container of the reference location whose references are updated (see {@link ReferenceAttributes.ReferenceType})
* @param targetRootContainerId root container of where the references will point after the update (see {@link ReferenceAttributes.ReferenceType})
* @param targetContainerId container of where the references will point after the update (see {@link ReferenceAttributes.ReferenceType})
* @param targetReferenceType type where the references will point after the update
*/
public void updateReferencesToSharedComposites(@NonNull List<UUID> elementsUuids, String userId, @NonNull UUID originReferenceUuid,
UUID targetReferenceUuid, ReferenceAttributes.ReferenceType targetReferenceType) {
Objects.requireNonNull(originReferenceUuid);
public void updateElementsReferences(@NonNull List<UUID> elementsUuids, String userId,
@NonNull UUID originRootContainerId, @NonNull UUID originContainerId,
UUID targetRootContainerId, UUID targetContainerId, ReferenceAttributes.ReferenceType targetReferenceType) {
Objects.requireNonNull(originRootContainerId);
Objects.requireNonNull(originContainerId);

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_ORIGIN_ROOT_CONTAINER_ID, originRootContainerId)
.queryParam(PARAM_ORIGIN_CONTAINER_ID, originContainerId)
.queryParam(PARAM_TARGET_ROOT_CONTAINER_ID, targetRootContainerId)
.queryParam(PARAM_TARGET_CONTAINER_ID, targetContainerId)
.queryParam(PARAM_TARGET_REFERENCE_TYPE, targetReferenceType)
.buildAndExpand()
.toUriString();
Expand Down
Original file line number Diff line number Diff line change
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<ReferenceData> getModificationReferences(List<UUID> modificationsUuids) {
Objects.requireNonNull(modificationsUuids);
var path = UriComponentsBuilder
.fromUriString(getNetworkModificationServerURI(false) + "references")
Expand Down
Loading
Loading