1
|
package eu.dnetlib.uoaadmintools.controllers;
|
2
|
|
3
|
import eu.dnetlib.uoaadmintools.dao.CommunityDAO;
|
4
|
import eu.dnetlib.uoaadmintools.dao.PageDAO;
|
5
|
import eu.dnetlib.uoaadmintools.entities.Community;
|
6
|
import eu.dnetlib.uoaadmintools.entities.Page;
|
7
|
import eu.dnetlib.uoaadmintools.entities.PageHelpContent;
|
8
|
import eu.dnetlib.uoaadmintools.dao.PageHelpContentDAO;
|
9
|
import eu.dnetlib.uoaadmintools.entities.PageHelpContentResponse;
|
10
|
|
11
|
import org.apache.log4j.Logger;
|
12
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
13
|
import org.springframework.web.bind.annotation.RequestMapping;
|
14
|
import org.springframework.web.bind.annotation.RequestMethod;
|
15
|
import org.springframework.web.bind.annotation.RequestBody;
|
16
|
import org.springframework.web.bind.annotation.PathVariable;
|
17
|
import org.springframework.beans.factory.annotation.Autowired;
|
18
|
import org.springframework.web.bind.annotation.RequestParam;
|
19
|
import org.springframework.web.bind.annotation.RestController;
|
20
|
|
21
|
import java.util.ArrayList;
|
22
|
import java.util.List;
|
23
|
|
24
|
@RestController
|
25
|
@CrossOrigin(origins = "*")
|
26
|
public class PageHelpContentController {
|
27
|
private final Logger log = Logger.getLogger(this.getClass());
|
28
|
|
29
|
@Autowired
|
30
|
private PageHelpContentDAO pageHelpContentDAO;
|
31
|
|
32
|
@Autowired
|
33
|
private PageDAO pageDAO;
|
34
|
|
35
|
@Autowired
|
36
|
private CommunityDAO communityDAO;
|
37
|
|
38
|
@RequestMapping(value = "/pagehelpcontent", method = RequestMethod.GET)
|
39
|
public List<PageHelpContentResponse> getPageHelpContents(@RequestParam(required=false) String community,
|
40
|
@RequestParam(required=false) String page,
|
41
|
@RequestParam(required=false) String position,
|
42
|
@RequestParam(required=false) String active,
|
43
|
@RequestParam(required=false) String before) {
|
44
|
List<PageHelpContent> pageHelpContents = null;
|
45
|
|
46
|
Community _community = null;
|
47
|
String communityId = null;
|
48
|
if(community != null) {
|
49
|
_community = communityDAO.findByPid(community);
|
50
|
if(_community != null) {
|
51
|
communityId = _community.getId();
|
52
|
}
|
53
|
}
|
54
|
//pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveAndisPriorToOrderByOrderAsc(community, position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
55
|
|
56
|
if(community != null && position != null && active != null && before != null) {
|
57
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(communityId, position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
58
|
} else if(community != null && position != null && active != null) {
|
59
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsActiveOrderByOrderAsc(communityId, position, Boolean.parseBoolean(active));
|
60
|
} else if(community != null && position != null && before != null) {
|
61
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementAndIsPriorToOrderByOrderAsc(communityId, position, Boolean.parseBoolean(before));
|
62
|
} else if(community != null && active != null && before != null) {
|
63
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
64
|
} else if(position != null && active != null && before != null) {
|
65
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveAndIsPriorToOrderByOrderAsc(position, Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
66
|
} else if(community != null && position != null ) {
|
67
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndPlacementOrderByOrderAsc(communityId, position);
|
68
|
} else if(community != null && active != null ) {
|
69
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndIsActiveOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(active));
|
70
|
} else if(community != null && before != null) {
|
71
|
pageHelpContents = pageHelpContentDAO.findByCommunityAndIsPriorToOrderByPlacementAscOrderAsc(communityId, Boolean.parseBoolean(before));
|
72
|
} else if(position != null && active != null) {
|
73
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsActiveOrderByOrderAsc(position, Boolean.parseBoolean(active));
|
74
|
} else if(position != null && before != null) {
|
75
|
pageHelpContents = pageHelpContentDAO.findByPlacementAndIsPriorToOrderByOrderAsc(position, Boolean.parseBoolean(before));
|
76
|
} else if(active != null && before != null) {
|
77
|
pageHelpContents = pageHelpContentDAO.findByIsActiveAndIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active), Boolean.parseBoolean(before));
|
78
|
} else if(community != null) {
|
79
|
pageHelpContents = pageHelpContentDAO.findByCommunityOrderByPlacementAscOrderAsc(communityId);
|
80
|
} else if(position != null) {
|
81
|
pageHelpContents = pageHelpContentDAO.findByPlacementOrderByOrderAsc(position);
|
82
|
} else if(active != null) {
|
83
|
pageHelpContents = pageHelpContentDAO.findByIsActiveOrderByPlacementAscOrderAsc(Boolean.parseBoolean(active));
|
84
|
} else if(before != null) {
|
85
|
pageHelpContents = pageHelpContentDAO.findByIsPriorToOrderByPlacementAscOrderAsc(Boolean.parseBoolean(before));
|
86
|
} else {
|
87
|
pageHelpContents = pageHelpContentDAO.findAllByOrderByPlacementAscOrderAsc();
|
88
|
}
|
89
|
|
90
|
List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
|
91
|
for (PageHelpContent pageHelpContent : pageHelpContents) {
|
92
|
Page _page = pageDAO.findById(pageHelpContent.getPage());
|
93
|
if(page == null || page.equals(_page.getRoute())) {
|
94
|
PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
|
95
|
|
96
|
pageHelpContentResponse.setPage(_page);
|
97
|
pageHelpContentResponse.setCommunity(communityDAO.findById(pageHelpContent.getCommunity()));
|
98
|
pageHelpContentResponses.add(pageHelpContentResponse);
|
99
|
}
|
100
|
}
|
101
|
return pageHelpContentResponses;
|
102
|
}
|
103
|
/*
|
104
|
@RequestMapping(value = "/pagehelpcontent/community/{id}", method = RequestMethod.GET)
|
105
|
public List<PageHelpContentResponse> getCommunityPageHelpContents(@PathVariable(value = "id") String communityId) {
|
106
|
List<PageHelpContent> pageHelpContents = pageHelpContentDAO.findByCommunity(communityId);
|
107
|
List<PageHelpContentResponse> pageHelpContentResponses = new ArrayList<>();
|
108
|
for (PageHelpContent pageHelpContent : pageHelpContents) {
|
109
|
PageHelpContentResponse pageHelpContentResponse = new PageHelpContentResponse(pageHelpContent);
|
110
|
pageHelpContentResponse.setPage(pageDAO.findById(pageHelpContent.getPage()));
|
111
|
pageHelpContentResponse.setCommunity(communityDAO.findById(pageHelpContent.getCommunity()));
|
112
|
pageHelpContentResponses.add(pageHelpContentResponse);
|
113
|
}
|
114
|
return pageHelpContentResponses;
|
115
|
}
|
116
|
*/
|
117
|
@RequestMapping(value = "/pagehelpcontent", method = RequestMethod.DELETE)
|
118
|
public void deleteAllPageHelpContents() {
|
119
|
pageHelpContentDAO.deleteAll();
|
120
|
}
|
121
|
|
122
|
@RequestMapping(value = "/pagehelpcontent/save", method = RequestMethod.POST)
|
123
|
public PageHelpContent insertPageHelpContent(@RequestBody PageHelpContent pageHelpContent) {
|
124
|
String communityId = communityDAO.findByPid(pageHelpContent.getCommunity()).getId();
|
125
|
pageHelpContent.setCommunity(communityId);
|
126
|
return pageHelpContentDAO.save(pageHelpContent);
|
127
|
}
|
128
|
|
129
|
@RequestMapping(value = "/pagehelpcontent/update", method = RequestMethod.POST)
|
130
|
public PageHelpContent updatePageHelpContent(@RequestBody PageHelpContent pageHelpContent) {
|
131
|
return pageHelpContentDAO.save(pageHelpContent);
|
132
|
}
|
133
|
|
134
|
@RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.GET)
|
135
|
public PageHelpContent getPageHelpContent(@PathVariable(value = "id") String id) {
|
136
|
return pageHelpContentDAO.findById(id);
|
137
|
}
|
138
|
|
139
|
@RequestMapping(value = "/pagehelpcontent/toggle", method = RequestMethod.POST)
|
140
|
public List<String> togglePageHelpContent(@RequestBody List<String> pageHelpContents, @RequestParam String status) throws Exception {
|
141
|
for (String id: pageHelpContents) {
|
142
|
log.debug("Id of pageHelpContent: "+id);
|
143
|
PageHelpContent pageHelpContent = pageHelpContentDAO.findById(id);
|
144
|
pageHelpContent.setIsActive(Boolean.parseBoolean(status));
|
145
|
pageHelpContentDAO.save(pageHelpContent);
|
146
|
}
|
147
|
return pageHelpContents;
|
148
|
}
|
149
|
|
150
|
@RequestMapping(value = "/pagehelpcontent/{id}", method = RequestMethod.DELETE)
|
151
|
public void deletePageHelpContent(@PathVariable(value = "id") String id) {
|
152
|
pageHelpContentDAO.delete(id);
|
153
|
}
|
154
|
|
155
|
@RequestMapping(value = "/pagehelpcontent/delete", method = RequestMethod.POST)
|
156
|
public Boolean deletePageHelpContents(@RequestBody List<String> pageHelpContents) throws Exception {
|
157
|
for (String id: pageHelpContents) {
|
158
|
pageHelpContentDAO.delete(id);
|
159
|
}
|
160
|
return true;
|
161
|
}
|
162
|
|
163
|
|
164
|
}
|
165
|
|
166
|
|