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 @@ -82,10 +82,10 @@ public ResponseEntity<ElementAttributes> duplicateElement(
@PathVariable("elementUuid") UUID elementUuid,
@Parameter(description = "ID of the new element") @RequestParam("newElementUuid") UUID newElementUuid,
@Parameter(description = "Optional UUID of the target directory where the new element will be placed. Defaults to the same directory as "
+ "the original element if not specified.")
@RequestParam(name = "targetDirectoryId", required = false) UUID targetDirectoryId,
+ "the original element if not specified.") @RequestParam(name = "targetDirectoryId", required = false) UUID targetDirectoryId,
@Parameter(description = "status of the new element") @RequestParam(value = "newElementStatus") DirectoryElementStatus newElementStatus,
@RequestHeader("userId") String userId) {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(service.duplicateElement(elementUuid, newElementUuid, targetDirectoryId, userId));
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(service.duplicateElement(elementUuid, newElementUuid, targetDirectoryId, newElementStatus, userId));
}

@PostMapping(value = "/directories/paths/elements", consumes = MediaType.APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.stream.Stream;

import static java.lang.Boolean.TRUE;
import static org.gridsuite.directory.server.dto.DirectoryElementStatus.CREATED;
import static org.gridsuite.directory.server.dto.ElementAttributes.toElementAttributes;
import static org.gridsuite.directory.server.dto.ElementAttributes.toElementAttributesWithReferences;
import static org.gridsuite.directory.server.error.DirectoryBusinessErrorCode.*;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void studyCreatedNotification(UUID studyUuid, String errorMessage, String
if (errorMessage != null && elementEntity.getName() != null) {
deleteElementWithNotif(studyUuid, userId);
} else {
elementEntity.setStatus(DirectoryElementStatus.CREATED);
elementEntity.setStatus(CREATED);
}
// At study creation, if the corresponding element doesn't exist here yet and doesn't have parent
// then avoid sending a notification with parentUuid=null and isRoot=true
Expand Down Expand Up @@ -110,7 +111,7 @@ private ElementAttributes createElementWithNotif(ElementAttributes elementAttrib
return toElementAttributesWithReferences(elementEntity);
}

public ElementAttributes duplicateElement(UUID elementId, UUID newElementId, UUID targetDirectoryId, String userId) {
public ElementAttributes duplicateElement(UUID elementId, UUID newElementId, UUID targetDirectoryId, DirectoryElementStatus elementStatus, String userId) {
DirectoryElementEntity directoryElementEntity = directoryElementRepository.findById(elementId)
.orElseThrow(() -> DirectoryException.createElementNotFound(ELEMENT, elementId));
String elementType = directoryElementEntity.getType();
Expand All @@ -121,6 +122,7 @@ public ElementAttributes duplicateElement(UUID elementId, UUID newElementId, UUI
.owner(userId)
.description(directoryElementEntity.getDescription())
.elementName(directoryElementEntity.getName())
.status(elementStatus)
.build();

assertDirectoryExist(parentDirectoryUuid);
Expand Down Expand Up @@ -162,7 +164,7 @@ private DirectoryElementEntity insertElement(ElementAttributes elementAttributes
now,
elementAttributes.getOwner(),
elementAttributes.getReferences().stream().map(this::createReferenceEntity).toList(),
elementAttributes.getStatus() != null ? elementAttributes.getStatus() : DirectoryElementStatus.CREATED);
elementAttributes.getStatus() != null ? elementAttributes.getStatus() : CREATED);

return tryInsertElement(elementEntity, parentDirectoryUuid, userId, generateNewName);
}
Expand Down Expand Up @@ -240,7 +242,7 @@ public void createElementInDirectoryPath(String directoryPath, ElementAttributes
} else {
//and then we create the rest of the path
parentDirectoryUuid = createElementWithNotif(
toElementAttributes(UUID.randomUUID(), s, DIRECTORY, userId, 0L, null, now, now, userId, DirectoryElementStatus.CREATED),
toElementAttributes(UUID.randomUUID(), s, DIRECTORY, userId, 0L, null, now, now, userId, CREATED),
parentDirectoryUuid,
userId, false).getElementUuid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.UUID;
import static org.gridsuite.directory.server.DirectoryService.DIRECTORY;
import static org.gridsuite.directory.server.DirectoryService.MAX_RETRY;
import static org.gridsuite.directory.server.dto.DirectoryElementStatus.CREATED;
import static org.gridsuite.directory.server.error.DirectoryBusinessErrorCode.*;
import static org.gridsuite.directory.server.utils.DirectoryTestUtils.*;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -143,7 +144,7 @@ void testDirectoryElementUniqueness() {
assertNotEquals(elementAttributes.getElementName(), newElementAttributes.getElementName());

// Duplicate an element in the same directory with new name generation does not throw an exception
newElementAttributes = directoryService.duplicateElement(elementUuid, UUID.randomUUID(), rootUuid, "User1");
newElementAttributes = directoryService.duplicateElement(elementUuid, UUID.randomUUID(), rootUuid, CREATED, "User1");
assertNotEquals(elementAttributes.getElementName(), newElementAttributes.getElementName());

// Insert a new element in a new root directory
Expand All @@ -153,7 +154,7 @@ void testDirectoryElementUniqueness() {
// Duplicate an element in the new root directory with new name generation throw an exception if all retries fail
InOrder inOrder = inOrder(directoryService);
when(directoryService.getDuplicateNameCandidate(root2Uuid, elementAttributes.getElementName(), elementAttributes.getType(), "User1")).thenReturn(elementAttributes.getElementName());
directoryException = assertThrows(DirectoryException.class, () -> directoryService.duplicateElement(element2Uuid, root2Uuid, root2Uuid, "User1"));
directoryException = assertThrows(DirectoryException.class, () -> directoryService.duplicateElement(element2Uuid, root2Uuid, root2Uuid, CREATED, "User1"));
assertEquals(DIRECTORY_ELEMENT_NAME_CONFLICT, directoryException.getBusinessErrorCode());
assertEquals(DirectoryException.createElementNameAlreadyExists(elementAttributes.getElementName()).getMessage(), directoryException.getMessage());
inOrder.verify(directoryService, calls(MAX_RETRY)).getDuplicateNameCandidate(root2Uuid, elementAttributes.getElementName(), elementAttributes.getType(), "User1");
Expand Down Expand Up @@ -285,7 +286,7 @@ void testDuplicateElementNotification() {
"user1", null, false, NotificationType.UPDATE_DIRECTORY);

// duplicate "element1" renamed "element1(1)"
directoryService.duplicateElement(newElementAttributes.getElementUuid(), UUID.randomUUID(), rootUuid, "user1");
directoryService.duplicateElement(newElementAttributes.getElementUuid(), UUID.randomUUID(), rootUuid, CREATED, "user1");
verify(notificationService, times(1)).emitDirectoryChanged(List.of(new DirectoryInfos(rootUuid, true)), List.of(elementAttributes.getElementName() + "(1)"),
"user1", null, false, NotificationType.UPDATE_DIRECTORY);

Expand Down
11 changes: 6 additions & 5 deletions src/test/java/org/gridsuite/directory/server/DirectoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import static com.vladmihalcea.sql.SQLStatementCountValidator.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.gridsuite.directory.server.NotificationService.*;
import static org.gridsuite.directory.server.dto.DirectoryElementStatus.CREATED;
import static org.gridsuite.directory.server.dto.ElementAttributes.toElementAttributes;
import static org.gridsuite.directory.server.services.ConsumerService.HEADER_STUDY_UUID;
import static org.gridsuite.directory.server.services.ConsumerService.UPDATE_TYPE_STUDY_CREATION_FINISHED;
Expand Down Expand Up @@ -1371,7 +1372,7 @@ void testStudyUpdateNotification() throws Exception {
assertEquals(List.of(studyName), headers.get(HEADER_ELEMENT_NAMES));

DirectoryElementEntity directoryElement = directoryElementRepository.findById(studyUuid).get();
assertEquals(DirectoryElementStatus.CREATED, directoryElement.getStatus());
assertEquals(CREATED, directoryElement.getStatus());
}

@Test
Expand Down Expand Up @@ -1918,7 +1919,7 @@ void duplicateElementTest() throws Exception {
UUID elementUUID = elementAttributes.getElementUuid();
UUID newElementUuid = UUID.randomUUID();
// duplicate the element
ElementAttributes duplicatedElement = directoryService.duplicateElement(elementUUID, newElementUuid, null, "user1");
ElementAttributes duplicatedElement = directoryService.duplicateElement(elementUUID, newElementUuid, null, CREATED, "user1");
assertEquals("elementName(1)", duplicatedElement.getElementName());
assertEquals(newElementUuid, duplicatedElement.getElementUuid());

Expand Down Expand Up @@ -2336,7 +2337,7 @@ void testGetElementsNotModifiedSince() throws Exception {
UUID.randomUUID(), uuidNewRootDirectory, "oldElement", TYPE_01, USER_ID, "descr old",
Instant.now().minus(400, ChronoUnit.DAYS),
Instant.now().minus(400, ChronoUnit.DAYS),
USER_ID, List.of(), DirectoryElementStatus.CREATED
USER_ID, List.of(), CREATED
);
directoryElementRepository.save(oldElement);

Expand Down Expand Up @@ -2419,14 +2420,14 @@ public void testUpdateElementsStatus() throws Exception {
UUID siblingElementUuid = siblingElementAttributes.getElementUuid();

// All elements are created CREATED
assertElementsStatusInRepository(DirectoryElementStatus.CREATED, rootDirUuid, subDirUuid, nestedElementUuid, siblingElementUuid);
assertElementsStatusInRepository(CREATED, rootDirUuid, subDirUuid, nestedElementUuid, siblingElementUuid);

// Mark subDir (a directory) and siblingElement (a plain element) as DELETING
updateElementsStatus(List.of(subDirUuid, siblingElementUuid), DirectoryElementStatus.DELETING, USER_ID);

// The directory, its descendant and the sibling element are DELETING; the root is untouched
assertElementsStatusInRepository(DirectoryElementStatus.DELETING, subDirUuid, nestedElementUuid, siblingElementUuid);
assertElementsStatusInRepository(DirectoryElementStatus.CREATED, rootDirUuid);
assertElementsStatusInRepository(CREATED, rootDirUuid);

// One notification per requested element: subDir itself (directory), rootDir (parent of siblingElement)
assertDirectoriesNotified(Set.of(subDirUuid, rootDirUuid), 2, USER_ID);
Expand Down
Loading