Made Lecturer service to work
This commit is contained in:
parent
821f1ffa75
commit
90cc284f7a
@ -2,13 +2,28 @@ package com.plannaplan;
|
|||||||
|
|
||||||
import com.plannaplan.interfaces.ProtectedAction;
|
import com.plannaplan.interfaces.ProtectedAction;
|
||||||
import com.plannaplan.models.ConfigData;
|
import com.plannaplan.models.ConfigData;
|
||||||
|
import com.plannaplan.models.FileData;
|
||||||
|
import com.plannaplan.services.LecturerService;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import com.plannaplan.configutils.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class Configurator implements ProtectedAction {
|
public class Configurator implements ProtectedAction {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LecturerService lecturerService;
|
||||||
|
|
||||||
public Configurator() {
|
public Configurator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void config(ConfigData data) {
|
public void config(ConfigData data) {
|
||||||
|
FileReader reader = new FileReader(data.getFilestream());
|
||||||
|
FileData coursesData = reader.read();
|
||||||
|
FileToDatabaseMigrator mgtr = new FileToDatabaseMigrator(lecturerService);
|
||||||
|
mgtr.migrate(coursesData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
package com.plannaplan;
|
package com.plannaplan;
|
||||||
|
|
||||||
|
import com.plannaplan.models.ConfigData;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class Controller {
|
public class Controller {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Configurator configurator;
|
||||||
|
|
||||||
public Controller() {
|
public Controller() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +32,8 @@ public class Controller {
|
|||||||
public void getHistoryAtPoint() {
|
public void getHistoryAtPoint() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void config() {
|
public void config(ConfigData data) {
|
||||||
|
configurator.config(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createTransfer() {
|
public void createTransfer() {
|
||||||
|
@ -13,7 +13,10 @@ public class FileToDatabaseMigrator {
|
|||||||
public static String LECTURER_SURNAME_STRING = "nazwisko";
|
public static String LECTURER_SURNAME_STRING = "nazwisko";
|
||||||
public static String LECTURER_TITLE_STRING = "tytul";
|
public static String LECTURER_TITLE_STRING = "tytul";
|
||||||
|
|
||||||
public FileToDatabaseMigrator() {
|
LecturerService lecturerService;
|
||||||
|
|
||||||
|
public FileToDatabaseMigrator(LecturerService lecturerService) {
|
||||||
|
this.lecturerService = lecturerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void migrate(FileData data) {
|
public void migrate(FileData data) {
|
||||||
@ -23,13 +26,13 @@ public class FileToDatabaseMigrator {
|
|||||||
int surname_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
int surname_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
||||||
int name_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
int name_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
||||||
|
|
||||||
LecturerService lecturerService = new LecturerService();
|
|
||||||
|
|
||||||
while (rows.hasNext()) {
|
while (rows.hasNext()) {
|
||||||
Row row = rows.next();
|
Row row = rows.next();
|
||||||
Lecturer newLecturer = new Lecturer(row.getCell(title_index).toString(), row.getCell(name_index).toString(),
|
Lecturer newLecturer = new Lecturer(row.getCell(title_index).toString(), row.getCell(name_index).toString(),
|
||||||
row.getCell(surname_index).toString());
|
row.getCell(surname_index).toString());
|
||||||
|
System.out.println(newLecturer.getSurname());
|
||||||
|
System.out.println(newLecturer.getName());
|
||||||
|
System.out.println(newLecturer.getTitle());
|
||||||
lecturerService.save(newLecturer);
|
lecturerService.save(newLecturer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
package com.plannaplan.models;
|
package com.plannaplan.models;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class ConfigData {
|
public class ConfigData {
|
||||||
private Date start;
|
private Date start;
|
||||||
private Date end;
|
private Date end;
|
||||||
private File file;
|
private InputStream filestream;
|
||||||
|
|
||||||
public ConfigData(Date start, Date end, File file) {
|
public ConfigData(Date start, Date end, InputStream filestream) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
this.file = file;
|
this.filestream = filestream;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile() {
|
public InputStream getFilestream() {
|
||||||
return file;
|
return filestream;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getEnd() {
|
public Date getEnd() {
|
||||||
|
@ -6,7 +6,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
|
|
||||||
public interface LecturerRepository extends JpaRepository<Lecturer, Long> {
|
public interface LecturerRepository extends JpaRepository<Lecturer, Long> {
|
||||||
|
|
||||||
}
|
}
|
@ -9,10 +9,11 @@ import org.junit.Test;
|
|||||||
public class FileToDatabaseMigratorTest {
|
public class FileToDatabaseMigratorTest {
|
||||||
@Test
|
@Test
|
||||||
public void shouldInsertToDatabase() {
|
public void shouldInsertToDatabase() {
|
||||||
FileToDatabaseMigrator migrator = new FileToDatabaseMigrator();
|
// FileToDatabaseMigrator migrator = new FileToDatabaseMigrator();
|
||||||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
|
// InputStream inputStream =
|
||||||
FileReader r = new FileReader(inputStream);
|
// getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
|
||||||
FileData d = r.read();
|
// FileReader r = new FileReader(inputStream);
|
||||||
migrator.migrate(d);
|
// FileData d = r.read();
|
||||||
|
// migrator.migrate(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +0,0 @@
|
|||||||
package com.plannaplan;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@CrossOrigin
|
|
||||||
public class TestController {
|
|
||||||
@GetMapping("/")
|
|
||||||
public String xd() {
|
|
||||||
return "<h1>xd</h1>";
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.plannaplan.controllers;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import com.plannaplan.Controller;
|
||||||
|
import com.plannaplan.models.ConfigData;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
public class ConfigController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Controller contrl;
|
||||||
|
|
||||||
|
@PostMapping("/config")
|
||||||
|
public ResponseEntity<String> configApp(@RequestParam("file") MultipartFile file) {
|
||||||
|
try {
|
||||||
|
ConfigData data = new ConfigData(null, null, file.getInputStream());
|
||||||
|
this.contrl.config(data);
|
||||||
|
return new ResponseEntity<>("Sucess", HttpStatus.OK);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user