Project

General

Profile

« Previous | Next » 

Revision 49863

Added by Tsampikos Livisianos about 7 years ago

initial commit <3

View differences:

modules/uoa-admin-tools/src/test/java/eu/dnetlib/uoaadmintools/UoaAdminToolsApplicationTests.java
1
package eu.dnetlib.uoaadmintools;
2

  
3
import org.junit.Test;
4
import org.junit.runner.RunWith;
5
import org.springframework.boot.test.context.SpringBootTest;
6
import org.springframework.test.context.junit4.SpringRunner;
7

  
8
@RunWith(SpringRunner.class)
9
@SpringBootTest
10
public class UoaAdminToolsApplicationTests {
11

  
12
	@Test
13
	public void contextLoads() {
14
	}
15

  
16
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/responses/ExceptionResponse.java
1
package eu.dnetlib.uoaadmintools.responses;
2

  
3
import java.util.List;
4

  
5
public class ExceptionResponse {
6

  
7
    private String errorCode;
8
    private String errorMessage;
9
    private String errors;
10

  
11
    public ExceptionResponse() {
12
    }
13

  
14
    public String getErrorCode() {
15
        return errorCode;
16
    }
17

  
18
    public void setErrorCode(String errorCode) {
19
        this.errorCode = errorCode;
20
    }
21

  
22
    public String getErrorMessage() {
23
        return errorMessage;
24
    }
25

  
26
    public void setErrorMessage(String errorMessage) {
27
        this.errorMessage = errorMessage;
28
    }
29

  
30
    public String getErrors() {
31
        return errors;
32
    }
33

  
34
    public void setErrors(String errors) {
35
        this.errors = errors;
36
    }
37
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/UoaAdminToolsApplication.java
1
package eu.dnetlib.uoaadmintools;
2

  
3
import org.springframework.boot.SpringApplication;
4
import org.springframework.boot.autoconfigure.SpringBootApplication;
5

  
6
@SpringBootApplication
7
public class UoaAdminToolsApplication {
8

  
9
    public static void main(String[] args) {
10
        SpringApplication.run(UoaAdminToolsApplication.class, args);
11
    }
12
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/PageDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

  
3
import eu.dnetlib.uoaadmintools.entities.Page;
4

  
5
import java.util.List;
6

  
7
public interface PageDAO {
8
    List<Page> findAll();
9

  
10
    Page findById(String Id);
11

  
12
    Page save(Page page);
13

  
14
    void deleteAll();
15

  
16
    void delete(String id);
17
}
18

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBQuestionDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

  
3
import eu.dnetlib.uoaadmintools.entities.Question;
4

  
5
import org.springframework.data.mongodb.repository.MongoRepository;
6

  
7
import java.util.List;
8

  
9
public interface MongoDBQuestionDAO extends QuestionDAO, MongoRepository<Question, String> {
10
    List<Question> findAll();
11

  
12
    Question findById(String id);
13

  
14
    List<Question> findByTopicsIn(String id);
15

  
16
    List<Question> findByTopicsInAndIsActiveIsTrue(String id);
17

  
18
    Question save(Question question);
19

  
20
    void deleteAll();
21

  
22
    void delete(String id);
23
}
24

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/TopicDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

  
3
import eu.dnetlib.uoaadmintools.entities.Topic;
4

  
5
import java.util.List;
6

  
7
public interface TopicDAO {
8
    List<Topic> findAll();
9

  
10
    Topic findById(String Id);
11

  
12
    Topic save(Topic topic);
13

  
14
    void deleteAll();
15

  
16
    void delete(String id);
17
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/PageHelpContentDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

  
3
import eu.dnetlib.uoaadmintools.entities.PageHelpContent;
4

  
5
import java.util.List;
6

  
7
public interface PageHelpContentDAO {
8
    List<PageHelpContent> findAll();
9

  
10
    PageHelpContent findById(String Id);
11

  
12
    PageHelpContent save(PageHelpContent pageHelpContent);
13

  
14
    void deleteAll();
15

  
16
    void delete(String id);
17
}
18

  
19

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBPageDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

  
3
import eu.dnetlib.uoaadmintools.entities.Page;
4

  
5
import org.springframework.data.mongodb.repository.MongoRepository;
6

  
7
import java.util.List;
8

  
9
public interface MongoDBPageDAO extends PageDAO, MongoRepository<Page, String> {
10
    List<Page> findAll();
11

  
12
    Page findById(String Id);
13

  
14
    Page save(Page page);
15

  
16
    void deleteAll();
17

  
18
    void delete(String id);
19
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBTopicDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

  
3
import eu.dnetlib.uoaadmintools.entities.Topic;
4

  
5
import org.springframework.data.mongodb.repository.MongoRepository;
6

  
7
import java.util.List;
8

  
9
public interface MongoDBTopicDAO extends TopicDAO, MongoRepository<Topic, String> {
10
    List<Topic> findAll();
11

  
12
    Topic findById(String Id);
13

  
14
    Topic save(Topic topic);
15

  
16
    void deleteAll();
17

  
18
    void delete(String id);
19
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/MongoDBPageHelpContentDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

  
3
import eu.dnetlib.uoaadmintools.entities.PageHelpContent;
4

  
5
import org.springframework.data.mongodb.repository.MongoRepository;
6

  
7
import java.util.List;
8

  
9
public interface MongoDBPageHelpContentDAO extends PageHelpContentDAO, MongoRepository<PageHelpContent, String> {
10
    List<PageHelpContent> findAll();
11

  
12
    PageHelpContent findById(String Id);
13

  
14
    PageHelpContent save(PageHelpContent pageHelpContent);
15

  
16
    void deleteAll();
17

  
18
    void delete(String id);
19
}
20

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/dao/QuestionDAO.java
1
package eu.dnetlib.uoaadmintools.dao;
2

  
3
import eu.dnetlib.uoaadmintools.entities.Question;
4

  
5
import java.util.List;
6

  
7
public interface QuestionDAO {
8
    List<Question> findAll();
9

  
10
    Question findById(String id);
11

  
12
    List<Question> findByTopicsIn(String id);
13

  
14
    List<Question> findByTopicsInAndIsActiveIsTrue(String id);
15

  
16
    Question save(Question question);
17

  
18
    void deleteAll();
19

  
20
    void delete(String id);
21
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/PageHelpContentResponse.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

  
7
public class PageHelpContentResponse {
8

  
9
    @Id
10
    @JsonProperty("_id")
11
    private String id;
12

  
13
    private Page page;
14
    private String placement;
15
    private int order;
16
    private String content;
17
    private boolean isActive = true;
18

  
19
    public PageHelpContentResponse() {
20
    }
21

  
22
    public PageHelpContentResponse(PageHelpContent pageHelpContent) {
23
        this.id = pageHelpContent.getId();
24
        this.placement = pageHelpContent.getPlacement();
25
        this.order = pageHelpContent.getOrder();
26
        this.content = pageHelpContent.getContent();
27
        this.isActive = pageHelpContent.getIsActive();
28
    }
29

  
30
    public String getId() {
31
        return id;
32
    }
33

  
34
    public void setId(String id) {
35
        this.id = id;
36
    }
37

  
38
    public Page getPage() {
39
        return page;
40
    }
41

  
42
    public void setPage(Page page) {
43
        this.page = page;
44
    }
45

  
46
    public String getPlacement() {
47
        return placement;
48
    }
49

  
50
    public void setPlacement(String placement) {
51
        this.placement = placement;
52
    }
53

  
54
    public int getOrder() {
55
        return order;
56
    }
57

  
58
    public void setOrder(int order) {
59
        this.order = order;
60
    }
61

  
62
    public String getContent() {
63
        return content;
64
    }
65

  
66
    public void setContent(String content) {
67
        this.content = content;
68
    }
69

  
70
    public boolean getIsActive() {
71
        return isActive;
72
    }
73

  
74
    public void setIsActive(boolean isActive) {
75
        this.isActive = isActive;
76
    }
77
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/PageHelpContent.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

  
7
public class PageHelpContent {
8

  
9
    @Id
10
    @JsonProperty("_id")
11
    private String id;
12

  
13
    private String page;
14
    private String placement;
15
    private int order;
16
    private String content;
17
    private boolean isActive = true;
18

  
19
    public PageHelpContent() {
20
    }
21

  
22
    public String getId() {
23
        return id;
24
    }
25

  
26
    public void setId(String id) {
27
        this.id = id;
28
    }
29

  
30
    public String getPage() {
31
        return page;
32
    }
33

  
34
    public void setPage(String page) {
35
        this.page = page;
36
    }
37

  
38
    public String getPlacement() {
39
        return placement;
40
    }
41

  
42
    public void setPlacement(String placement) {
43
        this.placement = placement;
44
    }
45

  
46
    public int getOrder() {
47
        return order;
48
    }
49

  
50
    public void setOrder(int order) {
51
        this.order = order;
52
    }
53

  
54
    public String getContent() {
55
        return content;
56
    }
57

  
58
    public void setContent(String content) {
59
        this.content = content;
60
    }
61

  
62
    public boolean getIsActive() {
63
        return isActive;
64
    }
65

  
66
    public void setIsActive(boolean isActive) {
67
        this.isActive = isActive;
68
    }
69
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/QuestionResponse.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

  
7
import java.util.Date;
8
import java.util.List;
9

  
10
public class QuestionResponse {
11

  
12
    @Id
13
    @JsonProperty("_id")
14
    private String id;
15

  
16
    private String question;
17
    private String answer;
18
    private Date date = new Date();
19
    private boolean isActive = true;
20
    private Float weight;
21
    private int hitCount = 0;
22
    private List<Topic> topics;
23

  
24
    public QuestionResponse() {
25
    }
26

  
27
    public QuestionResponse(Question question) {
28
        this.id = question.getId();
29
        this.question = question.getQuestion();
30
        this.answer = question.getAnswer();
31
        this.date = question.getDate();
32
        this.isActive = question.getIsActive();
33
        this.weight = question.getWeight();
34
        this.hitCount = question.getHitCount();
35
    }
36

  
37
    public String getId() {
38
        return id;
39
    }
40

  
41
    public void setId(String id) {
42
        this.id = id;
43
    }
44

  
45
    public String getQuestion() {
46
        return question;
47
    }
48

  
49
    public void setQuestion(String question) {
50
        this.question = question;
51
    }
52

  
53
    public String getAnswer() {
54
        return answer;
55
    }
56

  
57
    public void setAnswer(String answer) {
58
        this.answer = answer;
59
    }
60

  
61
    public Date getDate() {
62
        return date;
63
    }
64

  
65
    public void setDate(Date date) {
66
        this.date = date;
67
    }
68

  
69
    public boolean getIsActive() {
70
        return isActive;
71
    }
72

  
73
    public void setIsActive(boolean isActive) {
74
        this.isActive = isActive;
75
    }
76

  
77
    public Float getWeight() {
78
        return weight;
79
    }
80

  
81
    public void setWeight(Float weight) {
82
        this.weight = weight;
83
    }
84

  
85
    public int getHitCount() {
86
        return hitCount;
87
    }
88

  
89
    public void setHitCount(int hitCount) {
90
        this.hitCount = hitCount;
91
    }
92

  
93
    public List<Topic> getTopics() {
94
        return topics;
95
    }
96

  
97
    public void setTopics(List<Topic> topics) {
98
        this.topics = topics;
99
    }
100
}
101

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/Question.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

  
7
import java.util.Date;
8
import java.util.List;
9

  
10
public class Question {
11

  
12
    @Id
13
    @JsonProperty("_id")
14
    private String id;
15

  
16
    private String question;
17
    private String answer;
18
    private Date date = new Date();
19
    private boolean isActive = true;
20
    private Float weight;
21
    private int hitCount = 0;
22
    private List<String> topics;
23

  
24
    public Question() {
25
    }
26

  
27
    /*
28
    public Question(String question, String answer, boolean isActive, Float weight, List<String> topics) {
29
        this.question = question;
30
        this.answer = answer;
31
        this.isActive = isActive;
32
        this.weight = weight;
33
        this.topics = topics;
34
        this.hitCount = 0;
35
        this.isActive = true;
36
    }
37
    */
38

  
39
    public String getId() {
40
        return id;
41
    }
42

  
43
    public void setId(String id) {
44
        this.id = id;
45
    }
46

  
47
    public String getQuestion() {
48
        return question;
49
    }
50

  
51
    public void setQuestion(String question) {
52
        this.question = question;
53
    }
54

  
55
    public String getAnswer() {
56
        return answer;
57
    }
58

  
59
    public void setAnswer(String answer) {
60
        this.answer = answer;
61
    }
62

  
63
    public Date getDate() {
64
        return date;
65
    }
66

  
67
    public void setDate(Date date) {
68
        this.date = date;
69
    }
70

  
71
    public boolean getIsActive() {
72
        return isActive;
73
    }
74

  
75
    public void setIsActive(boolean isActive) {
76
        this.isActive = isActive;
77
    }
78

  
79
    public Float getWeight() {
80
        return weight;
81
    }
82

  
83
    public void setWeight(Float weight) {
84
        this.weight = weight;
85
    }
86

  
87
    public int getHitCount() {
88
        return hitCount;
89
    }
90

  
91
    public void setHitCount(int hitCount) {
92
        this.hitCount = hitCount;
93
    }
94

  
95
    public List<String> getTopics() {
96
        return topics;
97
    }
98

  
99
    public void setTopics(List<String> topics) {
100
        this.topics = topics;
101
    }
102

  
103
    public void increment() {
104
        hitCount++;
105
    }
106
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/Page.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

  
7
public class Page {
8

  
9
    @Id
10
    @JsonProperty("_id")
11
    private String id;
12

  
13
    private String route;
14
    private String name;
15

  
16
    public Page() {
17
    }
18

  
19
    public String getId() {
20
        return id;
21
    }
22

  
23
    public void setId(String id) {
24
        this.id = id;
25
    }
26

  
27
    public String getRoute() {
28
        return route;
29
    }
30

  
31
    public void setRoute(String route) {
32
        this.route = route;
33
    }
34

  
35
    public String getName() {
36
        return name;
37
    }
38

  
39
    public void setName(String name) {
40
        this.name = name;
41
    }
42
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/TopicResponse.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

  
7
import java.util.Date;
8
import java.util.List;
9

  
10
public class TopicResponse {
11

  
12
    @Id
13
    @JsonProperty("_id")
14
    private String id;
15

  
16
    private String name;
17
    private String description;
18
    private Date date = new Date();
19
    private Float weight;
20
    private String questionOrder;
21
    private List<Question> questions;
22

  
23

  
24
    public TopicResponse() {
25
    }
26

  
27
    public TopicResponse(Topic topic) {
28
        this.id = topic.getId();
29
        this.name = topic.getName();
30
        this.description = topic.getDescription();
31
        this.date = topic.getDate();
32
        this.weight = topic.getWeight();
33
        this.questionOrder = topic.getQuestionOrder();
34
    }
35

  
36
    public String getId() {
37
        return id;
38
    }
39

  
40
    public void setId(String id) {
41
        this.id = id;
42
    }
43

  
44
    public String getName() {
45
        return name;
46
    }
47

  
48
    public void setName(String name) {
49
        this.name = name;
50
    }
51

  
52
    public String getDescription() {
53
        return description;
54
    }
55

  
56
    public void setDescription(String description) {
57
        this.description = description;
58
    }
59

  
60
    public Date getDate() {
61
        return date;
62
    }
63

  
64
    public void setDate(Date date) {
65
        this.date = date;
66
    }
67

  
68
    public Float getWeight() {
69
        return weight;
70
    }
71

  
72
    public void setWeight(Float weight) {
73
        this.weight = weight;
74
    }
75

  
76
    public String getQuestionOrder() {
77
        return questionOrder;
78
    }
79

  
80
    public void setQuestionOrder(String questionOrder) {
81
        this.questionOrder = questionOrder;
82
    }
83

  
84
    public List<Question> getQuestions() {
85
        return questions;
86
    }
87

  
88
    public void setQuestions(List<Question> questions) {
89
        this.questions = questions;
90
    }
91
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/entities/Topic.java
1
package eu.dnetlib.uoaadmintools.entities;
2

  
3
import com.fasterxml.jackson.annotation.JsonProperty;
4

  
5
import org.springframework.data.annotation.Id;
6

  
7
import java.util.Date;
8

  
9
public class Topic {
10

  
11
    @Id
12
    @JsonProperty("_id")
13
    private String id;
14

  
15
    private String name;
16
    private String description;
17
    private Date date = new Date();
18
    private Float weight;
19
    private String questionOrder;
20

  
21
    public Topic() {
22
    }
23

  
24
    /*
25
    public Topic(String name, String description, Float weight, String questionOrder) {
26
        this.name = name;
27
        this.description = description;
28
        this.weight = weight;
29
        this.questionOrder = questionOrder;
30
    }
31
    */
32

  
33
    public String getId() {
34
        return id;
35
    }
36

  
37
    public void setId(String id) {
38
        this.id = id;
39
    }
40

  
41
    public String getName() {
42
        return name;
43
    }
44

  
45
    public void setName(String name) {
46
        this.name = name;
47
    }
48

  
49
    public String getDescription() {
50
        return description;
51
    }
52

  
53
    public void setDescription(String description) {
54
        this.description = description;
55
    }
56

  
57
    public Date getDate() {
58
        return date;
59
    }
60

  
61
    public void setDate(Date date) {
62
        this.date = date;
63
    }
64

  
65
    public Float getWeight() {
66
        return weight;
67
    }
68

  
69
    public void setWeight(Float weight) {
70
        this.weight = weight;
71
    }
72

  
73
    public String getQuestionOrder() {
74
        return questionOrder;
75
    }
76

  
77
    public void setQuestionOrder(String questionOrder) {
78
        this.questionOrder = questionOrder;
79
    }
80
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/PageController.java
1
package eu.dnetlib.uoaadmintools.controllers;
2

  
3
import eu.dnetlib.uoaadmintools.entities.Page;
4
import eu.dnetlib.uoaadmintools.dao.PageDAO;
5

  
6
import org.apache.log4j.Logger;
7
import org.springframework.web.bind.annotation.CrossOrigin;
8
import org.springframework.web.bind.annotation.RequestMapping;
9
import org.springframework.web.bind.annotation.RequestMethod;
10
import org.springframework.web.bind.annotation.RequestBody;
11
import org.springframework.web.bind.annotation.PathVariable;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.web.bind.annotation.RestController;
14

  
15
import java.util.List;
16

  
17
@RestController
18
@CrossOrigin(origins = "*")
19
public class PageController {
20
    private final Logger log = Logger.getLogger(this.getClass());
21

  
22
    @Autowired
23
    private PageDAO pageDAO;
24

  
25
    @RequestMapping(value = "/page", method = RequestMethod.GET)
26
    public List<Page> getAllPages() {
27
        return pageDAO.findAll();
28
    }
29

  
30
    @RequestMapping(value = "/page", method = RequestMethod.DELETE)
31
    public void deleteAllPages() {
32
        pageDAO.deleteAll();
33
    }
34

  
35
    @RequestMapping(value = "/page", method = RequestMethod.POST)
36
    public Page insertOrUpdatePage(@RequestBody Page page) {
37
        return pageDAO.save(page);
38
    }
39

  
40
    @RequestMapping(value = "/page/{id}", method = RequestMethod.GET)
41
    public Page getPage(@PathVariable(value = "id") String id) {
42
        return pageDAO.findById(id);
43
    }
44

  
45
    @RequestMapping(value = "/page/{id}", method = RequestMethod.DELETE)
46
    public void deletePage(@PathVariable(value = "id") String id) {
47
        pageDAO.delete(id);
48
    }
49

  
50

  
51
}
52

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/ExceptionController.java
1
package eu.dnetlib.uoaadmintools.controllers;
2

  
3
import eu.dnetlib.uoaadmintools.responses.ExceptionResponse;
4

  
5
import org.springframework.http.HttpStatus;
6
import org.springframework.http.ResponseEntity;
7
import org.springframework.web.bind.MissingServletRequestParameterException;
8
import org.springframework.web.bind.annotation.ControllerAdvice;
9
import org.springframework.web.bind.annotation.ExceptionHandler;
10

  
11
@ControllerAdvice
12
public class ExceptionController {
13

  
14
    @ExceptionHandler(MissingServletRequestParameterException.class)
15
    public ResponseEntity<ExceptionResponse> invalidInput(Exception ex) {
16
        ExceptionResponse response = new ExceptionResponse();
17
        response.setErrorCode("Validation Error");
18
        response.setErrorMessage("Invalid inputs.");
19
        response.setErrors(ex.getMessage());
20

  
21
        return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
22
    }
23
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/TopicController.java
1
package eu.dnetlib.uoaadmintools.controllers;
2

  
3
import eu.dnetlib.uoaadmintools.entities.Topic;
4
import eu.dnetlib.uoaadmintools.dao.TopicDAO;
5
import eu.dnetlib.uoaadmintools.entities.Question;
6
import eu.dnetlib.uoaadmintools.dao.QuestionDAO;
7
import eu.dnetlib.uoaadmintools.entities.TopicResponse;
8

  
9
import org.apache.log4j.Logger;
10
import org.springframework.web.bind.annotation.CrossOrigin;
11
import org.springframework.web.bind.annotation.RequestMapping;
12
import org.springframework.web.bind.annotation.RequestMethod;
13
import org.springframework.web.bind.annotation.RequestBody;
14
import org.springframework.web.bind.annotation.PathVariable;
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.web.bind.annotation.RequestParam;
17
import org.springframework.web.bind.annotation.RestController;
18

  
19
import java.util.ArrayList;
20
import java.util.Comparator;
21
import java.util.List;
22

  
23
@RestController
24
@CrossOrigin(origins = "*")
25
public class TopicController {
26
    private final Logger log = Logger.getLogger(this.getClass());
27

  
28
    @Autowired
29
    private TopicDAO topicDAO;
30

  
31
    @Autowired
32
    private QuestionDAO questionDAO;
33

  
34
    @RequestMapping(value = "/topic", method = RequestMethod.GET)
35
    public List<Topic> getAllTopics() {
36
        return topicDAO.findAll();
37
    }
38

  
39
    @RequestMapping(value = "/topic", method = RequestMethod.DELETE)
40
    public void deleteAllTopics() {
41
        topicDAO.deleteAll();
42
    }
43

  
44
    //TODO: if id is provided check that it exists!
45
    @RequestMapping(value = "/topic", method = RequestMethod.POST)
46
    public Topic insertOrUpdateTopic(@RequestBody Topic topic) {
47
        return topicDAO.save(topic);
48
    }
49

  
50
    @RequestMapping(value = "/topic/{id}", method = RequestMethod.GET)
51
    public Topic getTopic(@PathVariable(value = "id") String id) {
52
        return topicDAO.findById(id);
53
    }
54

  
55
    @RequestMapping(value = "/topic/{id}", method = RequestMethod.DELETE)
56
    public void deleteTopic(@PathVariable(value = "id") String id) {
57
        List<Question> questions = questionDAO.findByTopicsIn(id);
58
        for (Question question : questions) {
59
            List<String> topics = question.getTopics();
60
            topics.remove(id);
61
            if (topics.isEmpty()) {
62
                questionDAO.delete(question.getId());
63
            } else {
64
                questionDAO.save(question);
65
            }
66
        }
67
        topicDAO.delete(id);
68
    }
69

  
70
    @RequestMapping(value = "/topic/delete", method = RequestMethod.POST)
71
    public void deleteTopics(@RequestBody List<String> topics) {
72
        for (String topic : topics) {
73
            deleteTopic(topic);
74
        }
75
    }
76

  
77
    @RequestMapping(value = "/topic/toggle", method = RequestMethod.POST)
78
    public void toggleTopics(@RequestBody List<String> topics, @RequestParam(value="order", defaultValue = "") String order) throws Exception {
79
        for (String id: topics) {
80
            Topic topic = topicDAO.findById(id);
81
            topic.setQuestionOrder(order);
82
            topicDAO.save(topic);
83
        }
84
    }
85

  
86
    @RequestMapping(value = "/topic/active", method = RequestMethod.GET)
87
    public List<TopicResponse> getActiveTopic() {
88
        List<TopicResponse> topicResponses = new ArrayList<>();
89
        for(Topic topic : topicDAO.findAll()) {
90
            TopicResponse topicResponse = new TopicResponse(topic);
91
            List<Question> questions = questionDAO.findByTopicsInAndIsActiveIsTrue(topic.getId());
92
            if(topic.getQuestionOrder().equals("hits")) {
93
                questions.sort(Comparator.comparingInt(Question::getHitCount).reversed());
94
            } else if(topic.getQuestionOrder().equals("weight")) {
95
                questions.sort(Comparator.comparingDouble(Question::getWeight).reversed());
96
            }
97
            topicResponse.setQuestions(questions);
98
            topicResponses.add(topicResponse);
99
        }
100
        return topicResponses;
101
    }
102

  
103
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/PageHelpContentController.java
1
package eu.dnetlib.uoaadmintools.controllers;
2

  
3
import eu.dnetlib.uoaadmintools.dao.PageDAO;
4
import eu.dnetlib.uoaadmintools.entities.PageHelpContent;
5
import eu.dnetlib.uoaadmintools.dao.PageHelpContentDAO;
6
import eu.dnetlib.uoaadmintools.entities.PageHelpContentResponse;
7

  
8
import org.apache.log4j.Logger;
9
import org.springframework.web.bind.annotation.CrossOrigin;
10
import org.springframework.web.bind.annotation.RequestMapping;
11
import org.springframework.web.bind.annotation.RequestMethod;
12
import org.springframework.web.bind.annotation.RequestBody;
13
import org.springframework.web.bind.annotation.PathVariable;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.web.bind.annotation.RequestParam;
16
import org.springframework.web.bind.annotation.RestController;
17

  
18
import java.util.ArrayList;
19
import java.util.List;
20

  
21
@RestController
22
@CrossOrigin(origins = "*")
23
public class PageHelpContentController {
24
    private final Logger log = Logger.getLogger(this.getClass());
25

  
26
    @Autowired
27
    private PageHelpContentDAO pageHelpContentDAO;
28

  
29
    @Autowired
30
    private PageDAO pageDAO;
31

  
32
    @RequestMapping(value = "/pagehelpcontent", method = RequestMethod.GET)
33
    public List<PageHelpContentResponse> getAllPageHelpContents() {
34
        List<PageHelpContent> pageHelpContents =  pageHelpContentDAO.findAll();
35
        List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
36
        for (PageHelpContent pageHelpContent : pageHelpContents) {
37
           PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
38
           pageHelpContentResponse.setPage(pageDAO.findById(pageHelpContent.getPage()));
39
           pageHelpContentResponses.add(pageHelpContentResponse);
40
        }
41
        return pageHelpContentResponses;
42
    }
43

  
44
    @RequestMapping(value = "/pagehelpcontent", method = RequestMethod.DELETE)
45
    public void deleteAllPageHelpContents() {
46
        pageHelpContentDAO.deleteAll();
47
    }
48

  
49
    @RequestMapping(value = "/pagehelpcontent", method = RequestMethod.POST)
50
    public PageHelpContent insertOrUpdatePageHelpContent(@RequestBody PageHelpContent pageHelpContent) {
51
        return pageHelpContentDAO.save(pageHelpContent);
52
    }
53

  
54
    @RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.GET)
55
    public PageHelpContent getPageHelpContent(@PathVariable(value = "id") String id) {
56
        return pageHelpContentDAO.findById(id);
57
    }
58

  
59
    @RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.DELETE)
60
    public void deletePageHelpContent(@PathVariable(value = "id") String id) {
61
        pageHelpContentDAO.delete(id);
62
    }
63

  
64
    @RequestMapping(value = "/pagehelpcontent/toggle", method = RequestMethod.POST)
65
    public void togglePageHelpContent(@RequestBody List<String> pageHelpContents, @RequestParam String status) throws Exception {
66
        for (String id: pageHelpContents) {
67
            PageHelpContent pageHelpContent = pageHelpContentDAO.findById(id);
68
            pageHelpContent.setIsActive(Boolean.parseBoolean(status));
69
            pageHelpContentDAO.save(pageHelpContent);
70
        }
71
    }
72

  
73

  
74
}
75

  
76

  
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/controllers/QuestionController.java
1
package eu.dnetlib.uoaadmintools.controllers;
2

  
3
import eu.dnetlib.uoaadmintools.entities.Question;
4
import eu.dnetlib.uoaadmintools.entities.QuestionResponse;
5
import eu.dnetlib.uoaadmintools.dao.QuestionDAO;
6
import eu.dnetlib.uoaadmintools.entities.Topic;
7
import eu.dnetlib.uoaadmintools.dao.TopicDAO;
8

  
9
import org.apache.log4j.Logger;
10
import org.springframework.web.bind.annotation.CrossOrigin;
11
import org.springframework.web.bind.annotation.RequestMapping;
12
import org.springframework.web.bind.annotation.RequestMethod;
13
import org.springframework.web.bind.annotation.RequestBody;
14
import org.springframework.web.bind.annotation.PathVariable;
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.web.bind.annotation.RequestParam;
17
import org.springframework.web.bind.annotation.RestController;
18

  
19
import java.util.List;
20
import java.util.ArrayList;
21

  
22
import javax.validation.Valid;
23

  
24
@RestController
25
@CrossOrigin(origins = "*")
26
public class QuestionController {
27
    private final Logger log = Logger.getLogger(this.getClass());
28

  
29
    @Autowired
30
    private QuestionDAO questionDAO;
31

  
32
    @Autowired
33
    private TopicDAO topicDAO;
34

  
35
    @RequestMapping(value = "/question", method = RequestMethod.GET)
36
    public List<QuestionResponse> getAllQuestions() {
37
        List<Question> questions = questionDAO.findAll();
38
        List<QuestionResponse> questionResponses = new ArrayList<>();
39
        for (Question question : questions) {
40
            QuestionResponse questionResponse = new QuestionResponse(question);
41
            List<Topic> topics = new ArrayList<>();
42
            for (String topic : question.getTopics()) {
43
                topics.add(topicDAO.findById(topic));
44
            }
45
            questionResponse.setTopics(topics);
46
            questionResponses.add(questionResponse);
47
        }
48
        return questionResponses;
49
    }
50

  
51
    @RequestMapping(value = "/question", method = RequestMethod.DELETE)
52
    public void deleteAllQuestions() {
53
        questionDAO.deleteAll();
54
    }
55

  
56
    @RequestMapping(value = "/question", method = RequestMethod.POST)
57
    public QuestionResponse insertOrUpdateQuestion(@RequestBody Question question) {
58
        QuestionResponse questionResponse = new QuestionResponse(questionDAO.save(question));
59
        List<Topic> topics = new ArrayList<>();
60
        for (String topic : question.getTopics()) {
61
            topics.add(topicDAO.findById(topic));
62
        }
63
        questionResponse.setTopics(topics);
64
        return questionResponse;
65
    }
66

  
67
    @RequestMapping(value = "/question/{id}", method = RequestMethod.GET)
68
    public QuestionResponse getQuestion(@PathVariable(value = "id") String id) {
69
        Question question = questionDAO.findById(id);
70
        QuestionResponse questionResponse = new QuestionResponse(question);
71
        List<Topic> topics = new ArrayList<>();
72
        for (String topic : question.getTopics()) {
73
            topics.add(topicDAO.findById(topic));
74
        }
75
        questionResponse.setTopics(topics);
76
        return questionResponse;
77
    }
78

  
79
    @RequestMapping(value = "/question/{id}", method = RequestMethod.DELETE)
80
    public void deleteQuestion(@PathVariable(value = "id") String id) {
81
        questionDAO.delete(id);
82
    }
83

  
84
    @RequestMapping(value = "/question/inc/{id}", method = RequestMethod.PUT)
85
    public Question incQuestion(@PathVariable(value = "id") String id) {
86
        Question question = questionDAO.findById(id);
87
        question.increment();
88
        questionDAO.save(question);
89
        return question;
90
    }
91

  
92
    @RequestMapping(value = "/question/delete", method = RequestMethod.POST)
93
    public void deleteQuestions(@RequestBody List<String> questions) {
94
        for (String question : questions) {
95
            deleteQuestion(question);
96
        }
97
    }
98

  
99
    @RequestMapping(value = "/question/toggle", method = RequestMethod.POST)
100
    public void toggleQuestions(@RequestBody List<String> questions, @RequestParam String status) throws Exception {
101
        for (String id: questions) {
102
            Question question = questionDAO.findById(id);
103
            question.setIsActive(Boolean.parseBoolean(status));
104
            questionDAO.save(question);
105
        }
106
    }
107
}
modules/uoa-admin-tools/src/main/java/eu/dnetlib/uoaadmintools/ServletInitializer.java
1
package eu.dnetlib.uoaadmintools;
2

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

  
6
public class ServletInitializer extends SpringBootServletInitializer {
7

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

  
13
}
modules/uoa-admin-tools/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5

  
6
	<groupId>eu.dnetlib</groupId>
7
	<artifactId>uoa-admin-tools</artifactId>
8
	<version>0.0.1-SNAPSHOT</version>
9
	<packaging>war</packaging>
10

  
11
	<name>uoa-admin-tools</name>
12

  
13
	<parent>
14
		<groupId>org.springframework.boot</groupId>
15
		<artifactId>spring-boot-starter-parent</artifactId>
16
		<version>1.5.8.RELEASE</version>
17
		<relativePath/> <!-- lookup parent from repository -->
18
	</parent>
19

  
20
	<properties>
21
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23
		<java.version>1.8</java.version>
24
	</properties>
25

  
26
	<dependencies>
27
		<dependency>
28
			<groupId>org.springframework.boot</groupId>
29
			<artifactId>spring-boot-starter-data-mongodb</artifactId>
30
		</dependency>
31
		<dependency>
32
			<groupId>org.springframework.boot</groupId>
33
			<artifactId>spring-boot-starter-web</artifactId>
34
		</dependency>
35

  
36
		<dependency>
37
			<groupId>org.springframework.boot</groupId>
38
			<artifactId>spring-boot-starter-tomcat</artifactId>
39
			<scope>provided</scope>
40
		</dependency>
41
		<dependency>
42
			<groupId>org.springframework.boot</groupId>
43
			<artifactId>spring-boot-starter-test</artifactId>
44
			<scope>test</scope>
45
		</dependency>
46
	</dependencies>
47

  
48
	<build>
49
		<plugins>
50
			<plugin>
51
				<groupId>org.springframework.boot</groupId>
52
				<artifactId>spring-boot-maven-plugin</artifactId>
53
			</plugin>
54
		</plugins>
55
        <finalName>uoa-admin-tools</finalName>
56
	</build>
57

  
58

  
59
</project>

Also available in: Unified diff