11package de .doubleslash .keeptime .controller ;
22
3+ import com .fasterxml .jackson .core .JsonProcessingException ;
4+ import com .fasterxml .jackson .databind .ObjectMapper ;
35import de .doubleslash .keeptime .model .*;
46import de .doubleslash .keeptime .model .repos .ExternalProjectsMappingsRepository ;
57import de .doubleslash .keeptime .model .settings .HeimatSettings ;
@@ -26,6 +28,8 @@ public class HeimatController {
2628 private final HeimatSettings heimatSettings ;
2729 private final ExternalProjectsMappingsRepository externalProjectsMappingsRepository ;
2830
31+ private final ObjectMapper objectMapper = new ObjectMapper ();
32+
2933 private HeimatAPI heimatAPI ;
3034 private final Model model ;
3135
@@ -297,17 +301,16 @@ public void updateMappings(final List<ProjectMapping> newMappings) {
297301 projectMapping1 .setExternalTaskName (
298302 heimatTask .name ());
299303 projectMapping1 .setExternalTaskMetadata (
300- heimatTask . toString ( )); // TODO to json
304+ getAsJson ( heimatTask ));
301305
302306 return projectMapping1 ;
303307 }
304308 return new ExternalProjectMapping (
305309 ExternalSystem .Heimat ,
306310 heimatTask .taskHolderName (),
307311 heimatTask .id (),
308- heimatTask .name (),
309- heimatTask .toString ()
310- // TODO to json
312+ heimatTask .name (), getAsJson (
313+ heimatTask )
311314 , projectMapping .getProject ());
312315 })
313316 .filter (Objects ::nonNull )
@@ -335,6 +338,14 @@ public void updateMappings(final List<ProjectMapping> newMappings) {
335338 externalProjectsMappingsRepository .deleteAll (mappingsToRemove );
336339 }
337340
341+ private String getAsJson (final HeimatTask heimatTask ){
342+ try {
343+ return objectMapper .writeValueAsString (heimatTask );
344+ } catch (JsonProcessingException e ) {
345+ throw new RuntimeException (e );
346+ }
347+ }
348+
338349 public ExistingAndInvalidMappings getExistingProjectMappings (List <HeimatTask > externalProjects ) {
339350 final List <ExternalProjectMapping > alreadyMappedProjects = externalProjectsMappingsRepository .findByExternalSystemId (
340351 ExternalSystem .Heimat );
0 commit comments