Revision 60499
Added by Konstantina Galouni about 3 years ago
PortalSubscribersController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoaadmintools.controllers; |
2 | 2 |
|
3 |
import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig; |
|
3 |
//import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig;
|
|
4 | 4 |
import eu.dnetlib.uoaadmintools.dao.PortalSubscribersDAO; |
5 | 5 |
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO; |
6 | 6 |
import eu.dnetlib.uoaadmintools.entities.subscriber.PortalSubscribers; |
... | ... | |
8 | 8 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.ContentNotFoundException; |
9 | 9 |
import eu.dnetlib.uoaadmintools.handlers.utils.AuthorizationUtils; |
10 | 10 |
import eu.dnetlib.uoaadmintools.handlers.utils.UserInfo; |
11 |
import eu.dnetlib.uoaadmintools.responses.SingleValueWrapperResponse; |
|
11 |
import eu.dnetlib.uoaadmintoolslibrary.responses.SingleValueWrapperResponse;
|
|
12 | 12 |
import eu.dnetlib.uoaadmintoolslibrary.dao.PortalDAO; |
13 | 13 |
import org.apache.log4j.Logger; |
14 | 14 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
31 | 31 |
@Autowired |
32 | 32 |
PortalDAO portalDAO; |
33 | 33 |
|
34 |
@Autowired |
|
35 |
private SecurityConfig securityConfig; |
|
34 |
// @Autowired
|
|
35 |
// private SecurityConfig securityConfig;
|
|
36 | 36 |
|
37 | 37 |
private final Logger log = Logger.getLogger(this.getClass()); |
38 | 38 |
|
... | ... | |
91 | 91 |
// |
92 | 92 |
// } |
93 | 93 |
|
94 |
@RequestMapping(value = "/community/{pid}/is-subscriber", method = RequestMethod.GET) |
|
95 |
public Boolean getIsSubscribedToPortal(@PathVariable(value="pid", required = true) String pid, |
|
96 |
//@RequestBody String email, |
|
97 |
@RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException { |
|
98 |
AuthorizationUtils helper = new AuthorizationUtils(); |
|
99 |
helper.setUserInfoUrl(securityConfig.getUserInfoUrl()); |
|
100 |
UserInfo userInfo = helper.getUserInfo(token); |
|
101 |
|
|
102 |
if(userInfo != null) { |
|
103 |
String email = userInfo.getEmail(); |
|
104 |
PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid); |
|
105 |
if (communitySubscribers != null) { |
|
106 |
if (communitySubscribers.getSubscribers() != null) { |
|
107 |
for (Subscriber subscriber : communitySubscribers.getSubscribers()) { |
|
108 |
if (subscriber.getEmail().equals(email)) { |
|
109 |
return true; |
|
110 |
} |
|
111 |
} |
|
112 |
} |
|
113 |
} else { |
|
114 |
throw new ContentNotFoundException("Portal Subscribers not found"); |
|
115 |
|
|
116 |
} |
|
117 |
} |
|
118 |
return false; |
|
119 |
} |
|
120 |
|
|
121 |
@RequestMapping(value = "/community/{pid}/subscriber", method = RequestMethod.POST) |
|
122 |
public Boolean addSubscriberInPortal(@PathVariable(value="pid", required = true) String pid, |
|
123 |
@RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException { |
|
124 |
AuthorizationUtils helper = new AuthorizationUtils(); |
|
125 |
helper.setUserInfoUrl(securityConfig.getUserInfoUrl()); |
|
126 |
UserInfo userInfo = helper.getUserInfo(token); |
|
127 |
|
|
128 |
if(userInfo != null) { |
|
129 |
String email = userInfo.getEmail(); |
|
130 |
Subscriber subscriber = new Subscriber(email); |
|
131 |
|
|
132 |
PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid); |
|
133 |
if (communitySubscribers == null) { |
|
134 |
throw new ContentNotFoundException("Community Subscribers not found"); |
|
135 |
} |
|
136 |
|
|
137 |
Subscriber savedSubscriber = subscriberDAO.findByEmail(email); |
|
138 |
if (savedSubscriber == null) { |
|
139 |
savedSubscriber = subscriberDAO.save(subscriber); |
|
140 |
} |
|
141 |
for (Subscriber sub : communitySubscribers.getSubscribers()) { |
|
142 |
if (sub.getEmail().equals(subscriber.getEmail())) { |
|
143 |
//already subscribed |
|
144 |
return false; |
|
145 |
} |
|
146 |
} |
|
147 |
//not subscribed yet |
|
148 |
communitySubscribers.getSubscribers().add(savedSubscriber); |
|
149 |
portalSubscribersDAO.save(communitySubscribers); |
|
150 |
return true; |
|
151 |
} |
|
152 |
return false; |
|
153 |
|
|
154 |
} |
|
155 |
@RequestMapping(value = "/community/{pid}/subscriber/delete", method = RequestMethod.POST) |
|
156 |
public Boolean deleteSubscriberFromPortal(@PathVariable(value="pid", required = true) String pid, |
|
157 |
@RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException { |
|
158 |
AuthorizationUtils helper = new AuthorizationUtils(); |
|
159 |
helper.setUserInfoUrl(securityConfig.getUserInfoUrl()); |
|
160 |
UserInfo userInfo = helper.getUserInfo(token); |
|
161 |
|
|
162 |
if(userInfo != null) { |
|
163 |
String email = userInfo.getEmail(); |
|
164 |
|
|
165 |
PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid); |
|
166 |
if (communitySubscribers == null) { |
|
167 |
throw new ContentNotFoundException("Community Subscribers not found"); |
|
168 |
} |
|
169 |
|
|
170 |
Iterator<Subscriber> subscriberIterator = communitySubscribers.getSubscribers().iterator(); |
|
171 |
while(subscriberIterator.hasNext()) { |
|
172 |
Subscriber subscriber = subscriberIterator.next(); |
|
173 |
if(subscriber.getEmail().equals(email)) { |
|
174 |
subscriberIterator.remove(); |
|
175 |
portalSubscribersDAO.save(communitySubscribers); |
|
176 |
return true; |
|
177 |
} |
|
178 |
} |
|
179 |
} |
|
180 |
return false; |
|
181 |
} |
|
182 |
|
|
183 |
@RequestMapping(value = "/community/{pid}/subscribers", method = RequestMethod.POST) |
|
184 |
public PortalSubscribers addSubscriberInPortalByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody Subscriber subscriber) throws ContentNotFoundException { |
|
185 |
PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid); |
|
186 |
if(communitySubscribers == null){ |
|
187 |
throw new ContentNotFoundException("Community Subscribers not found"); |
|
188 |
} |
|
189 |
|
|
190 |
Subscriber savedSubscriber = subscriberDAO.findByEmail(subscriber.getEmail()); |
|
191 |
if(savedSubscriber==null){ |
|
192 |
savedSubscriber = subscriberDAO.save(subscriber); |
|
193 |
} |
|
194 |
for(Subscriber sub:communitySubscribers.getSubscribers()){ |
|
195 |
if(sub.getEmail().equals(subscriber.getEmail())){ |
|
196 |
//already subscribed |
|
197 |
return communitySubscribers; |
|
198 |
} |
|
199 |
} |
|
200 |
//not subscribed yet |
|
201 |
communitySubscribers.getSubscribers().add(savedSubscriber); |
|
202 |
return portalSubscribersDAO.save(communitySubscribers); |
|
203 |
|
|
204 |
} |
|
205 |
@RequestMapping(value = "/community/{pid}/subscribers/delete", method = RequestMethod.POST) |
|
206 |
public PortalSubscribers deleteSubscriberFromPortalByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody List<String> emails) throws ContentNotFoundException { |
|
207 |
PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid); |
|
208 |
if(communitySubscribers == null){ |
|
209 |
throw new ContentNotFoundException("Community Subscribers not found"); |
|
210 |
} |
|
211 |
List<Subscriber> list = new ArrayList<>(); |
|
212 |
for(Subscriber s:communitySubscribers.getSubscribers()){ |
|
213 |
if(emails.indexOf(s.getEmail())==-1){ |
|
214 |
list.add(s); |
|
215 |
} |
|
216 |
} |
|
217 |
communitySubscribers.setSubscribers(list); |
|
218 |
return portalSubscribersDAO.save(communitySubscribers); |
|
219 |
} |
|
220 |
|
|
221 |
@RequestMapping(value = "/subscriber/communities", method = RequestMethod.GET) |
|
222 |
public List<String> getPortalsPerSubcriber(//@RequestParam(value="email", required = true) String email, |
|
223 |
@RequestHeader("X-XSRF-TOKEN") String token) { |
|
224 |
AuthorizationUtils helper = new AuthorizationUtils(); |
|
225 |
helper.setUserInfoUrl(securityConfig.getUserInfoUrl()); |
|
226 |
UserInfo userInfo = helper.getUserInfo(token); |
|
227 |
|
|
228 |
List<String> list = new ArrayList<>(); |
|
229 |
|
|
230 |
if (userInfo != null) { |
|
231 |
String email = userInfo.getEmail(); |
|
232 |
List<PortalSubscribers> communitySubscribers = portalSubscribersDAO.findAll(); |
|
233 |
|
|
234 |
for (PortalSubscribers s : communitySubscribers) { |
|
235 |
for (Subscriber sub : s.getSubscribers()) { |
|
236 |
if (sub.getEmail().equals(email)) { |
|
237 |
list.add(s.getPid()); |
|
238 |
break; |
|
239 |
} |
|
240 |
} |
|
241 |
} |
|
242 |
} |
|
243 |
return list; |
|
244 |
} |
|
94 |
// @RequestMapping(value = "/community/{pid}/is-subscriber", method = RequestMethod.GET)
|
|
95 |
// public Boolean getIsSubscribedToPortal(@PathVariable(value="pid", required = true) String pid,
|
|
96 |
// //@RequestBody String email,
|
|
97 |
// @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
|
|
98 |
// AuthorizationUtils helper = new AuthorizationUtils();
|
|
99 |
// helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
|
100 |
// UserInfo userInfo = helper.getUserInfo(token);
|
|
101 |
// |
|
102 |
// if(userInfo != null) {
|
|
103 |
// String email = userInfo.getEmail();
|
|
104 |
// PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
|
|
105 |
// if (communitySubscribers != null) {
|
|
106 |
// if (communitySubscribers.getSubscribers() != null) {
|
|
107 |
// for (Subscriber subscriber : communitySubscribers.getSubscribers()) {
|
|
108 |
// if (subscriber.getEmail().equals(email)) {
|
|
109 |
// return true;
|
|
110 |
// }
|
|
111 |
// }
|
|
112 |
// }
|
|
113 |
// } else {
|
|
114 |
// throw new ContentNotFoundException("Portal Subscribers not found");
|
|
115 |
// |
|
116 |
// }
|
|
117 |
// }
|
|
118 |
// return false;
|
|
119 |
// }
|
|
120 |
// |
|
121 |
// @RequestMapping(value = "/community/{pid}/subscriber", method = RequestMethod.POST)
|
|
122 |
// public Boolean addSubscriberInPortal(@PathVariable(value="pid", required = true) String pid,
|
|
123 |
// @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
|
|
124 |
// AuthorizationUtils helper = new AuthorizationUtils();
|
|
125 |
// helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
|
126 |
// UserInfo userInfo = helper.getUserInfo(token);
|
|
127 |
// |
|
128 |
// if(userInfo != null) {
|
|
129 |
// String email = userInfo.getEmail();
|
|
130 |
// Subscriber subscriber = new Subscriber(email);
|
|
131 |
// |
|
132 |
// PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
|
|
133 |
// if (communitySubscribers == null) {
|
|
134 |
// throw new ContentNotFoundException("Community Subscribers not found");
|
|
135 |
// }
|
|
136 |
// |
|
137 |
// Subscriber savedSubscriber = subscriberDAO.findByEmail(email);
|
|
138 |
// if (savedSubscriber == null) {
|
|
139 |
// savedSubscriber = subscriberDAO.save(subscriber);
|
|
140 |
// }
|
|
141 |
// for (Subscriber sub : communitySubscribers.getSubscribers()) {
|
|
142 |
// if (sub.getEmail().equals(subscriber.getEmail())) {
|
|
143 |
// //already subscribed
|
|
144 |
// return false;
|
|
145 |
// }
|
|
146 |
// }
|
|
147 |
// //not subscribed yet
|
|
148 |
// communitySubscribers.getSubscribers().add(savedSubscriber);
|
|
149 |
// portalSubscribersDAO.save(communitySubscribers);
|
|
150 |
// return true;
|
|
151 |
// }
|
|
152 |
// return false;
|
|
153 |
// |
|
154 |
// }
|
|
155 |
// @RequestMapping(value = "/community/{pid}/subscriber/delete", method = RequestMethod.POST)
|
|
156 |
// public Boolean deleteSubscriberFromPortal(@PathVariable(value="pid", required = true) String pid,
|
|
157 |
// @RequestHeader("X-XSRF-TOKEN") String token) throws ContentNotFoundException {
|
|
158 |
// AuthorizationUtils helper = new AuthorizationUtils();
|
|
159 |
// helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
|
160 |
// UserInfo userInfo = helper.getUserInfo(token);
|
|
161 |
// |
|
162 |
// if(userInfo != null) {
|
|
163 |
// String email = userInfo.getEmail();
|
|
164 |
// |
|
165 |
// PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
|
|
166 |
// if (communitySubscribers == null) {
|
|
167 |
// throw new ContentNotFoundException("Community Subscribers not found");
|
|
168 |
// }
|
|
169 |
// |
|
170 |
// Iterator<Subscriber> subscriberIterator = communitySubscribers.getSubscribers().iterator();
|
|
171 |
// while(subscriberIterator.hasNext()) {
|
|
172 |
// Subscriber subscriber = subscriberIterator.next();
|
|
173 |
// if(subscriber.getEmail().equals(email)) {
|
|
174 |
// subscriberIterator.remove();
|
|
175 |
// portalSubscribersDAO.save(communitySubscribers);
|
|
176 |
// return true;
|
|
177 |
// }
|
|
178 |
// }
|
|
179 |
// }
|
|
180 |
// return false;
|
|
181 |
// }
|
|
182 |
// |
|
183 |
// @RequestMapping(value = "/community/{pid}/subscribers", method = RequestMethod.POST)
|
|
184 |
// public PortalSubscribers addSubscriberInPortalByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody Subscriber subscriber) throws ContentNotFoundException {
|
|
185 |
// PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
|
|
186 |
// if(communitySubscribers == null){
|
|
187 |
// throw new ContentNotFoundException("Community Subscribers not found");
|
|
188 |
// }
|
|
189 |
// |
|
190 |
// Subscriber savedSubscriber = subscriberDAO.findByEmail(subscriber.getEmail());
|
|
191 |
// if(savedSubscriber==null){
|
|
192 |
// savedSubscriber = subscriberDAO.save(subscriber);
|
|
193 |
// }
|
|
194 |
// for(Subscriber sub:communitySubscribers.getSubscribers()){
|
|
195 |
// if(sub.getEmail().equals(subscriber.getEmail())){
|
|
196 |
// //already subscribed
|
|
197 |
// return communitySubscribers;
|
|
198 |
// }
|
|
199 |
// }
|
|
200 |
// //not subscribed yet
|
|
201 |
// communitySubscribers.getSubscribers().add(savedSubscriber);
|
|
202 |
// return portalSubscribersDAO.save(communitySubscribers);
|
|
203 |
// |
|
204 |
// }
|
|
205 |
// @RequestMapping(value = "/community/{pid}/subscribers/delete", method = RequestMethod.POST)
|
|
206 |
// public PortalSubscribers deleteSubscriberFromPortalByEmail(@PathVariable(value="pid", required = true) String pid, @RequestBody List<String> emails) throws ContentNotFoundException {
|
|
207 |
// PortalSubscribers communitySubscribers = portalSubscribersDAO.findByPid(pid);
|
|
208 |
// if(communitySubscribers == null){
|
|
209 |
// throw new ContentNotFoundException("Community Subscribers not found");
|
|
210 |
// }
|
|
211 |
// List<Subscriber> list = new ArrayList<>();
|
|
212 |
// for(Subscriber s:communitySubscribers.getSubscribers()){
|
|
213 |
// if(emails.indexOf(s.getEmail())==-1){
|
|
214 |
// list.add(s);
|
|
215 |
// }
|
|
216 |
// }
|
|
217 |
// communitySubscribers.setSubscribers(list);
|
|
218 |
// return portalSubscribersDAO.save(communitySubscribers);
|
|
219 |
// }
|
|
220 |
// |
|
221 |
// @RequestMapping(value = "/subscriber/communities", method = RequestMethod.GET)
|
|
222 |
// public List<String> getPortalsPerSubcriber(//@RequestParam(value="email", required = true) String email,
|
|
223 |
// @RequestHeader("X-XSRF-TOKEN") String token) {
|
|
224 |
// AuthorizationUtils helper = new AuthorizationUtils();
|
|
225 |
// helper.setUserInfoUrl(securityConfig.getUserInfoUrl());
|
|
226 |
// UserInfo userInfo = helper.getUserInfo(token);
|
|
227 |
// |
|
228 |
// List<String> list = new ArrayList<>();
|
|
229 |
// |
|
230 |
// if (userInfo != null) {
|
|
231 |
// String email = userInfo.getEmail();
|
|
232 |
// List<PortalSubscribers> communitySubscribers = portalSubscribersDAO.findAll();
|
|
233 |
// |
|
234 |
// for (PortalSubscribers s : communitySubscribers) {
|
|
235 |
// for (Subscriber sub : s.getSubscribers()) {
|
|
236 |
// if (sub.getEmail().equals(email)) {
|
|
237 |
// list.add(s.getPid());
|
|
238 |
// break;
|
|
239 |
// }
|
|
240 |
// }
|
|
241 |
// }
|
|
242 |
// }
|
|
243 |
// return list;
|
|
244 |
// }
|
|
245 | 245 |
} |
Also available in: Unified diff
[Trunk | Admin Tools]:
1. SubscriberController.java & PortalSubscribersController.java: Commented POST/ DELETE methods from controllers related to subscribers (these files will be deleted after migration of roles to AAI).
2. StatisticsController.java: Commented all methods (file and statistics schema in general need update - currently not working).