Skip to content

Commit 6cfce16

Browse files
OndrejVaneppicha
authored andcommitted
#5 Implement user input checks
- added new data types for checking input parameters - chenged UI for showing error messages - refactor validation of input parameters
1 parent c3cfa61 commit 6cfce16

17 files changed

+366
-56
lines changed

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,17 @@ public String configurationPost(Model model,
137137
@RequestParam(value = "configValues", required = false) String[] configValues,
138138
@RequestParam(value = "configNames", required = false) String[] configNames) {
139139

140-
if (antiPatternService.saveNewConfiguration(configNames, configValues)) {
140+
List<AntiPattern> antiPatterns = antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns());
141+
List<String> wrongParameters = antiPatternService.saveNewConfiguration(configNames, configValues);
142+
143+
if (wrongParameters.isEmpty()) {
141144
model.addAttribute("successMessage", "All configuration values has been successfully saved.");
142145
} else {
143-
model.addAttribute("errorMessage", "One or more configuration values are not in correct format");
146+
model.addAttribute("errorMessage", "One or more configuration values are not in correct format, see messages below.");
147+
antiPatternService.setErrorMessages(antiPatterns, wrongParameters);
144148
}
145149

146-
model.addAttribute("antiPatterns", antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns()));
147-
150+
model.addAttribute("antiPatterns", antiPatterns);
148151
return "configuration";
149152
}
150153

