Skip to content

Commit bb38693

Browse files
authored
Merge pull request #75 from init-cloud/dev
refactor: refactoring for Improving maintenance.
2 parents 2dad6ed + 5f3da0f commit bb38693

26 files changed

+379
-384
lines changed

src/main/java/scanner/checklist/controller/CheckListController.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import io.swagger.annotations.ApiOperation;
66
import lombok.RequiredArgsConstructor;
77
import scanner.checklist.dto.CheckListDetailDto;
8-
import scanner.checklist.dto.CheckListModifyDto;
9-
import scanner.checklist.dto.CheckListSimpleDto;
8+
import scanner.checklist.dto.CheckListDto;
109
import scanner.checklist.service.CheckListService;
1110
import scanner.common.dto.CommonResponse;
1211
import scanner.common.enums.Language;
@@ -26,8 +25,8 @@ public class CheckListController {
2625
@ApiImplicitParams({
2726
@ApiImplicitParam(name = "Authorization", paramType = "header", value = "Access Token", required = true, dataTypeClass = String.class)})
2827
@GetMapping
29-
public CommonResponse<CheckListSimpleDto.Response> checkLists() {
30-
CheckListSimpleDto.Response dto = checkListService.getCheckLists(null);
28+
public CommonResponse<CheckListDto.Response> checkLists() {
29+
CheckListDto.Response dto = checkListService.getCheckLists(null);
3130

3231
return new CommonResponse<>(dto);
3332
}
@@ -46,7 +45,7 @@ public CommonResponse<CheckListDetailDto.Detail> addCheckList(CheckListDetailDto
4645
@ApiImplicitParams({
4746
@ApiImplicitParam(name = "Authorization", paramType = "header", value = "Access Token", required = true, dataTypeClass = String.class),
4847
@ApiImplicitParam(name = "ruleId", paramType = "path", value = "Checklist(rule) ID", required = true, dataTypeClass = String.class, example = "CKV_NCP_1"),
49-
@ApiImplicitParam(name = "lang", paramType = "query", value = "eng, kor", required = false, dataTypeClass = String.class)})
48+
@ApiImplicitParam(name = "lang", paramType = "query", value = "eng, kor", dataTypeClass = String.class)})
5049
@GetMapping("/{ruleId}")
5150
public CommonResponse<CheckListDetailDto.Detail> checkListDetails(@PathVariable String ruleId,
5251
@Nullable @RequestParam String lang) {
@@ -59,11 +58,11 @@ public CommonResponse<CheckListDetailDto.Detail> checkListDetails(@PathVariable
5958
@ApiImplicitParams({
6059
@ApiImplicitParam(name = "Authorization", paramType = "header", value = "Access Token", required = true, dataTypeClass = String.class),
6160
@ApiImplicitParam(name = "ruleId", paramType = "path", value = "ruleId.", required = true, dataTypeClass = String.class),
62-
@ApiImplicitParam(name = "CheckListSimpleDto.Simple", paramType = "body", value = "Modify ruleOnOff n to y, y to n", required = true, dataTypeClass = CheckListModifyDto.Modifying.class)})
61+
@ApiImplicitParam(name = "CheckListDto.Simple", paramType = "body", value = "Modify ruleOnOff n to y, y to n", required = true, dataTypeClass = CheckListDto.Modifying.class)})
6362
@PatchMapping("/{ruleId}")
64-
public CommonResponse<CheckListSimpleDto.Simple> modifyCheckListDetails(@PathVariable String ruleId,
65-
@RequestBody CheckListModifyDto.Modifying data) {
66-
CheckListSimpleDto.Simple dto = checkListService.modifyCheckList(ruleId, data);
63+
public CommonResponse<CheckListDto.Summary> modifyCheckListDetails(@PathVariable String ruleId,
64+
@RequestBody CheckListDto.Modifying data) {
65+
CheckListDto.Summary dto = checkListService.modifyCheckList(ruleId, data);
6766

6867
return new CommonResponse<>(dto);
6968
}
@@ -72,22 +71,22 @@ public CommonResponse<CheckListSimpleDto.Simple> modifyCheckListDetails(@PathVar
7271
@ApiImplicitParams({
7372
@ApiImplicitParam(name = "Authorization", paramType = "header", value = "Access Token", required = true, dataTypeClass = String.class),
7473
@ApiImplicitParam(name = "ruleId", paramType = "path", value = "ruleId.", required = true, dataTypeClass = String.class),
75-
@ApiImplicitParam(name = "CheckListSimpleDto.Simple", paramType = "body", value = "Modify ruleOnOff n to y, y to n", required = true, dataTypeClass = CheckListModifyDto.State.class)})
74+
@ApiImplicitParam(name = "CheckListDto.RuleState", paramType = "body", value = "Modify ruleOnOff n to y, y to n", required = true, dataTypeClass = CheckListDto.RuleState.class)})
7675
@PatchMapping("/state/{ruleId}")
77-
public CommonResponse<CheckListSimpleDto.Simple> modifyCheckListOnOff(@PathVariable String ruleId,
78-
@RequestBody CheckListSimpleDto.Simple data) {
79-
CheckListSimpleDto.Simple dto = checkListService.modifyCheckListAsOnOff(ruleId, data);
76+
public CommonResponse<CheckListDto.Summary> modifyCheckListOnOff(@PathVariable String ruleId,
77+
@RequestBody CheckListDto.Summary data) {
78+
CheckListDto.Summary dto = checkListService.modifyCheckListAsOnOff(ruleId, data);
8079

8180
return new CommonResponse<>(dto);
8281
}
8382

8483
@ApiOperation(value = "Reset Checklist", notes = "Reset custom checklist to origin.", response = CommonResponse.class)
8584
@ApiImplicitParams({
8685
@ApiImplicitParam(name = "Authorization", paramType = "header", value = "Access Token", required = true, dataTypeClass = String.class),
87-
@ApiImplicitParam(name = "CheckListSimpleDto.Simple", paramType = "body", value = "Body need ruleId.", required = true, dataTypeClass = CheckListSimpleDto.Simple.class)})
86+
@ApiImplicitParam(name = "CheckListDto.Simple", paramType = "body", value = "Body need ruleId.", required = true, dataTypeClass = CheckListDto.Summary.class)})
8887
@PostMapping("/state")
89-
public CommonResponse<CheckListSimpleDto.Simple> resetCheckList(@RequestBody CheckListSimpleDto.Simple data) {
90-
CheckListSimpleDto.Simple dto = checkListService.resetCheckList(data);
88+
public CommonResponse<CheckListDto.Summary> resetCheckList(@RequestBody CheckListDto.Summary data) {
89+
CheckListDto.Summary dto = checkListService.resetCheckList(data);
9190

9291
return new CommonResponse<>(dto);
9392
}

src/main/java/scanner/checklist/dto/CheckListDetailDto.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
@NoArgsConstructor(access = AccessLevel.PROTECTED)
1212
public class CheckListDetailDto {
1313

14-
@AllArgsConstructor
15-
@Builder
1614
@Getter
1715
public static class Detail {
1816
private String ruleId;
@@ -30,7 +28,26 @@ public static class Detail {
3028
private Character isModifiable;
3129
private Character isModified;
3230

33-
@Builder
31+
@Builder(builderClassName = "checklistDetailsBuilder", builderMethodName = "checklistDetailsBuilder")
32+
public Detail(String ruleId, List<TagDto> tags, List<SecurityType> type, String level, String description,
33+
String explanation, String possibleImpact, String insecureExample, String secureExample, Solution solution,
34+
String state, String customDetail, Character isModifiable, Character isModified) {
35+
this.ruleId = ruleId;
36+
this.tags = tags;
37+
this.type = type;
38+
this.level = level;
39+
this.description = description;
40+
this.explanation = explanation;
41+
this.possibleImpact = possibleImpact;
42+
this.insecureExample = insecureExample;
43+
this.secureExample = secureExample;
44+
this.solution = solution;
45+
this.state = state;
46+
this.customDetail = customDetail;
47+
this.isModifiable = isModifiable;
48+
this.isModified = isModified;
49+
}
50+
3451
public Detail(CustomRule rule) {
3552
this.ruleId = rule.getRuleId();
3653
this.tags = rule.getTagDto();
@@ -56,8 +73,8 @@ public static class Solution {
5673
private String code;
5774
}
5875

59-
public static Detail toDto(CustomRule rule, CustomRuleDetails details) {
60-
return Detail.builder()
76+
public static Detail toDetailsDto(final CustomRule rule, final CustomRuleDetails details) {
77+
return Detail.checklistDetailsBuilder()
6178
.ruleId(rule.getRuleId())
6279
.tags(rule.getTagDto())
6380
.level(rule.getLevel())
@@ -74,8 +91,8 @@ public static Detail toDto(CustomRule rule, CustomRuleDetails details) {
7491
.build();
7592
}
7693

77-
public static Detail toDto(CustomRule rule) {
78-
return Detail.builder()
94+
public static Detail toDto(final CustomRule rule) {
95+
return Detail.checklistDetailsBuilder()
7996
.ruleId(rule.getRuleId())
8097
.tags(rule.getTagDto())
8198
.level(rule.getLevel())
@@ -92,8 +109,8 @@ public static Detail toDto(CustomRule rule) {
92109
.build();
93110
}
94111

95-
public static CustomRule toEntity(final Detail dto) {
96-
return CustomRule.builder()
112+
public static CustomRule toNewEntity(final Detail dto) {
113+
return CustomRule.customRuleAddBuilder()
97114
.ruleId(dto.getRuleId())
98115
.ruleOnOff(dto.getState())
99116
.isModified('y')
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package scanner.checklist.dto;
2+
3+
import lombok.*;
4+
import scanner.checklist.entity.CustomRule;
5+
import scanner.common.enums.ResponseCode;
6+
import scanner.common.exception.ApiException;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
import com.fasterxml.jackson.core.JsonProcessingException;
12+
import com.fasterxml.jackson.databind.ObjectMapper;
13+
14+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
15+
public class CheckListDto {
16+
17+
@Getter
18+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
19+
public static class Response {
20+
List<CheckListDto.Summary> data = new ArrayList<>();
21+
22+
public Response(List<CheckListDto.Summary> data) {
23+
this.data = data;
24+
}
25+
}
26+
27+
@Getter
28+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
29+
public static class Summary {
30+
private String ruleId;
31+
private String ruleOnOff;
32+
private String level;
33+
private String custom;
34+
35+
public Summary(final CustomRule rule) {
36+
this.ruleId = rule.getRuleId();
37+
this.ruleOnOff = rule.getRuleOnOff();
38+
this.level = rule.getLevel();
39+
this.custom = rule.getCustomDetail();
40+
}
41+
}
42+
43+
/**
44+
* @Todo Need to Modifying Camel Case with DB Update.
45+
*/
46+
@Getter
47+
@AllArgsConstructor
48+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
49+
public static class Modifying {
50+
private String rule_id;
51+
private List<CheckListDto.Modifying.Details> custom;
52+
53+
public static String toJsonString(List<CheckListDto.Modifying.Details> dto) {
54+
try {
55+
ObjectMapper objectMapper = new ObjectMapper();
56+
return objectMapper.writeValueAsString(dto);
57+
} catch (JsonProcessingException e) {
58+
throw new ApiException(ResponseCode.INVALID_REQUEST);
59+
}
60+
}
61+
62+
@Getter
63+
@AllArgsConstructor
64+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
65+
static class Details {
66+
private String name;
67+
private String value;
68+
}
69+
}
70+
71+
@Getter
72+
@AllArgsConstructor
73+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
74+
public static class RuleState {
75+
private String rule_id;
76+
private String ruleOnOff;
77+
}
78+
}

src/main/java/scanner/checklist/dto/CheckListModifyDto.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/main/java/scanner/checklist/dto/CheckListSimpleDto.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/java/scanner/checklist/dto/TagDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static TagDto toDto(final Tag entity) {
2424
}
2525

2626
public static Tag toEntity(final TagDto dto) {
27-
return Tag.builder()
27+
return Tag.tagFromRuleBuilder()
2828
.tagName(dto.getTag())
2929
.build();
3030
}

src/main/java/scanner/checklist/entity/ComplianceEng.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
import lombok.*;
1515
import scanner.common.entity.BaseEntity;
1616

17+
/*
18+
@Written by @Floodnut, v0.3.1-beta
19+
@Todo
20+
Tables separated by language(Korean, English) will be combined into one table.
21+
Details will be organized into separate tables.
22+
*/
23+
1724
@Entity
1825
@Getter
1926
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@@ -55,7 +62,7 @@ public class ComplianceEng extends BaseEntity {
5562
@Column(name = "DETAIL")
5663
private String detail;
5764

58-
@Builder
65+
@Builder(builderClassName = "complianceEnglishBuilder", builderMethodName = "complianceEnglishBuilder")
5966
public ComplianceEng(CustomRule ruleSeq, String complianceName, String complianceNumber, String category,
6067
String article, String description, String detail) {
6168
this.ruleSeq = ruleSeq;

src/main/java/scanner/checklist/entity/ComplianceKor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
import lombok.NoArgsConstructor;
1919
import scanner.common.entity.BaseEntity;
2020

21+
/*
22+
@Written by @Floodnut, v0.3.1-beta
23+
@Todo
24+
Tables separated by language(Korean, English) will be combined into one table.
25+
Details will be organized into separate tables.
26+
*/
27+
2128
@Entity
2229
@Getter
2330
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@@ -59,7 +66,7 @@ public class ComplianceKor extends BaseEntity {
5966
@Column(name = "DETAIL")
6067
private String detail;
6168

62-
@Builder
69+
@Builder(builderClassName = "complianceKoreanBuilder", builderMethodName = "complianceKoreanBuilder")
6370
public ComplianceKor(CustomRule ruleSeq, String complianceName, String complianceNumber, String category,
6471
String article, String description, String detail) {
6572
this.ruleSeq = ruleSeq;

src/main/java/scanner/checklist/entity/CustomRule.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
import scanner.checklist.dto.TagDto;
1616
import scanner.history.entity.ScanHistoryDetail;
1717

18+
/*
19+
@Written by @Floodnut, v0.3.1-beta
20+
@Todo
21+
Columns moved to the CustomRuleDetails table will be deleted.
22+
*/
23+
1824
@Getter
1925
@Entity
2026
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@@ -110,7 +116,7 @@ public class CustomRule extends BaseEntity {
110116
@OneToMany(mappedBy = "ruleSeq")
111117
private List<CustomRuleDetails> ruleDetails = new ArrayList<>();
112118

113-
@Builder
119+
@Builder(builderClassName = "customRuleAddBuilder", builderMethodName = "customRuleAddBuilder")
114120
public CustomRule(String ruleId, String defaultRuleId, String ruleOnOff, Provider provider, String ruleType,
115121
String level, Character isModified, Character isModifiable, String description, String explanation,
116122
String possibleImpact, String insecureExample, String secureExample, String sol, String code,

0 commit comments

Comments
 (0)