source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/frontend/StatisticsPage.java @ 4550

Last change on this file since 4550 was 4550, checked in by twagoo, 10 years ago

Fixed errors due to schema change allowing only one root element in a profile or component (see r4525)

File size: 5.5 KB
Line 
1package clarin.cmdi.componentregistry.frontend;
2
3import java.io.IOException;
4import java.util.List;
5
6import org.apache.wicket.PageParameters;
7import org.apache.wicket.markup.html.WebMarkupContainer;
8import org.apache.wicket.markup.html.basic.Label;
9import org.apache.wicket.markup.html.link.Link;
10import org.apache.wicket.markup.repeater.RepeatingView;
11import org.apache.wicket.spring.injection.annot.SpringBean;
12
13import clarin.cmdi.componentregistry.ComponentRegistry;
14import clarin.cmdi.componentregistry.ComponentRegistryException;
15import clarin.cmdi.componentregistry.ComponentRegistryFactory;
16import clarin.cmdi.componentregistry.components.CMDComponentSpec;
17import clarin.cmdi.componentregistry.components.CMDComponentType;
18import clarin.cmdi.componentregistry.components.CMDElementType;
19import clarin.cmdi.componentregistry.impl.database.CMDComponentSpecExpanderDbImpl;
20import clarin.cmdi.componentregistry.impl.database.ComponentRegistryDbImpl;
21import clarin.cmdi.componentregistry.model.ComponentDescription;
22import clarin.cmdi.componentregistry.model.ProfileDescription;
23import java.util.Collection;
24import java.util.Collections;
25
26/**
27 *
28 * @author paucas
29 */
30public class StatisticsPage extends SecureAdminWebPage {
31
32    private static final long serialVersionUID = 1L;
33    @SpringBean(name = "componentRegistryFactory")
34    private ComponentRegistryFactory componentRegistryFactory;
35
36    private static class Statistics {
37        private int componentnumber = 0;
38        private int elementcounter = 0;
39        private int conceptlinkcounter = 0;
40    }
41
42    public StatisticsPage(final PageParameters pageParameters) throws IOException, ComponentRegistryException {
43        super(pageParameters);
44        ComponentRegistry registry = componentRegistryFactory.getPublicRegistry();
45        addLinks();
46        displayStatistics(registry);
47    }
48
49    private void displayStatistics(ComponentRegistry registry) throws ComponentRegistryException {
50        List<ProfileDescription> profileList = registry.getProfileDescriptions();
51        RepeatingView repeating = new RepeatingView("repeating");
52        add(repeating);
53        add(new Label("profilenumbermessage", "Current number of profiles in the component registry: " + profileList.size()));
54        for (ProfileDescription pd : profileList) {
55            displayProfileStatistics(pd, repeating, registry);
56        }
57        List<ComponentDescription> componentList = registry.getComponentDescriptions();
58        RepeatingView repeatingcomp = new RepeatingView("repeatingcomp");
59        add(repeatingcomp);
60        add(new Label("componentnumbermessage", "Current number of components in the component registry: " + componentList.size()));
61        for (ComponentDescription cd : componentList) {
62            displayComponentStatistics(cd, repeatingcomp, registry);
63        }
64    }
65
66    private void displayProfileStatistics(ProfileDescription pd, RepeatingView repeatingview, ComponentRegistry registry) throws ComponentRegistryException {
67        WebMarkupContainer item = new WebMarkupContainer(repeatingview.newChildId());
68        repeatingview.add(item);
69        item.add(new Label("ID", pd.getId()));
70        item.add(new Label("profname", pd.getName()));
71        CMDComponentSpec profile = CMDComponentSpecExpanderDbImpl.expandProfile(pd.getId(), (ComponentRegistryDbImpl) registry);
72        Statistics stats = new Statistics();
73        componentCounter(profile, stats);
74        item.add(new Label("nrcomp", "" + stats.componentnumber));
75        item.add(new Label("nrprofelem", "" + stats.elementcounter));
76        item.add(new Label("nrproflinks", "" + stats.conceptlinkcounter));
77    }
78
79    private void displayComponentStatistics(ComponentDescription cd, RepeatingView repeatingview,  ComponentRegistry registry) throws ComponentRegistryException {
80        WebMarkupContainer item = new WebMarkupContainer(repeatingview.newChildId());
81        repeatingview.add(item);
82        item.add(new Label("ID", cd.getId()));
83        item.add(new Label("compname", cd.getName()));
84        CMDComponentSpec compspec = CMDComponentSpecExpanderDbImpl.expandComponent(cd.getId(), (ComponentRegistryDbImpl) registry);
85        Statistics stats = new Statistics();
86        componentCounter(compspec, stats);
87        item.add(new Label("nrcomp", "" + stats.componentnumber));
88        item.add(new Label("nrelem", "" + stats.elementcounter));
89        item.add(new Label("nrcomplinks", "" + stats.conceptlinkcounter));
90    }
91
92    private void componentCounter(CMDComponentSpec components, Statistics stats) {
93        componentCounter(Collections.singleton(components.getCMDComponent()), stats);
94    }
95   
96    private void componentCounter(Collection<CMDComponentType> components, Statistics stats) {
97        if (components != null) {
98            for (CMDComponentType component : components) {
99                stats.componentnumber++;
100                List<CMDElementType> elementlist = component.getCMDElement();
101                if (elementlist != null) {
102                    stats.elementcounter += elementlist.size();
103                    for (CMDElementType elem : elementlist) {
104                        if (elem.getConceptLink() != null) {
105                            stats.conceptlinkcounter++;
106                        }
107                    }
108                }
109                componentCounter(component.getCMDComponent(), stats);
110            }
111        }
112    }
113
114    @SuppressWarnings("serial")
115    private void addLinks() {
116        add(new Link("home") {
117
118            @Override
119            public void onClick() {
120                setResponsePage(AdminHomePage.class);
121            }
122        });
123    }
124}
Note: See TracBrowser for help on using the repository browser.