[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).
This commit is contained in:
parent
04d9e7a91f
commit
c65b205365
|
@ -4,12 +4,12 @@ import eu.dnetlib.uoaadmintools.configuration.properties.SecurityConfig;
|
|||
import eu.dnetlib.uoaadmintools.dao.CommunityDAO;
|
||||
import eu.dnetlib.uoaadmintools.dao.CommunitySubscribersDAO;
|
||||
import eu.dnetlib.uoaadmintools.dao.SubscriberDAO;
|
||||
import eu.dnetlib.uoaadmintools.entities.Community;
|
||||
import eu.dnetlib.uoaadmintools.entities.CommunitySubscribers;
|
||||
import eu.dnetlib.uoaadmintools.entities.Subscriber;
|
||||
import eu.dnetlib.uoaadmintools.handlers.ContentNotFoundException;
|
||||
import eu.dnetlib.uoaadmintools.handlers.utils.AuthorizationUtils;
|
||||
import eu.dnetlib.uoaadmintools.handlers.utils.UserInfo;
|
||||
import eu.dnetlib.uoaadmintools.responses.SingleValueWrapperResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
@ -52,17 +52,19 @@ public class CommunitySubscribersController {
|
|||
}
|
||||
|
||||
@RequestMapping(value = "/community/{pid}/subscribers/count", method = RequestMethod.GET)
|
||||
public Integer getNumberOfSubscribersPerCommunity(@PathVariable(value="pid", required = true) String pid) throws ContentNotFoundException {
|
||||
public SingleValueWrapperResponse<Integer> getNumberOfSubscribersPerCommunity(@PathVariable(value="pid", required = true) String pid) throws ContentNotFoundException {
|
||||
SingleValueWrapperResponse<Integer> singleValueWrapperResponse = new SingleValueWrapperResponse(0);
|
||||
|
||||
CommunitySubscribers communitySubscribers = communitySubscriberDAO.findByPid(pid);
|
||||
if(communitySubscribers != null){
|
||||
if(communitySubscribers.getSubscribers() != null) {
|
||||
return communitySubscribers.getSubscribers().size();
|
||||
singleValueWrapperResponse.setValue(communitySubscribers.getSubscribers().size());
|
||||
}
|
||||
}else{
|
||||
throw new ContentNotFoundException("Community Subscribers not found");
|
||||
|
||||
}
|
||||
return 0;
|
||||
return singleValueWrapperResponse;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/community/{pid}/is-subscriber", method = RequestMethod.GET)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package eu.dnetlib.uoaadmintools.responses;
|
||||
|
||||
public class SingleValueWrapperResponse<T> {
|
||||
private T value = null;
|
||||
|
||||
public SingleValueWrapperResponse() { }
|
||||
public SingleValueWrapperResponse(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue