@@ -171,28 +171,15 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
171171 if (optionalExistingMapping .isPresent ()) {
172172 final Mapping existingMapping = optionalExistingMapping .get ();
173173
174- // Ensure we merge projects robustly: include any projects mapped to the same Heimat task
174+ // Only include projects that were actually worked on at this date
175175 final ArrayList <Project > projects = new ArrayList <>(existingMapping .projects ());
176- if (optHeimatMapping .isPresent ()) {
177- final long mappedTaskId = optHeimatMapping .get ().getExternalTaskId ();
178- final List <Project > allMappedForTask = mappedProjects .stream ()
179- .filter (
180- mp -> mp .getExternalTaskId () == mappedTaskId )
181- .map (ExternalProjectMapping ::getProject )
182- .toList ();
183- for (Project p : allMappedForTask ) {
184- boolean alreadyContains = projects .stream ().anyMatch (pp -> pp .getId () == p .getId ());
185- if (!alreadyContains ) {
186- projects .add (p );
187- }
188- }
189- } else {
190- // fallback: ensure current project is present
191- boolean alreadyContains = projects .stream ().anyMatch (p -> p .getId () == project .getId ());
192- if (!alreadyContains ) {
193- projects .add (project );
194- }
176+ // Ensure current project is present (it's already in workedProjectsSet, so it was worked on)
177+ boolean alreadyContains = projects .stream ().anyMatch (p -> p .getId () == project .getId ());
178+ if (!alreadyContains ) {
179+ projects .add (project );
195180 }
181+ // Filter to only keep projects that were actually worked on
182+ projects .removeIf (p -> !workedProjectsSet .contains (p ));
196183
197184 final long keepTimeSeconds = existingMapping .keeptimeSeconds () + projectWorkSeconds ;
198185 final long heimatSeconds = existingMapping .heimatSeconds ();
@@ -214,15 +201,14 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
214201 list .remove (existingMapping );
215202 list .add (mapping );
216203 } else {
217- // FIX: when creating a new mapping row for a project that is mapped to a Heimat task,
218- // include ALL Projects that are mapped to the same Heimat task so that projects without
219- // KeepTime entries (no worked time) are also shown in the same row (case 4).
204+ // Only include projects that were actually worked on at this date
220205 final List <Project > projects ;
221206 if (optHeimatMapping .isPresent ()) {
222207 final long mappedTaskId = optHeimatMapping .get ().getExternalTaskId ();
223208 projects = mappedProjects .stream ()
224209 .filter (mp -> mp .getExternalTaskId () == mappedTaskId )
225210 .map (ExternalProjectMapping ::getProject )
211+ .filter (workedProjectsSet ::contains )
226212 .collect (Collectors .toList ());
227213 } else {
228214 projects = Collections .singletonList (project );
@@ -256,9 +242,12 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
256242 taskName = heimatTask .name () + "\n " + heimatTask .taskHolderName ();
257243 }
258244
259- final Mapping mapping = new Mapping (id , true , false ,
260- StyledMessage .of (new StyledMessage .TextSegment ("Not mapped in KeepTime\n \n " + taskName )), "" , times ,
245+ // Build sync message with task name in bold
246+ StyledMessage syncMessage = StyledMessage .of (
247+ new StyledMessage .TextSegment ("Not mapped in KeepTime\n \n " ),
248+ new StyledMessage .TextSegment (taskName , true ));
261249
250+ final Mapping mapping = new Mapping (id , true , false , syncMessage , "" , times ,
262251 new ArrayList <>(0 ), heimatNotes , "" , heimatTimeSeconds , 0 );
263252 list .add (mapping );
264253 });
@@ -281,23 +270,8 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
281270 long heimatTimeSeconds = addHeimatTimes (times );
282271
283272 final Optional <Mapping > existingMappingInList = list .stream ().filter (m -> m .heimatTaskId == id ).findAny ();
273+ // If there's already a mapping from worked-on projects, don't add non-worked projects to it
284274 if (existingMappingInList .isPresent ()) {
285- Mapping existing = existingMappingInList .get ();
286- // only add if not already present
287- boolean alreadyContains = existing .projects ()
288- .stream ()
289- .anyMatch (
290- p -> p .getId () == externalProjectMapping .getProject ().getId ());
291- if (!alreadyContains ) {
292- ArrayList <Project > newProjects = new ArrayList <>(existing .projects ());
293- newProjects .add (externalProjectMapping .getProject ());
294- Mapping updated = new Mapping (existing .heimatTaskId , existing .canBeSynced , existing .shouldBeSynced ,
295- existing .syncMessage , existing .bookingHint , existing .existingTimes , newProjects ,
296- existing .heimatNotes , existing .keeptimeNotes , existing .heimatSeconds , existing .keeptimeSeconds );
297- list .remove (existing );
298- list .add (updated );
299- }
300- // skip creating a separate entry
301275 continue ;
302276 }
303277
0 commit comments