diff --git a/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java b/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java index 0f9f033..44af1f6 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java +++ b/buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java @@ -92,8 +92,12 @@ public class FileToDatabaseMigrator { .orElseGet(() -> this.lecturerService .save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname))); - this.groupService.find(zajCykId, grNr).orElseGet( - () -> this.groupService.save(new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr))); + Groups group = this.groupService.find(zajCykId, grNr).orElseGet( + () -> new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr)); + + group.update(capacity, room, course, time, null, groupDay, lecturer); + + this.groupService.save(group); } diff --git a/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java b/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java index c6bbf4e..e26ce6a 100755 --- a/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java +++ b/buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java @@ -130,6 +130,47 @@ public class Groups { this(capacity, room, course, time, time + DEFAULT_CLASS_TIME, day, lecturer); } + /** + * Updates given values other that are not null + * + * @param capacity capacity given to the groups + * @param room room given to the groups + * @param course course given to the groups + * @param time time given to the groups + * @param endTime end time of class in minutes + * @param day day given to the groups + * @param lecturer lecturer given to the groups + */ + public void update(Integer capacity, String room, Course course, Integer time, Integer endTime, WeekDay day, Lecturer lecturer){ + if (capacity != null){ + this.capacity = capacity; + } + + if (room != null){ + this.room = room; + } + + if (course != null){ + this.course = course; + } + + if (time != null){ + this.time = time; + } + + if (endTime != null){ + this.endTime = endTime; + } + + if (day != null){ + this.day = day; + } + + if (lecturer != null){ + this.lecturer = lecturer; + } + } + /** * get time of class end * diff --git a/buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java b/buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java index 0190b2c..d69754d 100755 --- a/buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java @@ -2,6 +2,8 @@ package com.plannaplan.services; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.annotation.DirtiesContext.MethodMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -9,9 +11,11 @@ import static org.junit.Assert.assertTrue; import java.io.InputStream; import java.sql.Date; +import java.util.Optional; import com.plannaplan.TestApplication; import com.plannaplan.entities.AppConfig; +import com.plannaplan.entities.Groups; import com.plannaplan.models.ConfigData; import com.plannaplan.models.TourData; import com.plannaplan.repositories.AppConfigRepository; @@ -24,6 +28,9 @@ import org.junit.runner.RunWith; @ContextConfiguration public class ConfiguratorServiceTest { + private final static String BEFORE_UPDATE_FILE = "ZajeciaBeforeUpdate.xlsx"; + private final static String AFTER_UPDATE_FILE = "ZajeciaAfterUpdate.xlsx"; + @Autowired private ConfiguratorService configuratorService; @@ -57,6 +64,31 @@ public class ConfiguratorServiceTest { assertTrue(courses_ammount > 0 && groups_ammount > 0 && lecturers_ammount > 0); } + @Test + @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD) + public void shouldUpdatePreviousImport(){ + final InputStream inputStream = getClass().getClassLoader() + .getResourceAsStream(ConfiguratorServiceTest.BEFORE_UPDATE_FILE); + this.configuratorService.importCoursesStream(inputStream); + int groups_ammount = this.groupService.getGroupsAmmount(); + + assertTrue(groups_ammount == 2); + + final InputStream inputStream2 = getClass().getClassLoader() + .getResourceAsStream(ConfiguratorServiceTest.AFTER_UPDATE_FILE); + this.configuratorService.importCoursesStream(inputStream2); + int groups_ammount2 = this.groupService.getGroupsAmmount(); + + Optional newGroup = this.groupService.find(456458, 3); + Optional updateGroup = this.groupService.find(456457, 2); + + assertTrue(groups_ammount2 == 3); + assertTrue(newGroup.isPresent()); + assertTrue(updateGroup.get().getLecturer().getSurname().equals("Murawski")); + assertTrue(updateGroup.get().getLecturer().getName().equals("Roman")); + assertTrue(updateGroup.get().getLecturer().getTitle().equals("prof. dr hab.")); + } + @Test public void shouldRetrunNewestConfig() throws InterruptedException { final Date dateToCheck = new Date(System.currentTimeMillis()); diff --git a/buisnesslogic/src/test/resources/ZajeciaAfterUpdate.xlsx b/buisnesslogic/src/test/resources/ZajeciaAfterUpdate.xlsx new file mode 100644 index 0000000..bb3d360 Binary files /dev/null and b/buisnesslogic/src/test/resources/ZajeciaAfterUpdate.xlsx differ diff --git a/buisnesslogic/src/test/resources/ZajeciaBeforeUpdate.xlsx b/buisnesslogic/src/test/resources/ZajeciaBeforeUpdate.xlsx new file mode 100644 index 0000000..15b7367 Binary files /dev/null and b/buisnesslogic/src/test/resources/ZajeciaBeforeUpdate.xlsx differ