Revize f6e7917d
Přidáno uživatelem stepanekp před více než 1 rok
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/Activity.java | ||
---|---|---|
16 | 16 |
public class Activity implements DatabaseObject { |
17 | 17 |
|
18 | 18 |
@Id |
19 |
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
19 |
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
20 | 20 |
@Column(name = "id", nullable = false) |
21 | 21 |
private Long id; |
22 | 22 |
|
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/Iteration.java | ||
---|---|---|
16 | 16 |
public class Iteration implements DatabaseObject { |
17 | 17 |
|
18 | 18 |
@Id |
19 |
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
19 |
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
20 | 20 |
@Column(name = "id", nullable = false) |
21 | 21 |
private Long id; |
22 | 22 |
|
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/management/Phase.java | ||
---|---|---|
16 | 16 |
public class Phase implements DatabaseObject { |
17 | 17 |
|
18 | 18 |
@Id |
19 |
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
19 |
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
20 | 20 |
@Column(name = "id", nullable = false) |
21 | 21 |
private Long id; |
22 | 22 |
|
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/v2/controller/management/CategoryController.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Category; |
4 | 4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.AdditionalInformationDto; |
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.CategoryChangeRequest; |
|
5 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.CategoryDto; |
6 | 7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.GeneralResponseDto; |
7 | 8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.management.category.ICategories; |
... | ... | |
32 | 33 |
} |
33 | 34 |
|
34 | 35 |
@PostMapping("/changeCategory") |
35 |
public ResponseEntity<GeneralResponseDto<CategoryDto, AdditionalInformationDto<String>>> changeCategory(@RequestParam(value = "selectedBox", required = false) List<CategoryDto> selectedCategories, |
|
36 |
@RequestParam(value = "submitType", required = false) Integer submitType, |
|
37 |
@RequestParam(value = "submitId", required = false) String submitId) { |
|
38 |
return categories.handleCategoryChangeRequest(selectedCategories, submitType, submitId); |
|
36 |
public ResponseEntity<GeneralResponseDto<CategoryDto, AdditionalInformationDto<String>>> changeCategory(@RequestBody CategoryChangeRequest categoryChangeRequest) { |
|
37 |
return categories.handleCategoryChangeRequest(categoryChangeRequest); |
|
39 | 38 |
} |
40 | 39 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/CategoryChangeRequest.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
public class CategoryChangeRequest { |
|
6 |
|
|
7 |
private List<CategoryDto> categories; |
|
8 |
|
|
9 |
private Integer submitType; |
|
10 |
|
|
11 |
private long projectId; |
|
12 |
|
|
13 |
public List<CategoryDto> getCategories() { |
|
14 |
return categories; |
|
15 |
} |
|
16 |
|
|
17 |
public void setCategories(List<CategoryDto> categories) { |
|
18 |
this.categories = categories; |
|
19 |
} |
|
20 |
|
|
21 |
public Integer getSubmitType() { |
|
22 |
return submitType; |
|
23 |
} |
|
24 |
|
|
25 |
public void setSubmitType(Integer submitType) { |
|
26 |
this.submitType = submitType; |
|
27 |
} |
|
28 |
|
|
29 |
public long getProjectId() { |
|
30 |
return projectId; |
|
31 |
} |
|
32 |
|
|
33 |
public void setProjectId(long projectId) { |
|
34 |
this.projectId = projectId; |
|
35 |
} |
|
36 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/CategoryDto.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.model; |
2 | 2 |
|
3 |
import lombok.AllArgsConstructor; |
|
3 | 4 |
import lombok.Builder; |
4 | 5 |
import lombok.Data; |
6 |
import lombok.NoArgsConstructor; |
|
5 | 7 |
|
6 | 8 |
@Data |
7 | 9 |
@Builder |
10 |
@NoArgsConstructor |
|
11 |
@AllArgsConstructor |
|
8 | 12 |
public class CategoryDto { |
9 | 13 |
|
10 | 14 |
private Long id; |
... | ... | |
15 | 19 |
|
16 | 20 |
public static CategoryDtoBuilder builder() { return new CategoryDtoBuilder(); } |
17 | 21 |
|
22 |
public Long getId() { |
|
23 |
return id; |
|
24 |
} |
|
18 | 25 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/management/category/ICategories.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.management.Category; |
4 | 4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.AdditionalInformationDto; |
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.CategoryChangeRequest; |
|
5 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.CategoryDto; |
6 | 7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.GeneralResponseDto; |
7 | 8 |
import org.springframework.http.ResponseEntity; |
... | ... | |
11 | 12 |
|
12 | 13 |
public interface ICategories { |
13 | 14 |
|
15 |
/** |
|
16 |
* Returns the list of categories for given project id |
|
17 |
* @param projectId project ID |
|
18 |
* @return ResponseEntity with the list of categories |
|
19 |
*/ |
|
14 | 20 |
ResponseEntity<GeneralResponseDto<CategoryDto, AdditionalInformationDto<String>>> findCategoriesForProject(String projectId); |
15 | 21 |
|
16 |
ResponseEntity<GeneralResponseDto<CategoryDto, AdditionalInformationDto<String>>> handleCategoryChangeRequest(@Nullable List<CategoryDto> selectedCategories, |
|
17 |
@Nullable Integer submitType, |
|
18 |
@Nullable String submitId); |
|
22 |
/** |
|
23 |
* Manage the request for categories change according to the given data |
|
24 |
* @param categoryChangeRequest Input data with categories to change and type of the operation |
|
25 |
* @return ResponseEntity with the results of the operation |
|
26 |
*/ |
|
27 |
ResponseEntity<GeneralResponseDto<CategoryDto, AdditionalInformationDto<String>>> handleCategoryChangeRequest(CategoryChangeRequest categoryChangeRequest); |
|
19 | 28 |
|
20 | 29 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/management/category/impl/CategoriesImpl.java | ||
---|---|---|
7 | 7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService; |
8 | 8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.managment.*; |
9 | 9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.AdditionalInformationDto; |
10 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.CategoryChangeRequest; |
|
10 | 11 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.CategoryDto; |
11 | 12 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.GeneralResponseDto; |
12 | 13 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.management.category.ICategories; |
... | ... | |
35 | 36 |
private final ActivityService activityService; |
36 | 37 |
private final PhaseService phaseService; |
37 | 38 |
private final String GENERAL_ERROR_MESSAGE = "ERROR: Application error occurred"; |
38 |
private final String SUBMISSION_ERROR_MESSAGE = "Cannot proceed: Submission went wrong"; |
|
39 | 39 |
private final CategoryToDto categoryMapper = new CategoryToDto(); |
40 | 40 |
private final String PROJECT_NOT_FOUND_MESSAGE = "Project not found!"; |
41 | 41 |
private final String CATEGORIES_NOT_FOUND_MESSAGE = "Categories not found for the project!"; |
42 | 42 |
private final String INVALID_PROJECT_ID = "Provided project ID is in invalid format!"; |
43 |
private final String CATEGORY_NOT_FOUND = "Category not found!"; |
|
43 | 44 |
|
44 | 45 |
private Project getProjectById(Long id) { |
45 | 46 |
return projectService.getProjectById(id); |
46 | 47 |
} |
47 | 48 |
|
48 | 49 |
@Override |
49 |
public ResponseEntity<GeneralResponseDto<CategoryDto, AdditionalInformationDto<String>>> handleCategoryChangeRequest(@Nullable List<CategoryDto> selectedCategories, |
|
50 |
@Nullable Integer submitType, |
|
51 |
@Nullable String submitId) { |
|
52 |
List<Category> categories = new ArrayList<>(); |
|
50 |
public ResponseEntity<GeneralResponseDto<CategoryDto, AdditionalInformationDto<String>>> handleCategoryChangeRequest(CategoryChangeRequest categoryChangeRequest) { |
|
51 |
List<CategoryDto> categoryDtos = categoryChangeRequest.getCategories(); |
|
52 |
Integer submitType = categoryChangeRequest.getSubmitType(); |
|
53 | 53 |
|
54 |
if (selectedCategories != null && submitType != null) { // Selected submit |
|
54 |
// Checking input data |
|
55 |
if (categoryDtos != null && submitType != null) { |
|
55 | 56 |
if (submitType <= 0 || submitType > Constants.SUBMIT_TYPES) { // ERROR: Unknown submitType |
56 |
logger.warn("@PostMapping(\"/v2/management/changeCategory\") - Cannot proceed: Unknown submitType " + submitType); |
|
57 |
return createResponseEntity(HttpStatus.BAD_REQUEST, GENERAL_ERROR_MESSAGE, null, null); |
|
58 |
} |
|
59 |
} else if (submitId != null) { //Inline submit |
|
60 |
Pair<Integer, Long> resultPair = extractTypeAndId(submitId); |
|
61 |
if (resultPair == null) { // Cannot be extracted |
|
62 |
logger.warn("@PostMapping(\"/v2/management/changeCategory\") - Cannot proceed: Unknown submitId " + submitId); |
|
63 | 57 |
return createResponseEntity(HttpStatus.BAD_REQUEST, GENERAL_ERROR_MESSAGE, null, null); |
64 | 58 |
} |
59 |
} |
|
65 | 60 |
|
66 |
// Add one category into new list |
|
67 |
submitType = resultPair.getFirst(); |
|
68 |
Long id = resultPair.getSecond(); |
|
69 |
categories.add(categoryService.getCategoryById(id)); |
|
70 |
|
|
71 |
} else { //Unspecific error |
|
72 |
logger.warn("@PostMapping(\"/management/segment-category\") - Cannot proceed: Submission went wrong"); |
|
73 |
return createResponseEntity(HttpStatus.BAD_REQUEST, SUBMISSION_ERROR_MESSAGE, null, null); |
|
61 |
// Mapping CategoryDto to Category |
|
62 |
List<Category> categories = new ArrayList<>(); |
|
63 |
for (CategoryDto categoryDto : categoryDtos) { |
|
64 |
Category categoryTmp = categoryService.getCategoryById(categoryDto.getId()); |
|
65 |
if (categoryTmp != null) { |
|
66 |
categories.add(categoryTmp); |
|
67 |
} |
|
68 |
else { |
|
69 |
return createResponseEntity(HttpStatus.BAD_REQUEST, CATEGORY_NOT_FOUND, null, null); |
|
70 |
} |
|
74 | 71 |
} |
75 | 72 |
|
76 |
// Process all selected categories |
|
73 |
// Processing all selected categories
|
|
77 | 74 |
Pair<String, Boolean> result = processSelectedCategories(submitType, categories); |
78 | 75 |
|
76 |
// Creating reponse information |
|
79 | 77 |
AdditionalInformationDto<String> additionalInformation = new AdditionalInformationDto<>(); |
78 |
|
|
80 | 79 |
if (!result.getSecond()) { |
81 | 80 |
additionalInformation.addIntoCollection("successMessage", "All selected categories (" + categories.size() + ") were assign"); |
82 | 81 |
} else { |
... | ... | |
130 | 129 |
@Nullable String message, |
131 | 130 |
@Nullable List<CategoryDto> categories, |
132 | 131 |
@Nullable AdditionalInformationDto<String> additionalInfo) { |
133 |
|
|
134 |
|
|
135 | 132 |
return new ResponseEntity<>( |
136 | 133 |
GeneralResponseDto |
137 | 134 |
.<CategoryDto, AdditionalInformationDto<String>>builder() |
Také k dispozici: Unified diff
https://kivprogrammers.atlassian.net/browse/TSP2-60
Implementace změn kategorií