Commit 25cb49f3 authored by jcorvi's avatar jcorvi
Browse files

Merge branch 'develop' into 'master'

"Merge branch 'allevidence' into 'develop'"

See merge request !15
parents e76edc20 ec4987b3
Pipeline #25857 passed with stage
in 3 seconds
......@@ -8,7 +8,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -17,8 +16,6 @@ import es.bsc.inb.ades.rest.api.model.Document;
import es.bsc.inb.ades.rest.api.model.DocumentAnnotations;
import es.bsc.inb.ades.rest.api.model.DocumentTracking;
import es.bsc.inb.ades.rest.api.model.Status;
import es.bsc.inb.ades.rest.api.model.Tracking;
import es.bsc.inb.ades.rest.api.security.basic.inmemory.AuthenticationBean;
import es.bsc.inb.ades.rest.api.services.DocumentService;
......@@ -79,6 +76,12 @@ public class DocumentController {
return "true";
}
@RequestMapping("/documents/{id}/srFindingValidation/{srDomainId}/{status}")
public String setSRFindingValidation(@PathVariable(value="id") Long id, @PathVariable(value="srDomainId") Integer srDomainId, @PathVariable(value="status") String status) {
documentService.setValidationSRDomainFinding(id, srDomainId, status);
return "true";
}
@RequestMapping("/documents/{id}/findingValidation/{findingId}/{status}")
public String setFindingValidation(@PathVariable(value="id") Long id, @PathVariable(value="findingId") Integer findingId, @PathVariable(value="status") String status) {
documentService.setFindingValidation(id, findingId, status);
......@@ -91,19 +94,37 @@ public class DocumentController {
return snippet;
}
@RequestMapping("/documents/{id}/evidence/findings")
public String findAllFindingEvidence(@PathVariable(value="id") Long id) {
String snippet = documentService.findFindingsEvidenceByDocumentId(id);
return snippet;
}
@RequestMapping("/documents/{id}/evidence/all")
public String findAllEvidence(@PathVariable(value="id") Long id) {
String snippet = documentService.findFindingsEvidenceByDocumentId(id);
String snippet = documentService.findAllEvidenceByDocumentId(id);
return snippet;
}
@RequestMapping("/documents/{id}/evidence/sentences")
public String findSentencesEvidence(@PathVariable(value="id") Long id) {
String snippet = documentService.findSentencesEvidenceByDocumentId(id);
//String snippet = documentService.findAllEvidenceByDocumentId(id);
return snippet;
}
@RequestMapping("/documents/{id}/finding2/{findingId}")
public String findFinding2(@PathVariable(value="id") Long id, @PathVariable(value="findingId") Integer findingId) {
String snippet = documentService.findTextSnippetByDocumentIdAndFindingId2(id, findingId);
@RequestMapping("/documents/{id}/text")
public String findDocumentText(@PathVariable(value="id") Long id) {
String snippet = documentService.findTextByDocumentId(id);
return snippet;
}
// @RequestMapping("/documents/{id}/finding2/{findingId}")
// public String findFinding2(@PathVariable(value="id") Long id, @PathVariable(value="findingId") Integer findingId) {
// String snippet = documentService.findTextSnippetByDocumentIdAndFindingId2(id, findingId);
// return snippet;
// }
@RequestMapping(value = "/documents/export/{id}")
public ResponseEntity<byte[]> generateReport(@PathVariable("id") long documentId){
String filename = "Study_Report_" + documentId +".txt";
......
package es.bsc.inb.ades.rest.api.model;
import org.apache.tomcat.util.bcel.classfile.Constant;
import es.bsc.inb.ades.rest.api.util.Constants;
/**
* This class describes a finding in SR-Domain format.
* No textual evidence.
......@@ -23,21 +27,79 @@ public class SRDomainFinding implements Cloneable{
private String SRENPHSE="";
private String SROBENDY="";
private String SRDOMAIN="";
private String SRDOMAIN_DESC="";
private String SRSPEC="";
private String SRSPEC_DESC="";
private String SRTSTCD="";
private String SRTSTCD_DESC="";
private String SRFNDG="";
private String SRFNDG_DESC="";
private String SRORES="";
private String SROBSV="";
private String SROBSV_DESC="";
private String SROBSQ="";
private String SRSEV="";
private String SRPCNT="";
private String SRSIGF="";
private String SRTRTEF="";
private String SRCOMNT="";
private Boolean export;
private Integer findingId;
private Integer srDomainId;
private String status="non_curated";
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getSrdomain_value() {
if(Constants.SEND_DOMAIN_NAMES.get(SRDOMAIN)!=null) {
return Constants.SEND_DOMAIN_NAMES.get(SRDOMAIN) + "(" + SRDOMAIN + ")";
}else if(SRDOMAIN==null || SRDOMAIN.equals("")) {
return "";
}else {
return SRDOMAIN;
}
}
public String getSrfndg_value() {
if(SRFNDG ==null || SRFNDG.equals("")) {
return SRORES;
}
return SRFNDG_DESC + "(" + SRFNDG + ")";
}
public String getSrtstcd_value() {
if(SRTSTCD ==null || SRTSTCD.equals("")) {
return SRTSTCD_DESC;
}
return SRTSTCD_DESC + "(" + SRTSTCD + ")";
}
public String getSrobsv_value() {
if(SROBSV ==null || SROBSV.equals("")) {
return SROBSV_DESC;
}
return SROBSV_DESC + "(" + SROBSV + ")";
}
public String getSrspec_value() {
if(SRSPEC ==null || SRSPEC.equals("")) {
return SRSPEC_DESC;
}
return SRSPEC_DESC + "(" + SRSPEC + ")";
}
public String getSTUDYID() {
return STUDYID;
......@@ -156,9 +218,9 @@ public class SRDomainFinding implements Cloneable{
public String getSROBSV() {
return SROBSV;
}
public void setSROBSV(String sROBSV) {
SROBSV = sROBSV;
}
public String getSROBSQ() {
return SROBSQ;
}
......@@ -195,10 +257,41 @@ public class SRDomainFinding implements Cloneable{
public void setSRCOMNT(String sRCOMNT) {
SRCOMNT = sRCOMNT;
}
public void setSRDOMAIN_DESC(String sRDOMAIN_DESC) {
SRDOMAIN_DESC = sRDOMAIN_DESC;
}
public void setSROBSV(String sROBSV) {
SROBSV = sROBSV;
}
public String getSRDOMAIN_DESC() {
return SRDOMAIN_DESC;
}
public String getSRSPEC_DESC() {
return SRSPEC_DESC;
}
public void setSRSPEC_DESC(String sRSPEC_DESC) {
SRSPEC_DESC = sRSPEC_DESC;
}
public String getSRTSTCD_DESC() {
return SRTSTCD_DESC;
}
public void setSRTSTCD_DESC(String sRTSTCD_DESC) {
SRTSTCD_DESC = sRTSTCD_DESC;
}
public String getSRFNDG_DESC() {
return SRFNDG_DESC;
}
public void setSRFNDG_DESC(String sRFNDG_DESC) {
SRFNDG_DESC = sRFNDG_DESC;
}
public String getSROBSV_DESC() {
return SROBSV_DESC;
}
public void setSROBSV_DESC(String sROBSV_DESC) {
SROBSV_DESC = sROBSV_DESC;
}
public Boolean getExport() {
if(export==null)return true;
return export;
......
......@@ -6,7 +6,6 @@ import es.bsc.inb.ades.rest.api.model.Document;
import es.bsc.inb.ades.rest.api.model.DocumentAnnotations;
import es.bsc.inb.ades.rest.api.model.DocumentTracking;
import es.bsc.inb.ades.rest.api.model.Status;
import es.bsc.inb.ades.rest.api.model.Tracking;
public interface DocumentService {
......@@ -17,7 +16,7 @@ public interface DocumentService {
Document findByDocumentId2(Long id);
String findTextSnippetByDocumentIdAndFindingId2(Long id, Integer findingId);
//String findTextSnippetByDocumentIdAndFindingId2(Long id, Integer findingId);
String findFindingEvidenceByDocumentIdAndFindingId(Long id, Integer findingId);
......@@ -30,9 +29,17 @@ public interface DocumentService {
byte[] exportDocumentAnnotation(Long documentId);
String findFindingsEvidenceByDocumentId(Long id);
String findAllEvidenceByDocumentId(Long id);
String findSentencesEvidenceByDocumentId(Long id);
String findTextByDocumentId(Long id);
Boolean setExportSRDomainFinding(Long id, Integer findingId, Boolean export_srdomain);
Boolean setValidationSRDomainFinding(Long id, Integer srDomainFindingId,String status);
Boolean setFindingValidation(Long id, Integer findingId,String status);
Status moveDocument(Long id, Status status);
......
......@@ -88,41 +88,66 @@ public class DocumentServiceImpl implements DocumentService {
}
// @Override
// public String findTextSnippetByDocumentIdAndFindingId2(Long id, Integer findingId) {
// DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
// Document document = this.findByDocumentId(id);
// Finding findingSelected = null;
// for (Finding finding : documentAnnotations.getFindings()) {
// if(finding.getFindingId().equals(findingId)) {
// findingSelected = finding;
// break;
// }
// }
//
// if(findingSelected!=null) {
// return this.generateFindingSnippet2(document.getText(), findingSelected);
// }
// return "";
// }
@Override
public String findTextSnippetByDocumentIdAndFindingId2(Long id, Integer findingId) {
public Boolean setFindingValidation(Long id, Integer findingId, String status) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Document document = this.findByDocumentId(id);
Finding findingSelected = null;
for (Finding finding : documentAnnotations.getFindings()) {
if(finding.getFindingId().equals(findingId)) {
for (Annotation annotation : documentAnnotations.getRelevantSentences()) {
for (Finding finding : annotation.getFindings()) {
if(finding.getFindingId().equals(findingId)) {
findingSelected = finding;
break;
}
}
}
if(findingSelected!=null) {
return this.generateFindingSnippet2(document.getText(), findingSelected);
//https://stackoverflow.com/questions/47699646/updating-replacing-a-deeply-nested-object-in-mongodb-with-spring-data-mongodb
findingSelected.setStatus(status);
documentAnnotationsRepository.save(documentAnnotations);
createTracking(id, "admin", Action.ACCEPT, findingSelected.getTrackingSummary());
return true;
}
return "";
return false;
}
@Override
public Boolean setFindingValidation(Long id, Integer findingId, String status) {
public Boolean setValidationSRDomainFinding(Long id, Integer srDomainFindingId, String status) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Finding findingSelected = null;
SRDomainFinding srDomainFindingelected = null;
for (Annotation annotation : documentAnnotations.getRelevantSentences()) {
for (Finding finding : annotation.getFindings()) {
if(finding.getFindingId().equals(findingId)) {
findingSelected = finding;
break;
for (SRDomainFinding srDomainFinding : finding.getSrDomainFindings()) {
if(srDomainFinding.getSrDomainId().equals(srDomainFindingId)) {
srDomainFindingelected = srDomainFinding;
break;
}
}
}
}
if(findingSelected!=null) {
if(srDomainFindingelected!=null) {
//https://stackoverflow.com/questions/47699646/updating-replacing-a-deeply-nested-object-in-mongodb-with-spring-data-mongodb
findingSelected.setStatus(status);
srDomainFindingelected.setStatus(status);
documentAnnotationsRepository.save(documentAnnotations);
createTracking(id, "admin", Action.ACCEPT, findingSelected.getTrackingSummary());
createTracking(id, "admin", Action.ACCEPT, srDomainFindingelected.getTrackingSummary());
return true;
}
return false;
......@@ -130,6 +155,7 @@ public class DocumentServiceImpl implements DocumentService {
@Override
public Boolean setExportSRDomainFinding(Long id, Integer srDomainId,Boolean export_srdomainfinding) {
System.out.println("Entra:"+srDomainId);
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
SRDomainFinding sRDomainFindingSelected = null;
for (Annotation annotation : documentAnnotations.getRelevantSentences()) {
......@@ -185,13 +211,42 @@ public class DocumentServiceImpl implements DocumentService {
return "";
}
/**
* Get Findings evidence from a document
*/
public String findFindingsEvidenceByDocumentId(Long id) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Document document = this.findByDocumentId(id);
return this.generateFindingsSnippet4(document.getText(), documentAnnotations.getFindings());
return this.generateAllFindingsEvidenceSnippet(document.getText(), documentAnnotations.getRelevantSentences());
}
/**
* Get Findings evidence from a document
*/
public String findAllEvidenceByDocumentId(Long id) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Document document = this.findByDocumentId(id);
return this.generateAllEvidenceSnippet(document.getText(), documentAnnotations.getRelevantSentences());
}
/**
* Get relevant sentences evidence from a document
*/
public String findSentencesEvidenceByDocumentId(Long id) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Document document = this.findByDocumentId(id);
return this.generateAllRelevantSentenceEvidenceSnippet(document.getText(), documentAnnotations.getRelevantSentences());
}
/**
* Find only the text in evidence format of for a document
*/
public String findTextByDocumentId(Long id) {
Document document = this.findByDocumentId(id);
return this.generateOnlyTextSnippet(document.getText());
}
@Override
public String findFindingEvidenceByDocumentIdAndFindingId(Long id, Integer findingId) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
......@@ -221,12 +276,6 @@ public class DocumentServiceImpl implements DocumentService {
// annotation.setStartOffset(start_off + Constants.POINTS_INT);
// annotation.setEndOffset(start_off + Constants.POINTS_INT + text_size);
// return this.generateFindingSnippet3(subtext, findingSelected, start_annotation_aux);
Annotation annotation = findingSelected.getRelevant_text();
int text_size = annotation.getEndOffset() - annotation.getStartOffset();
int start_ = 0;
......@@ -242,12 +291,14 @@ public class DocumentServiceImpl implements DocumentService {
int start_annotation_aux = annotation.getStartOffset();
annotation.setStartOffset(Constants.SLICE_START + Constants.POINTS_INT);
annotation.setEndOffset(Constants.SLICE_START + Constants.POINTS_INT + text_size);
return this.generateFindingSnippet3(subtext, findingSelected, start_off, start_annotation_aux);
return this.generateFindingSnippet(subtext, findingSelected, start_off, start_annotation_aux);
}
return "";
}
/**
* Export SR-Domain format marked as exportable.
*/
public byte[] exportDocumentAnnotation(Long id) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
StringBuilder retStr = new StringBuilder("");
......@@ -291,9 +342,15 @@ public class DocumentServiceImpl implements DocumentService {
//SROBSTDY --> Start Phase Day of Observation
retStr.append("");
retStr.append("|");
//SRENDY --> ??
retStr.append("");
retStr.append("|");
//SRENPHSE -->Study Phase of last Observation
retStr.append("");
retStr.append("|");
//SROBENDY --> ??
retStr.append("");
retStr.append("|");
//SRDOMAIN --> Domain of Finding
retStr.append(srDomainFinding.getSRDOMAIN()==null?"":srDomainFinding.getSRDOMAIN());
retStr.append("|");
......@@ -339,6 +396,7 @@ public class DocumentServiceImpl implements DocumentService {
}
/**
* Generate the evidence snippet for a sentence
*
* @param text
* @param findingSelected
......@@ -348,12 +406,11 @@ public class DocumentServiceImpl implements DocumentService {
Gson gsonBuilder = new GsonBuilder().create();
JsonObject json_to_return = new JsonObject();
json_to_return.addProperty("text", text);
//[["T1","FINDING",[[1206,1231]]],["T2","SPECIMEN",[[1260,1264]]]]
JsonArray entities = new JsonArray();
String id_sentence = "T"+sentence.getId();
String id_sentence = "T"+sentence.getId()+ " - SCORE: " + sentence.getFeature("PRETOX_REL_SCORE");
JsonArray values = new JsonArray();
values.add(id_sentence);
values.add("PRETOX_RELEVANT_SENTENCE");
values.add("RELEVANT_SENTENCE");
JsonArray offste = new JsonArray();
JsonArray offste2 = new JsonArray();
offste.add(sentence.getStartOffset());
......@@ -365,145 +422,312 @@ public class DocumentServiceImpl implements DocumentService {
return gsonBuilder.toJson(json_to_return).toString();
}
private String generateFindingsEvidence(String text, List<Finding> findings) {
Gson gsonBuilder = new GsonBuilder().create();
JsonObject evidence = new JsonObject();
evidence.addProperty("text", text);
for (Finding finding_selected : findings) {
this.generateFindingEvidence(evidence, finding_selected);
}
return gsonBuilder.toJson(evidence).toString();
}
// /**
// * Generate the evidence snippet for a findind
// * @param text
// * @param findingSelected
// * @return
// */
// private void generateFindingEvidence(JsonObject evidence, Finding findingSelected) {
// List<Annotation> all = findingSelected.generateSortedAnnotationsAll();
// JsonArray entities = new JsonArray();
// JsonArray attributes = new JsonArray();
// JsonArray relations = new JsonArray();
// int t = 1;
// int a = 1;
// int r = 1;
// String id_finding = "";
// for (Annotation annotation : all) {
// JsonArray values = new JsonArray();
// String type = annotation.getFeature("ANNOTATION_TYPE");
// values.add("T"+t);
// values.add(type);
// JsonArray offste = new JsonArray();
// JsonArray offste2 = new JsonArray();
// offste.add(annotation.getStartOffset());
// offste.add(annotation.getEndOffset());
// offste2.add(offste);
// values.add(offste2);
// entities.add(values);
// if(type.equals("FINDING") || type.equals("STUDY_TESTCD") ) {
// id_finding = "T"+t;
// JsonArray values_a = new JsonArray();
// values_a.add("A"+a);
// values_a.add("Notorious");
// values_a.add(id_finding);
// attributes.add(values_a);
// a++;
// }else {
// JsonArray values_r = new JsonArray();
// values_r.add("R"+r);
// values_r.add("Relation");
// JsonArray values_r_e = new JsonArray();
// JsonArray values_r_e_v = new JsonArray();
// values_r_e_v.add("Entity");
// values_r_e_v.add(id_finding);
// values_r_e.add(values_r_e_v);
// JsonArray values_r_e_v_2 = new JsonArray();
// values_r_e_v_2.add("Subentity");
// values_r_e_v_2.add("T"+t);
// values_r_e.add(values_r_e_v_2);
// values_r.add(values_r_e);
// relations.add(values_r);
// r++;
// }
// t++;
// }
// evidence.add("entities", entities);
// evidence.add("attributes", attributes);
// evidence.add("relations", relations);
// }
//
// /**
// *
// * @param text
// * @param findingSelected
// * @return
// */
// private String generateFindingSnippet2(String text, Finding findingSelected) {
// Gson gsonBuilder = new GsonBuilder().create();
// JsonObject finding = new JsonObject();
// finding.addProperty("text", text);
// List<Annotation> all = findingSelected.generateSortedAnnotationsAll();
// JsonArray entities = new JsonArray();
// JsonArray attributes = new JsonArray();
// JsonArray relations = new JsonArray();
// int t = 1;
// int a = 1;
// int r = 1;
// String id_finding = "";
// for (Annotation annotation : all) {
// JsonArray values = new JsonArray();
// String type = annotation.getFeature("ANNOTATION_TYPE");
// values.add("T"+t);
// values.add(type);
// JsonArray offste = new JsonArray();
// JsonArray offste2 = new JsonArray();
// offste.add(annotation.getStartOffset());
// offste.add(annotation.getEndOffset());
// offste2.add(offste);
// values.add(offste2);
// entities.add(values);
// if(type.equals("FINDING") || type.equals("STUDY_TESTCD") ) {
// id_finding = "T"+t;
// JsonArray values_a = new JsonArray();
// values_a.add("A"+a);
// values_a.add("Notorious");
// values_a.add(id_finding);
// attributes.add(values_a);
// a++;
// }else {
// JsonArray values_r = new JsonArray();
// values_r.add("R"+r);
// values_r.add("Relation");
// JsonArray values_r_e = new JsonArray();
// JsonArray values_r_e_v = new JsonArray();
// values_r_e_v.add("Entity");
// values_r_e_v.add(id_finding);
// values_r_e.add(values_r_e_v);
// JsonArray values_r_e_v_2 = new JsonArray();
// values_r_e_v_2.add("Subentity");
// values_r_e_v_2.add("T"+t);
// values_r_e.add(values_r_e_v_2);
// values_r.add(values_r_e);
// relations.add(values_r);
// r++;
// }
// t++;
// }