Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Remove the unnecessarily added copy attachments method - EXO-74754 - Meeds-io/MIPs#145 #4202

Merged
merged 1 commit into from
Nov 26, 2024
Merged
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 @@ -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());
}

}