|
@@ -2,12 +2,14 @@ package es.uv.garcosda.services;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Scanner;
|
|
import java.util.Scanner;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.core.io.Resource;
|
|
import org.springframework.core.io.Resource;
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
|
|
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
@@ -16,6 +18,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
import es.uv.garcosda.domain.Document;
|
|
import es.uv.garcosda.domain.Document;
|
|
|
|
+import es.uv.garcosda.domain.MyUser;
|
|
import reactor.core.publisher.Flux;
|
|
import reactor.core.publisher.Flux;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -23,6 +26,9 @@ public class ImportService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private NewsService ns;
|
|
private NewsService ns;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserService us;
|
|
|
|
|
|
private List<Document> generateDocs(List<String> lines) throws JsonMappingException, JsonProcessingException {
|
|
private List<Document> generateDocs(List<String> lines) throws JsonMappingException, JsonProcessingException {
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
@@ -48,6 +54,15 @@ public class ImportService {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void insertUsers() {
|
|
|
|
+ List<MyUser> users = new ArrayList<MyUser>(
|
|
|
|
+ Arrays.asList(new MyUser("user", "user", new BCryptPasswordEncoder().encode("1234"), "ROLE_USER") ,
|
|
|
|
+ new MyUser("admin", "admin", new BCryptPasswordEncoder().encode("1234"), "ROLE_ADMIN")));
|
|
|
|
+ for(MyUser u : users) {
|
|
|
|
+ this.us.insert(u).block();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
public int doImport(Resource resource) throws JsonMappingException, JsonProcessingException {
|
|
public int doImport(Resource resource) throws JsonMappingException, JsonProcessingException {
|
|
ArrayList<String> jsonlines = new ArrayList<>();
|
|
ArrayList<String> jsonlines = new ArrayList<>();
|
|
@@ -60,6 +75,7 @@ public class ImportService {
|
|
System.out.println("[ERROR] data file not found");
|
|
System.out.println("[ERROR] data file not found");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ this.insertUsers();
|
|
List<Document> docs = generateDocs(jsonlines);
|
|
List<Document> docs = generateDocs(jsonlines);
|
|
return insert(docs);
|
|
return insert(docs);
|
|
}
|
|
}
|