From 22cd5f9b1b95efe00c08cda6e9200b55208a52a3 Mon Sep 17 00:00:00 2001 From: sofyenne Date: Mon, 9 Dec 2024 17:34:19 +0100 Subject: [PATCH] feat: Enhance createAttachment method accessibility - EXO-75694 - Meeds-io/MIPs#145 --- .../social/attachment/AttachmentService.java | 23 +++++++++ .../attachment/AttachmentServiceImpl.java | 48 ++++++++++--------- 2 files changed, 48 insertions(+), 23 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 a810580cacd..a691571325f 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 @@ -303,4 +303,27 @@ InputStream getAttachmentInputStream(String objectType, * @param userIdentityId the ID of the user performing the operation */ void moveAttachments(String sourceObjectType, String sourceObjectId, String destinationObjectType, String destinationObjectId, String destinationParentObjectId, long userIdentityId); + + /** + * Creates an attachment for a specified object. + * + * @param fileId the identifier of the file to be attached + * @param objectType the type of the object + * @param objectId the identifier of the object to which the attachment is being + * added. + * @param parentObjectId the parent object identifier + * @param userIdentityId user + * {@link org.exoplatform.social.core.identity.model.Identity} id + * @param properties the attachment properties + * @throws ObjectNotFoundException when the object identified by its id doesn't + * exist + * @throws ObjectAlreadyExistsException when attachment already exists for given + * object + */ + void createAttachment(String fileId, + String objectType, + String objectId, + String parentObjectId, + long userIdentityId, + Map properties) throws ObjectNotFoundException, ObjectAlreadyExistsException; } 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 b96fc8a169f..43e0e9a39b6 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 @@ -373,6 +373,31 @@ public void moveAttachments(String sourceObjectType, } } + @Override + public void createAttachment(String fileId, + String objectType, + String objectId, + String parentObjectId, + long userIdentityId, + Map properties) throws ObjectNotFoundException, ObjectAlreadyExistsException { + MetadataKey metadataKey = null; + metadataKey = new MetadataKey(METADATA_TYPE.getName(), fileId, getAudienceId(objectType, objectId)); + MetadataObject object = new MetadataObject(objectType, + objectId, + parentObjectId, + getSpaceId(objectType, objectId)); + metadataService.createMetadataItem(object, + metadataKey, + properties, + userIdentityId); + broadcastAttachmentChange(ATTACHMENT_CREATED_EVENT, + fileId, + objectType, + objectId, + getUserName(userIdentityId)); + } + + private org.exoplatform.social.core.identity.model.Identity checkAccessPermission(String objectType, String objectId, String fileId, @@ -503,29 +528,6 @@ private void saveAttachment(UploadedAttachmentDetail uploadedAttachmentDetail, } } - private void createAttachment(String fileId, - String objectType, - String objectId, - String parentObjectId, - long userIdentityId, - Map properties) throws ObjectNotFoundException, ObjectAlreadyExistsException { - MetadataKey metadataKey = null; - metadataKey = new MetadataKey(METADATA_TYPE.getName(), fileId, getAudienceId(objectType, objectId)); - MetadataObject object = new MetadataObject(objectType, - objectId, - parentObjectId, - getSpaceId(objectType, objectId)); - metadataService.createMetadataItem(object, - metadataKey, - properties, - userIdentityId); - broadcastAttachmentChange(ATTACHMENT_CREATED_EVENT, - fileId, - objectType, - objectId, - getUserName(userIdentityId)); - } - private void updateAttachment(String fileId, String objectType, String objectId,