1717package de .doubleslash .keeptime .view ;
1818
1919import de .doubleslash .keeptime .controller .Controller ;
20+ import de .doubleslash .keeptime .controller .HeimatController ;
2021import de .doubleslash .keeptime .model .ExternalProjectMapping ;
2122import de .doubleslash .keeptime .model .ExternalSystem ;
2223import de .doubleslash .keeptime .model .Model ;
4344import java .time .LocalDate ;
4445import java .util .ArrayList ;
4546import java .util .List ;
47+ import java .util .Objects ;
4648import java .util .Optional ;
4749import java .util .stream .Collectors ;
4850
@@ -53,7 +55,7 @@ public class MapExternalProjectsController {
5355
5456 private final Model model ;
5557 private final Controller controller ;
56- private final HeimatSettings heimatSettings ;
58+ private final HeimatController heimatController ;
5759 private final ExternalProjectsMappingsRepository externalProjectsMappingsRepository ;
5860
5961 private Stage thisStage ;
@@ -76,11 +78,11 @@ public class MapExternalProjectsController {
7678 @ FXML
7779 private DatePicker tasksForDateDatePicker ;
7880
79- public MapExternalProjectsController (final Model model , Controller controller , HeimatSettings heimatSettings ,
81+ public MapExternalProjectsController (final Model model , Controller controller , HeimatController heimatController ,
8082 ExternalProjectsMappingsRepository externalProjectsMappingsRepository ) {
8183 this .model = model ;
8284 this .controller = controller ;
83- this .heimatSettings = heimatSettings ;
85+ this .heimatController = heimatController ;
8486 this .externalProjectsMappingsRepository = externalProjectsMappingsRepository ;
8587 }
8688
@@ -95,8 +97,7 @@ private void initialize() {
9597 // TODO add listener on this thing
9698 // but what happens with mapped projects not existing at that date? but actually not related to this feature alone
9799
98- final HeimatAPI heimatAPI = new HeimatAPI (heimatSettings .getHeimatUrl (), heimatSettings .getHeimatPat ());
99- final List <HeimatTask > allExternalProjects = heimatAPI .getMyTasks (tasksForDateDatePicker .getValue ());
100+ final List <HeimatTask > allExternalProjects = heimatController .getTasks (tasksForDateDatePicker .getValue ());
100101 final List <HeimatTask > externalProjects = allExternalProjects .stream ()
101102 .filter (p -> !p .isStartAndEndTimeRequired ())
102103 .collect (Collectors .toCollection (ArrayList ::new ));
@@ -249,6 +250,10 @@ protected void updateItem(HeimatTask item, boolean empty) {
249250 final HeimatTask heimatTask = projectMapping .getHeimatTask ();
250251 if (any .isPresent ()) {
251252 final ExternalProjectMapping projectMapping1 = any .get ();
253+ if (projectMapping1 .getExternalTaskId () == heimatTask .id ()){
254+ // mapping did not change
255+ return null ;
256+ }
252257 projectMapping1 .setExternalProjectName (
253258 heimatTask .taskHolderName ());
254259 projectMapping1 .setExternalTaskId (
@@ -257,6 +262,7 @@ protected void updateItem(HeimatTask item, boolean empty) {
257262 heimatTask .name ());
258263 projectMapping1 .setExternalTaskMetadata (
259264 heimatTask .toString ()); // TODO to json
265+
260266 return projectMapping1 ;
261267 }
262268 return new ExternalProjectMapping (
@@ -268,9 +274,8 @@ protected void updateItem(HeimatTask item, boolean empty) {
268274 // TODO to json
269275 ,
270276 projectMapping .project );
271- })
277+ }). filter ( Objects :: nonNull )
272278 .toList ();
273- // TODO the list also contains unchanged mappings
274279 externalProjectsMappingsRepository .saveAll (mappingsToCreateOrUpdate );
275280
276281 // remove mappings which were removed also from database
0 commit comments