Revize 20a4d17d
Přidáno uživatelem stepanekp před asi 3 roky(ů)
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java | ||
---|---|---|
103 | 103 |
@GetMapping("/anti-patterns/{id}") |
104 | 104 |
public String getAntiPatternById(@PathVariable Long id, Model model) { |
105 | 105 |
model.addAttribute("antiPattern", antiPatternService.getAntiPatternById(id).getAntiPatternModel()); |
106 |
model.addAttribute("description", antiPatternService.getDescriptionFromCatalogue(id)); |
|
106 | 107 |
return "anti-pattern"; |
107 | 108 |
} |
108 | 109 |
|
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/AntiPattern.java | ||
---|---|---|
101 | 101 |
return Constants.ANTI_PATTERN_CATALOGUE_URL + this.catalogueFileName; |
102 | 102 |
} |
103 | 103 |
|
104 |
public String getDescriptionFromCatalogue() { |
|
105 |
String descriptionHeader = "## Summary "; |
|
106 |
String url = Constants.ANTI_PATTERN_CATALOGUE_URL_RAW + this.getCatalogueFileName(); |
|
107 |
String html; |
|
108 |
|
|
109 |
try { |
|
110 |
html = Jsoup.connect(url).get().html(); |
|
111 |
} |
|
112 |
catch (Exception e){ |
|
113 |
/* If html from catalogue is not extracted, the description from anti-pattern configuration is returned */ |
|
114 |
return this.getDescription(); |
|
115 |
} |
|
116 |
|
|
117 |
String body = Jsoup.parse(html).body().text(); |
|
118 |
|
|
119 |
/* Description parsing */ |
|
120 |
int startIndex = body.indexOf(descriptionHeader); |
|
121 |
String resultDescription = ""; |
|
122 |
|
|
123 |
if(startIndex == 0) |
|
124 |
return this.getDescription(); |
|
125 |
|
|
126 |
int tmpIndex = startIndex + descriptionHeader.length(); // starting index position |
|
127 |
|
|
128 |
do { |
|
129 |
resultDescription += body.charAt(tmpIndex); |
|
130 |
tmpIndex ++; |
|
131 |
|
|
132 |
/* If the next headline is reached, the loop is exited */ |
|
133 |
if(body.substring(tmpIndex, tmpIndex + 2).equals("##")) |
|
134 |
break; |
|
135 |
} while(tmpIndex < body.length() - 1); |
|
136 |
|
|
137 |
return resultDescription.trim(); |
|
138 |
} |
|
139 |
|
|
140 | 104 |
public String getOperationalizationText() { |
141 | 105 |
String myPath = new FileSystemResource("").getFile().getAbsolutePath() + "\\src\\main\\webapp\\operationalizations\\" + this.getName() + ".html"; |
142 | 106 |
String content = null; |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternService.java | ||
---|---|---|
39 | 39 |
AntiPattern setErrorMessages(AntiPattern antiPattern, List<String> wrongParameters); |
40 | 40 |
|
41 | 41 |
AntiPattern getAntiPatternFromJsonFile(String fileName); |
42 |
|
|
43 |
String getDescriptionFromCatalogue(long id); |
|
42 | 44 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternServiceImpl.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.service; |
2 | 2 |
|
3 | 3 |
import com.fasterxml.jackson.databind.JsonNode; |
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.Constants; |
|
4 | 5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.detectors.AntiPatternDetector; |
5 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern; |
6 | 7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.CacheablesValues; |
... | ... | |
12 | 13 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.AntiPatternRepository; |
13 | 14 |
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.JsonParser; |
14 | 15 |
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils; |
16 |
import org.jsoup.Jsoup; |
|
15 | 17 |
import org.springframework.beans.factory.annotation.Autowired; |
16 | 18 |
import org.springframework.core.io.FileSystemResource; |
17 | 19 |
import org.springframework.stereotype.Service; |
... | ... | |
267 | 269 |
return null; |
268 | 270 |
} |
269 | 271 |
|
272 |
@Override |
|
273 |
public String getDescriptionFromCatalogue(long id) { |
|
274 |
AntiPattern ap = this.getAntiPatternById(id).getAntiPatternModel(); |
|
275 |
|
|
276 |
String descriptionHeader = "## Summary "; |
|
277 |
String url = Constants.ANTI_PATTERN_CATALOGUE_URL_RAW + ap.getCatalogueFileName(); |
|
278 |
String html; |
|
279 |
|
|
280 |
try { |
|
281 |
html = Jsoup.connect(url).get().html(); |
|
282 |
} |
|
283 |
catch (Exception e){ |
|
284 |
/* If html from catalogue is not extracted, the description from anti-pattern configuration is returned */ |
|
285 |
return ap.getDescription(); |
|
286 |
} |
|
287 |
|
|
288 |
String body = Jsoup.parse(html).body().text(); |
|
289 |
|
|
290 |
/* Description parsing */ |
|
291 |
int startIndex = body.indexOf(descriptionHeader); |
|
292 |
String resultDescription = ""; |
|
293 |
|
|
294 |
if(startIndex == 0) |
|
295 |
return ap.getDescription(); |
|
296 |
|
|
297 |
int tmpIndex = startIndex + descriptionHeader.length(); // starting index position |
|
298 |
|
|
299 |
do { |
|
300 |
resultDescription += body.charAt(tmpIndex); |
|
301 |
tmpIndex ++; |
|
302 |
|
|
303 |
/* If the next headline is reached, the loop is exited */ |
|
304 |
if(body.substring(tmpIndex, tmpIndex + 2).equals("##")) |
|
305 |
break; |
|
306 |
} while(tmpIndex < body.length() - 1); |
|
307 |
|
|
308 |
return resultDescription.trim(); |
|
309 |
} |
|
270 | 310 |
} |
src/main/webapp/WEB-INF/templates/anti-pattern.html | ||
---|---|---|
69 | 69 |
<div class="form-group"> |
70 | 70 |
<h5 for="antiPatternDescription">Anti Pattern Description</h5> |
71 | 71 |
<textarea disabled class="form-control" id="antiPatternDescription" rows="5" |
72 |
th:text="${antiPattern.getDescriptionFromCatalogue()}"></textarea>
|
|
72 |
th:text="${description}"></textarea>
|
|
73 | 73 |
</div> |
74 | 74 |
<!-- ./Anti pattern description --> |
75 | 75 |
|
Také k dispozici: Unified diff
Description from cataloque get function moved