|
17 | 17 |
|
18 | 18 | import java.io.ByteArrayOutputStream; |
19 | 19 | import java.util.*; |
| 20 | +import java.util.function.Supplier; |
20 | 21 | import java.util.stream.Collectors; |
21 | 22 | import java.util.stream.StreamSupport; |
22 | 23 |
|
|
47 | 48 | import org.ohdsi.webapi.service.annotations.SearchDataTransformer; |
48 | 49 | import org.ohdsi.webapi.service.dto.AnnotationDetailsDTO; |
49 | 50 | import org.ohdsi.webapi.service.dto.ConceptSetDTO; |
| 51 | +import org.ohdsi.webapi.service.dto.LockedConceptSetsResponse; |
50 | 52 | import org.ohdsi.webapi.service.dto.SaveConceptSetAnnotationsRequest; |
51 | 53 | import org.ohdsi.webapi.service.dto.AnnotationDTO; |
52 | 54 | import org.ohdsi.webapi.service.dto.CopyAnnotationsRequest; |
| 55 | +import org.ohdsi.webapi.service.lock.ConceptSetLockingService; |
| 56 | +import org.ohdsi.webapi.service.lock.dto.ConceptSetSnapshotActionRequest; |
| 57 | +import org.ohdsi.webapi.service.lock.dto.ConceptSetSnapshotParameters; |
| 58 | +import org.ohdsi.webapi.service.lock.dto.GetConceptSetSnapshotItemsRequest; |
| 59 | +import org.ohdsi.webapi.service.lock.dto.GetConceptSetSnapshotItemsResponse; |
| 60 | +import org.ohdsi.webapi.service.lock.dto.IsLockedBatchCheckRequest; |
| 61 | +import org.ohdsi.webapi.service.lock.dto.IsLockedBatchCheckResponse; |
53 | 62 | import org.ohdsi.webapi.shiro.Entities.UserEntity; |
54 | 63 | import org.ohdsi.webapi.shiro.Entities.UserRepository; |
55 | 64 | import org.ohdsi.webapi.shiro.management.Security; |
@@ -145,6 +154,8 @@ public void customize(CacheManager cacheManager) { |
145 | 154 | @Autowired |
146 | 155 | private ObjectMapper mapper; |
147 | 156 |
|
| 157 | + @Autowired |
| 158 | + private ConceptSetLockingService conceptSetLockingService; |
148 | 159 |
|
149 | 160 | @Value("${security.defaultGlobalReadPermissions}") |
150 | 161 | private boolean defaultGlobalReadPermissions; |
@@ -191,6 +202,19 @@ public Collection<ConceptSetDTO> getConceptSets() { |
191 | 202 |
|
192 | 203 | } |
193 | 204 |
|
| 205 | + /** |
| 206 | + * Get the list of concept sets that were locked using the snapshot lock feature |
| 207 | + * |
| 208 | + * @summary Get all locked concept sets |
| 209 | + * @return A list of locked concept sets |
| 210 | + */ |
| 211 | + @GET |
| 212 | + @Path("/locked") |
| 213 | + @Produces(MediaType.APPLICATION_JSON) |
| 214 | + public Collection<LockedConceptSetsResponse> getLockedConceptSets() { |
| 215 | + return conceptSetLockingService.getLockedConceptSets(defaultGlobalReadPermissions); |
| 216 | + } |
| 217 | + |
194 | 218 | /** |
195 | 219 | * Get the concept set items for a selected concept set ID. |
196 | 220 | * |
@@ -564,6 +588,71 @@ public ConceptSetDTO updateConceptSet(@PathParam("id") final int id, ConceptSetD |
564 | 588 | ConceptSet conceptSet = conversionService.convert(conceptSetDTO, ConceptSet.class); |
565 | 589 | return conversionService.convert(updateConceptSet(updated, conceptSet), ConceptSetDTO.class); |
566 | 590 | } |
| 591 | + @Path("/{id}/snapshots") |
| 592 | + @GET |
| 593 | + @Produces(MediaType.APPLICATION_JSON) |
| 594 | + public List<ConceptSetSnapshotParameters> listSnapshots(@PathParam("id") final int id) throws Exception { |
| 595 | + return conceptSetLockingService.listSnapshotsByConceptSetId(id); |
| 596 | + } |
| 597 | + |
| 598 | + @Path("/{id}/snapshot") |
| 599 | + @GET |
| 600 | + @Produces(MediaType.APPLICATION_JSON) |
| 601 | + public ConceptSetSnapshotParameters getLastSnapshot(@PathParam("id") final int id) throws Exception { |
| 602 | + return conceptSetLockingService.getLastSnapshotByConceptSetId(id); |
| 603 | + } |
| 604 | + |
| 605 | + @POST |
| 606 | + @Path("/{id}/snapshot") |
| 607 | + @Consumes(MediaType.APPLICATION_JSON) |
| 608 | + @Produces(MediaType.APPLICATION_JSON) |
| 609 | + public Response invokeSnapshotAction(@PathParam("id") final int id, ConceptSetSnapshotActionRequest snapshotActionRequest) { |
| 610 | + try { |
| 611 | + Supplier<ConceptSetExpression> conceptSetExpressionSupplier = () -> getConceptSetExpression(id, snapshotActionRequest.getSourceKey()); |
| 612 | + conceptSetLockingService.invokeSnapshotAction(id, snapshotActionRequest, conceptSetExpressionSupplier); |
| 613 | + return Response.ok().entity("Snapshot action successfully invoked.").build(); |
| 614 | + } catch (Exception e) { |
| 615 | + log.error("Invoke snapshot action failed", e); |
| 616 | + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) |
| 617 | + .entity("Invoke snapshot action failed: " + e.getMessage()) |
| 618 | + .build(); |
| 619 | + } |
| 620 | + } |
| 621 | + |
| 622 | + @POST |
| 623 | + @Path("/locked") |
| 624 | + @Consumes(MediaType.APPLICATION_JSON) |
| 625 | + @Produces(MediaType.APPLICATION_JSON) |
| 626 | + public Response checkIsLockedBatch(IsLockedBatchCheckRequest isLockedBatchCheckRequest) { |
| 627 | + IsLockedBatchCheckResponse response = new IsLockedBatchCheckResponse(); |
| 628 | + try { |
| 629 | + List<Integer> ids = isLockedBatchCheckRequest.getConceptSetIds(); |
| 630 | + Map<Integer, Boolean> lockStatuses = conceptSetLockingService.areLocked(ids); |
| 631 | + response.setLockStatus(lockStatuses); |
| 632 | + return Response.ok(response).build(); |
| 633 | + } catch (Exception e) { |
| 634 | + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) |
| 635 | + .entity("Error checking lock statuses: " + e.getMessage()) |
| 636 | + .build(); |
| 637 | + } |
| 638 | + } |
| 639 | + |
| 640 | + @POST |
| 641 | + @Path("/snapshot-items") |
| 642 | + @Consumes(MediaType.APPLICATION_JSON) |
| 643 | + @Produces(MediaType.APPLICATION_JSON) |
| 644 | + public Response getSnapshotItems(GetConceptSetSnapshotItemsRequest request) { |
| 645 | + try { |
| 646 | + List<ConceptSetExpression.ConceptSetItem> conceptSetItems = conceptSetLockingService.getConceptSetSnapshotItemsBySnapshotId(request.getSnapshotId(), request.getSnapshotItemType()); |
| 647 | + GetConceptSetSnapshotItemsResponse response = new GetConceptSetSnapshotItemsResponse(); |
| 648 | + response.setConceptSetItems(conceptSetItems); |
| 649 | + return Response.ok(response).build(); |
| 650 | + } catch (Exception e) { |
| 651 | + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) |
| 652 | + .entity("Error fetching snapshot items: " + e.getMessage()) |
| 653 | + .build(); |
| 654 | + } |
| 655 | + } |
567 | 656 |
|
568 | 657 | private ConceptSet updateConceptSet(ConceptSet dst, ConceptSet src) { |
569 | 658 |
|
|
0 commit comments