From 38cba60894407ab670cc83e2f7857d89245b9234 Mon Sep 17 00:00:00 2001 From: Sofien Haj Chedhli Date: Tue, 26 Nov 2024 14:04:43 +0100 Subject: [PATCH] feat: Remove the unnecessarily added copy attachments method - EXO-74754 - Meeds-io/MIPs#145 (#4202) --- .../social/attachment/AttachmentService.java | 12 -------- .../attachment/AttachmentServiceImpl.java | 30 ------------------- .../attachment/AttachmentServiceTest.java | 23 -------------- 3 files changed, 65 deletions(-) diff --git a/component/api/src/main/java/org/exoplatform/social/attachment/AttachmentService.java b/component/api/src/main/java/org/exoplatform/social/attachment/AttachmentService.java index 4d216a22965..a810580cacd 100644 --- a/component/api/src/main/java/org/exoplatform/social/attachment/AttachmentService.java +++ b/component/api/src/main/java/org/exoplatform/social/attachment/AttachmentService.java @@ -292,18 +292,6 @@ InputStream getAttachmentInputStream(String objectType, */ Map getAttachmentPlugins(); - /** - * Copies attachments from a specified source object type to a specified destination object type. - * - * @param sourceObjectType the type of the source object - * @param sourceObjectId the ID of the source object - * @param destinationObjectType the type of the destination object - * @param destinationObjectId the ID of the destination object - * @param destinationParentObjectId the ID of the destination's parent object - * @param userIdentityId the ID of the user performing the operation - */ - void copyAttachments(String sourceObjectType, String sourceObjectId, String destinationObjectType, String destinationObjectId, String destinationParentObjectId, long userIdentityId); - /** * Moves attachments from a specified source object type to a specified destination object type. * diff --git a/component/core/src/main/java/org/exoplatform/social/core/attachment/AttachmentServiceImpl.java b/component/core/src/main/java/org/exoplatform/social/core/attachment/AttachmentServiceImpl.java index b3c4ddaa6a2..b96fc8a169f 100644 --- a/component/core/src/main/java/org/exoplatform/social/core/attachment/AttachmentServiceImpl.java +++ b/component/core/src/main/java/org/exoplatform/social/core/attachment/AttachmentServiceImpl.java @@ -327,36 +327,6 @@ public boolean hasEditPermission(Identity userIdentity, String objectType, Strin return attachmentPlugin != null && attachmentPlugin.hasEditPermission(userIdentity, objectId); } - @Override - public void copyAttachments(String sourceObjectType, - String sourceObjectId, - String destinationObjectType, - String destinationObjectId, - String destinationParentObjectId, - long userIdentityId) { - ObjectAttachmentList objectAttachmentList = getAttachments(sourceObjectType, sourceObjectId); - List attachments = objectAttachmentList.getAttachments(); - if (CollectionUtils.isNotEmpty(attachments)) { - attachments.forEach(attachment -> { - String altText = attachment.getAltText(); - String format = attachment.getFormat(); - Map properties = new HashMap<>(); - properties.put(ATTACHMENT_ALT_TEXT, altText); - properties.put(ATTACHMENT_FORMAT, format); - try { - createAttachment(attachment.getId(), - destinationObjectType, - destinationObjectId, - destinationParentObjectId, - userIdentityId, - properties); - } catch (Exception e) { - LOG.error("Error when creating attachment", e); - } - }); - } - } - @Override public void moveAttachments(String sourceObjectType, String sourceObjectId, diff --git a/component/core/src/test/java/org/exoplatform/social/attachment/AttachmentServiceTest.java b/component/core/src/test/java/org/exoplatform/social/attachment/AttachmentServiceTest.java index 00972b5d62f..58d63dd388e 100644 --- a/component/core/src/test/java/org/exoplatform/social/attachment/AttachmentServiceTest.java +++ b/component/core/src/test/java/org/exoplatform/social/attachment/AttachmentServiceTest.java @@ -414,27 +414,4 @@ public void testMoveAttachments() throws Exception { // NOSONAR assertEquals(0, sourceObjectAttachmentList.getAttachments().size()); } - public void testCopyAttachments() throws Exception { // NOSONAR - startSessionAndRegisterAs(USERNAME); - String identityId = identityManager.getOrCreateUserIdentity(USERNAME).getId(); - String fileId = createAttachment(USERNAME); - - String destinationObjectId = "destinationObjectId" + System.currentTimeMillis(); - String destinationParentObjectId = null; - - attachmentService.copyAttachments(OBJECT_TYPE, objectId, DEST_OBJECT_TYPE, destinationObjectId, destinationParentObjectId, Long.parseLong(identityId)); - - // Verify the attachments are copied to the destination object - ObjectAttachmentList destinationObjectAttachmentList = attachmentService.getAttachments(DEST_OBJECT_TYPE, destinationObjectId); - assertNotNull(destinationObjectAttachmentList); - assertEquals(1, destinationObjectAttachmentList.getAttachments().size()); - assertEquals(fileId, destinationObjectAttachmentList.getAttachments().get(0).getId()); - - // Verify the attachments are still present in the source object - ObjectAttachmentList sourceObjectAttachmentList = attachmentService.getAttachments(OBJECT_TYPE, objectId); - assertNotNull(sourceObjectAttachmentList); - assertEquals(1, sourceObjectAttachmentList.getAttachments().size()); - assertEquals(fileId, destinationObjectAttachmentList.getAttachments().get(0).getId()); - } - }