4 |
4 |
import eu.dnetlib.uoaadmintools.dao.CommunityDAO;
|
5 |
5 |
import eu.dnetlib.uoaadmintools.dao.CommunitySubscribersDAO;
|
6 |
6 |
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO;
|
7 |
|
import eu.dnetlib.uoaadmintools.entities.Community;
|
8 |
7 |
import eu.dnetlib.uoaadmintools.entities.CommunitySubscribers;
|
9 |
8 |
import eu.dnetlib.uoaadmintools.entities.Subscriber;
|
10 |
9 |
import eu.dnetlib.uoaadmintools.handlers.ContentNotFoundException;
|
11 |
10 |
import eu.dnetlib.uoaadmintools.handlers.utils.AuthorizationUtils;
|
12 |
11 |
import eu.dnetlib.uoaadmintools.handlers.utils.UserInfo;
|
|
12 |
import eu.dnetlib.uoaadmintools.responses.SingleValueWrapperResponse;
|
13 |
13 |
import org.apache.log4j.Logger;
|
14 |
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
15 |
15 |
import org.springframework.web.bind.annotation.*;
|
... | ... | |
52 |
52 |
}
|
53 |
53 |
|
54 |
54 |
@RequestMapping(value = "/community/{pid}/subscribers/count", method = RequestMethod.GET)
|
55 |
|
public Integer getNumberOfSubscribersPerCommunity(@PathVariable(value="pid", required = true) String pid) throws ContentNotFoundException {
|
|
55 |
public SingleValueWrapperResponse<Integer> getNumberOfSubscribersPerCommunity(@PathVariable(value="pid", required = true) String pid) throws ContentNotFoundException {
|
|
56 |
SingleValueWrapperResponse<Integer> singleValueWrapperResponse = new SingleValueWrapperResponse(0);
|
|
57 |
|
56 |
58 |
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid);
|
57 |
59 |
if(communitySubscribers != null){
|
58 |
60 |
if(communitySubscribers.getSubscribers() != null) {
|
59 |
|
return communitySubscribers.getSubscribers().size();
|
|
61 |
singleValueWrapperResponse.setValue(communitySubscribers.getSubscribers().size());
|
60 |
62 |
}
|
61 |
63 |
}else{
|
62 |
64 |
throw new ContentNotFoundException("Community Subscribers not found");
|
63 |
65 |
|
64 |
66 |
}
|
65 |
|
return 0;
|
|
67 |
return singleValueWrapperResponse;
|
66 |
68 |
}
|
67 |
69 |
|
68 |
70 |
@RequestMapping(value = "/community/{pid}/is-subscriber", method = RequestMethod.GET)
|
[Trunk | Admin Tools Service]:
1. SingleValueWrapperResponse.java: Generic class SingleValueWrapperResponse created, with field "value" of type defined when instance is created (used for returning single value from API methods).
2. CommunitySubscribersController.java: In method "getNumberOfSubscribersPerCommunity()" (/community/{pid}/subscribers/count) return SingleValueWrapperResponse<Integer>
(Used to return Integer but it is not always considered as valid JSON).