stats summary, addresses #62
parent
6cb7e74046
commit
bdfdbbadbc
|
@ -53,11 +53,10 @@ public class JSONClientView extends AbstractView {
|
|||
|
||||
response.setContentType("application/json");
|
||||
|
||||
Writer out;
|
||||
|
||||
try {
|
||||
|
||||
out = response.getWriter();
|
||||
Writer out = response.getWriter();
|
||||
Object obj = model.get("entity");
|
||||
if (obj == null) {
|
||||
obj = model;
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.mitre.openid.connect.view;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
import org.springframework.web.servlet.view.AbstractView;
|
||||
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
/**
|
||||
* @author jricher
|
||||
*
|
||||
*/
|
||||
@Component("statsSummaryJson")
|
||||
public class StatsSummary extends AbstractView {
|
||||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
Gson gson = new GsonBuilder()
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}).create();
|
||||
|
||||
response.setContentType("application/json");
|
||||
|
||||
|
||||
try {
|
||||
|
||||
Writer out = response.getWriter();
|
||||
Object obj = model.get("entity");
|
||||
if (obj == null) {
|
||||
obj = model;
|
||||
}
|
||||
|
||||
gson.toJson(obj, out);
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
logger.error("IOException in JSONClientView.java: " + e.getStackTrace());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package org.mitre.openid.connect.web;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mitre.openid.connect.model.ApprovedSite;
|
||||
import org.mitre.openid.connect.service.ApprovedSiteService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
@PreAuthorize("hasRole('ROLE_USER')")
|
||||
@RequestMapping("stats")
|
||||
public class StatsAPI {
|
||||
|
||||
@Autowired
|
||||
private ApprovedSiteService approvedSiteService;
|
||||
|
||||
public StatsAPI() {
|
||||
|
||||
}
|
||||
|
||||
@RequestMapping("summary")
|
||||
public String statsSummary(ModelMap m) {
|
||||
|
||||
// get all approved sites
|
||||
Collection<ApprovedSite> allSites = approvedSiteService.getAll();
|
||||
|
||||
// process to find number of unique users and sites
|
||||
Set<String> userIds = new HashSet<String>();
|
||||
Set<String> clientIds = new HashSet<String>();
|
||||
for (ApprovedSite approvedSite : allSites) {
|
||||
userIds.add(approvedSite.getUserId());
|
||||
clientIds.add(approvedSite.getClientId());
|
||||
}
|
||||
|
||||
Map<String, Integer> e = new HashMap<String, Integer>();
|
||||
|
||||
e.put("approvalCount", allSites.size());
|
||||
e.put("userCount", userIds.size());
|
||||
e.put("clientCount", clientIds.size());
|
||||
|
||||
m.put("entity", e);
|
||||
|
||||
return "statsSummaryJson";
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue