@@ -44,9 +44,7 @@ public HeimatController(HeimatAPI heimatAPI, ExternalProjectsMappingsRepository
4444 }
4545
4646 public List <Mapping > getTableRows (final LocalDate currentReportDate , final List <Work > currentWorkItems ) {
47- // TODO check if external projects are available for the currentDay
4847 final List <HeimatTask > heimatTasks = heimatAPI .getMyTasks (currentReportDate );
49-
5048 final List <HeimatTime > heimatTimes = heimatAPI .getMyTimes (currentReportDate );
5149 final List <ExternalProjectMapping > mappedProjects = externalProjectsMappingsRepository .findByExternalSystemId (
5250 ExternalSystem .Heimat );
@@ -63,20 +61,20 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
6361 String heimatNotes = "" ;
6462 long heimatTimeSeconds = 0 ;
6563 boolean isMappedInHeimat = false ;
66- final Optional <ExternalProjectMapping > heimatMappings = mappedProjects .stream ()
64+ final Optional <ExternalProjectMapping > optHeimatMapping = mappedProjects .stream ()
6765 .filter (mp -> mp .getProject ().getId ()
6866 == project .getId ())
6967 .findAny ();
7068 List <HeimatTime > optionalAlreadyBookedTimes = new ArrayList <>();
7169 Optional <Mapping > optionalExistingMapping = Optional .empty ();
72- if (heimatMappings .isPresent ()) {
70+ if (optHeimatMapping .isPresent ()) {
7371 isMappedInHeimat = true ;
7472 optionalExistingMapping = list .stream ()
75- .filter (mapping -> mapping .heimatTaskId == heimatMappings .get ()
73+ .filter (mapping -> mapping .heimatTaskId == optHeimatMapping .get ()
7674 .getExternalTaskId ())
7775 .findAny ();
7876 optionalAlreadyBookedTimes = heimatTimes .stream ()
79- .filter (heimatTime -> heimatMappings .stream ()
77+ .filter (heimatTime -> optHeimatMapping .stream ()
8078 .anyMatch (
8179 hm -> heimatTime .taskId ()
8280 == hm .getExternalTaskId ()))
@@ -105,11 +103,11 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
105103 String canBeSynced ;
106104 if (!isMappedInHeimat ) {
107105 canBeSynced = "Not mapped in Heimat" ;
108- } else if (heimatTasks .stream ().noneMatch (ht -> ht .id () == heimatMappings .get ().getExternalTaskId ())) {
106+ } else if (heimatTasks .stream ().noneMatch (ht -> ht .id () == optHeimatMapping .get ().getExternalTaskId ())) {
109107 canBeSynced = "Heimat Task is no longer available." ;
110108 isMappedInHeimat = false ;
111109 } else {
112- final ExternalProjectMapping externalProjectMapping = heimatMappings .get ();
110+ final ExternalProjectMapping externalProjectMapping = optHeimatMapping .get ();
113111 canBeSynced = "Sync to " + externalProjectMapping .getExternalTaskName () + "("
114112 + externalProjectMapping .getExternalProjectName () + ")" ;
115113 }
@@ -118,7 +116,7 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
118116 final Mapping existingMapping = optionalExistingMapping .get ();
119117 final ArrayList <Project > projects = new ArrayList <>(existingMapping .projects ());
120118 projects .add (project );
121- final Mapping mapping = new Mapping (isMappedInHeimat ? heimatMappings .get ().getExternalTaskId () : -1 ,
119+ final Mapping mapping = new Mapping (isMappedInHeimat ? optHeimatMapping .get ().getExternalTaskId () : -1 ,
122120 isMappedInHeimat , canBeSynced , existingMapping .existingTimes (), projects ,
123121 existingMapping .heimatNotes (),
124122 existingMapping .keeptimeNotes () + ". " + keeptimeNotes ,
@@ -128,13 +126,27 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
128126 list .add (mapping );
129127 } else {
130128 final List <Project > projects = Collections .singletonList (project );
131- final Mapping mapping = new Mapping (isMappedInHeimat ? heimatMappings .get ().getExternalTaskId () : -1 ,
129+ final Mapping mapping = new Mapping (isMappedInHeimat ? optHeimatMapping .get ().getExternalTaskId () : -1 ,
132130 isMappedInHeimat , canBeSynced , optionalAlreadyBookedTimes , projects , heimatNotes , keeptimeNotes ,
133131 heimatTimeSeconds , projectWorkSeconds );
134132 list .add (mapping );
135133 }
136134 }
137-
135+ final List <Long > mappedIds = mappedProjects .stream ().map (ExternalProjectMapping ::getExternalTaskId ).toList ();
136+ final Map <Long , List <HeimatTime >> notMappedExistingTimes = heimatTimes .stream ().filter (ht -> !mappedIds .contains (ht .taskId ())).collect (
137+ Collectors .groupingBy (HeimatTime ::taskId ));
138+ notMappedExistingTimes .forEach ((id , times )->{
139+ String heimatNotes = times .stream ()
140+ .map (HeimatTime ::note )
141+ .collect (Collectors .joining (". " ));
142+ long heimatTimeSeconds = times .stream ()
143+ .reduce (0L , (subtotal , element ) -> subtotal
144+ + element .durationInMinutes () * 60L , Long ::sum );
145+ final Mapping mapping = new Mapping (id ,
146+ false , "Not mapped in KeepTime" , times , new ArrayList <>(0 ), heimatNotes , "" ,
147+ heimatTimeSeconds , 0 );
148+ list .add (mapping );
149+ });
138150 return list ;
139151 }
140152
0 commit comments