Commit edd63286 authored by jcorvi's avatar jcorvi
Browse files

Merge branch 'develop' into 'master'

Develop

See merge request !2
parents 5b11c74e 106b7e59
Pipeline #25271 passed with stage
in 4 minutes and 45 seconds
variables:
DOCKER_USER: javicorvi
DOCKER_BUILD: $DOCKER_USER/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME
#DOCKER_USER: javicorvi
#DOCKER_BUILD: $DOCKER_USER/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME
DOCKER_REGISTRY: registry.gitlab.bsc.es
#any doubts regarind gitlab ci cd enviroment variables go to
#https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
IMAGE_FULL_PATH: $DOCKER_REGISTRY/$CI_PROJECT_PATH:$CI_COMMIT_REF_NAME
stages:
- build
build_docker_image:
stage: build
script:
- docker login -u javicorvi -p $DOCKER_PASS
- docker build -t $DOCKER_BUILD .
- docker push $DOCKER_BUILD
#- docker login -u javicorvi -p $DOCKER_PASS
#- docker build -t registry.gitlab.bsc.es/ .
#- docker push $DOCKER_BUILD
#- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $DOCKER_REGISTRY
#- docker build -t registry.gitlab.bsc.es/inb/etransafe/pretox-rest-api:develop .
#- docker push registry.gitlab.bsc.es/inb/etransafe/pretox-rest-api:develop
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $DOCKER_REGISTRY
- docker build -t $IMAGE_FULL_PATH .
- docker push $IMAGE_FULL_PATH
tags:
- build
......@@ -51,7 +51,10 @@
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -11,13 +11,14 @@ import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.services.DocumentService;
@RestController
@CrossOrigin
@CrossOrigin()
public class DocumentController {
@Autowired
......@@ -30,7 +31,12 @@ public class DocumentController {
@RequestMapping("/documents/{id}")
public DocumentAnnotations find(@PathVariable(value="id") Long id) {
return documentService.findByDocumentAnnotationsByDocumentId(id);
return documentService.findDocumentAnnotationsByDocumentId(id);
}
@RequestMapping("/documents/{id}/srdomain")
public DocumentAnnotations findDocumentSRDomain(@PathVariable(value="id") Long id) {
return documentService.findDocumentSRDomainByDocumentId(id);
}
// @RequestMapping("/documents/{id}")
......@@ -47,26 +53,19 @@ public class DocumentController {
@RequestMapping("/documents/{id}/findings/{findingIds}")
public String findFindings(@PathVariable(value="id") Long id, @PathVariable(value="findingIds") List<Integer> findingIds) {
//String snippet = documentService.findFindingEvidenceByDocumentIdAndFindingId(id, findingId);
//return snippet;
//return snippet;
return "";
}
@RequestMapping("/documents/{id}/acceptFinding/{findingId}")
public String acceptFinding(@PathVariable(value="id") Long id, @PathVariable(value="findingId") Integer findingId) {
documentService.acceptFinding(id, findingId);
return "true";
}
@RequestMapping("/documents/{id}/rejectFinding/{findingId}")
public String rejectFinding(@PathVariable(value="id") Long id, @PathVariable(value="findingId") Integer findingId) {
documentService.rejectFinding(id, findingId);
@RequestMapping("/documents/{id}/setExportSRDomain/{srDomainId}/{export_srDomain}")
public String setExportFinding(@PathVariable(value="id") Long id, @PathVariable(value="srDomainId") Integer srDomainId, @PathVariable(value="export_srDomain") Boolean export_srDomain) {
documentService.setExportSRDomainFinding(id, srDomainId, export_srDomain);
return "true";
}
@RequestMapping("/documents/{id}/exportFinding/{findingId}/{export_finding}")
public String setExportFinding(@PathVariable(value="id") Long id, @PathVariable(value="findingId") Integer findingId, @PathVariable(value="export_finding") String export_finding) {
documentService.setExportFinding(id, findingId, export_finding);
@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);
return "true";
}
......
package es.bsc.inb.ades.rest.api.model;
import java.util.ArrayList;
import java.util.List;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
......@@ -22,6 +23,8 @@ public class DocumentAnnotations {
private ArrayList<Annotation> relevantSentences;
private ArrayList<Finding> findings;
private List<SRDomainFinding> srdomainfindings;
public DocumentAnnotations() {}
......@@ -46,7 +49,6 @@ public class DocumentAnnotations {
return documentId;
}
public ArrayList<Annotation> getRelevantSentences() {
return relevantSentences;
}
......@@ -59,20 +61,22 @@ public class DocumentAnnotations {
this.documentId = documentId;
}
public ArrayList<Finding> getFindings() {
return findings;
}
public void setFindings(ArrayList<Finding> findings) {
this.findings = findings;
}
public List<SRDomainFinding> getSrdomainfindings() {
return srdomainfindings;
}
public void setSrdomainfindings(List<SRDomainFinding> srdomainfindings) {
this.srdomainfindings = srdomainfindings;
}
}
......@@ -34,6 +34,11 @@ public class SRDomainFinding implements Cloneable{
private String SRSIGF="";
private String SRTRTEF="";
private String SRCOMNT="";
private Boolean export;
private Integer findingId;
private Integer srDomainId;
public String getSTUDYID() {
return STUDYID;
}
......@@ -191,6 +196,28 @@ public class SRDomainFinding implements Cloneable{
SRCOMNT = sRCOMNT;
}
public Boolean getExport() {
if(export==null)return true;
return export;
}
public void setExport(Boolean export) {
this.export = export;
}
public Integer getSrDomainId() {
return srDomainId;
}
public void setSrDomainId(Integer srDomainId) {
this.srDomainId = srDomainId;
}
public Integer getFindingId() {
return findingId;
}
public void setFindingId(Integer findingId) {
this.findingId = findingId;
}
public SRDomainFinding clone() {
try {
return (SRDomainFinding)super.clone();
......
......@@ -9,9 +9,9 @@ import java.security.Principal;
@Controller
public class WebController {
@RequestMapping("/")
@RequestMapping("/api/v1/nada")
public String index(Model model, Principal principal) {
return "index";
return "login correct";
}
@GetMapping("/greeting")
public String greeting(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
......
package es.bsc.inb.ades.rest.api.security.basic.inmemory;
public class AuthenticationBean {
private String message;
public AuthenticationBean(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
return String.format("HelloWorldBean [message=%s]", message);
}
}
package es.bsc.inb.ades.rest.api.security.basic.inmemory;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
//Controller
@CrossOrigin()
@RestController
public class BasicAuthenticationController {
@GetMapping(path = "/basicauth")
public AuthenticationBean helloWorldBean() {
//throw new RuntimeException("Some Error has Happened! Contact Support at ***-***");
return new AuthenticationBean("You are authenticated");
}
}
package es.bsc.inb.ades.rest.api.security.basic.inmemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable().
//http.csrf().disable().
authorizeRequests().antMatchers(HttpMethod.OPTIONS, "/**").permitAll().anyRequest().authenticated()
.and().httpBasic();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("admin").password("{noop}password").roles("USER");
}
}
......@@ -18,7 +18,9 @@ public interface DocumentService {
String findFindingEvidenceByDocumentIdAndFindingId(Long id, Integer findingId);
DocumentAnnotations findByDocumentAnnotationsByDocumentId(Long id);
DocumentAnnotations findDocumentAnnotationsByDocumentId(Long id);
DocumentAnnotations findDocumentSRDomainByDocumentId(Long id);
String findSentenceEvidenceByDocumentIdAndSentenceId(Long id, Integer sentenceId);
......@@ -26,9 +28,7 @@ public interface DocumentService {
String findFindingsEvidenceByDocumentId(Long id);
Boolean acceptFinding(Long id, Integer findingId);
Boolean setExportSRDomainFinding(Long id, Integer findingId, Boolean export_srdomain);
Boolean rejectFinding(Long id, Integer findingId);
Boolean setExportFinding(Long id, Integer findingId, String export_finding);
Boolean setFindingValidation(Long id, Integer findingId,String status);
}
......@@ -28,6 +28,7 @@ import es.bsc.inb.ades.rest.api.model.Annotation;
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.Finding;
import es.bsc.inb.ades.rest.api.model.SRDomainFinding;
import es.bsc.inb.ades.rest.api.repository.DocumentAnnotationsRepository;
import es.bsc.inb.ades.rest.api.repository.DocumentRepository;
import es.bsc.inb.ades.rest.api.util.Constants;
......@@ -44,6 +45,8 @@ public class DocumentServiceImpl implements DocumentService {
@Autowired
public DocumentAnnotationsRepository documentAnnotationsRepository;
static final Map<String, String> ANNOTATION_CLASS_STYLE = createMap();
public List<Document> findAll() {
return documentRepository.findAllNamesByOrderByName();
}
......@@ -60,45 +63,42 @@ public class DocumentServiceImpl implements DocumentService {
return documentRepository.findDocumentTextSubstringByDocumentId(id, start, end);
}
public DocumentAnnotations findByDocumentAnnotationsByDocumentId(Long id) {
public DocumentAnnotations findDocumentAnnotationsByDocumentId(Long id) {
return documentAnnotationsRepository.findByDocumentId(id);
}
public DocumentAnnotations findDocumentSRDomainByDocumentId(Long id) {
DocumentAnnotations docAnno = documentAnnotationsRepository.findByDocumentId(id);
List<SRDomainFinding> srdomains = new ArrayList<SRDomainFinding>();
for (Annotation sentence : docAnno.getRelevantSentences()) {
for (Finding finding : sentence.getFindings()) {
for (SRDomainFinding sr : finding.getSrDomainFindings()) {
srdomains.add(sr);
}
}
}
docAnno.setSrdomainfindings(srdomains);
docAnno.setRelevantSentences(null);
docAnno.setFindings(null);
return docAnno;
}
public Document findByDocumentId2(Long id) {
documentRepository.findByDocumentId(id);
return documentRepository.findByDocumentId(id);
}
static final Map<String, String> ANNOTATION_CLASS_STYLE = createMap();
// @Override
// public String findTextSnippetByDocumentIdAndFindingId(Long id, Integer findingId) {
// Document document = this.findByDocumentId(id);
// Finding findingSelected = null;
// for (Finding finding : document.getFindings()) {
// if(finding.getFindingId().equals(findingId)) {
// findingSelected = finding;
// break;
// }
// }
// if(findingSelected!=null) {
// return this.generateFindingSnippet(document.getText(), findingSelected);
// }
// return "";
// }
@Override
public String findTextSnippetByDocumentIdAndFindingId2(Long id, Integer findingId) {
DocumentAnnotations documentAnnotations = this.findByDocumentAnnotationsByDocumentId(id);
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;
}
findingSelected = finding;
break;
}
}
if(findingSelected!=null) {
......@@ -107,31 +107,9 @@ public class DocumentServiceImpl implements DocumentService {
return "";
}
@Override
public Boolean acceptFinding(Long id, Integer findingId) {
DocumentAnnotations documentAnnotations = this.findByDocumentAnnotationsByDocumentId(id);
Finding findingSelected = null;
for (Annotation annotation : documentAnnotations.getRelevantSentences()) {
for (Finding finding : annotation.getFindings()) {
if(finding.getFindingId().equals(findingId)) {
findingSelected = finding;
break;
}
}
}
if(findingSelected!=null) {
findingSelected.setStatus("accepted");
documentAnnotationsRepository.save(documentAnnotations);
return true;
}
return false;
}
@Override
public Boolean rejectFinding(Long id, Integer findingId) {
DocumentAnnotations documentAnnotations = this.findByDocumentAnnotationsByDocumentId(id);
public Boolean setFindingValidation(Long id, Integer findingId,String status) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Finding findingSelected = null;
for (Annotation annotation : documentAnnotations.getRelevantSentences()) {
for (Finding finding : annotation.getFindings()) {
......@@ -143,7 +121,7 @@ public class DocumentServiceImpl implements DocumentService {
}
if(findingSelected!=null) {
//https://stackoverflow.com/questions/47699646/updating-replacing-a-deeply-nested-object-in-mongodb-with-spring-data-mongodb
findingSelected.setStatus("rejected");
findingSelected.setStatus(status);
documentAnnotationsRepository.save(documentAnnotations);
return true;
}
......@@ -151,20 +129,23 @@ public class DocumentServiceImpl implements DocumentService {
}
@Override
public Boolean setExportFinding(Long id, Integer findingId,String export_finding) {
DocumentAnnotations documentAnnotations = this.findByDocumentAnnotationsByDocumentId(id);
Finding findingSelected = null;
public Boolean setExportSRDomainFinding(Long id, Integer srDomainId,Boolean export_srdomainfinding) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
SRDomainFinding sRDomainFindingSelected = 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(srDomainId)) {
sRDomainFindingSelected = srDomainFinding;
break;
}
}
}
}
if(findingSelected!=null) {
if(sRDomainFindingSelected!=null) {
//https://stackoverflow.com/questions/47699646/updating-replacing-a-deeply-nested-object-in-mongodb-with-spring-data-mongodb
findingSelected.setExport(export_finding);
sRDomainFindingSelected.setExport(export_srdomainfinding);
documentAnnotationsRepository.save(documentAnnotations);
return true;
}
......@@ -174,7 +155,7 @@ public class DocumentServiceImpl implements DocumentService {
@Override
public String findSentenceEvidenceByDocumentIdAndSentenceId(Long id, Integer sentenceId) {
DocumentAnnotations documentAnnotations = this.findByDocumentAnnotationsByDocumentId(id);
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Annotation annotation = null;
for (Annotation sentence : documentAnnotations.getRelevantSentences()) {
if(sentence.getId().equals(sentenceId)) {
......@@ -205,14 +186,14 @@ public class DocumentServiceImpl implements DocumentService {
}
public String findFindingsEvidenceByDocumentId(Long id) {
DocumentAnnotations documentAnnotations = this.findByDocumentAnnotationsByDocumentId(id);
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Document document = this.findByDocumentId(id);
return this.generateFindingsSnippet4(document.getText(), documentAnnotations.getFindings());
}
@Override
public String findFindingEvidenceByDocumentIdAndFindingId(Long id, Integer findingId) {
DocumentAnnotations documentAnnotations = this.findByDocumentAnnotationsByDocumentId(id);
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Finding findingSelected = null;
for (Annotation annotation : documentAnnotations.getRelevantSentences()) {
for (Finding finding : annotation.getFindings()) {
......@@ -267,132 +248,95 @@ public class DocumentServiceImpl implements DocumentService {
public byte[] exportDocumentAnnotation(Long id) {
DocumentAnnotations documentAnnotations = this.findByDocumentAnnotationsByDocumentId(id);
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
StringBuilder retStr = new StringBuilder("");
retStr.append("STUDYID|DOMAIN|SRSEQ|SRRISK|SPGRPCD|GRPLBL|SRGRPDOS|SRSEX|SRSTDY|SRSTPHSE|SROBSTDY|SRENDY|SRENPHSE|SROBENDY|SRDOMAIN|SRSPEC|SRTSTCD|SRFNDG|SRORES|SROBSV|SROBSQ|SRSEV|SRPCNT|SRSIGF|SRTRTEF|SRCOMNT");
retStr.append(System.getProperty("line.separator"));
for (Finding finding : documentAnnotations.getFindings()) {
//STUDYID -- > Study Identifier
retStr.append(id);
retStr.append("|");
//DOMAIN -- > Domain Abbreviation, always SR
retStr.append("SR");
retStr.append("|");
//SRSEQ -- > Sequence number
retStr.append("");
retStr.append("|");
//SRRISK --> Effect Level Associated with a Group/Sex, NOEL, LOEL, NOAEL, LOAEL, HNSTD, STD, MTD
retStr.append(finding.getRisk_level()==null?"":finding.getRisk_level().getValue());
retStr.append("|");
//SPGRPCD --> Sponsor-defined Group Code, group 1 , A
retStr.append(finding.getGroup()==null?"":finding.getGroup().getValue());
retStr.append("|");
//GRPLBL --> Sponsor-defined Group Name, "low dose", "mid dose"
retStr.append(finding.getGroup()==null?"":finding.getGroup().getValue());
retStr.append("|");
//SRGRPDOS --> Group Dose Level, "20 mg/kg"
retStr.append(finding.getGroup()==null?"":finding.getGroup().getValue());
retStr.append("|");
//SRSEX -- > Sex
retStr.append(finding.getSex()==null?"":finding.getSex().getValue());
retStr.append("|");
//SRSTDY --> Study Day of Start of Finding
retStr.append("");
retStr.append("|");
//SRSTPHSE --> Study Phase of first Observation, “PRE-DOSING”, “DOSING”, “RECOVERY”
retStr.append("");
retStr.append("|");
//SROBSTDY --> Start Phase Day of Observation
retStr.append("");
retStr.append("|");
//SRENPHSE -->Study Phase of last Observation
retStr.append("");
retStr.append("|");
//SRDOMAIN --> Domain of Finding
retStr.append(finding.getStudy_domain()==null?"":finding.getStudy_domain().getValue());
retStr.append("|");
//SRSPEC --> Specimen of Finding
retStr.append(finding.getSpecimen()==null?"":finding.getSpecimen().getValue());
retStr.append("|");
//SRTSTCD --> Test Short Name
retStr.append(finding.getStudy_testcd()==null?"":finding.getStudy_testcd().getValue());
retStr.append("|");
//SRFNDG --> Finding
retStr.append(finding.getFinding()==null?"":finding.getFinding().getValue());
retStr.append("|");
//SRORES --> Observation (original result)
retStr.append(finding.getFinding()==null?"":finding.getFinding().getValue());
retStr.append("|");
//SROBSV --> Manifestation of Finding, “I” (Increase), “D” (Decrease), “P” (Present) or “A” (Absent)
retStr.append(finding.getManifestation_finding()==null?"":finding.getManifestation_finding().getValue());
retStr.append("|");
//SROBSQ --> Observation Qualifier, “R” (Reversible), “T” (Transient) or ‘none’
retStr.append(finding.getObservation_qualification()==null?"":finding.getObservation_qualification().getValue());
retStr.append("|");
//SRSEV --> Severity of Finding
retStr.append("");
retStr.append("|");
//SRPCNT --> Scale of this Finding
retStr.append("");
retStr.append("|");
//SRSIGF --> Statistical Significance
retStr.append(finding.getStatistical_significance()==null?"":finding.getStatistical_significance().getValue());
retStr.append("|");
//SRTRTEF --> Treatment-Related
retStr.append(finding.getIs_treatment_related()==null?"":finding.getIs_treatment_related().getValue());
retStr.append("|");
//SRCOMNT --> Comment
retStr.append("\n");
for (Annotation relevantSentences : documentAnnotations.getRelevantSentences()) {
for (Finding finding : relevantSentences.getFindings()) {
if(finding.getSrDomainFindings()!=null) {
for (SRDomainFinding srDomainFinding : finding.getSrDomainFindings()) {
if(srDomainFinding.getExport()) {
//STUDYID -- > Study Identifier
retStr.append(id);
retStr.append("|");