Skip to content

Commit f40a666

Browse files
oleg-odysseusalex-odysseus
authored andcommitted
[ATL-58] Implemented copying of annotations along with ConceptSet
1 parent 7adb69b commit f40a666

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

src/main/java/org/ohdsi/webapi/service/ConceptSetService.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.ohdsi.webapi.service.dto.ConceptSetDTO;
4848
import org.ohdsi.webapi.service.dto.ConceptSetAnnotationDTO;
4949
import org.ohdsi.webapi.service.dto.AnnotationDTO;
50+
import org.ohdsi.webapi.service.dto.CopyAnnotationsRequest;
5051
import org.ohdsi.webapi.shiro.Entities.UserEntity;
5152
import org.ohdsi.webapi.shiro.Entities.UserRepository;
5253
import org.ohdsi.webapi.shiro.management.Security;
@@ -916,6 +917,32 @@ public boolean saveConceptSetAnnotation(@PathParam("id") final int id, ConceptSe
916917
return true;
917918
}
918919

920+
private ConceptSetAnnotation copyAnnotation(ConceptSetAnnotation sourceConceptSetAnnotation, int targetConceptSetId){
921+
ConceptSetAnnotation targetConceptSetAnnotation = new ConceptSetAnnotation();
922+
targetConceptSetAnnotation.setConceptSetId(targetConceptSetId);
923+
targetConceptSetAnnotation.setConceptSetVersion(sourceConceptSetAnnotation.getConceptSetVersion());
924+
targetConceptSetAnnotation.setAnnotationDetails(sourceConceptSetAnnotation.getAnnotationDetails());
925+
targetConceptSetAnnotation.setConceptId(sourceConceptSetAnnotation.getConceptId());
926+
targetConceptSetAnnotation.setVocabularyVersion(sourceConceptSetAnnotation.getVocabularyVersion());
927+
targetConceptSetAnnotation.setCreatedBy(sourceConceptSetAnnotation.getCreatedBy());
928+
targetConceptSetAnnotation.setCreatedDate(sourceConceptSetAnnotation.getCreatedDate());
929+
targetConceptSetAnnotation.setModifiedBy(sourceConceptSetAnnotation.getModifiedBy());
930+
targetConceptSetAnnotation.setModifiedDate(sourceConceptSetAnnotation.getModifiedDate());
931+
return targetConceptSetAnnotation;
932+
}
933+
934+
@POST
935+
@Path("/copy-annotations")
936+
@Produces(MediaType.APPLICATION_JSON)
937+
@Transactional
938+
public void copyAnnotations(CopyAnnotationsRequest copyAnnotationsRequest ) {
939+
List<ConceptSetAnnotation> sourceAnnotations = getConceptSetAnnotationRepository().findByConceptSetId(copyAnnotationsRequest.getSourceConceptSetId());
940+
List<ConceptSetAnnotation> copiedAnnotations= sourceAnnotations.stream()
941+
.map(sourceAnnotation -> copyAnnotation(sourceAnnotation, copyAnnotationsRequest.getTargetConceptSetId()))
942+
.collect(Collectors.toList());
943+
getConceptSetAnnotationRepository().save(copiedAnnotations);
944+
}
945+
919946
@GET
920947
@Path("/{id}/annotation")
921948
@Produces(MediaType.APPLICATION_JSON)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.ohdsi.webapi.service.dto;
2+
3+
public class CopyAnnotationsRequest {
4+
5+
private int sourceConceptSetId;
6+
private int targetConceptSetId;
7+
8+
public int getSourceConceptSetId() {
9+
return sourceConceptSetId;
10+
}
11+
12+
public int getTargetConceptSetId() {
13+
return targetConceptSetId;
14+
}
15+
16+
public void setSourceConceptSetId(int sourceConceptSetId) {
17+
this.sourceConceptSetId = sourceConceptSetId;
18+
}
19+
20+
public void setTargetConceptSetId(int targetConceptSetId) {
21+
this.targetConceptSetId = targetConceptSetId;
22+
}
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
INSERT INTO ${ohdsiSchema}.sec_permission(id, value, description) VALUES
3+
(nextval('${ohdsiSchema}.sec_permission_id_seq'), 'conceptset:copy-annotations', 'Copy Concept Set Annotations');
4+
5+
INSERT INTO ${ohdsiSchema}.sec_role_permission(id, role_id, permission_id)
6+
SELECT nextval('${ohdsiSchema}.sec_role_permission_sequence'), sr.id, sp.id
7+
FROM ${ohdsiSchema}.sec_permission SP, ${ohdsiSchema}.sec_role sr
8+
WHERE sp.value IN (
9+
'conceptset:copy-annotations'
10+
) AND sr.name IN ('admin');
11+
12+
INSERT INTO ${ohdsiSchema}.sec_role_permission(id, role_id, permission_id)
13+
SELECT nextval('${ohdsiSchema}.sec_role_permission_sequence'), sr.id, sp.id
14+
FROM ${ohdsiSchema}.sec_permission SP, ${ohdsiSchema}.sec_role sr
15+
WHERE sp.value IN (
16+
'conceptset:copy-annotations'
17+
) AND sr.name IN ('Atlas users');
18+
19+
UPDATE ${ohdsiSchema}.sec_permission SET value='conceptset:annotation:*:delete'
20+
WHERE value='conceptset:annotation:%s:delete';

0 commit comments

Comments
 (0)