-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extending Concept Set Items with Annotations #2403
Changes from 3 commits
e6c3857
633eb78
757929a
83579dd
7e9359c
25f44ae
948fde3
0fff858
7adb69b
f40a666
2b9c35a
485b41a
937c72e
6a88e5d
deed559
1f6476c
4ee6b48
57491c3
4c3a304
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
package org.ohdsi.webapi.service; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
@@ -29,8 +28,6 @@ | |
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.shiro.authz.UnauthorizedException; | ||
import org.ohdsi.circe.vocabulary.ConceptSetExpression; | ||
import org.ohdsi.vocabulary.Concept; | ||
|
@@ -895,7 +892,7 @@ private ConceptSetVersion saveVersion(int id) { | |
@Transactional | ||
public boolean saveConceptSetAnnotation(@PathParam("id") final int conceptSetId, SaveConceptSetAnnotationsRequest request) { | ||
removeAnnotations(conceptSetId, request); | ||
if (CollectionUtils.isNotEmpty(request.getNewAnnotation())) { | ||
if (request.getNewAnnotation() != null && !request.getNewAnnotation().isEmpty()) { | ||
List<ConceptSetAnnotation> annotationList = request.getNewAnnotation() | ||
.stream() | ||
.map(newAnnotationData -> { | ||
|
@@ -908,13 +905,12 @@ public boolean saveConceptSetAnnotation(@PathParam("id") final int conceptSetId, | |
annotationDetailsDTO.setSearchData(newAnnotationData.getSearchData()); | ||
conceptSetAnnotation.setAnnotationDetails(mapper.writeValueAsString(annotationDetailsDTO)); | ||
} catch (JsonProcessingException e) { | ||
log.error("Could not serialize Concept Set AnnotationDetailsDTO", e); | ||
throw new RuntimeException(e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a log entry |
||
} | ||
conceptSetAnnotation.setVocabularyVersion(newAnnotationData.getVocabularyVersion()); | ||
conceptSetAnnotation.setConceptSetVersion(newAnnotationData.getConceptSetVersion()); | ||
conceptSetAnnotation.setConceptId(newAnnotationData.getConceptId()); | ||
conceptSetAnnotation.setCreatedBy(getCurrentUser()); | ||
conceptSetAnnotation.setCreatedDate(new Date()); | ||
return conceptSetAnnotation; | ||
}).collect(Collectors.toList()); | ||
|
||
|
@@ -924,46 +920,40 @@ public boolean saveConceptSetAnnotation(@PathParam("id") final int conceptSetId, | |
return true; | ||
} | ||
private void removeAnnotations(int id, SaveConceptSetAnnotationsRequest request){ | ||
if (CollectionUtils.isNotEmpty(request.getRemoveAnnotation())) { | ||
if (request.getRemoveAnnotation() != null && !request.getRemoveAnnotation().isEmpty()) { | ||
for (AnnotationDTO annotationDTO : request.getRemoveAnnotation()) { | ||
this.getConceptSetAnnotationRepository().deleteAnnotationByConceptSetIdAndConceptId(id, annotationDTO.getConceptId()); | ||
} | ||
} | ||
} | ||
@POST | ||
@Path("/copy-annotations") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Transactional | ||
public void copyAnnotations(CopyAnnotationsRequest copyAnnotationsRequest ) { | ||
List<ConceptSetAnnotation> sourceAnnotations = getConceptSetAnnotationRepository().findByConceptSetId(copyAnnotationsRequest.getSourceConceptSetId()); | ||
List<ConceptSetAnnotation> copiedAnnotations= sourceAnnotations.stream() | ||
.map(sourceAnnotation -> copyAnnotation(sourceAnnotation, copyAnnotationsRequest.getSourceConceptSetId(), copyAnnotationsRequest.getTargetConceptSetId())) | ||
.collect(Collectors.toList()); | ||
getConceptSetAnnotationRepository().save(copiedAnnotations); | ||
} | ||
private ConceptSetAnnotation copyAnnotation(ConceptSetAnnotation sourceConceptSetAnnotation, int sourceConceptSetId, int targetConceptSetId){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move it down below the public method where it is used |
||
ConceptSetAnnotation targetConceptSetAnnotation = new ConceptSetAnnotation(); | ||
targetConceptSetAnnotation.setConceptSetId(targetConceptSetId); | ||
targetConceptSetAnnotation.setConceptSetVersion(sourceConceptSetAnnotation.getConceptSetVersion()); | ||
targetConceptSetAnnotation.setAnnotationDetails(sourceConceptSetAnnotation.getAnnotationDetails()); | ||
targetConceptSetAnnotation.setConceptId(sourceConceptSetAnnotation.getConceptId()); | ||
targetConceptSetAnnotation.setVocabularyVersion(sourceConceptSetAnnotation.getVocabularyVersion()); | ||
targetConceptSetAnnotation.setCreatedBy(sourceConceptSetAnnotation.getCreatedBy()); | ||
targetConceptSetAnnotation.setCreatedDate(sourceConceptSetAnnotation.getCreatedDate()); | ||
targetConceptSetAnnotation.setModifiedBy(sourceConceptSetAnnotation.getModifiedBy()); | ||
targetConceptSetAnnotation.setModifiedDate(sourceConceptSetAnnotation.getModifiedDate()); | ||
targetConceptSetAnnotation.setCopiedFromConceptSetIds(appendCopiedFromConceptSetId(sourceConceptSetAnnotation.getCopiedFromConceptSetIds(), sourceConceptSetId)); | ||
return targetConceptSetAnnotation; | ||
} | ||
|
||
private String appendCopiedFromConceptSetId(String copiedFromConceptSetIds, int sourceConceptSetId) { | ||
if(StringUtils.isEmpty(copiedFromConceptSetIds)){ | ||
if(copiedFromConceptSetIds == null || copiedFromConceptSetIds.isEmpty()){ | ||
return Integer.toString(sourceConceptSetId); | ||
} | ||
return copiedFromConceptSetIds.concat(",").concat(Integer.toString(sourceConceptSetId)); | ||
} | ||
|
||
@POST | ||
@Path("/copy-annotations") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Transactional | ||
public void copyAnnotations(CopyAnnotationsRequest copyAnnotationsRequest ) { | ||
List<ConceptSetAnnotation> sourceAnnotations = getConceptSetAnnotationRepository().findByConceptSetId(copyAnnotationsRequest.getSourceConceptSetId()); | ||
List<ConceptSetAnnotation> copiedAnnotations= sourceAnnotations.stream() | ||
.map(sourceAnnotation -> copyAnnotation(sourceAnnotation, copyAnnotationsRequest.getSourceConceptSetId(), copyAnnotationsRequest.getTargetConceptSetId())) | ||
.collect(Collectors.toList()); | ||
getConceptSetAnnotationRepository().save(copiedAnnotations); | ||
} | ||
|
||
@GET | ||
@Path("/{id}/annotation") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
|
@@ -980,6 +970,7 @@ private AnnotationDTO convertAnnotationEntityToDTO(ConceptSetAnnotation conceptS | |
try { | ||
annotationDetails = mapper.readValue(conceptSetAnnotation.getAnnotationDetails(), AnnotationDetailsDTO.class); | ||
} catch (JsonProcessingException e) { | ||
log.error("Could not deserialize Concept Set AnnotationDetailsDTO", e); | ||
throw new RuntimeException(e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A log entry should be added additionally |
||
} | ||
|
||
|
@@ -995,34 +986,17 @@ private AnnotationDTO convertAnnotationEntityToDTO(ConceptSetAnnotation conceptS | |
annotationDTO.setVocabularyVersion(conceptSetAnnotation.getVocabularyVersion()); | ||
annotationDTO.setConceptSetVersion(conceptSetAnnotation.getConceptSetVersion()); | ||
annotationDTO.setCopiedFromConceptSetIds(conceptSetAnnotation.getCopiedFromConceptSetIds()); | ||
annotationDTO.setCreatedBy(conceptSetAnnotation.getCreatedBy() != null ? conceptSetAnnotation.getCreatedBy().getName() : null); | ||
annotationDTO.setCreatedDate(conceptSetAnnotation.getCreatedDate() != null ? conceptSetAnnotation.getCreatedDate().toString() : null); | ||
|
||
return annotationDTO; | ||
} | ||
|
||
@DELETE | ||
@Path("/annotation/{id}") | ||
@Path("/{conceptSetId}/annotation/{annotationId}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Response deleteConceptSetAnnotation(@PathParam("id") final int id) { | ||
ConceptSetAnnotation conceptSetAnnotation = getConceptSetAnnotationRepository().findById(id); | ||
public Response deleteConceptSetAnnotation(@PathParam("conceptSetId") final int conceptSetId, @PathParam("annotationId") final int annotationId) { | ||
ConceptSetAnnotation conceptSetAnnotation = getConceptSetAnnotationRepository().findById(annotationId); | ||
if (conceptSetAnnotation != null) { | ||
getConceptSetAnnotationRepository().deleteById(id); | ||
getConceptSetAnnotationRepository().deleteById(annotationId); | ||
return Response.ok().build(); | ||
} else throw new NotFoundException("Concept set annotation not found"); | ||
} | ||
|
||
@PUT | ||
@Path("/update/{id}/annotation") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public AnnotationDTO updateConceptSetAnnotation(@PathParam("id") final int id, AnnotationDTO annotationDTO) throws IOException { | ||
ConceptSetAnnotation conceptSetAnnotation = getConceptSetAnnotationRepository() | ||
.findConceptSetAnnotationByConceptIdAndConceptId(id, annotationDTO.getConceptId()) | ||
.orElseThrow(() -> new RuntimeException("Concept set annotation not found")); | ||
conceptSetAnnotation.setAnnotationDetails(mapper.writeValueAsString(annotationDTO)); | ||
conceptSetAnnotation.setModifiedBy(getCurrentUser()); | ||
conceptSetAnnotation.setModifiedDate(new Date()); | ||
getConceptSetAnnotationRepository().save(conceptSetAnnotation); | ||
return annotationDTO; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should not be * permissions. What happens is that when you delete the entity, it finds the write permission schema and deletes it, thus deleting the wildcard permission' from all users, and then preventing access to the endpiont for all users.
However, this is what happens when you extend the 'CommonEntity' which you didn't do in this case, however, ou are using a permissionSchema as if it was a common entity, so there may be a little confusion here.
But, in any case, we shouldn't see * permissions in any writePermission schema because these permission schemas are targeting a specific entity ID.