Commit 301490df authored by Javi Corvi's avatar Javi Corvi
Browse files

Merge branch 'develop' of

https://gitlab.bsc.es/inb/etransafe/pretox-rest-api.git into develop

Conflicts:
	src/main/java/es/bsc/inb/ades/rest/api/controllers/DocumentController.java
	src/main/resources/application.properties
parents 6af263f0 7b756ea2
Pipeline #25590 passed with stage
in 3 seconds
......@@ -15,6 +15,9 @@ 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.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;
......@@ -36,6 +39,11 @@ public class DocumentController {
return documentService.findDocumentAnnotationsByDocumentId(id);
}
@RequestMapping("/document_data/{id}")
public Document findDocument(@PathVariable(value="id") Long id) {
return documentService.findByDocumentId(id);
}
@RequestMapping("/documents/{id}/srdomain")
public DocumentAnnotations findDocumentSRDomain(@PathVariable(value="id") Long id) {
return documentService.findDocumentSRDomainByDocumentId(id);
......@@ -59,6 +67,12 @@ public class DocumentController {
return "";
}
@RequestMapping("/documents/{id}/move/{status}")
public String moveDocument(@PathVariable(value="id") Long id, @PathVariable(value="status") Status status) {
documentService.moveDocument(id, status);
return "true";
}
@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);
......@@ -101,5 +115,11 @@ public class DocumentController {
head.setCacheControl("must-revalidate, post-check=0, pre-check=0");
return new ResponseEntity<>(content, head,HttpStatus.OK);
}
@RequestMapping("/documents/{id}/tracking")
public DocumentTracking findTrackings(@PathVariable(value="id") Long id) {
return documentService.findTrackings(id);
}
}
\ No newline at end of file
package es.bsc.inb.ades.rest.api.model;
public enum Action {
MOVE, REJECT, ACCEPT, EXPORT_SR_FINDING, NOT_EXPORT_SR_FINDING
}
\ No newline at end of file
......@@ -23,8 +23,8 @@ public class Document{
private String processDate;
private String fileName;
private List<Finding> findings;
private Status status;
public Document() {
super();
......@@ -63,22 +63,15 @@ public class Document{
this.name = name;
}
public List<Finding> getFindings() {
return findings;
public Status getStatus() {
if(status==null)return Status.DRAFT;
return status;
}
public void setFindings(List<Finding> findings) {
this.findings = findings;
public void setStatus(Status status) {
this.status = status;
}
public String getProcessDate() {
return processDate;
}
......
......@@ -5,7 +5,6 @@ import java.util.List;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Field;
@org.springframework.data.mongodb.core.mapping.Document(collection="annotations")
public class DocumentAnnotations {
......@@ -25,7 +24,9 @@ public class DocumentAnnotations {
private ArrayList<Finding> findings;
private List<SRDomainFinding> srdomainfindings;
private Status status;
public DocumentAnnotations() {}
public ObjectId get_id() {
......@@ -77,6 +78,16 @@ public class DocumentAnnotations {
this.srdomainfindings = srdomainfindings;
}
public Status getStatus() {
if(status==null)return Status.DRAFT;
return status;
}
public void setStatus(Status status) {
this.status = status;
}
}
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;
import org.springframework.data.mongodb.core.mapping.Field;
@org.springframework.data.mongodb.core.mapping.Document(collection="tracking")
public class DocumentTracking {
@Field("_id")
@Id
private ObjectId _id;
@Field("id")
private Long documentId;
List<Tracking> trackings;
public DocumentTracking() {
super();
}
public DocumentTracking(Long documentId) {
this.documentId=documentId;
this.trackings = new ArrayList<Tracking>();
}
public void addTracking(Tracking tracking) {
if(trackings==null) {
trackings = new ArrayList<Tracking>();
}
trackings.add(tracking);
}
public Long getDocumentId() {
return documentId;
}
public void setDocumentId(Long documentId) {
this.documentId = documentId;
}
public List<Tracking> getTrackings() {
return trackings;
}
public void setTrackings(List<Tracking> trackings) {
this.trackings = trackings;
}
}
\ No newline at end of file
......@@ -432,6 +432,12 @@ public class Finding {
public void setSrDomainFindings(List<SRDomainFinding> srDomainFindings) {
this.srDomainFindings = srDomainFindings;
}
public String getTrackingSummary() {
return findingId.toString();
}
......
......@@ -227,5 +227,9 @@ public class SRDomainFinding implements Cloneable{
}
return null;
}
public String getTrackingSummary() {
String summary = SRSEQ ;
return summary;
}
}
package es.bsc.inb.ades.rest.api.model;
public enum Status {
DRAFT, IN_PROGRESS, FINISHED, CLOSED
}
package es.bsc.inb.ades.rest.api.model;
import java.util.Date;
public class Tracking {
private Date date;
private String userName;
private Action action;
private String comment;
public Tracking() {
super();
}
public Tracking(String userName, Action action, String comment) {
super();
this.date=new Date();
this.userName = userName;
this.action = action;
this.comment = comment;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Action getAction() {
return action;
}
public void setAction(Action action) {
this.action = action;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
package es.bsc.inb.ades.rest.api.repository;
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;
......
......@@ -9,11 +9,9 @@ import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.MatchOperation;
import org.springframework.data.mongodb.core.aggregation.ProjectionOperation;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
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;
......@@ -34,6 +32,7 @@ public class DocumentRepositoryImpl implements DocumentRepositoryCustom{
query.fields().include("fileName");
query.fields().include("name");
query.fields().include("processDate");
query.fields().include("status");
Sort sort = new Sort(Sort.Direction.ASC, "name");
query.with(sort);
List<Document> documents = mongoTemplate.find(query, Document.class);
......
package es.bsc.inb.ades.rest.api.repository;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import es.bsc.inb.ades.rest.api.model.DocumentTracking;
@Repository
public interface DocumentTrackingRepository extends DocumentTrackingRepositoryCustom, MongoRepository<DocumentTracking, String> {
DocumentTracking findByDocumentId(Long documentId);
}
package es.bsc.inb.ades.rest.api.repository;
public interface DocumentTrackingRepositoryCustom {
}
......@@ -4,6 +4,9 @@ import java.util.List;
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 {
......@@ -31,4 +34,8 @@ public interface DocumentService {
Boolean setExportSRDomainFinding(Long id, Integer findingId, Boolean export_srdomain);
Boolean setFindingValidation(Long id, Integer findingId,String status);
Status moveDocument(Long id, Status status);
DocumentTracking findTrackings(Long documentId);
}
package es.bsc.inb.ades.rest.api.services;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import com.google.gson.Gson;
......@@ -24,13 +15,18 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import es.bsc.inb.ades.rest.api.model.Action;
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.DocumentTracking;
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.model.Status;
import es.bsc.inb.ades.rest.api.model.Tracking;
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.repository.DocumentTrackingRepository;
import es.bsc.inb.ades.rest.api.util.Constants;
......@@ -45,6 +41,9 @@ public class DocumentServiceImpl implements DocumentService {
@Autowired
public DocumentAnnotationsRepository documentAnnotationsRepository;
@Autowired
public DocumentTrackingRepository documentTrackingRepository;
static final Map<String, String> ANNOTATION_CLASS_STYLE = createMap();
public List<Document> findAll() {
......@@ -108,7 +107,7 @@ public class DocumentServiceImpl implements DocumentService {
}
@Override
public Boolean setFindingValidation(Long id, Integer findingId,String status) {
public Boolean setFindingValidation(Long id, Integer findingId, String status) {
DocumentAnnotations documentAnnotations = this.findDocumentAnnotationsByDocumentId(id);
Finding findingSelected = null;
for (Annotation annotation : documentAnnotations.getRelevantSentences()) {
......@@ -123,6 +122,7 @@ public class DocumentServiceImpl implements DocumentService {
//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 false;
......@@ -147,6 +147,7 @@ public class DocumentServiceImpl implements DocumentService {
//https://stackoverflow.com/questions/47699646/updating-replacing-a-deeply-nested-object-in-mongodb-with-spring-data-mongodb
sRDomainFindingSelected.setExport(export_srdomainfinding);
documentAnnotationsRepository.save(documentAnnotations);
createTracking(id, "admin", export_srdomainfinding?Action.EXPORT_SR_FINDING:Action.NOT_EXPORT_SR_FINDING, sRDomainFindingSelected.getTrackingSummary());
return true;
}
return false;
......@@ -718,6 +719,41 @@ public class DocumentServiceImpl implements DocumentService {
return Collections.unmodifiableMap(result);
}
@Override
public Status moveDocument(Long id, Status status) {
Document document = this.findByDocumentId(id);
DocumentAnnotations documentAnnotation = this.findDocumentAnnotationsByDocumentId(id);
document.setStatus(status);
documentAnnotation.setStatus(status);
documentRepository.save(document);
documentAnnotationsRepository.save(documentAnnotation);
createTracking(id, "admin", Action.MOVE, status.toString());
return status;
}
private void createTracking(Long id, String userName , Action action, String comment) {
DocumentTracking documentTracking = this.findDocumentTrackingById(id);
Tracking tracking = new Tracking (userName, action, comment);
documentTracking.addTracking(tracking);
documentTrackingRepository.save(documentTracking);
}
private DocumentTracking findDocumentTrackingById(Long id) {
DocumentTracking documentTracking = documentTrackingRepository.findByDocumentId(id);
if(documentTracking==null) {
documentTracking = new DocumentTracking(id);
}
return documentTracking;
}
public DocumentTracking findTrackings(Long documentId) {
DocumentTracking documentTracking = this.findDocumentTrackingById(documentId);
return documentTracking;
}
}
......@@ -5,7 +5,7 @@ server.servlet.context-path=/pretoxapi
server.port = 8090
#ADES Database
#spring.data.mongodb.uri=mongodb://localhost:27017/etransafe
spring.data.mongodb.uri=mongodb://etransafe_rw:etransafe_rw2019!@mdb-login.bsc.es:27017/etransafe
spring.data.mongodb.uri=mongodb://REMOVED!REMOVED:REMOVED/REMOVED
#development enviroment
#docker run -d -p 27017-27019:27017-27019 -v /home/javi/eTRANSAFE_DATA/mongo-data-dev://data/db --name mongodb mongo:4.0.4
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment