1 |
|
---|
2 | package de.ugoe.cs.autoquest.usability.evaluation.result;
|
---|
3 |
|
---|
4 | import static java.lang.String.format;
|
---|
5 |
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Map;
|
---|
8 |
|
---|
9 | import lombok.AllArgsConstructor;
|
---|
10 | import lombok.ExtensionMethod;
|
---|
11 | import lombok.Getter;
|
---|
12 |
|
---|
13 | import org.apache.commons.lang.StringUtils;
|
---|
14 |
|
---|
15 | import com.google.common.base.CharMatcher;
|
---|
16 | import com.google.common.base.Joiner;
|
---|
17 | import com.google.common.collect.Lists;
|
---|
18 |
|
---|
19 | import de.ugoe.cs.autoquest.usability.DefectDescription;
|
---|
20 | import de.ugoe.cs.autoquest.usability.ParameterFragment;
|
---|
21 | import de.ugoe.cs.autoquest.usability.util.DefectDescriptionExtensionMethods;
|
---|
22 |
|
---|
23 | @AllArgsConstructor
|
---|
24 | @ExtensionMethod({DefectDescriptionExtensionMethods.class})
|
---|
25 | public class UsabilityDefect {
|
---|
26 |
|
---|
27 | @Getter
|
---|
28 | private UsabilityDefectSeverityLevel severityLevel;
|
---|
29 |
|
---|
30 | private DefectDescription defectDescription;
|
---|
31 |
|
---|
32 | private Map<String, String> descriptionParametersValues;
|
---|
33 |
|
---|
34 | public String defectDescription() {
|
---|
35 | if(defectDescription.containsParameterFragments()) {
|
---|
36 | return assembleDefectDescription();
|
---|
37 | } else {
|
---|
38 | return Joiner.on(" ").skipNulls().join(defectDescription.getTextFragmentOrParameterFragment());
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | private String assembleDefectDescription() {
|
---|
43 | List<String> descriptionParts =
|
---|
44 | Lists.newArrayListWithCapacity(defectDescription.getTextFragmentOrParameterFragment().size());
|
---|
45 |
|
---|
46 | for (Object fragment : defectDescription.getTextFragmentOrParameterFragment()) {
|
---|
47 | if (fragment.isParameterFragment()) {
|
---|
48 | descriptionParts.add(parameterFragmentAsString((ParameterFragment) fragment));
|
---|
49 | } else {
|
---|
50 | descriptionParts.add(CharMatcher.WHITESPACE.collapseFrom((String) fragment, ' ').trim());
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | return Joiner.on(' ').join(descriptionParts);
|
---|
55 | }
|
---|
56 |
|
---|
57 | private String parameterFragmentAsString(ParameterFragment fragment) {
|
---|
58 | String value = descriptionParametersValues.getValueOrEmptyString(fragment.getParameterName());
|
---|
59 | if (StringUtils.isNotEmpty(value)) {
|
---|
60 | return value;
|
---|
61 | } else {
|
---|
62 | throw new IllegalArgumentException(format("required parameter \"%s\" for usability defect description not provided", fragment.getParameterName()));
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | }
|
---|