commit 3cb730404fafff9ff3403bd76072e12c655ff0fb
Author: Hrabikv <75799502+Hrabikv@users.noreply.github.com>
Date:   Fri Nov 24 21:03:30 2023 +0100

    https://kivprogrammers.atlassian.net/browse/TSP2-62 endpoint aktivity a workunit

diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/SegmentActivityController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/SegmentActivityController.java
index c473740..8c843ab 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/SegmentActivityController.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/SegmentActivityController.java
@@ -11,7 +11,6 @@ import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit;
 import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.enums.WuType;
 import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.ActivityRepository;
 import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.WorkUnitRepository;
-import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.ActivityService;
 import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.CategoryService;
 import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.WorkUnitService;
 import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.enums.WuTypeService;
@@ -39,9 +38,6 @@ public class SegmentActivityController {
     @Autowired
     private ProjectService projectService;
 
-    @Autowired
-    private ActivityService activityService;
-
     @Autowired
     private WorkUnitService workUnitService;
 
@@ -125,16 +121,17 @@ public class SegmentActivityController {
                                  RedirectAttributes redirectAttrs,
                                  HttpSession session) {
 
-        Activity activity = activityService.getActivityById(activityId);
-        if(activity == null) {
-            redirectAttrs.addFlashAttribute("errorMessage", "ERROR: Activity not found");
-            LOGGER.info("@GetMapping(\"/management/segment-activity\")- Activity not found");
-            return "redirect:/management/segment-activity";
-        }
-
-        session.setAttribute("activity", activity);
-        LOGGER.info("@GetMapping(\"/management/segment-activity\") - Accessing page");
-        return "redirect:/management/segment-activity";
+//        Activity activity = activityService.getActivityById(activityId);
+//        if(activity == null) {
+//            redirectAttrs.addFlashAttribute("errorMessage", "ERROR: Activity not found");
+//            LOGGER.info("@GetMapping(\"/management/segment-activity\")- Activity not found");
+//            return "redirect:/management/segment-activity";
+//        }
+//
+//        session.setAttribute("activity", activity);
+//        LOGGER.info("@GetMapping(\"/management/segment-activity\") - Accessing page");
+//        return "redirect:/management/segment-activity";
+        return null;
     }
 
     /**
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/SegmentCategoryController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/SegmentCategoryController.java
index e103bc3..4f27165 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/SegmentCategoryController.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/SegmentCategoryController.java
@@ -273,7 +273,7 @@ public class SegmentCategoryController {
                                     category.getName(),
                                     category.getDescription(),
                                     category.getProjectInstance().getProjectId());
-                        return activityService.saveActivity(activity);
+//                        return activityService.saveActivity(activity);
                     }
                 }
                 break;
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/WorkUnit.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/WorkUnit.java
index 1fd0a12..962e00b 100644
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/WorkUnit.java
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/WorkUnit.java
@@ -57,7 +57,7 @@ public class WorkUnit {
     private Project project;
 
     @ManyToMany
-    @JoinTable(name = "WorkUnitCategory",
+    @JoinTable(name = "Work_Unit_Category",
             joinColumns = @JoinColumn(name = "workunitid"),
             inverseJoinColumns = @JoinColumn(name = "categoryid"))
     private Set<Category> categories = new LinkedHashSet<>();
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/managment/ActivityService.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/managment/ActivityService.java
deleted file mode 100644
index 67cd8f5..0000000
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/managment/ActivityService.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package cz.zcu.fav.kiv.antipatterndetectionapp.service.managment;
-
-import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity;
-
-import java.util.List;
-
-public interface ActivityService {
-
-    /**
-     * Method getting all activities from database
-     * @return  List of all activities
-     */
-    List<Activity> getAllActivities();
-
-    /**
-     * Method saving activity into database
-     * @param activity  Activity tha will be safe
-     * @return          Activity saved in database
-     */
-    Activity saveActivity(Activity activity);
-
-    /**
-     * Method getting activity by id
-     * @param id    ID of activity
-     * @return      Activity with that ID
-     */
-    Activity getActivityById(Long id);
-}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/managment/ActivityServiceImpl.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/managment/ActivityServiceImpl.java
deleted file mode 100644
index a94c66b..0000000
--- a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/managment/ActivityServiceImpl.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package cz.zcu.fav.kiv.antipatterndetectionapp.service.managment;
-
-import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity;
-import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.ActivityRepository;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import javax.transaction.Transactional;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Optional;
-
-@Service
-@Transactional
-public class ActivityServiceImpl implements ActivityService {
-
-    @Autowired
-    private ActivityRepository activityRepository;
-
-    @Override
-    public List<Activity> getAllActivities() {
-        List<Activity> activities = activityRepository.findAll();
-        Collections.sort(activities, Comparator.comparing(Activity::getName, String.CASE_INSENSITIVE_ORDER));
-        return activities;
-    }
-
-    @Override
-    public Activity saveActivity(Activity activity) {
-        Activity newActivity = activityRepository.save(activity);
-        activityRepository.flush();
-        return newActivity;
-    }
-
-    @Override
-    public Activity getActivityById(Long id) {
-        Optional<Activity> result = activityRepository.findById(id);
-        if (result.isEmpty()) {
-            return null;
-        } else {
-            return result.get();
-        }
-    }
-}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/ActivityController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/ActivityController.java
new file mode 100644
index 0000000..6c90299
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/ActivityController.java
@@ -0,0 +1,50 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller.management;
+
+import com.google.gson.Gson;
+import cz.zcu.fav.kiv.antipatterndetectionapp.Constants;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity;
+import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService;
+import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.ActivityDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.ProjectDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.activity.ActivityService;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.ActivityToDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.ClassToDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.ProjectToDto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("v2/management")
+public class ActivityController {
+
+    @Autowired
+    ActivityService activityService;
+
+    //"/v2/management/activity_list"
+    @GetMapping("/activity_list")
+    public ResponseEntity<String> getProjectsList(@RequestParam Map<String, String> requestData) {
+        Long projectId = Long.parseLong(requestData.get("selectedProjectId").toString());
+
+        //ProjectToDto projectToDto = new ProjectToDto();
+        //List<ProjectDto> projects = projectToDto.convert(projectService.getAllProjects());
+        List<Activity> projectActivities = activityService.fetchAllProjectActivities(projectId);
+        if(projectActivities == null) {
+            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+        }
+        ClassToDto<Activity, ActivityDto> mapper = new ActivityToDto();
+        List<ActivityDto> activityDto = mapper.convert(projectActivities);
+
+        return ResponseEntity.status(HttpStatus.OK).body(new Gson().toJson(activityDto  ));
+    }
+
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/WorkUnitController.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/WorkUnitController.java
new file mode 100644
index 0000000..7eaddfd
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/WorkUnitController.java
@@ -0,0 +1,41 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller.management;
+
+import com.google.gson.Gson;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.WorkUnitDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.workUnit.WorkUnitServiceV2;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.ClassToDto;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.WorkUnitToDto;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.util.List;
+
+@RequestMapping("v2/work_unit")
+@Controller
+public class WorkUnitController {
+    @Autowired
+    WorkUnitServiceV2 workUnitService;
+
+    @GetMapping("/activity_work_units")
+    public ResponseEntity<String> getActivityWorkUnits(Long projectId) {
+        if(projectId == null) {
+            return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
+        }
+        List<WorkUnit> units = this.workUnitService.fetchProjectWorkUnits(projectId);
+        if(units.size() == 0) {
+            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+        }
+        ClassToDto<WorkUnit, WorkUnitDto> mapper = new WorkUnitToDto();
+        List<WorkUnitDto> dto = mapper.convert(units);
+        return ResponseEntity.ok(new Gson().toJson(dto));
+    }
+
+
+
+
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/ActivityDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/ActivityDto.java
new file mode 100644
index 0000000..875442f
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/ActivityDto.java
@@ -0,0 +1,24 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class ActivityDto {
+
+    private String name;
+    private String description;
+    private long externalId;
+    private Date startDate;
+    private Date endDate;
+
+
+    public static ActivityDto.ActivityDtoBuilder builder() {return new ActivityDto.ActivityDtoBuilder();}
+
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/WorkUnitDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/WorkUnitDto.java
new file mode 100644
index 0000000..bd4103f
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/WorkUnitDto.java
@@ -0,0 +1,27 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model;
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Category;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.Date;
+import java.util.Set;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WorkUnitDto {
+
+    private String assignee;
+    private String type;
+    private Set<String> category;
+    private long id;
+    private Date startDate;
+    private Date endDate;
+    private String activity;
+
+    public static WorkUnitDto.WorkUnitDtoBuilder builder() {return new WorkUnitDto.WorkUnitDtoBuilder();}
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/activity/ActivityService.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/activity/ActivityService.java
new file mode 100644
index 0000000..5cf9072
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/activity/ActivityService.java
@@ -0,0 +1,11 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.activity;
+
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity;
+
+import java.util.List;
+
+public interface ActivityService {
+List<Activity> fetchAllProjectActivities(long projectId);
+
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/activity/ActivityServiceImpl.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/activity/ActivityServiceImpl.java
new file mode 100644
index 0000000..af977c9
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/activity/ActivityServiceImpl.java
@@ -0,0 +1,63 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.activity;
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.Constants;
+import cz.zcu.fav.kiv.antipatterndetectionapp.controller.management.SegmentActivityController;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Category;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.ProjectInstance;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.enums.WuType;
+import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.ActivityRepository;
+import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.WorkUnitRepository;
+import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService;
+import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.CategoryService;
+import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.WorkUnitService;
+import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.enums.WuTypeService;
+import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.mvc.support.RedirectAttributes;
+
+import javax.servlet.http.HttpSession;
+import java.util.*;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class ActivityServiceImpl implements ActivityService {
+    private final Logger LOGGER = LoggerFactory.getLogger(SegmentActivityController.class);
+
+    @Autowired
+    private ProjectService projectService;
+
+    @Autowired
+    private WorkUnitService workUnitService;
+
+    @Autowired
+    private CategoryService categoryService;
+
+    @Autowired
+    private WuTypeService wuTypeService;
+
+    @Autowired
+    private ActivityRepository activityRepository;
+
+    @Autowired
+    private WorkUnitRepository workUnitRepository;
+
+    @Override
+    public List<Activity> fetchAllProjectActivities(long projectId) {
+        Project p = this.projectService.getProjectById(projectId);
+        if(p == null){
+            return null;
+        }
+        List<Activity> activities = p.getActivities();
+        return activities;
+    }
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/workUnit/WorkUnitServiceV2.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/workUnit/WorkUnitServiceV2.java
new file mode 100644
index 0000000..a9dc163
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/workUnit/WorkUnitServiceV2.java
@@ -0,0 +1,9 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.workUnit;
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit;
+
+import java.util.List;
+
+public interface WorkUnitServiceV2 {
+    List<WorkUnit> fetchProjectWorkUnits(long activityId);
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/workUnit/WorkUnitServiceV2Impl.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/workUnit/WorkUnitServiceV2Impl.java
new file mode 100644
index 0000000..304da3b
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/workUnit/WorkUnitServiceV2Impl.java
@@ -0,0 +1,24 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.workUnit;
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit;
+import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.WorkUnitRepository;
+import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.WorkUnitService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class WorkUnitServiceV2Impl implements WorkUnitServiceV2 {
+    @Autowired
+    WorkUnitRepository workUnitRepository;
+
+    @Override
+    public List<WorkUnit> fetchProjectWorkUnits(long projectId){
+        //List<WorkUnit> units = this.workUnitRepository.fetchActivityWorkUnits(activityId);
+        List<WorkUnit> units = this.workUnitRepository.fetchAllProjectWorkUnits(projectId);
+        return units;
+    }
+
+
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/ActivityToDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/ActivityToDto.java
new file mode 100644
index 0000000..c1ad8c2
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/ActivityToDto.java
@@ -0,0 +1,36 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters;
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.ActivityDto;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ActivityToDto implements ClassToDto<Activity, ActivityDto> {
+
+    @Override
+    public ActivityDto convert(Activity source) {
+        if (source == null) {
+            return null;
+        }
+
+        return ActivityDto.builder()
+                .externalId(Long.parseLong(source.getExternalId()))
+                .endDate(source.getEndDate())
+                .startDate(source.getStartDate())
+                .name(source.getName())
+                .description(source.getDescription())
+                .build();
+    }
+
+    @Override
+    public List<ActivityDto> convert(List<Activity> source) {
+        List<ActivityDto> convertedList = new ArrayList<>();
+
+        if(source == null){
+            return convertedList;
+        }
+        source.stream().forEach(sourceItem->convertedList.add(this.convert(sourceItem)));
+        return convertedList;
+    }
+}
diff --git a/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/WorkUnitToDto.java b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/WorkUnitToDto.java
new file mode 100644
index 0000000..0882cdf
--- /dev/null
+++ b/src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/WorkUnitToDto.java
@@ -0,0 +1,54 @@
+package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters;
+
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Category;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Person;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit;
+import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.enums.WuType;
+import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.WorkUnitDto;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class WorkUnitToDto implements ClassToDto<WorkUnit, WorkUnitDto> {
+    @Override
+    public WorkUnitDto convert(WorkUnit source) {
+        if (source == null) {
+            return null;
+        }
+        Set<String> categories = new HashSet<>();
+        for(Category category : source.getCategories()){
+            categories.add(category.getName());
+        }
+        Activity activity = source.getActivity();
+        String name = activity != null ? activity.getName() : "";
+
+        Person ass = source.getAssignee();
+        String assName = ass != null ? ass.getName() : "";
+
+        WuType type = source.getType();
+        String wuType = type != null ? type.getName() : "";
+        return WorkUnitDto.builder()
+                .startDate(source.getStartDate())
+                .id(source.getId())
+                .endDate(source.getDueDate())
+                .type(wuType)
+                .assignee(assName)
+                .category(categories)
+                .activity(name)
+                .build();
+    }
+
+    @Override
+    public List<WorkUnitDto> convert(List<WorkUnit> source) {
+        List<WorkUnitDto> convertedList = new ArrayList<>();
+
+        if(source == null){
+            return convertedList;
+        }
+        source.stream().forEach(sourceItem->convertedList.add(this.convert(sourceItem)));
+        return convertedList;
+    }
+}
