Skip to content
Open
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 @@ -15,6 +15,7 @@ public class ConceptSetPermissionSchema extends EntityPermissionSchema {
put("conceptset:%s:annotation:*:delete", "Delete Annotations of Concept Set with ID = %s");
put("conceptset:*:annotation:*:delete", "Delete Annotations of any Concept Set");
put("conceptset:%s:delete", "Delete Concept Set with ID = %s");
put("conceptset:%s:snapshot:post", "Invoke Snapshot Action for Concept Set with ID = %s");
}};

private static Map<String, String> readPermissions = new HashMap<String, String>() {{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,9 @@ protected <T extends CommonEntityDTO> List<T> listByTags(List<? extends CommonEn
})
.collect(Collectors.toList());
}

public TagService getTagService() {
return tagService;
}

}
89 changes: 89 additions & 0 deletions src/main/java/org/ohdsi/webapi/service/ConceptSetService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.ByteArrayOutputStream;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

Expand Down Expand Up @@ -47,9 +48,17 @@
import org.ohdsi.webapi.service.annotations.SearchDataTransformer;
import org.ohdsi.webapi.service.dto.AnnotationDetailsDTO;
import org.ohdsi.webapi.service.dto.ConceptSetDTO;
import org.ohdsi.webapi.service.dto.LockedConceptSetsResponse;
import org.ohdsi.webapi.service.dto.SaveConceptSetAnnotationsRequest;
import org.ohdsi.webapi.service.dto.AnnotationDTO;
import org.ohdsi.webapi.service.dto.CopyAnnotationsRequest;
import org.ohdsi.webapi.service.lock.ConceptSetLockingService;
import org.ohdsi.webapi.service.lock.dto.ConceptSetSnapshotActionRequest;
import org.ohdsi.webapi.service.lock.dto.ConceptSetSnapshotParameters;
import org.ohdsi.webapi.service.lock.dto.GetConceptSetSnapshotItemsRequest;
import org.ohdsi.webapi.service.lock.dto.GetConceptSetSnapshotItemsResponse;
import org.ohdsi.webapi.service.lock.dto.IsLockedBatchCheckRequest;
import org.ohdsi.webapi.service.lock.dto.IsLockedBatchCheckResponse;
import org.ohdsi.webapi.shiro.Entities.UserEntity;
import org.ohdsi.webapi.shiro.Entities.UserRepository;
import org.ohdsi.webapi.shiro.management.Security;
Expand Down Expand Up @@ -145,6 +154,8 @@ public void customize(CacheManager cacheManager) {
@Autowired
private ObjectMapper mapper;

@Autowired
private ConceptSetLockingService conceptSetLockingService;

@Value("${security.defaultGlobalReadPermissions}")
private boolean defaultGlobalReadPermissions;
Expand Down Expand Up @@ -191,6 +202,19 @@ public Collection<ConceptSetDTO> getConceptSets() {

}

/**
* Get the list of concept sets that were locked using the snapshot lock feature
*
* @summary Get all locked concept sets
* @return A list of locked concept sets
*/
@GET
@Path("/locked")
@Produces(MediaType.APPLICATION_JSON)
public Collection<LockedConceptSetsResponse> getLockedConceptSets() {
return conceptSetLockingService.getLockedConceptSets(defaultGlobalReadPermissions);
}

/**
* Get the concept set items for a selected concept set ID.
*
Expand Down Expand Up @@ -564,6 +588,71 @@ public ConceptSetDTO updateConceptSet(@PathParam("id") final int id, ConceptSetD
ConceptSet conceptSet = conversionService.convert(conceptSetDTO, ConceptSet.class);
return conversionService.convert(updateConceptSet(updated, conceptSet), ConceptSetDTO.class);
}
@Path("/{id}/snapshots")
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<ConceptSetSnapshotParameters> listSnapshots(@PathParam("id") final int id) throws Exception {
return conceptSetLockingService.listSnapshotsByConceptSetId(id);
}

@Path("/{id}/snapshot")
@GET
@Produces(MediaType.APPLICATION_JSON)
public ConceptSetSnapshotParameters getLastSnapshot(@PathParam("id") final int id) throws Exception {
return conceptSetLockingService.getLastSnapshotByConceptSetId(id);
}

@POST
@Path("/{id}/snapshot")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response invokeSnapshotAction(@PathParam("id") final int id, ConceptSetSnapshotActionRequest snapshotActionRequest) {
try {
Supplier<ConceptSetExpression> conceptSetExpressionSupplier = () -> getConceptSetExpression(id, snapshotActionRequest.getSourceKey());
conceptSetLockingService.invokeSnapshotAction(id, snapshotActionRequest, conceptSetExpressionSupplier);
return Response.ok().entity("Snapshot action successfully invoked.").build();
} catch (Exception e) {
log.error("Invoke snapshot action failed", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Invoke snapshot action failed: " + e.getMessage())
.build();
}
}

@POST
@Path("/locked")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response checkIsLockedBatch(IsLockedBatchCheckRequest isLockedBatchCheckRequest) {
IsLockedBatchCheckResponse response = new IsLockedBatchCheckResponse();
try {
List<Integer> ids = isLockedBatchCheckRequest.getConceptSetIds();
Map<Integer, Boolean> lockStatuses = conceptSetLockingService.areLocked(ids);
response.setLockStatus(lockStatuses);
return Response.ok(response).build();
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Error checking lock statuses: " + e.getMessage())
.build();
}
}

@POST
@Path("/snapshot-items")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getSnapshotItems(GetConceptSetSnapshotItemsRequest request) {
try {
List<ConceptSetExpression.ConceptSetItem> conceptSetItems = conceptSetLockingService.getConceptSetSnapshotItemsBySnapshotId(request.getSnapshotId(), request.getSnapshotItemType());
GetConceptSetSnapshotItemsResponse response = new GetConceptSetSnapshotItemsResponse();
response.setConceptSetItems(conceptSetItems);
return Response.ok(response).build();
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Error fetching snapshot items: " + e.getMessage())
.build();
}
}

private ConceptSet updateConceptSet(ConceptSet dst, ConceptSet src) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.ohdsi.webapi.service.dto;

import org.ohdsi.webapi.service.lock.dto.ConceptSetSnapshotParameters;

public class LockedConceptSetsResponse {
private ConceptSetDTO conceptSet;
private ConceptSetSnapshotParameters snapshotParameters;

public LockedConceptSetsResponse(ConceptSetDTO conceptSet, ConceptSetSnapshotParameters snapshotParameters) {
this.conceptSet = conceptSet;
this.snapshotParameters = snapshotParameters;
}


public ConceptSetSnapshotParameters getSnapshotParameters() {
return snapshotParameters;
}

public void setSnapshotParameters(ConceptSetSnapshotParameters snapshotParameters) {
this.snapshotParameters = snapshotParameters;
}

public ConceptSetDTO getConceptSet() {
return conceptSet;
}

public void setConceptSet(ConceptSetDTO conceptSet) {
this.conceptSet = conceptSet;
}
}
Loading
Loading