Skip to content

Commit

Permalink
feat: Remove the unnecessarily added copy attachments method - EXO-74754
Browse files Browse the repository at this point in the history
  • Loading branch information
sofyenne authored Nov 26, 2024
1 parent d310f51 commit 6fca958
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,6 @@ InputStream getAttachmentInputStream(String objectType,
*/
Map<String, AttachmentPlugin> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ObjectAttachmentDetail> attachments = objectAttachmentList.getAttachments();
if (CollectionUtils.isNotEmpty(attachments)) {
attachments.forEach(attachment -> {
String altText = attachment.getAltText();
String format = attachment.getFormat();
Map<String, String> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}

0 comments on commit 6fca958

Please sign in to comment.