@@ -155,13 +158,17 @@ public String antiPatternsPost(Model model,
155158
@RequestParam(value = "configNames", required = false) String[] configNames,
156159
RedirectAttributes redirectAttrs) {
157160

158-
if (antiPatternService.saveNewConfiguration(configNames, configValues)) {
161+
AntiPattern antiPattern = antiPatternService.antiPatternToModel(antiPatternService.getAntiPatternById(id));
162+
List<String> wrongParameters = antiPatternService.saveNewConfiguration(configNames, configValues);
163+
164+
if (wrongParameters.isEmpty()) {
159165
redirectAttrs.addFlashAttribute("successMessage", "All threshold values has been successfully saved.");
160166
} else {
161-
redirectAttrs.addFlashAttribute("errorMessage", "One or more configuration values are not in correct format");
167+
redirectAttrs.addFlashAttribute("errorMessage", "One or more configuration values are not in correct format, see messages below.");
168+
antiPatternService.setErrorMessages(antiPattern, wrongParameters);
162169
}
163170

164-
model.addAttribute("antiPatterns", antiPatternService.antiPatternToModel(antiPatternService.getAntiPatternById(id)));
171+
model.addAttribute("antiPatterns", antiPattern);
165172

166173
return "redirect:/anti-patterns/{id}";
167174
}

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/detectors/BusinessAsUsualDetectorImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cz.zcu.fav.kiv.antipatterndetectionapp.Constants;
44
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.DatabaseConnection;
55
import cz.zcu.fav.kiv.antipatterndetectionapp.model.*;
6+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.Percentage;
67
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils;
78
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
@@ -19,12 +20,15 @@ public class BusinessAsUsualDetectorImpl implements AntiPatternDetector {
1920
"Absence of a retrospective after individual " +
2021
"iterations or after the completion project.",
2122
new HashMap<>() {{
22-
put("divisionOfIterationsWithRetrospective", new Configuration<Float>("divisionOfIterationsWithRetrospective",
23+
put("divisionOfIterationsWithRetrospective", new Configuration<Percentage>("divisionOfIterationsWithRetrospective",
2324
"Division of iterations with retrospective",
24-
"Minimum percentage of the total number of iterations with a retrospective (0,1)", 0.66666f));
25+
"Minimum percentage of the total number of iterations with a retrospective (0,100)",
26+
"Percentage must be between 0 and 100",
27+
new Percentage(66)));
2528
put("searchSubstringsWithRetrospective", new Configuration<String>("searchSubstringsWithRetrospective",
2629
"Search substrings with retrospective",
2730
"Substring that will be search in wikipages and activities",
31+
"Maximum number of substrings is ten and must not starts and ends with characters || ",
2832
"%retr%" + Constants.SUBSTRING_DELIMITER +
2933
"%revi%" + Constants.SUBSTRING_DELIMITER +
3034
"%week%scrum%"));
@@ -37,7 +41,7 @@ public class BusinessAsUsualDetectorImpl implements AntiPatternDetector {
3741
private List<String> sqlQueries;
3842

3943
private float getDivisionOfIterationsWithRetrospective() {
40-
return (float) antiPattern.getConfigurations().get("divisionOfIterationsWithRetrospective").getValue();
44+
return ((Percentage) antiPattern.getConfigurations().get("divisionOfIterationsWithRetrospective").getValue()).getValue();
4145
}
4246

4347
private List<String> getSearchSubstringsWithRetrospective() {

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/detectors/LongOrNonExistentFeedbackLoopsDetectorImpl.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import cz.zcu.fav.kiv.antipatterndetectionapp.Constants;
44
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.DatabaseConnection;
55
import cz.zcu.fav.kiv.antipatterndetectionapp.model.*;
6+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.Percentage;
7+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveFloat;
68
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils;
79
import org.slf4j.Logger;
810
import org.slf4j.LoggerFactory;
@@ -24,16 +26,21 @@ public class LongOrNonExistentFeedbackLoopsDetectorImpl implements AntiPatternDe
2426
"some misunderstood functionality can be created and we have to spend " +
2527
"a lot of effort and time to redo it. ",
2628
new HashMap<>() {{
27-
put("divisionOfIterationsWithFeedbackLoop", new Configuration<Float>("divisionOfIterationsWithFeedbackLoop",
29+
put("divisionOfIterationsWithFeedbackLoop", new Configuration<Percentage>("divisionOfIterationsWithFeedbackLoop",
2830
"Division of iterations with feedback loop",
29-
"Minimum percentage of the total number of iterations with feedback loop (0,1)", 0.5f));
30-
put("maxGapBetweenFeedbackLoopRate", new Configuration<Float>("maxGapBetweenFeedbackLoopRate",
31+
"Minimum percentage of the total number of iterations with feedback loop (0,1)",
32+
"Percentage must be between 0 and 100",
33+
new Percentage(50)));
34+
put("maxGapBetweenFeedbackLoopRate", new Configuration<PositiveFloat>("maxGapBetweenFeedbackLoopRate",
3135
"Maximum gap between feedback loop rate",
3236
"Value that multiplies average iteration length for given project. Result" +
33-
" is maximum threshold value for gap between feedback loops in days.", 2f));
37+
" is maximum threshold value for gap between feedback loops in days.",
38+
"Maximum gap between feedback loop rate must be positive float number",
39+
new PositiveFloat(2f)));
3440
put("searchSubstringsWithFeedbackLoop", new Configuration<String>("searchSubstringsWithFeedbackLoop",
3541
"Search substrings with feedback loop",
3642
"Substring that will be search in wikipages and activities",
43+
"Maximum number of substrings is ten and must not starts and ends with characters ||",
3744
"%schůz%zákazník%" + Constants.SUBSTRING_DELIMITER +
3845
"%předvedení%zákazník%" + Constants.SUBSTRING_DELIMITER +
3946
"%zákazn%demo%" + Constants.SUBSTRING_DELIMITER +
@@ -49,7 +56,7 @@ public class LongOrNonExistentFeedbackLoopsDetectorImpl implements AntiPatternDe
4956
private List<String> sqlQueries;
5057

5158
private float getDivisionOfIterationsWithFeedbackLoop() {
52-
return (float) antiPattern.getConfigurations().get("divisionOfIterationsWithFeedbackLoop").getValue();
59+
return ((Percentage) antiPattern.getConfigurations().get("divisionOfIterationsWithFeedbackLoop").getValue()).getValue();
5360
}
5461

5562
private float getMaxGapBetweenFeedbackLoopRate() {

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/detectors/NinetyNinetyRuleDetectorImpl.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.DatabaseConnection;
44
import cz.zcu.fav.kiv.antipatterndetectionapp.model.*;
5+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveFloat;
6+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveInteger;
57
import org.slf4j.Logger;
68
import org.slf4j.LoggerFactory;
79

@@ -20,12 +22,16 @@ public class NinetyNinetyRuleDetectorImpl implements AntiPatternDetector {
2022
"The functionality is almost done, some number is already closed and is only waiting " +
2123
"for one activity to close, but it has been open for a long time.",
2224
new HashMap<>() {{
23-
put("maxDivisionRange", new Configuration<Double>("maxDivisionRange",
25+
put("maxDivisionRange", new Configuration<PositiveFloat>("maxDivisionRange",
2426
"Maximum ration value",
25-
"Maximum ratio value of spent and estimated time", 1.25));
26-
put("maxBadDivisionLimit", new Configuration<Integer>("maxBadDivisionLimit",
27+
"Maximum ratio value of spent and estimated time",
28+
"Ration values must be positive float number",
29+
new PositiveFloat(1.25f)));
30+
put("maxBadDivisionLimit", new Configuration<PositiveInteger>("maxBadDivisionLimit",
2731
"Maximum iterations thresholds",
28-
"Maximum number of consecutive iterations where the thresholds were exceeded", 2));
32+
"Maximum number of consecutive iterations where the thresholds were exceeded",
33+
"Maximum number of consecutive iterations must be positive integer number",
34+
new PositiveInteger(2)));
2935
}});
3036

3137
private final String sqlFileName = "ninety_ninety_rule.sql";

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/detectors/RoadToNowhereDetectorImpl.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cz.zcu.fav.kiv.antipatterndetectionapp.Constants;
44
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.DatabaseConnection;
55
import cz.zcu.fav.kiv.antipatterndetectionapp.model.*;
6+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveInteger;
67
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils;
78
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
@@ -22,15 +23,20 @@ public class RoadToNowhereDetectorImpl implements AntiPatternDetector {
2223
"takes place on an ad hoc basis with an uncertain " +
2324
"outcome and deadline. There is no project plan in the project.",
2425
new HashMap<>() {{
25-
put("minNumberOfWikiPagesWithProjectPlan", new Configuration<Integer>("minNumberOfWikiPagesWithProjectPlan",
26+
put("minNumberOfWikiPagesWithProjectPlan", new Configuration<PositiveInteger>("minNumberOfWikiPagesWithProjectPlan",
2627
"Minimum number of wiki pages with project plan",
27-
"Number of wiki pages", 1));
28-
put("minNumberOfActivitiesWithProjectPlan", new Configuration<Integer>("minNumberOfActivitiesWithProjectPlan",
28+
"Number of wiki pages",
29+
"Minimum number of wikipages must be positive integer number",
30+
new PositiveInteger(1)));
31+
put("minNumberOfActivitiesWithProjectPlan", new Configuration<PositiveInteger>("minNumberOfActivitiesWithProjectPlan",
2932
"Minimum number of activities with project plan",
30-
"Number of activities", 1));
33+
"Number of activities",
34+
"Minimum number of activities must be positive integer number",
35+
new PositiveInteger(1)));
3136
put("searchSubstringsWithProjectPlan", new Configuration<String>("searchSubstringsWithProjectPlan",
3237
"Search substrings with project plan",
3338
"Substring that will be search in wikipages and activities",
39+
"Maximum number of substrings is ten and must not starts and ends with characters ||",
3440
"%plán projektu%" + Constants.SUBSTRING_DELIMITER +
3541
"%project plan%" + Constants.SUBSTRING_DELIMITER +
3642
"%plan project%" + Constants.SUBSTRING_DELIMITER +

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/detectors/SpecifyNothingDetectorImpl.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cz.zcu.fav.kiv.antipatterndetectionapp.Constants;
44
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.DatabaseConnection;
55
import cz.zcu.fav.kiv.antipatterndetectionapp.model.*;
6+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveInteger;
67
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils;
78
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
@@ -21,18 +22,25 @@ public class SpecifyNothingDetectorImpl implements AntiPatternDetector {
2122
"The specification is not done intentionally. Programmers are " +
2223
"expected to work better without written specifications.",
2324
new HashMap<>() {{
24-
put("minNumberOfWikiPagesWithSpecification", new Configuration<Integer>("minNumberOfWikiPagesWithSpecification",
25+
put("minNumberOfWikiPagesWithSpecification", new Configuration<PositiveInteger>("minNumberOfWikiPagesWithSpecification",
2526
"Minimum number of wiki pages with project specification",
26-
"Number of wiki pages", 1));
27-
put("minNumberOfActivitiesWithSpecification", new Configuration<Integer>("minNumberOfActivitiesWithSpecification",
27+
"Number of wiki pages",
28+
"Minimum number of wikipages must be positive integer number",
29+
new PositiveInteger(1)));
30+
put("minNumberOfActivitiesWithSpecification", new Configuration<PositiveInteger>("minNumberOfActivitiesWithSpecification",
2831
"Minimum number of activities with project specification",
29-
"Number of activities", 1));
30-
put("minAvgLengthOfActivityDescription", new Configuration<Integer>("minAvgLengthOfActivityDescription",
32+
"Number of activities",
33+
"Minimum number of activities with project specification must be positive integer number",
34+
new PositiveInteger(1)));
35+
put("minAvgLengthOfActivityDescription", new Configuration<PositiveInteger>("minAvgLengthOfActivityDescription",
3136
"Minimum average length of activity description",
32-
"Minimum average number of character of activity description", 150));
37+
"Minimum average number of character of activity description",
38+
"Minimum average length of activity description must be positive integer number",
39+
new PositiveInteger(150)));
3340
put("searchSubstringsWithProjectSpecification", new Configuration<String>("searchSubstringsWithProjectSpecification",
3441
"Search substrings with project specification",
3542
"Substring that will be search in wikipages and activities",
43+
"Maximum number of substrings is ten and must not starts and ends with characters ||",
3644
"%dsp%" + Constants.SUBSTRING_DELIMITER +
3745
"%specifikace%" + Constants.SUBSTRING_DELIMITER +
3846
"%specification%" + Constants.SUBSTRING_DELIMITER +

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/detectors/TooLongSprintDetectorImpl.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.DatabaseConnection;
44
import cz.zcu.fav.kiv.antipatterndetectionapp.model.*;
5+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveInteger;
56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
78

@@ -23,12 +24,16 @@ public class TooLongSprintDetectorImpl implements AntiPatternDetector {
2324
"beginning and at the end of the project, but it should not " +
2425
"change in the already started project).",
2526
new HashMap<>() {{
26-
put("maxIterationLength", new Configuration<Integer>("maxIterationLength",
27+
put("maxIterationLength", new Configuration<PositiveInteger>("maxIterationLength",
2728
"Max Iteration Length",
28-
"Maximum iteration length in days", 21));
29-
put("maxNumberOfTooLongIterations", new Configuration<Integer>("maxNumberOfTooLongIterations",
29+
"Maximum iteration length in days",
30+
"Max iteration length must be positive integer",
31+
new PositiveInteger(21)));
32+
put("maxNumberOfTooLongIterations", new Configuration<PositiveInteger>("maxNumberOfTooLongIterations",
3033
"Max number of foo long iterations",
31-
"Maximum number of too long iterations in project", 0));
34+
"Maximum number of too long iterations in project",
35+
"Max number of too long iterations must be positive integer",
36+
new PositiveInteger(0)));
3237
}}
3338
);
3439

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/detectors/VaryingSprintLengthDetectorImpl.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.DatabaseConnection;
44
import cz.zcu.fav.kiv.antipatterndetectionapp.model.*;
5+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveInteger;
56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
78

@@ -24,12 +25,16 @@ public class VaryingSprintLengthDetectorImpl implements AntiPatternDetector {
2425
"but the length of the sprint should not change " +
2526
"during the project.",
2627
new HashMap<>() {{
27-
put("maxDaysDifference", new Configuration<Integer>("maxDaysDifference",
28+
put("maxDaysDifference", new Configuration<PositiveInteger>("maxDaysDifference",
2829
"Max days difference",
29-
"Maximum distance of two consecutive iterations in days", 7));
30-
put("maxIterationChanged", new Configuration<Integer>("maxIterationChanged",
30+
"Maximum distance of two consecutive iterations in days",
31+
"Maximum distance must be positive integer number",
32+
new PositiveInteger(7)));
33+
put("maxIterationChanged", new Configuration<PositiveInteger>("maxIterationChanged",
3134
"Max number of iteration changed",
32-
"Maximum allowed number of significant changes in iteration lengths", 1));
35+
"Maximum allowed number of significant changes in iteration lengths",
36+
"Maximum number of iterations changed must be positive integer number",
37+
new PositiveInteger(1)));
3338
}});
3439

3540
private final String sqlFileName = "varying_sprint_length.sql";

0 commit comments

Comments
 (0)