30
30
import com .fasterxml .jackson .databind .ObjectMapper ;
31
31
32
32
import org .apache .commons .collections4 .CollectionUtils ;
33
+ import org .apache .commons .lang3 .StringUtils ;
33
34
import org .apache .shiro .authz .UnauthorizedException ;
34
35
import org .ohdsi .circe .vocabulary .ConceptSetExpression ;
35
36
import org .ohdsi .vocabulary .Concept ;
@@ -929,7 +930,7 @@ private void removeAnnotations(int id, SaveConceptSetAnnotationsRequest request)
929
930
}
930
931
}
931
932
}
932
- private ConceptSetAnnotation copyAnnotation (ConceptSetAnnotation sourceConceptSetAnnotation , int targetConceptSetId ){
933
+ private ConceptSetAnnotation copyAnnotation (ConceptSetAnnotation sourceConceptSetAnnotation , int sourceConceptSetId , int targetConceptSetId ){
933
934
ConceptSetAnnotation targetConceptSetAnnotation = new ConceptSetAnnotation ();
934
935
targetConceptSetAnnotation .setConceptSetId (targetConceptSetId );
935
936
targetConceptSetAnnotation .setConceptSetVersion (sourceConceptSetAnnotation .getConceptSetVersion ());
@@ -940,17 +941,25 @@ private ConceptSetAnnotation copyAnnotation(ConceptSetAnnotation sourceConceptSe
940
941
targetConceptSetAnnotation .setCreatedDate (sourceConceptSetAnnotation .getCreatedDate ());
941
942
targetConceptSetAnnotation .setModifiedBy (sourceConceptSetAnnotation .getModifiedBy ());
942
943
targetConceptSetAnnotation .setModifiedDate (sourceConceptSetAnnotation .getModifiedDate ());
944
+ targetConceptSetAnnotation .setCopiedFromConceptSetIds (appendCopiedFromConceptSetId (sourceConceptSetAnnotation .getCopiedFromConceptSetIds (), sourceConceptSetId ));
943
945
return targetConceptSetAnnotation ;
944
946
}
945
947
948
+ private String appendCopiedFromConceptSetId (String copiedFromConceptSetIds , int sourceConceptSetId ) {
949
+ if (StringUtils .isEmpty (copiedFromConceptSetIds )){
950
+ return Integer .toString (sourceConceptSetId );
951
+ }
952
+ return copiedFromConceptSetIds .concat ("," ).concat (Integer .toString (sourceConceptSetId ));
953
+ }
954
+
946
955
@ POST
947
956
@ Path ("/copy-annotations" )
948
957
@ Produces (MediaType .APPLICATION_JSON )
949
958
@ Transactional
950
959
public void copyAnnotations (CopyAnnotationsRequest copyAnnotationsRequest ) {
951
960
List <ConceptSetAnnotation > sourceAnnotations = getConceptSetAnnotationRepository ().findByConceptSetId (copyAnnotationsRequest .getSourceConceptSetId ());
952
961
List <ConceptSetAnnotation > copiedAnnotations = sourceAnnotations .stream ()
953
- .map (sourceAnnotation -> copyAnnotation (sourceAnnotation , copyAnnotationsRequest .getTargetConceptSetId ()))
962
+ .map (sourceAnnotation -> copyAnnotation (sourceAnnotation , copyAnnotationsRequest .getSourceConceptSetId (), copyAnnotationsRequest . getTargetConceptSetId ()))
954
963
.collect (Collectors .toList ());
955
964
getConceptSetAnnotationRepository ().save (copiedAnnotations );
956
965
}
@@ -985,6 +994,7 @@ private AnnotationDTO convertAnnotationEntityToDTO(ConceptSetAnnotation conceptS
985
994
986
995
annotationDTO .setVocabularyVersion (conceptSetAnnotation .getVocabularyVersion ());
987
996
annotationDTO .setConceptSetVersion (conceptSetAnnotation .getConceptSetVersion ());
997
+ annotationDTO .setCopiedFromConceptSetIds (conceptSetAnnotation .getCopiedFromConceptSetIds ());
988
998
annotationDTO .setCreatedBy (conceptSetAnnotation .getCreatedBy () != null ? conceptSetAnnotation .getCreatedBy ().getName () : null );
989
999
annotationDTO .setCreatedDate (conceptSetAnnotation .getCreatedDate () != null ? conceptSetAnnotation .getCreatedDate ().toString () : null );
990
1000
0 commit comments