Revize 3cb73040
Přidáno uživatelem Václav Hrabík před více než 1 rok
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/SegmentActivityController.java | ||
---|---|---|
11 | 11 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.enums.WuType; |
12 | 12 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.ActivityRepository; |
13 | 13 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.WorkUnitRepository; |
14 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.ActivityService; |
|
15 | 14 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.CategoryService; |
16 | 15 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.WorkUnitService; |
17 | 16 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.enums.WuTypeService; |
... | ... | |
39 | 38 |
@Autowired |
40 | 39 |
private ProjectService projectService; |
41 | 40 |
|
42 |
@Autowired |
|
43 |
private ActivityService activityService; |
|
44 |
|
|
45 | 41 |
@Autowired |
46 | 42 |
private WorkUnitService workUnitService; |
47 | 43 |
|
... | ... | |
125 | 121 |
RedirectAttributes redirectAttrs, |
126 | 122 |
HttpSession session) { |
127 | 123 |
|
128 |
Activity activity = activityService.getActivityById(activityId); |
|
129 |
if(activity == null) { |
|
130 |
redirectAttrs.addFlashAttribute("errorMessage", "ERROR: Activity not found"); |
|
131 |
LOGGER.info("@GetMapping(\"/management/segment-activity\")- Activity not found"); |
|
132 |
return "redirect:/management/segment-activity"; |
|
133 |
} |
|
134 |
|
|
135 |
session.setAttribute("activity", activity); |
|
136 |
LOGGER.info("@GetMapping(\"/management/segment-activity\") - Accessing page"); |
|
137 |
return "redirect:/management/segment-activity"; |
|
124 |
// Activity activity = activityService.getActivityById(activityId); |
|
125 |
// if(activity == null) { |
|
126 |
// redirectAttrs.addFlashAttribute("errorMessage", "ERROR: Activity not found"); |
|
127 |
// LOGGER.info("@GetMapping(\"/management/segment-activity\")- Activity not found"); |
|
128 |
// return "redirect:/management/segment-activity"; |
|
129 |
// } |
|
130 |
// |
|
131 |
// session.setAttribute("activity", activity); |
|
132 |
// LOGGER.info("@GetMapping(\"/management/segment-activity\") - Accessing page"); |
|
133 |
// return "redirect:/management/segment-activity"; |
|
134 |
return null; |
|
138 | 135 |
} |
139 | 136 |
|
140 | 137 |
/** |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/management/SegmentCategoryController.java | ||
---|---|---|
273 | 273 |
category.getName(), |
274 | 274 |
category.getDescription(), |
275 | 275 |
category.getProjectInstance().getProjectId()); |
276 |
return activityService.saveActivity(activity); |
|
276 |
// return activityService.saveActivity(activity);
|
|
277 | 277 |
} |
278 | 278 |
} |
279 | 279 |
break; |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/WorkUnit.java | ||
---|---|---|
57 | 57 |
private Project project; |
58 | 58 |
|
59 | 59 |
@ManyToMany |
60 |
@JoinTable(name = "WorkUnitCategory",
|
|
60 |
@JoinTable(name = "Work_Unit_Category",
|
|
61 | 61 |
joinColumns = @JoinColumn(name = "workunitid"), |
62 | 62 |
inverseJoinColumns = @JoinColumn(name = "categoryid")) |
63 | 63 |
private Set<Category> categories = new LinkedHashSet<>(); |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/managment/ActivityService.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.service.managment; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
public interface ActivityService { |
|
8 |
|
|
9 |
/** |
|
10 |
* Method getting all activities from database |
|
11 |
* @return List of all activities |
|
12 |
*/ |
|
13 |
List<Activity> getAllActivities(); |
|
14 |
|
|
15 |
/** |
|
16 |
* Method saving activity into database |
|
17 |
* @param activity Activity tha will be safe |
|
18 |
* @return Activity saved in database |
|
19 |
*/ |
|
20 |
Activity saveActivity(Activity activity); |
|
21 |
|
|
22 |
/** |
|
23 |
* Method getting activity by id |
|
24 |
* @param id ID of activity |
|
25 |
* @return Activity with that ID |
|
26 |
*/ |
|
27 |
Activity getActivityById(Long id); |
|
28 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/managment/ActivityServiceImpl.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.service.managment; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.ActivityRepository; |
|
5 |
import org.springframework.beans.factory.annotation.Autowired; |
|
6 |
import org.springframework.stereotype.Service; |
|
7 |
|
|
8 |
import javax.transaction.Transactional; |
|
9 |
import java.util.Collections; |
|
10 |
import java.util.Comparator; |
|
11 |
import java.util.List; |
|
12 |
import java.util.Optional; |
|
13 |
|
|
14 |
@Service |
|
15 |
@Transactional |
|
16 |
public class ActivityServiceImpl implements ActivityService { |
|
17 |
|
|
18 |
@Autowired |
|
19 |
private ActivityRepository activityRepository; |
|
20 |
|
|
21 |
@Override |
|
22 |
public List<Activity> getAllActivities() { |
|
23 |
List<Activity> activities = activityRepository.findAll(); |
|
24 |
Collections.sort(activities, Comparator.comparing(Activity::getName, String.CASE_INSENSITIVE_ORDER)); |
|
25 |
return activities; |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
public Activity saveActivity(Activity activity) { |
|
30 |
Activity newActivity = activityRepository.save(activity); |
|
31 |
activityRepository.flush(); |
|
32 |
return newActivity; |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
public Activity getActivityById(Long id) { |
|
37 |
Optional<Activity> result = activityRepository.findById(id); |
|
38 |
if (result.isEmpty()) { |
|
39 |
return null; |
|
40 |
} else { |
|
41 |
return result.get(); |
|
42 |
} |
|
43 |
} |
|
44 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/ActivityController.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller.management; |
|
2 |
|
|
3 |
import com.google.gson.Gson; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.Constants; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project; |
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity; |
|
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService; |
|
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils; |
|
9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.ActivityDto; |
|
10 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.ProjectDto; |
|
11 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.activity.ActivityService; |
|
12 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.ActivityToDto; |
|
13 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.ClassToDto; |
|
14 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.ProjectToDto; |
|
15 |
import org.springframework.beans.factory.annotation.Autowired; |
|
16 |
import org.springframework.http.HttpStatus; |
|
17 |
import org.springframework.http.ResponseEntity; |
|
18 |
import org.springframework.web.bind.annotation.GetMapping; |
|
19 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
20 |
import org.springframework.web.bind.annotation.RequestParam; |
|
21 |
import org.springframework.web.bind.annotation.RestController; |
|
22 |
|
|
23 |
import java.util.List; |
|
24 |
import java.util.Map; |
|
25 |
|
|
26 |
@RestController |
|
27 |
@RequestMapping("v2/management") |
|
28 |
public class ActivityController { |
|
29 |
|
|
30 |
@Autowired |
|
31 |
ActivityService activityService; |
|
32 |
|
|
33 |
//"/v2/management/activity_list" |
|
34 |
@GetMapping("/activity_list") |
|
35 |
public ResponseEntity<String> getProjectsList(@RequestParam Map<String, String> requestData) { |
|
36 |
Long projectId = Long.parseLong(requestData.get("selectedProjectId").toString()); |
|
37 |
|
|
38 |
//ProjectToDto projectToDto = new ProjectToDto(); |
|
39 |
//List<ProjectDto> projects = projectToDto.convert(projectService.getAllProjects()); |
|
40 |
List<Activity> projectActivities = activityService.fetchAllProjectActivities(projectId); |
|
41 |
if(projectActivities == null) { |
|
42 |
return new ResponseEntity<>(HttpStatus.NOT_FOUND); |
|
43 |
} |
|
44 |
ClassToDto<Activity, ActivityDto> mapper = new ActivityToDto(); |
|
45 |
List<ActivityDto> activityDto = mapper.convert(projectActivities); |
|
46 |
|
|
47 |
return ResponseEntity.status(HttpStatus.OK).body(new Gson().toJson(activityDto )); |
|
48 |
} |
|
49 |
|
|
50 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/management/WorkUnitController.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller.management; |
|
2 |
|
|
3 |
import com.google.gson.Gson; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.WorkUnitDto; |
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.workUnit.WorkUnitServiceV2; |
|
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.ClassToDto; |
|
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters.WorkUnitToDto; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 |
import org.springframework.http.HttpStatus; |
|
11 |
import org.springframework.http.ResponseEntity; |
|
12 |
import org.springframework.stereotype.Controller; |
|
13 |
import org.springframework.web.bind.annotation.GetMapping; |
|
14 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
15 |
|
|
16 |
import java.util.List; |
|
17 |
|
|
18 |
@RequestMapping("v2/work_unit") |
|
19 |
@Controller |
|
20 |
public class WorkUnitController { |
|
21 |
@Autowired |
|
22 |
WorkUnitServiceV2 workUnitService; |
|
23 |
|
|
24 |
@GetMapping("/activity_work_units") |
|
25 |
public ResponseEntity<String> getActivityWorkUnits(Long projectId) { |
|
26 |
if(projectId == null) { |
|
27 |
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); |
|
28 |
} |
|
29 |
List<WorkUnit> units = this.workUnitService.fetchProjectWorkUnits(projectId); |
|
30 |
if(units.size() == 0) { |
|
31 |
return new ResponseEntity<>(HttpStatus.NOT_FOUND); |
|
32 |
} |
|
33 |
ClassToDto<WorkUnit, WorkUnitDto> mapper = new WorkUnitToDto(); |
|
34 |
List<WorkUnitDto> dto = mapper.convert(units); |
|
35 |
return ResponseEntity.ok(new Gson().toJson(dto)); |
|
36 |
} |
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/ActivityDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model; |
|
2 |
|
|
3 |
import lombok.AllArgsConstructor; |
|
4 |
import lombok.Builder; |
|
5 |
import lombok.Data; |
|
6 |
import lombok.NoArgsConstructor; |
|
7 |
|
|
8 |
import java.util.Date; |
|
9 |
@Data |
|
10 |
@Builder |
|
11 |
@NoArgsConstructor |
|
12 |
@AllArgsConstructor |
|
13 |
public class ActivityDto { |
|
14 |
|
|
15 |
private String name; |
|
16 |
private String description; |
|
17 |
private long externalId; |
|
18 |
private Date startDate; |
|
19 |
private Date endDate; |
|
20 |
|
|
21 |
|
|
22 |
public static ActivityDto.ActivityDtoBuilder builder() {return new ActivityDto.ActivityDtoBuilder();} |
|
23 |
|
|
24 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/WorkUnitDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Category; |
|
4 |
import lombok.AllArgsConstructor; |
|
5 |
import lombok.Builder; |
|
6 |
import lombok.Data; |
|
7 |
import lombok.NoArgsConstructor; |
|
8 |
|
|
9 |
import java.util.Date; |
|
10 |
import java.util.Set; |
|
11 |
|
|
12 |
@Data |
|
13 |
@Builder |
|
14 |
@NoArgsConstructor |
|
15 |
@AllArgsConstructor |
|
16 |
public class WorkUnitDto { |
|
17 |
|
|
18 |
private String assignee; |
|
19 |
private String type; |
|
20 |
private Set<String> category; |
|
21 |
private long id; |
|
22 |
private Date startDate; |
|
23 |
private Date endDate; |
|
24 |
private String activity; |
|
25 |
|
|
26 |
public static WorkUnitDto.WorkUnitDtoBuilder builder() {return new WorkUnitDto.WorkUnitDtoBuilder();} |
|
27 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/activity/ActivityService.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.activity; |
|
2 |
|
|
3 |
|
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity; |
|
5 |
|
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
public interface ActivityService { |
|
9 |
List<Activity> fetchAllProjectActivities(long projectId); |
|
10 |
|
|
11 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/activity/ActivityServiceImpl.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.activity; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.Constants; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.controller.management.SegmentActivityController; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project; |
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity; |
|
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Category; |
|
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.ProjectInstance; |
|
9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit; |
|
10 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.enums.WuType; |
|
11 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.ActivityRepository; |
|
12 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.WorkUnitRepository; |
|
13 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService; |
|
14 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.CategoryService; |
|
15 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.WorkUnitService; |
|
16 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.enums.WuTypeService; |
|
17 |
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils; |
|
18 |
import org.slf4j.Logger; |
|
19 |
import org.slf4j.LoggerFactory; |
|
20 |
import org.springframework.beans.factory.annotation.Autowired; |
|
21 |
import org.springframework.ui.Model; |
|
22 |
import org.springframework.web.bind.annotation.GetMapping; |
|
23 |
import org.springframework.web.bind.annotation.PostMapping; |
|
24 |
import org.springframework.web.bind.annotation.RequestParam; |
|
25 |
import org.springframework.web.servlet.mvc.support.RedirectAttributes; |
|
26 |
|
|
27 |
import javax.servlet.http.HttpSession; |
|
28 |
import java.util.*; |
|
29 |
|
|
30 |
import org.springframework.stereotype.Service; |
|
31 |
|
|
32 |
@Service |
|
33 |
public class ActivityServiceImpl implements ActivityService { |
|
34 |
private final Logger LOGGER = LoggerFactory.getLogger(SegmentActivityController.class); |
|
35 |
|
|
36 |
@Autowired |
|
37 |
private ProjectService projectService; |
|
38 |
|
|
39 |
@Autowired |
|
40 |
private WorkUnitService workUnitService; |
|
41 |
|
|
42 |
@Autowired |
|
43 |
private CategoryService categoryService; |
|
44 |
|
|
45 |
@Autowired |
|
46 |
private WuTypeService wuTypeService; |
|
47 |
|
|
48 |
@Autowired |
|
49 |
private ActivityRepository activityRepository; |
|
50 |
|
|
51 |
@Autowired |
|
52 |
private WorkUnitRepository workUnitRepository; |
|
53 |
|
|
54 |
@Override |
|
55 |
public List<Activity> fetchAllProjectActivities(long projectId) { |
|
56 |
Project p = this.projectService.getProjectById(projectId); |
|
57 |
if(p == null){ |
|
58 |
return null; |
|
59 |
} |
|
60 |
List<Activity> activities = p.getActivities(); |
|
61 |
return activities; |
|
62 |
} |
|
63 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/workUnit/WorkUnitServiceV2.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.workUnit; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
public interface WorkUnitServiceV2 { |
|
8 |
List<WorkUnit> fetchProjectWorkUnits(long activityId); |
|
9 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/workUnit/WorkUnitServiceV2Impl.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.workUnit; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.managment.WorkUnitRepository; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.WorkUnitService; |
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.stereotype.Service; |
|
8 |
|
|
9 |
import java.util.List; |
|
10 |
|
|
11 |
@Service |
|
12 |
public class WorkUnitServiceV2Impl implements WorkUnitServiceV2 { |
|
13 |
@Autowired |
|
14 |
WorkUnitRepository workUnitRepository; |
|
15 |
|
|
16 |
@Override |
|
17 |
public List<WorkUnit> fetchProjectWorkUnits(long projectId){ |
|
18 |
//List<WorkUnit> units = this.workUnitRepository.fetchActivityWorkUnits(activityId); |
|
19 |
List<WorkUnit> units = this.workUnitRepository.fetchAllProjectWorkUnits(projectId); |
|
20 |
return units; |
|
21 |
} |
|
22 |
|
|
23 |
|
|
24 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/ActivityToDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.ActivityDto; |
|
5 |
|
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
public class ActivityToDto implements ClassToDto<Activity, ActivityDto> { |
|
10 |
|
|
11 |
@Override |
|
12 |
public ActivityDto convert(Activity source) { |
|
13 |
if (source == null) { |
|
14 |
return null; |
|
15 |
} |
|
16 |
|
|
17 |
return ActivityDto.builder() |
|
18 |
.externalId(Long.parseLong(source.getExternalId())) |
|
19 |
.endDate(source.getEndDate()) |
|
20 |
.startDate(source.getStartDate()) |
|
21 |
.name(source.getName()) |
|
22 |
.description(source.getDescription()) |
|
23 |
.build(); |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
public List<ActivityDto> convert(List<Activity> source) { |
|
28 |
List<ActivityDto> convertedList = new ArrayList<>(); |
|
29 |
|
|
30 |
if(source == null){ |
|
31 |
return convertedList; |
|
32 |
} |
|
33 |
source.stream().forEach(sourceItem->convertedList.add(this.convert(sourceItem))); |
|
34 |
return convertedList; |
|
35 |
} |
|
36 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/converters/WorkUnitToDto.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.converters; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Activity; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Category; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Person; |
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.WorkUnit; |
|
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.enums.WuType; |
|
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.WorkUnitDto; |
|
9 |
|
|
10 |
import java.util.ArrayList; |
|
11 |
import java.util.HashSet; |
|
12 |
import java.util.List; |
|
13 |
import java.util.Set; |
|
14 |
|
|
15 |
public class WorkUnitToDto implements ClassToDto<WorkUnit, WorkUnitDto> { |
|
16 |
@Override |
|
17 |
public WorkUnitDto convert(WorkUnit source) { |
|
18 |
if (source == null) { |
|
19 |
return null; |
|
20 |
} |
|
21 |
Set<String> categories = new HashSet<>(); |
|
22 |
for(Category category : source.getCategories()){ |
|
23 |
categories.add(category.getName()); |
|
24 |
} |
|
25 |
Activity activity = source.getActivity(); |
|
26 |
String name = activity != null ? activity.getName() : ""; |
|
27 |
|
|
28 |
Person ass = source.getAssignee(); |
|
29 |
String assName = ass != null ? ass.getName() : ""; |
|
30 |
|
|
31 |
WuType type = source.getType(); |
|
32 |
String wuType = type != null ? type.getName() : ""; |
|
33 |
return WorkUnitDto.builder() |
|
34 |
.startDate(source.getStartDate()) |
|
35 |
.id(source.getId()) |
|
36 |
.endDate(source.getDueDate()) |
|
37 |
.type(wuType) |
|
38 |
.assignee(assName) |
|
39 |
.category(categories) |
|
40 |
.activity(name) |
|
41 |
.build(); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public List<WorkUnitDto> convert(List<WorkUnit> source) { |
|
46 |
List<WorkUnitDto> convertedList = new ArrayList<>(); |
|
47 |
|
|
48 |
if(source == null){ |
|
49 |
return convertedList; |
|
50 |
} |
|
51 |
source.stream().forEach(sourceItem->convertedList.add(this.convert(sourceItem))); |
|
52 |
return convertedList; |
|
53 |
} |
|
54 |
} |
Také k dispozici: Unified diff
https://kivprogrammers.atlassian.net/browse/TSP2-62 endpoint aktivity a workunit