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