|
@@ -0,0 +1,65 @@
|
|
|
+package es.uv.garcosda.services;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import es.uv.garcosda.domain.Document;
|
|
|
+import es.uv.garcosda.domain.Notification;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class DocumentService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ NotificationService ns;
|
|
|
+
|
|
|
+ private List<Document> documents;
|
|
|
+ private Random rd;
|
|
|
+
|
|
|
+ public DocumentService() {
|
|
|
+ this.documents = new ArrayList<Document>();
|
|
|
+ this.rd = new Random();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Document> findAll(){
|
|
|
+ return this.documents;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Document> findByOwner(String owner) {
|
|
|
+ return this.documents.stream().filter(x -> x.getOwner().toLowerCase().equals(owner.toLowerCase())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean add(Document document) {
|
|
|
+ this.compute(document);
|
|
|
+ boolean n = this.documents.add(document);
|
|
|
+ return n;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void compute(Document document) {
|
|
|
+ try {
|
|
|
+ //Thread.sleep(this.rd.ints(20, 62).findFirst().getAsInt() * 1000);
|
|
|
+ Thread.sleep(1 * 1000);
|
|
|
+ }
|
|
|
+ catch (InterruptedException ie) {
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ }
|
|
|
+
|
|
|
+ Notification n;
|
|
|
+ if(this.rd.nextBoolean()){
|
|
|
+ n = new Notification("Fraud found in document owned by "+document.getOwner(), true, LocalDate.now(), document);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ n = new Notification("No fraud found in document owned by "+document.getOwner(), false, LocalDate.now(), document);
|
|
|
+ }
|
|
|
+ this.ns.add(n);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|