Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 24c3740e

Přidáno uživatelem stepanekp před asi 3 roky(ů)

#15 Collect relevant data from AP catalogue implemented

Zobrazit rozdíly:

pom.xml
50 50
			<artifactId>reflections</artifactId>
51 51
			<version>0.9.12</version>
52 52
		</dependency>
53
		<dependency>
54
			<!-- jsoup HTML parser library @ https://jsoup.org/ -->
55
			<groupId>org.jsoup</groupId>
56
			<artifactId>jsoup</artifactId>
57
			<version>1.14.3</version>
58
		</dependency>
53 59
	</dependencies>
54 60

  
55 61
	<build>
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/Constants.java
3 3
public class Constants {
4 4
    public static final String ANTI_PATTERN_CATALOGUE_URL = "https://github.com/ReliSA/Software-process-antipatterns-catalogue/blob/master/catalogue/";
5 5
    public static final String SUBSTRING_DELIMITER = "||";
6
    public static final String ANTI_PATTERN_CATALOGUE_URL_RAW = "https://raw.githubusercontent.com/ReliSA/Software-process-antipatterns-catalogue/master/catalogue/";
6 7
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/AntiPattern.java
1 1
package cz.zcu.fav.kiv.antipatterndetectionapp.model;
2 2

  
3 3
import cz.zcu.fav.kiv.antipatterndetectionapp.Constants;
4
import org.jsoup.Jsoup;
4 5

  
5 6
import java.util.Map;
6 7

  
......
96 97
        return Constants.ANTI_PATTERN_CATALOGUE_URL + this.catalogueFileName;
97 98
    }
98 99

  
100
    public String getDescriptionFromCatalogue() {
101
        String descriptionHeader = "## Summary ";
102
        String url = Constants.ANTI_PATTERN_CATALOGUE_URL_RAW + this.getCatalogueFileName();
103
        String html;
104

  
105
        try {
106
            html = Jsoup.connect(url).get().html();
107
        }
108
        catch (Exception e){
109
            /* If html from catalogue is not extracted, the description from anti-pattern configuration is returned */
110
            return this.getDescription();
111
        }
112

  
113
        String body = Jsoup.parse(html).body().text();
114

  
115
        /* Description parsing */
116
        int startIndex = body.indexOf(descriptionHeader);
117
        String resultDescription = "";
118

  
119
        if(startIndex == 0)
120
            return this.getDescription();
121

  
122
        int tmpIndex = startIndex + descriptionHeader.length(); // starting index position
123

  
124
        do {
125
            resultDescription += body.charAt(tmpIndex);
126
            tmpIndex ++;
127

  
128
            /* If the next headline is reached, the loop is exited */
129
            if(body.substring(tmpIndex, tmpIndex + 2).equals("##"))
130
                break;
131
        } while(tmpIndex < body.length() - 1);
132

  
133
        return resultDescription.trim();
134
    }
135

  
99 136
    @Override
100 137
    public String toString() {
101 138
        return "AntiPattern{" +
src/main/webapp/WEB-INF/templates/anti-pattern.html
68 68
        <div class="form-group">
69 69
            <label for="antiPatternDescription">Anti Pattern description:</label>
70 70
            <textarea disabled class="form-control" id="antiPatternDescription" rows="5"
71
                      th:text="${antiPattern.description}"></textarea>
71
                      th:text="${antiPattern.getDescriptionFromCatalogue()}"></textarea>
72 72
        </div>
73 73
        <!-- ./Anti pattern description -->
74 74

  

Také k dispozici: Unified diff