Skip to content

Commit a75cc0a

Browse files
committed
fix: Refactor process addon - EXO-79327
This change will do some refactoring on the process addon, renaming, intoducing spring...
1 parent b15350b commit a75cc0a

File tree

17 files changed

+1139
-1205
lines changed

17 files changed

+1139
-1205
lines changed

processes-api/src/main/java/org/exoplatform/processes/storage/ProcessStorage.java

Lines changed: 0 additions & 113 deletions
This file was deleted.

processes-api/src/main/java/org/exoplatform/processes/storage/RequestStorage.java

Lines changed: 0 additions & 102 deletions
This file was deleted.

processes-services/src/main/java/org/exoplatform/processes/rest/AttachmentRest.java

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package org.exoplatform.processes.rest;
1818

1919
import java.io.InputStream;
20+
import java.util.ArrayList;
2021
import java.util.Date;
22+
import java.util.List;
2123

2224
import javax.annotation.security.RolesAllowed;
2325
import javax.jcr.ItemExistsException;
@@ -27,12 +29,15 @@
2729
import org.apache.commons.lang3.StringUtils;
2830

2931
import org.exoplatform.commons.exception.ObjectNotFoundException;
32+
import org.exoplatform.commons.utils.CommonsUtils;
3033
import org.exoplatform.processes.model.IllustrativeAttachment;
3134
import org.exoplatform.processes.model.WorkFlow;
3235
import org.exoplatform.processes.rest.util.RestUtils;
3336
import org.exoplatform.processes.service.ProcessAttachmentService;
3437
import org.exoplatform.processes.service.ProcessService;
3538
import org.exoplatform.services.attachments.model.Attachment;
39+
import org.exoplatform.services.attachments.rest.model.AttachmentEntity;
40+
import org.exoplatform.services.attachments.service.AttachmentService;
3641
import org.exoplatform.services.log.ExoLogger;
3742
import org.exoplatform.services.log.Log;
3843
import org.exoplatform.services.rest.resource.ResourceContainer;
@@ -46,8 +51,8 @@
4651
import io.swagger.v3.oas.annotations.tags.Tag;
4752

4853

49-
@Path("/process")
50-
@Tag(name = "/process", description = "Manages processes attachements")
54+
@Path("/process/attachment")
55+
@Tag(name = "/process/attachment", description = "Manages processes attachments")
5156

5257
public class AttachmentRest implements ResourceContainer {
5358

@@ -73,7 +78,6 @@ public AttachmentRest(ProcessService processService,
7378
}
7479

7580
@POST
76-
@Path("/attachment/newDoc")
7781
@RolesAllowed("users")
7882
@Produces(MediaType.APPLICATION_JSON)
7983
@Operation(
@@ -130,7 +134,7 @@ public Response createNewFormDocument(@Parameter(description = "title", required
130134
}
131135

132136
@GET
133-
@Path("/illustration/{workflowId}")
137+
@Path("/{workflowId}")
134138
@RolesAllowed("users")
135139
@Operation(
136140
summary = "Gets a workflow illustration image by its id",
@@ -184,4 +188,41 @@ public Response getImageIllustration(@Context Request request,
184188
return Response.serverError().build();
185189
}
186190
}
191+
@GET
192+
@Path( "/attachement/{entityType}/{entityId}")
193+
@Produces(MediaType.APPLICATION_JSON)
194+
@Operation(summary = "Get list of attachments linked to an entity", method = "GET", description = "Get the list of attachments linked to the given entity")
195+
@ApiResponses(value = {
196+
@ApiResponse(responseCode = "200", description = "Request fulfilled"),
197+
@ApiResponse(responseCode = "400", description = "Invalid query input"),
198+
@ApiResponse(responseCode = "401", description = "Unauthorized operation"),
199+
@ApiResponse(responseCode = "500", description = "Internal server error") })
200+
public Response getAttachmentsByEntity(@Parameter(description = "Entity technical identifier", required = true) @PathParam("entityId") long entityId,
201+
@Parameter(description = "Entity type", required = true) @PathParam("entityType") String entityType) throws Exception {
202+
203+
if (entityId <= 0) {
204+
return Response.status(Response.Status.BAD_REQUEST).entity("Entity identifier must be a positive integer").build();
205+
}
206+
if (StringUtils.isEmpty(entityType)) {
207+
return Response.status(Response.Status.BAD_REQUEST).entity("Entity type must not be empty").build();
208+
}
209+
long userIdentityId = RestUtils.getCurrentUserIdentityId(identityManager);
210+
try {
211+
AttachmentService attachmentService = CommonsUtils.getService(AttachmentService.class);
212+
List<Attachment> attachments = attachmentService.getAttachmentsByEntity(userIdentityId, entityId, entityType);
213+
List<AttachmentEntity> attachmentsEntities = new ArrayList<>();
214+
if (!attachments.isEmpty()) {
215+
attachmentsEntities = attachments.stream()
216+
.map(attachment -> org.exoplatform.services.attachments.utils.EntityBuilder.fromAttachment(identityManager, attachment))
217+
.filter(attachmentEntity -> attachmentEntity.getAcl().isCanView())
218+
.toList();
219+
}
220+
return Response.ok(attachmentsEntities).build();
221+
} catch (IllegalAccessException e) {
222+
return Response.status(Response.Status.UNAUTHORIZED).entity(e.getMessage()).build();
223+
} catch (Exception e) {
224+
LOG.error("Error when trying to get attachments of entity type {} with id {}: ", entityType, entityId, e);
225+
return Response.serverError().entity(e.getMessage()).build();
226+
}
227+
}
187228
}

0 commit comments

Comments
 (0)