Skip to content

Commit

Permalink
SAK-50124 SiteStats wicket9 upgrade (#12606)
Browse files Browse the repository at this point in the history
  • Loading branch information
ottenhoff committed May 28, 2024
1 parent 93fb42d commit 2673b5f
Show file tree
Hide file tree
Showing 29 changed files with 344 additions and 349 deletions.
7 changes: 1 addition & 6 deletions sitestats/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<commons-betwixt.version>0.8</commons-betwixt.version>
<fop.version>1.0</fop.version>
<jfreechart.version>1.5.3</jfreechart.version>
<sst.wicket.version>6.30.0</sst.wicket.version>
<sst.wicket.version>9.17.0</sst.wicket.version>
</properties>

<!-- Project modules -->
Expand Down Expand Up @@ -127,11 +127,6 @@
<artifactId>wicket-datetime</artifactId>
<version>${sst.wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-devutils</artifactId>
<version>${sst.wicket.version}</version>
</dependency>
<!-- JFreeChart -->
<dependency>
<groupId>org.jfree</groupId>
Expand Down
6 changes: 1 addition & 5 deletions sitestats/sitestats-tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<!-- Sakai Wicket library -->
<dependency>
<groupId>org.sakaiproject.wicket</groupId>
<artifactId>wicket-tool-6</artifactId>
<artifactId>wicket-tool-9</artifactId>
</dependency>

<!-- Apache Wicket -->
Expand All @@ -89,10 +89,6 @@
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-spring</artifactId>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-devutils</artifactId>
</dependency>

<!-- Apache Commons -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.wicket.core.request.mapper.CryptoMapper;
import org.apache.wicket.core.util.crypt.KeyInSessionSunJceCryptFactory;
import org.apache.wicket.request.IRequestMapper;
import org.apache.wicket.settings.IExceptionSettings;
import org.sakaiproject.sitestats.tool.wicket.pages.AdminPage;


Expand All @@ -38,9 +37,6 @@ protected void init() {
getApplicationSettings().setAccessDeniedPage(AdminPage.class);
getApplicationSettings().setInternalErrorPage(AdminPage.class);

// show internal error page rather than default developer page
getExceptionSettings().setUnexpectedExceptionDisplay(IExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);

// Encrypt URLs. This immediately sets up a session (note that things like CSS now becomes bound to the session)
getSecuritySettings().setCryptFactory(new KeyInSessionSunJceCryptFactory()); // Different key per user
final IRequestMapper cryptoMapper = new CryptoMapper(getRootRequestMapper(), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,21 @@

import java.util.Locale;

import lombok.Getter;
import lombok.Setter;
import org.apache.wicket.Component;
import org.apache.wicket.core.request.mapper.CryptoMapper;
import org.apache.wicket.core.util.crypt.KeyInSessionSunJceCryptFactory;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.cycle.IRequestCycleListener;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.request.cycle.AbstractRequestCycleListener;
import org.apache.wicket.resource.loader.IStringResourceLoader;
import org.apache.wicket.settings.IExceptionSettings;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.apache.wicket.util.resource.IResourceStream;
import org.apache.wicket.core.util.resource.locator.ResourceStreamLocator;
import org.apache.wicket.core.util.file.WebApplicationPath;
import org.apache.wicket.devutils.debugbar.DebugBar;
import org.apache.wicket.devutils.debugbar.InspectorDebugPanel;
import org.apache.wicket.devutils.debugbar.PageSizeDebugPanel;
import org.apache.wicket.devutils.debugbar.SessionSizeDebugPanel;
import org.apache.wicket.devutils.debugbar.VersionDebugContributor;
import org.apache.wicket.request.IRequestMapper;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.sitestats.tool.facade.SakaiFacade;
import org.sakaiproject.sitestats.tool.wicket.components.JavaScriptToBucketResponseDecorator;
import org.sakaiproject.sitestats.tool.wicket.pages.OverviewPage;
Expand All @@ -49,11 +44,11 @@
import org.sakaiproject.util.ResourceLoader;


@Setter
@Getter
public class SiteStatsApplication extends WebApplication {
private static final ResourceLoader msgs = new ResourceLoader("Messages");
private static final ResourceLoader evnts = new ResourceLoader("Events");

private boolean debug = false;

private transient SakaiFacade facade;

Expand All @@ -63,15 +58,15 @@ protected void init() {

// Configure general wicket application settings
getComponentInstantiationListeners().add(new SpringComponentInjector(this));
getCspSettings().blocking().disabled();
getResourceSettings().setThrowExceptionOnMissingResource(false);
getMarkupSettings().setStripWicketTags(true);
getResourceSettings().getStringResourceLoaders().add(new SiteStatsStringResourceLoader());
getResourceSettings().getResourceFinders().add(new WebApplicationPath(getServletContext(), "html"));
getResourceSettings().setResourceStreamLocator(new SiteStatsResourceStreamLocator());
getDebugSettings().setAjaxDebugModeEnabled(debug);

// configure bottom page script loading
setHeaderResponseDecorator(new JavaScriptToBucketResponseDecorator("bottom-script-container"));
//setHeaderResponseDecorator(new JavaScriptToBucketResponseDecorator("bottom-script-container"));

// Mount pages
mountPage("/home", OverviewPage.class);
Expand All @@ -83,29 +78,9 @@ protected void init() {
getApplicationSettings().setPageExpiredErrorPage(OverviewPage.class);
getApplicationSettings().setAccessDeniedPage(OverviewPage.class);

// Debugging
debug = ServerConfigurationService.getBoolean("sitestats.debug", false);
if(debug) {
getDebugSettings().setComponentUseCheck(true);
getDebugSettings().setAjaxDebugModeEnabled(true);
getDebugSettings().setLinePreciseReportingOnAddComponentEnabled(true);
getDebugSettings().setLinePreciseReportingOnNewComponentEnabled(true);
getDebugSettings().setOutputComponentPath(true);
getDebugSettings().setOutputMarkupContainerClassName(true);
getDebugSettings().setDevelopmentUtilitiesEnabled(true);
getMarkupSettings().setStripWicketTags(false);
getExceptionSettings().setUnexpectedExceptionDisplay(IExceptionSettings.SHOW_EXCEPTION_PAGE);
// register standard debug contributors so that just setting the sitestats.debug property is enough to turn these on
// otherwise, you have to turn wicket development mode on to get this populated due to the order methods are called
DebugBar.registerContributor(VersionDebugContributor.DEBUG_BAR_CONTRIB, this);
DebugBar.registerContributor(InspectorDebugPanel.DEBUG_BAR_CONTRIB, this);
DebugBar.registerContributor(SessionSizeDebugPanel.DEBUG_BAR_CONTRIB, this);
DebugBar.registerContributor(PageSizeDebugPanel.DEBUG_BAR_CONTRIB, this);
}
else
{
// Throw RuntimeDeceptions so they are caught by the Sakai ErrorReportHandler
getRequestCycleListeners().add(new AbstractRequestCycleListener()
getRequestCycleListeners().add(new IRequestCycleListener()
{
@Override
public IRequestHandler onException(RequestCycle cycle, Exception ex)
Expand All @@ -120,24 +95,16 @@ public IRequestHandler onException(RequestCycle cycle, Exception ex)
}

// Encrypt URLs. This immediately sets up a session (note that things like CSS now becomes bound to the session)
getSecuritySettings().setCryptFactory(new KeyInSessionSunJceCryptFactory()); // Different key per user
final IRequestMapper cryptoMapper = new CryptoMapper(getRootRequestMapper(), this);
setRootRequestMapper(cryptoMapper);
//getSecuritySettings().setCryptFactory(new KeyInSessionSunJceCryptFactory()); // Different key per user
//final IRequestMapper cryptoMapper = new CryptoMapper(getRootRequestMapper(), this);
//setRootRequestMapper(cryptoMapper);
}

public Class getHomePage() {
return OverviewPage.class;
}

public SakaiFacade getFacade() {
return facade;
}

public void setFacade(final SakaiFacade facade) {
this.facade = facade;
}

/**
/**
* Custom bundle loader to pickup bundles from sitestats-bundles/
* @author Nuno Fernandes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.sakaiproject.sitestats.tool.wicket.components;

import java.time.Duration;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.Page;
Expand All @@ -43,7 +45,6 @@
import org.apache.wicket.request.resource.AbstractResource;
import org.apache.wicket.request.resource.DynamicImageResource;
import org.apache.wicket.request.resource.IResource;
import org.apache.wicket.util.time.Duration;
import org.sakaiproject.sitestats.tool.wicket.pages.MaximizedImagePage;


Expand Down Expand Up @@ -247,7 +248,7 @@ protected void configureResponse(AbstractResource.ResourceResponse response, IRe
{
super.configureResponse(response, attributes);

response.setCacheDuration(Duration.NONE);
response.setCacheDuration(Duration.ZERO);
response.setCacheScope(CacheScope.PRIVATE);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.sakaiproject.sitestats.tool.wicket.components;

import java.awt.image.BufferedImage;
import java.time.Duration;

import lombok.extern.slf4j.Slf4j;
import org.apache.wicket.request.resource.IResource;
Expand All @@ -27,7 +28,6 @@
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.http.WebResponse;
import org.apache.wicket.request.resource.AbstractResource;
import org.apache.wicket.util.time.Duration;


/**
Expand Down Expand Up @@ -75,7 +75,7 @@ protected void configureResponse(AbstractResource.ResourceResponse response, IRe
{
super.configureResponse(response, attributes);

response.setCacheDuration(Duration.NONE);
response.setCacheDuration(Duration.ZERO);
response.setCacheScope(WebResponse.CacheScope.PRIVATE);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.CheckBox;
Expand Down Expand Up @@ -58,7 +59,7 @@ public EventRegistryTree(String id, List<?> eventRegistry, String toolId) {
ul.add(new AttributeModifier("style", new Model("padding: 0 0 0 20px; display: none;")));
ul.add(new AttributeModifier("class", new Model("events")));
}else{
ul.add(new AttributeModifier("style", new Model("padding: 0px;")));
ul.add(new AttributeModifier("style", new Model("padding: 0;")));
ul.add(new AttributeModifier("class", new Model("tools")));
}
add(ul);
Expand All @@ -67,10 +68,10 @@ public EventRegistryTree(String id, List<?> eventRegistry, String toolId) {
}

@Override
public void renderHead(HtmlHeaderContainer container) {
container.getHeaderResponse().render(JavaScriptHeaderItem.forUrl(StatsManager.SITESTATS_WEBAPP+"/script/prefs.js"));
container.getHeaderResponse().render(OnDomReadyHeaderItem.forScript("updateAllToolsSelection()"));
super.renderHead(container);
public void renderHead(IHeaderResponse response) {
response.render(JavaScriptHeaderItem.forUrl(StatsManager.SITESTATS_WEBAPP+"/script/prefs.js"));
response.render(OnDomReadyHeaderItem.forScript("updateAllToolsSelection()"));
super.renderHead(response);
}

public List<?> getEventRegistry() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.request.Request;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
Expand Down Expand Up @@ -133,9 +135,7 @@ public void setSelectedFiles(String filesEncoded) {
List<String> files = new ArrayList<String>();
if(filesEncoded != null) {
String[] t = filesEncoded.split("\\|\\|\\|");
for(int i=0; i<t.length; i++) {
files.add(t[i]);
}
Collections.addAll(files, t);
}
setDefaultModelObject(files);
}
Expand All @@ -154,21 +154,16 @@ private boolean isFolderPartOfSelectedFiles(String collectionId) {
}

@Override
public void renderHead(HtmlHeaderContainer container) {
container.getHeaderResponse().render(JavaScriptHeaderItem.forUrl(BasePage.JQUERYSCRIPT));
super.renderHead(container); // needs to be rendered after jQuery but before the page specifc scripts
container.getHeaderResponse().render(JavaScriptHeaderItem.forUrl(StatsManager.SITESTATS_WEBAPP+"/html/components/jqueryFileTree/jqueryFileTree.js"));
container.getHeaderResponse().render(CssHeaderItem.forUrl(StatsManager.SITESTATS_WEBAPP+"/html/components/jqueryFileTree/jqueryFileTree.css"));
StringBuilder onDomReady = new StringBuilder();
onDomReady.append("jQuery('#sitestats-containerInner').fileTree(");
onDomReady.append(" {root: '");
onDomReady.append(BASE_DIR);
onDomReady.append("', script: '");
onDomReady.append(ajaxResourcesLoader.getCallbackUrl());
onDomReady.append("', duration: 100},");
onDomReady.append(" function(file) {return false;}");
onDomReady.append(");");
container.getHeaderResponse().render(OnDomReadyHeaderItem.forScript(onDomReady.toString()));
public void renderHead(IHeaderResponse response) {
response.render(JavaScriptHeaderItem.forUrl(BasePage.JQUERYSCRIPT));
super.renderHead(response); // needs to be rendered after jQuery but before the page specifc scripts
response.render(JavaScriptHeaderItem.forUrl(StatsManager.SITESTATS_WEBAPP+"/html/components/jqueryFileTree/jqueryFileTree.js"));
response.render(CssHeaderItem.forUrl(StatsManager.SITESTATS_WEBAPP+"/html/components/jqueryFileTree/jqueryFileTree.css"));
String onDomReady = "jQuery('#sitestats-containerInner').fileTree(" +
" {root: '" + BASE_DIR + "', script: '" + ajaxResourcesLoader.getCallbackUrl() + "', duration: 100}," +
" function(file) {return false;}" +
");";
response.render(OnDomReadyHeaderItem.forScript(onDomReady));
}

private List<CHResourceModel> getResources(String dir) throws IdUnusedException, TypeException, PermissionException {
Expand Down Expand Up @@ -222,18 +217,13 @@ protected void respond(AjaxRequestTarget target) {
RequestCycle.get().scheduleRequestHandlerAfterCurrent(new EmptyRequestHandler());
WebResponse response = (WebResponse) getResponse();
response.setContentType("text/html;charset="+enc);
OutputStream out = getResponse().getOutputStream();
try{
try (OutputStream out = getResponse().getOutputStream()) {
out.write("<ul class=\"jqueryFileTree\" style=\"display: none;\">".getBytes(enc));
boolean expandToSelection = currentDir.equals(BASE_DIR) && getSelectedFilesId() != null && getSelectedFilesId().size() > 0;
getResourcesMarkup(currentDir, out, expandToSelection, enc);
boolean expandToSelection = currentDir.equals(BASE_DIR) && getSelectedFilesId() != null && !getSelectedFilesId().isEmpty();
getResourcesMarkup(currentDir, out, expandToSelection, enc);
out.write("</ul>".getBytes(enc));
}finally{
out.close();
}
}catch(RuntimeException e){
// ignore - do nothing
}catch(Exception e){
} catch(Exception e){
// ignore - do nothing
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ private void renderBody() {
String serverDateStr = timeServ.shortLocalizedTimestamp(d.toInstant(), TimeZone.getDefault(), getSession().getLocale());
lastJobRunDate.setDefaultModel(new Model(dStr));
String localSakaiName = Locator.getFacade().getStatsManager().getLocalSakaiName();
StringResourceModel model = new StringResourceModel("lastJobRun_server_time", getPage(), null,
new Object[] {localSakaiName, serverDateStr});
StringResourceModel model = new StringResourceModel("lastJobRun_server_time").setParameters(localSakaiName, serverDateStr);
lastJobRunServerDate.setDefaultModel(model);
}catch(Exception e){
lastJobRunDate.setDefaultModel(new Model());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,12 @@ private SakaiNavigatorLabel(final String id, final PageableComponent table) {
super(id);
Model model = new Model(new LabelModelObject(table));
setDefaultModel(
new StringResourceModel(
"pager_textStatus",
this,
model,
"Viewing {0} - {1} of {2} {3}",
new Object[] {
new StringResourceModel("pager_textStatus").setParameters(
new PropertyModel(model, "from"),
new PropertyModel(model, "to"),
new PropertyModel(model, "of"),
new ResourceModel("pager_textItem"),
})
new ResourceModel("pager_textItem")
)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.sakaiproject.sitestats.tool.wicket.components;

import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
Expand Down Expand Up @@ -75,9 +76,9 @@ public void onSubmit() {
}

@Override
public void renderHead(HtmlHeaderContainer container) {
container.getHeaderResponse().render(JavaScriptHeaderItem.forUrl(BasePage.JQUERYSCRIPT));
super.renderHead(container);
public void renderHead(IHeaderResponse response) {
response.render(JavaScriptHeaderItem.forUrl(BasePage.JQUERYSCRIPT));
super.renderHead(response);
}

public void setSearchKeyword(String keyword) {
Expand Down
Loading

0 comments on commit 2673b5f

Please sign in to comment.