Skip to content
Open
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 @@ -329,19 +329,18 @@ public ResponseEntity<String> elementNameCandidate(@PathVariable("directoryUuid"
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(service.getDuplicateNameCandidate(directoryUuid, elementName, type, userId));
}

@PutMapping(value = "/elements/references")
@Operation(summary = "For each shared element from a list, updates one of their reference from an origin reference to a target reference")
@PutMapping(value = "/elements/{elementUuid}/references/{referenceUuid}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Update an element reference")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "References were successfully updated"),
@ApiResponse(responseCode = "200", description = "Reference were successfully updated"),
@ApiResponse(responseCode = "404", description = "At least one element was not found"),
@ApiResponse(responseCode = "403", description = "Not authorized to update at least one element")
})
public ResponseEntity<Void> updateSharedElementsReferences(@RequestParam("ids") List<UUID> elementUuids,
@RequestParam("originReferenceUuid") UUID originReferenceUuid,
@RequestParam("targetReferenceUuid") UUID targetReferenceUuid,
@RequestParam("targetReferenceType") ReferenceAttributes.ReferenceType targetReferenceType,
@RequestHeader("userId") String userId) {
service.updateElementsReferences(elementUuids, originReferenceUuid, targetReferenceUuid, targetReferenceType, userId);
public ResponseEntity<Void> updateElementReference(@PathVariable("elementUuid") UUID elementId,
@PathVariable("referenceUuid") UUID referenceId,
@RequestBody ReferenceAttributes referenceAttributes,
@RequestHeader("userId") String userId) {
service.updateElementReference(elementId, referenceId, referenceAttributes, userId);
return ResponseEntity.ok().build();
}

Expand Down
29 changes: 14 additions & 15 deletions src/main/java/org/gridsuite/directory/server/DirectoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.gridsuite.directory.server.error.DirectoryException;
import org.gridsuite.directory.server.repository.DirectoryElementEntity;
import org.gridsuite.directory.server.repository.DirectoryElementRepository;
import org.gridsuite.directory.server.repository.ReferenceContainerEmbeddable;
import org.gridsuite.directory.server.repository.ReferenceEmbeddable;
import org.gridsuite.directory.server.services.*;
import org.springframework.dao.DataIntegrityViolationException;
Expand Down Expand Up @@ -41,6 +42,7 @@
public class DirectoryService {
public static final String DIRECTORY = "DIRECTORY";
public static final String ELEMENT = "ELEMENT";
public static final String REFERENCE = "REFERENCE";
private static final int ES_PAGE_MAX_SIZE = 50;
static final int MAX_RETRY = 3;
static final int DELAY_RETRY = 50;
Expand Down Expand Up @@ -346,32 +348,29 @@ public void createElementReference(UUID elementUuid, ReferenceAttributes referen
private ReferenceEmbeddable createReferenceEntity(ReferenceAttributes referenceAttributes) {
return new ReferenceEmbeddable(
referenceAttributes.getReferenceId(),
createReferencePathEntity(referenceAttributes.getReferenceContainer()),
referenceAttributes.getReferenceType().name()
);
}

private ReferenceContainerEmbeddable createReferencePathEntity(ReferenceContainer referenceId) {
return new ReferenceContainerEmbeddable(referenceId.getRootContainerId(), referenceId.getContainerId());
}

@Transactional
public void updateElementsReferences(@NonNull List<UUID> elementsUuids, @NonNull UUID originReferenceUuid,
@NonNull UUID targetReferenceUuid, @NonNull ReferenceAttributes.ReferenceType targetReferenceType, String userId) {
elementsUuids.forEach(elementUuid -> {
DirectoryElementEntity directoryElementEntity = getDirectoryElementEntity(elementUuid);

directoryElementEntity.getReferences().stream()
.filter(ref -> originReferenceUuid.equals(ref.getReferenceId()))
.findFirst()
.ifPresent(ref -> {
ref.setReferenceId(targetReferenceUuid);
ref.setReferenceType(targetReferenceType.name());
notifyDirectoryHasChanged(directoryElementEntity.getParentId() == null ? elementUuid : directoryElementEntity.getParentId(), userId, directoryElementEntity.getName());
});
});
public void updateElementReference(@NonNull UUID elementId, @NonNull UUID referenceId, @NonNull ReferenceAttributes referenceAttributes, String userId) {
DirectoryElementEntity directoryElementEntity = getDirectoryElementEntity(elementId);
ReferenceEmbeddable reference = directoryElementEntity.getReference(referenceId)
.orElseThrow(() -> DirectoryException.createElementNotFound(REFERENCE, referenceAttributes.getReferenceId()));
reference.setReferenceContainer(createReferencePathEntity(referenceAttributes.getReferenceContainer()));
reference.setReferenceType(referenceAttributes.getReferenceType().name());
notifyDirectoryHasChanged(directoryElementEntity.getParentId() == null ? elementId : directoryElementEntity.getParentId(), userId, directoryElementEntity.getName());
}

@Transactional
public void deleteElementReference(UUID elementUuid, UUID referenceUuid, String userId) {
DirectoryElementEntity directoryElementEntity = getDirectoryElementEntity(elementUuid);
directoryElementEntity.removeReference(referenceUuid);

notifyDirectoryHasChanged(directoryElementEntity.getParentId() == null ? elementUuid : directoryElementEntity.getParentId(), userId, directoryElementEntity.getName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/
package org.gridsuite.directory.server.dto;

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

Expand All @@ -21,14 +21,14 @@
@Setter
@NoArgsConstructor
@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;
@NonNull private UUID referenceId;
@NonNull private ReferenceContainer referenceContainer;
@NonNull private ReferenceType referenceType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
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.directory.server.dto;

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

import java.util.UUID;

/**
* @author Slimane Amar <slimane.amar at rte-france.com>
*/
@Getter
@Setter
@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 @@ -126,10 +126,13 @@ public void addReference(ReferenceEmbeddable reference) {
}

public void removeReference(UUID referenceId) {
this.references.stream()
.filter(reference -> Objects.equals(reference.getReferenceId(), referenceId))
.findFirst()
.ifPresent(this::removeReference);
getReference(referenceId).ifPresent(this::removeReference);
}

public Optional<ReferenceEmbeddable> getReference(UUID referenceId) {
return this.references.stream()
.filter(reference -> reference.getReferenceId().equals(referenceId))
.findFirst();
}

public void removeReference(ReferenceEmbeddable reference) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 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.directory.server.repository;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.*;
import org.gridsuite.directory.server.dto.ReferenceContainer;

import java.util.UUID;

/**
* @author Slimane Amar <slimane.amar at rte-france.com>
*/
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
@Embeddable
public class ReferenceContainerEmbeddable {
@Column(name = "rootContainerId")
private UUID rootContainerId;

@Column(name = "containerId")
@NonNull private UUID containerId;

public ReferenceContainer toReferenceAttributes() {
return ReferenceContainer.builder()
.rootContainerId(rootContainerId)
.containerId(containerId)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import lombok.*;
import org.gridsuite.directory.server.dto.ReferenceAttributes;
import org.gridsuite.directory.server.dto.ReferenceAttributes.ReferenceType;
Expand All @@ -27,12 +28,16 @@ public class ReferenceEmbeddable {
@Column(name = "reference_id")
private UUID referenceId;

@Embedded
private ReferenceContainerEmbeddable referenceContainer;

@Column(name = "reference_type")
private String referenceType;

public ReferenceAttributes toReferenceAttributes() {
return ReferenceAttributes.builder()
.referenceId(referenceId)
.referenceContainer(referenceContainer.toReferenceAttributes())
.referenceType(ReferenceType.valueOf(referenceType))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="amarsli (generated)" id="1788773163987-1">
<addColumn tableName="reference">
<column name="container_id" type="UUID"/>
</addColumn>
<addColumn tableName="reference">
<column name="root_container_id" type="UUID"/>
</addColumn>
</changeSet>
</databaseChangeLog>
4 changes: 4 additions & 0 deletions src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ databaseChangeLog:
- include:
file: changesets/changelog_20260715T123918Z.xml
relativeToChangelogFile: true

- include:
file: changesets/changelog_20260907T092547Z.xml
relativeToChangelogFile: true
Loading
Loading