15
15
*/
16
16
package org .ohdsi .webapi .service ;
17
17
18
- import java .io .ByteArrayOutputStream ;
19
- import java .util .*;
20
- import java .util .stream .Collectors ;
21
- import java .util .stream .StreamSupport ;
22
-
23
- import javax .transaction .Transactional ;
24
- import javax .ws .rs .*;
25
- import javax .ws .rs .core .MediaType ;
26
- import javax .ws .rs .core .Response ;
27
-
28
18
import com .fasterxml .jackson .core .JsonProcessingException ;
29
19
import com .fasterxml .jackson .databind .ObjectMapper ;
30
- import javax .cache .CacheManager ;
31
- import javax .cache .configuration .MutableConfiguration ;
32
-
33
20
import org .apache .shiro .authz .UnauthorizedException ;
34
21
import org .ohdsi .circe .vocabulary .ConceptSetExpression ;
35
22
import org .ohdsi .vocabulary .Concept ;
40
27
import org .ohdsi .webapi .conceptset .ConceptSetGenerationInfo ;
41
28
import org .ohdsi .webapi .conceptset .ConceptSetGenerationInfoRepository ;
42
29
import org .ohdsi .webapi .conceptset .ConceptSetItem ;
43
- import org .ohdsi .webapi .conceptset .dto .ConceptSetVersionFullDTO ;
44
30
import org .ohdsi .webapi .conceptset .annotation .ConceptSetAnnotation ;
31
+ import org .ohdsi .webapi .conceptset .dto .ConceptSetVersionFullDTO ;
45
32
import org .ohdsi .webapi .exception .ConceptNotExistException ;
46
33
import org .ohdsi .webapi .security .PermissionService ;
47
34
import org .ohdsi .webapi .service .annotations .SearchDataTransformer ;
35
+ import org .ohdsi .webapi .service .dto .AnnotationDTO ;
48
36
import org .ohdsi .webapi .service .dto .AnnotationDetailsDTO ;
49
37
import org .ohdsi .webapi .service .dto .ConceptSetDTO ;
50
- import org .ohdsi .webapi .service .dto .SaveConceptSetAnnotationsRequest ;
51
- import org .ohdsi .webapi .service .dto .AnnotationDTO ;
52
38
import org .ohdsi .webapi .service .dto .CopyAnnotationsRequest ;
39
+ import org .ohdsi .webapi .service .dto .SaveConceptSetAnnotationsRequest ;
40
+ import org .ohdsi .webapi .service .lock .ConceptSetLockingService ;
41
+ import org .ohdsi .webapi .service .lock .dto .ConceptSetSnapshotActionRequest ;
42
+ import org .ohdsi .webapi .service .lock .dto .ConceptSetSnapshotParameters ;
43
+ import org .ohdsi .webapi .service .lock .dto .GetConceptSetSnapshotItemsRequest ;
44
+ import org .ohdsi .webapi .service .lock .dto .GetConceptSetSnapshotItemsResponse ;
45
+ import org .ohdsi .webapi .service .lock .dto .IsLockedBatchCheckRequest ;
46
+ import org .ohdsi .webapi .service .lock .dto .IsLockedBatchCheckResponse ;
53
47
import org .ohdsi .webapi .shiro .Entities .UserEntity ;
54
48
import org .ohdsi .webapi .shiro .Entities .UserRepository ;
55
49
import org .ohdsi .webapi .shiro .management .Security ;
60
54
import org .ohdsi .webapi .tag .domain .HasTags ;
61
55
import org .ohdsi .webapi .tag .dto .TagNameListRequestDTO ;
62
56
import org .ohdsi .webapi .util .CacheHelper ;
57
+ import org .ohdsi .webapi .util .ExceptionUtils ;
63
58
import org .ohdsi .webapi .util .ExportUtil ;
64
59
import org .ohdsi .webapi .util .NameUtils ;
65
- import org .ohdsi .webapi .util .ExceptionUtils ;
66
60
import org .ohdsi .webapi .versioning .domain .ConceptSetVersion ;
67
61
import org .ohdsi .webapi .versioning .domain .Version ;
68
62
import org .ohdsi .webapi .versioning .domain .VersionBase ;
79
73
import org .springframework .dao .EmptyResultDataAccessException ;
80
74
import org .springframework .stereotype .Component ;
81
75
76
+ import javax .cache .CacheManager ;
77
+ import javax .cache .configuration .MutableConfiguration ;
78
+ import javax .transaction .Transactional ;
79
+ import javax .ws .rs .Consumes ;
80
+ import javax .ws .rs .DELETE ;
81
+ import javax .ws .rs .DefaultValue ;
82
+ import javax .ws .rs .GET ;
83
+ import javax .ws .rs .NotFoundException ;
84
+ import javax .ws .rs .POST ;
85
+ import javax .ws .rs .PUT ;
86
+ import javax .ws .rs .Path ;
87
+ import javax .ws .rs .PathParam ;
88
+ import javax .ws .rs .Produces ;
89
+ import javax .ws .rs .QueryParam ;
90
+ import javax .ws .rs .core .MediaType ;
91
+ import javax .ws .rs .core .Response ;
92
+ import java .io .ByteArrayOutputStream ;
93
+ import java .util .ArrayList ;
94
+ import java .util .Arrays ;
95
+ import java .util .Collection ;
96
+ import java .util .Collections ;
97
+ import java .util .Date ;
98
+ import java .util .HashMap ;
99
+ import java .util .List ;
100
+ import java .util .Locale ;
101
+ import java .util .Map ;
102
+ import java .util .Objects ;
103
+ import java .util .Set ;
104
+ import java .util .stream .Collectors ;
105
+ import java .util .stream .StreamSupport ;
106
+
82
107
/**
83
108
* Provides REST services for working with
84
109
* concept sets.
@@ -145,6 +170,8 @@ public void customize(CacheManager cacheManager) {
145
170
@ Autowired
146
171
private ObjectMapper mapper ;
147
172
173
+ @ Autowired
174
+ private ConceptSetLockingService conceptSetLockingService ;
148
175
149
176
@ Value ("${security.defaultGlobalReadPermissions}" )
150
177
private boolean defaultGlobalReadPermissions ;
@@ -564,6 +591,75 @@ public ConceptSetDTO updateConceptSet(@PathParam("id") final int id, ConceptSetD
564
591
ConceptSet conceptSet = conversionService .convert (conceptSetDTO , ConceptSet .class );
565
592
return conversionService .convert (updateConceptSet (updated , conceptSet ), ConceptSetDTO .class );
566
593
}
594
+ @ Path ("/{id}/list-snapshots" )
595
+ @ GET
596
+ @ Produces (MediaType .APPLICATION_JSON )
597
+ @ Transactional
598
+ public List <ConceptSetSnapshotParameters > listSnapshots (@ PathParam ("id" ) final int id ) throws Exception {
599
+ return conceptSetLockingService .listSnapshotsByConceptSetId (id );
600
+ }
601
+ @ POST
602
+ @ Path ("/{id}/snapshot" )
603
+ @ Consumes (MediaType .APPLICATION_JSON )
604
+ @ Produces (MediaType .APPLICATION_JSON )
605
+ @ Transactional
606
+ public Response invokeSnapshotAction (@ PathParam ("id" ) final int id , ConceptSetSnapshotActionRequest snapshotActionRequest ) {
607
+ try {
608
+ String sourceKey = snapshotActionRequest .getSourceKey ();
609
+
610
+ if (snapshotActionRequest .isTakeSnapshot ()) {
611
+
612
+ ConceptSetExpression conceptSetExpression = getConceptSetExpression (id , sourceKey );
613
+ Collection <Concept > includedConcepts = vocabService .executeIncludedConceptLookup (sourceKey , conceptSetExpression );
614
+ Collection <Concept > includedSourceCodes = vocabService .executeMappedLookup (sourceKey , conceptSetExpression );
615
+
616
+ conceptSetLockingService .invokeSnapshotAction (id , snapshotActionRequest , conceptSetExpression , includedConcepts , includedSourceCodes );
617
+ } else {
618
+ conceptSetLockingService .invokeSnapshotAction (id , snapshotActionRequest , null , null , null );
619
+ }
620
+ return Response .ok ().entity ("Snapshot action successfully invoked." ).build ();
621
+ } catch (Exception e ) {
622
+ log .error ("Invoke snapshot action failed" , e );
623
+ return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
624
+ .entity ("Invoke snapshot action failed: " + e .getMessage ())
625
+ .build ();
626
+ }
627
+ }
628
+
629
+ @ POST
630
+ @ Path ("/check-locked" )
631
+ @ Consumes (MediaType .APPLICATION_JSON )
632
+ @ Produces (MediaType .APPLICATION_JSON )
633
+ public Response checkIsLockedBatch (IsLockedBatchCheckRequest isLockedBatchCheckRequest ) {
634
+ IsLockedBatchCheckResponse response = new IsLockedBatchCheckResponse ();
635
+ try {
636
+ List <Integer > ids = isLockedBatchCheckRequest .getConceptSetIds ();
637
+ Map <Integer , Boolean > lockStatuses = conceptSetLockingService .areLocked (ids );
638
+ response .setLockStatus (lockStatuses );
639
+ return Response .ok (response ).build ();
640
+ } catch (Exception e ) {
641
+ return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
642
+ .entity ("Error checking lock statuses: " + e .getMessage ())
643
+ .build ();
644
+ }
645
+ }
646
+
647
+ @ POST
648
+ @ Path ("/get-snapshot-items" )
649
+ @ Consumes (MediaType .APPLICATION_JSON )
650
+ @ Produces (MediaType .APPLICATION_JSON )
651
+ public Response getSnapshotItems (GetConceptSetSnapshotItemsRequest request ) {
652
+ try {
653
+ List <ConceptSetExpression .ConceptSetItem > conceptSetItems = conceptSetLockingService .getConceptSetSnapshotItemsBySnapshotId (request .getSnapshotId (), request .getSnapshotItemType ());
654
+ GetConceptSetSnapshotItemsResponse response = new GetConceptSetSnapshotItemsResponse ();
655
+ response .setConceptSetItems (conceptSetItems );
656
+ return Response .ok (response ).build ();
657
+ } catch (Exception e ) {
658
+ return Response .status (Response .Status .INTERNAL_SERVER_ERROR )
659
+ .entity ("Error fetching snapshot items: " + e .getMessage ())
660
+ .build ();
661
+ }
662
+ }
567
663
568
664
private ConceptSet updateConceptSet (ConceptSet dst , ConceptSet src ) {
569
665
@@ -1030,4 +1126,4 @@ public Response deleteConceptSetAnnotation(@PathParam("conceptSetId") final int
1030
1126
return Response .ok ().build ();
1031
1127
} else throw new NotFoundException ("Concept set annotation not found" );
1032
1128
}
1033
- }
1129
+ }
0 commit comments