Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 455a4035

Přidáno uživatelem Ondřej Váně před asi 4 roky(ů)

Added logging and package refactor

Zobrazit rozdíly:

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/ApplicationProperties.java
1
package cz.zcu.fav.kiv.antipatterndetectionapp;
2

  
3
import org.springframework.beans.factory.annotation.Autowired;
4
import org.springframework.core.env.Environment;
5
import org.springframework.stereotype.Component;
6

  
7
@Component
8
public class ApplicationProperties {
9

  
10
    @Autowired
11
    private Environment environment;
12

  
13
    public String getDataSourceUrl () {
14
        return environment.getProperty("spring.datasource.url");
15
    }
16

  
17
    public String getDataSourceUsername() {
18
        return environment.getProperty("spring.datasource.username");
19
    }
20

  
21
    public String getDataSourcePassword() {
22
        return environment.getProperty("spring.datasource.password");
23
    }
24
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/ServletInitializer.java
1
package cz.zcu.fav.kiv.antipatterndetectionapp;
2

  
3
import org.springframework.boot.builder.SpringApplicationBuilder;
4
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
5

  
6
public class ServletInitializer extends SpringBootServletInitializer {
7

  
8
	@Override
9
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
10
		return application.sources(AntiPatternDetectionAppApplication.class);
11
	}
12

  
13
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/SpringApplicationContext.java
1
package cz.zcu.fav.kiv.antipatterndetectionapp;
2

  
3
import org.springframework.beans.BeansException;
4
import org.springframework.context.ApplicationContext;
5
import org.springframework.context.ApplicationContextAware;
6
import org.springframework.context.annotation.Configuration;
7

  
8
@Configuration
9
public class SpringApplicationContext implements ApplicationContextAware {
10

  
11
    static ApplicationContext applicationContext = null;
12

  
13
    public void setApplicationContext(ApplicationContext context)    throws BeansException {
14
        applicationContext = context;
15
    }
16

  
17
    /**
18
     * Note that this is a static method which expose ApplicationContext
19
     **/
20
    public static ApplicationContext getContext(){
21
        return applicationContext;
22
    }
23
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/Utils.java
1
package cz.zcu.fav.kiv.antipatterndetectionapp;
2

  
3
import java.io.BufferedReader;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.io.InputStreamReader;
7
import java.sql.Date;
8
import java.time.LocalDate;
9
import java.time.temporal.ChronoUnit;
10
import java.util.ArrayList;
11
import java.util.List;
12

  
13
public class Utils {
14

  
15
    public static String bindValues(String query, List<String> parameters) {
16
        for (String parameter : parameters) {
17
            query = query.replace("?", parameter);
18
        }
19
        return query;
20
    }
21

  
22
    public static List<String> loadQueryFromFile(String fileName) {
23
        List<String> queries = new ArrayList<>();
24
        InputStream is = Utils.class.getClassLoader().getResourceAsStream(fileName);
25
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
26
        try {
27
            while (reader.ready()) {
28

  
29
                String line = reader.readLine();
30
                if (line.startsWith("select") || line.startsWith("set")) {
31
                    queries.add(line);
32
                }
33

  
34
            }
35
        } catch (IOException e) {
36
            e.printStackTrace();
37
        }
38
        return queries;
39
    }
40

  
41
    public static long daysBetween(Date firstDate, Date secondDate) {
42
        //24-May-2017, change this to your desired Start Date
43
        LocalDate dateBefore = firstDate.toLocalDate();
44
        //29-July-2017, change this to your desired End Date
45
        LocalDate dateAfter = secondDate.toLocalDate();
46
        return ChronoUnit.DAYS.between(dateBefore, dateAfter);
47
    }
48
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java
6 6
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Query;
7 7
import cz.zcu.fav.kiv.antipatterndetectionapp.service.AntiPatternService;
8 8
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService;
9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
9 11
import org.springframework.beans.factory.annotation.Autowired;
10 12
import org.springframework.stereotype.Controller;
11 13
import org.springframework.ui.Model;
......
16 18
@Controller
17 19
public class AppController {
18 20

  
21
    private final Logger LOGGER = LoggerFactory.getLogger(AppController.class);
22

  
19 23
    @Autowired
20 24
    private ProjectService projectService;
21 25

  
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/AntiPatternsEnum.java
1
package cz.zcu.fav.kiv.antipatterndetectionapp.detecting;
2

  
3
public enum AntiPatternsEnum {
4

  
5
    TooLongSprint(1L,
6
            "TooLongSprint",
7
            "Too Long Sprint - DONE",
8
            "Iterations too long. (ideal iteration length is about 1-2 weeks, " +
9
                    "maximum 3 weeks). It could also be detected here if the length " +
10
                    "of the iteration does not change often (It can change at the " +
11
                    "beginning and at the end of the project, but it should not " +
12
                    "change in the already started project)."),
13

  
14
    VaryingSprintLength(2L,
15
            "VaryingSprintLength",
16
            "Varying Sprint Length - DONE",
17
            "The length of the sprint changes very often. " +
18
                    "It is clear that iterations will be different " +
19
                    "lengths at the beginning and end of the project, " +
20
                    "but the length of the sprint should not change " +
21
                    "during the project."),
22

  
23
    RoadToNowhere(3L,
24
            "RoadToNowhere",
25
            "Road To Nowhere - DONE",
26
            "The project is not sufficiently planned and therefore " +
27
                    "takes place on an ad hoc basis with an uncertain " +
28
                    "outcome and deadline. There is no project plan in the project."),
29

  
30
    SpecifyNothing(4L,
31
            "SpecifyNothing",
32
            "Specify Nothing - DONE",
33
            "The specification is not done intentionally. Programmers are " +
34
                    "expected to work better without written specifications."),
35

  
36
    BusinessAsUsual(5L,
37
            "BusinessAsUsual",
38
            "Business As Usual - DONE",
39
            "Absence of a retrospective after individual " +
40
                    "iterations or after the completion project."),
41

  
42
    IndifferentSpecialist(6L,
43
            "IndifferentSpecialist",
44
            "Indifferent specialist",
45
            "A team member who is a specialist in just one thing and does not want to learn new things. " +
46
                    "He refuses to learn new things outside of his specialization. It often disparages other " +
47
                    "\"technologies\". They reduce the seriousness of things that do not specialize in his specialization."),
48

  
49
    LongOrNonExistentFeedbackLoops(7L,
50
            "LongOrNonExistentFeedbackLoops",
51
            "Long Or Non-Existent Feedback Loops",
52
            "Long spacings between customer feedback or no feedback. The customer " +
53
                    "enters the project and sees the final result. In the end, the customer " +
54
                    "may not get what he really wanted. With long intervals of feedback, " +
55
                    "some misunderstood functionality can be created and we have to spend " +
56
                    "a lot of effort and time to redo it. ");
57

  
58

  
59

  
60

  
61
    public final Long id;
62
    public final String name;
63
    public final String printName;
64
    public final String description;
65

  
66
    AntiPatternsEnum(Long id, String name, String printName, String description) {
67
        this.id = id;
68
        this.name = name;
69
        this.printName = printName;
70
        this.description = description;
71
    }
72
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/DatabaseConnection.java
1 1
package cz.zcu.fav.kiv.antipatterndetectionapp.detecting;
2 2

  
3
import cz.zcu.fav.kiv.antipatterndetectionapp.ApplicationProperties;
4
import cz.zcu.fav.kiv.antipatterndetectionapp.SpringApplicationContext;
3
import cz.zcu.fav.kiv.antipatterndetectionapp.spring.ApplicationProperties;
4
import cz.zcu.fav.kiv.antipatterndetectionapp.spring.SpringApplicationContext;
5 5

  
6 6
import java.sql.Connection;
7 7
import java.sql.DriverManager;
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/detectors/BusinessAsUsualDetectorImpl.java
1 1
package cz.zcu.fav.kiv.antipatterndetectionapp.detecting.detectors;
2 2

  
3
import cz.zcu.fav.kiv.antipatterndetectionapp.controller.AppController;
3 4
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.DatabaseConnection;
4 5
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
5 6
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
6 7
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResultItem;
8
import org.slf4j.Logger;
9
import org.slf4j.LoggerFactory;
7 10

  
8 11
public class BusinessAsUsualDetectorImpl implements AntiPatternDetector {
9 12

  
13
    private final Logger LOGGER = LoggerFactory.getLogger(BusinessAsUsualDetectorImpl.class);
14

  
10 15
    private final AntiPattern antiPattern = new AntiPattern(3L,
11 16
            "Business As Usual",
12 17
            "BusinessAsUsual",
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/detectors/TooLongSprintDetectorImpl.java
4 4
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
5 5
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
6 6
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResultItem;
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
7 9

  
8 10
public class TooLongSprintDetectorImpl implements AntiPatternDetector {
9 11

  
12
    private final Logger LOGGER = LoggerFactory.getLogger(TooLongSprintDetectorImpl.class);
13

  
10 14
    private final AntiPattern antiPattern = new AntiPattern(1L,
11 15
            "Too Long Sprint",
12 16
            "TooLongSprint",
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/detectors/VaryingSprintLengthDetectorImpl.java
4 4
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
5 5
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project;
6 6
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResultItem;
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
7 9

  
8 10
public class VaryingSprintLengthDetectorImpl implements AntiPatternDetector {
9 11

  
12
    private final Logger LOGGER = LoggerFactory.getLogger(VaryingSprintLengthDetectorImpl.class);
13

  
10 14
    private final AntiPattern antiPattern = new AntiPattern(2L,
11 15
            "Varying Sprint Length",
12 16
            "VaryingSprintLength",
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/AntiPatternRepository.java
2 2

  
3 3
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.detectors.AntiPatternDetector;
4 4
import org.reflections.Reflections;
5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
5 7
import org.springframework.stereotype.Component;
6 8

  
7 9
import java.lang.reflect.InvocationTargetException;
......
12 14
@Component
13 15
public class AntiPatternRepository {
14 16

  
17
    private final Logger LOGGER = LoggerFactory.getLogger(AntiPatternRepository.class);
18

  
15 19
    private List<AntiPatternDetector> antiPatternDetectors = init();
16 20

  
17 21
    private List<AntiPatternDetector> init() {
......
24 28
            }
25 29
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
26 30
            e.printStackTrace();
27
            // TODO LOG
31
            LOGGER.error("Cannot get all detectors with reflection", e);
28 32
        }
29 33
        return antiPatterns;
30 34
    }
......
35 39

  
36 40
    public AntiPatternDetector getAntiPatternById(Long id) {
37 41
        for (AntiPatternDetector antiPatternDetector : antiPatternDetectors) {
38
            if(antiPatternDetector.getAntiPatternId().equals(id)) {
42
            if (antiPatternDetector.getAntiPatternId().equals(id)) {
39 43
                return antiPatternDetector;
40 44
            }
41 45
            return antiPatternDetector;
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/spring/ApplicationProperties.java
1
package cz.zcu.fav.kiv.antipatterndetectionapp.spring;
2

  
3
import org.springframework.beans.factory.annotation.Autowired;
4
import org.springframework.core.env.Environment;
5
import org.springframework.stereotype.Component;
6

  
7
@Component
8
public class ApplicationProperties {
9

  
10
    @Autowired
11
    private Environment environment;
12

  
13
    public String getDataSourceUrl () {
14
        return environment.getProperty("spring.datasource.url");
15
    }
16

  
17
    public String getDataSourceUsername() {
18
        return environment.getProperty("spring.datasource.username");
19
    }
20

  
21
    public String getDataSourcePassword() {
22
        return environment.getProperty("spring.datasource.password");
23
    }
24
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/spring/ServletInitializer.java
1
package cz.zcu.fav.kiv.antipatterndetectionapp.spring;
2

  
3
import cz.zcu.fav.kiv.antipatterndetectionapp.AntiPatternDetectionAppApplication;
4
import org.springframework.boot.builder.SpringApplicationBuilder;
5
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
6

  
7
public class ServletInitializer extends SpringBootServletInitializer {
8

  
9
	@Override
10
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
11
		return application.sources(AntiPatternDetectionAppApplication.class);
12
	}
13

  
14
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/spring/SpringApplicationContext.java
1
package cz.zcu.fav.kiv.antipatterndetectionapp.spring;
2

  
3
import org.springframework.beans.BeansException;
4
import org.springframework.context.ApplicationContext;
5
import org.springframework.context.ApplicationContextAware;
6
import org.springframework.context.annotation.Configuration;
7

  
8
@Configuration
9
public class SpringApplicationContext implements ApplicationContextAware {
10

  
11
    static ApplicationContext applicationContext = null;
12

  
13
    public void setApplicationContext(ApplicationContext context)    throws BeansException {
14
        applicationContext = context;
15
    }
16

  
17
    /**
18
     * Note that this is a static method which expose ApplicationContext
19
     **/
20
    public static ApplicationContext getContext(){
21
        return applicationContext;
22
    }
23
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/utils/Utils.java
1
package cz.zcu.fav.kiv.antipatterndetectionapp.utils;
2

  
3
import java.io.BufferedReader;
4
import java.io.IOException;
5
import java.io.InputStream;
6
import java.io.InputStreamReader;
7
import java.sql.Date;
8
import java.time.LocalDate;
9
import java.time.temporal.ChronoUnit;
10
import java.util.ArrayList;
11
import java.util.List;
12

  
13
public class Utils {
14

  
15
    public static String bindValues(String query, List<String> parameters) {
16
        for (String parameter : parameters) {
17
            query = query.replace("?", parameter);
18
        }
19
        return query;
20
    }
21

  
22
    public static List<String> loadQueryFromFile(String fileName) {
23
        List<String> queries = new ArrayList<>();
24
        InputStream is = Utils.class.getClassLoader().getResourceAsStream(fileName);
25
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
26
        try {
27
            while (reader.ready()) {
28

  
29
                String line = reader.readLine();
30
                if (line.startsWith("select") || line.startsWith("set")) {
31
                    queries.add(line);
32
                }
33

  
34
            }
35
        } catch (IOException e) {
36
            e.printStackTrace();
37
        }
38
        return queries;
39
    }
40

  
41
    public static long daysBetween(Date firstDate, Date secondDate) {
42
        //24-May-2017, change this to your desired Start Date
43
        LocalDate dateBefore = firstDate.toLocalDate();
44
        //29-July-2017, change this to your desired End Date
45
        LocalDate dateAfter = secondDate.toLocalDate();
46
        return ChronoUnit.DAYS.between(dateBefore, dateAfter);
47
    }
48
}

Také k dispozici: Unified diff