@@ -27,16 +27,16 @@ public class HeimatController {
2727 private final Controller controller ;
2828 private final HeimatSettings heimatSettings ;
2929 private final ExternalProjectsMappingsRepository externalProjectsMappingsRepository ;
30- private final HeimatAPI heimatAPI ;
30+
31+ private HeimatAPI heimatAPI ;
3132
3233 @ Autowired
3334 public HeimatController (HeimatSettings heimatSettings ,
3435 ExternalProjectsMappingsRepository externalProjectsMappingsRepository , final Controller controller ) {
3536 this .heimatSettings = heimatSettings ;
3637 this .controller = controller ;
3738 this .externalProjectsMappingsRepository = externalProjectsMappingsRepository ;
38-
39- heimatAPI = new HeimatAPI (heimatSettings .getHeimatUrl (), heimatSettings .getHeimatPat ());
39+ this .heimatAPI = new HeimatAPI (heimatSettings .getHeimatUrl (), heimatSettings .getHeimatPat ());
4040 }
4141
4242 // for testing only
@@ -48,6 +48,24 @@ public HeimatController(HeimatSettings heimatSettings,
4848 this .heimatAPI = heimatAPI ;
4949 }
5050
51+ /**
52+ * can be called when heimat settings have changed
53+ */
54+ public void refreshConnection () {
55+ heimatAPI = new HeimatAPI (heimatSettings .getHeimatUrl (), heimatSettings .getHeimatPat ());
56+ }
57+
58+ /**
59+ * throws SecurityException when login or url is not valid
60+ */
61+ public void tryLogin () {
62+ try {
63+ heimatAPI .isLoginValid ();
64+ } catch (Exception e ) {
65+ throw new SecurityException ("Could not connect to HEIMAT API. Maybe wrong configuration?" , e );
66+ }
67+ }
68+
5169 public List <Mapping > getTableRows (final LocalDate currentReportDate , final List <Work > currentWorkItems ) {
5270 final List <HeimatTask > heimatTasks = heimatAPI .getMyTasks (currentReportDate );
5371 final List <HeimatTime > heimatTimes = heimatAPI .getMyTimes (currentReportDate );
@@ -62,7 +80,8 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
6280 .collect (Collectors .toCollection (() -> new TreeSet <>(
6381 Comparator .comparing (Project ::getIndex ))));
6482 final Map <Long , List <HeimatTime >> taskIdToHeimatTimesMap = heimatTimes .stream ()
65- .collect (Collectors .groupingBy (HeimatTime ::taskId ));
83+ .collect (Collectors .groupingBy (
84+ HeimatTime ::taskId ));
6685
6786 for (final Project project : workedProjectsSet ) {
6887 String heimatNotes = "" ;
@@ -83,7 +102,7 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
83102
84103 final List <HeimatTime > heimatTimesForTaskId = taskIdToHeimatTimesMap .get (
85104 optHeimatMapping .get ().getExternalTaskId ());
86- if (heimatTimesForTaskId != null ) {
105+ if (heimatTimesForTaskId != null ) {
87106 optionalAlreadyBookedTimes = heimatTimesForTaskId ;
88107 }
89108 if (!optionalAlreadyBookedTimes .isEmpty ()) {
@@ -155,10 +174,9 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
155174 list .add (mapping );
156175 });
157176
158- taskIdToHeimatTimesMap .forEach ((id ,times ) -> {
177+ taskIdToHeimatTimesMap .forEach ((id , times ) -> {
159178 final Optional <ExternalProjectMapping > mapping = mappedProjects .stream ()
160- .filter (mp -> mp .getExternalTaskId ()
161- == id )
179+ .filter (mp -> mp .getExternalTaskId () == id )
162180 .findAny ();
163181 if (mapping .isEmpty ())
164182 return ;
@@ -176,9 +194,13 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
176194
177195 final Mapping mapping2 = new Mapping (id , true ,
178196 "Present in HEIMAT but not KeepTime\n \n " + externalProjectMapping .getExternalTaskName () + "\n "
179- + externalProjectMapping .getExternalProjectName (), times ,
180- mappedProjects .stream ().filter (mp ->mp .getExternalTaskId () == id ).map (
181- ExternalProjectMapping ::getProject ).toList (), heimatNotes , "" , heimatTimeSeconds , 0 );
197+ + externalProjectMapping .getExternalProjectName (), times , mappedProjects .stream ()
198+ .filter (
199+ mp -> mp .getExternalTaskId ()
200+ == id )
201+ .map (ExternalProjectMapping ::getProject )
202+ .toList (), heimatNotes , "" ,
203+ heimatTimeSeconds , 0 );
182204 list .add (mapping2 );
183205 });
184206
@@ -195,9 +217,7 @@ private static long addHeimatTimes(final List<HeimatTime> optionalAlreadyBookedT
195217
196218 private static String addHeimatNotes (final List <HeimatTime > optionalAlreadyBookedTimes ) {
197219 String heimatNotes ;
198- heimatNotes = optionalAlreadyBookedTimes .stream ()
199- .map (HeimatTime ::note )
200- .collect (Collectors .joining (". " ));
220+ heimatNotes = optionalAlreadyBookedTimes .stream ().map (HeimatTime ::note ).collect (Collectors .joining (". " ));
201221 return heimatNotes ;
202222 }
203223
@@ -247,7 +267,10 @@ public List<HeimatTask> getTasks(final LocalDate forDate) {
247267 uniqueMap .putIfAbsent (obj .id (), obj );
248268 }
249269
250- return uniqueMap .values ().stream ().sorted (Comparator .comparing (HeimatTask ::taskHolderName ).thenComparing (HeimatTask ::name )).toList ();
270+ return uniqueMap .values ()
271+ .stream ()
272+ .sorted (Comparator .comparing (HeimatTask ::taskHolderName ).thenComparing (HeimatTask ::name ))
273+ .toList ();
251274 }
252275
253276 public record UserMapping (Mapping mapping , boolean shouldSync , String userNotes , int userMinutes ) {}
0 commit comments