Skip to content

Commit

Permalink
SAK-49989 Gradebook upgrade wicket 6 to wicket 9 (sakaiproject#12513)
Browse files Browse the repository at this point in the history
Co-authored-by: Code Hugger (Matthew Jones) <[email protected]>

https://sakaiproject.atlassian.net/browse/SAK-49989
  • Loading branch information
ottenhoff authored Apr 22, 2024
1 parent 4e66c8e commit e941491
Show file tree
Hide file tree
Showing 80 changed files with 767 additions and 438 deletions.
2 changes: 1 addition & 1 deletion gradebookng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<wicket.version>6.30.0</wicket.version>
<wicket.version>9.17.0</wicket.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions gradebookng/tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
</dependency>
<dependency>
<groupId>org.sakaiproject.wicket</groupId>
<artifactId>wicket-tool-6</artifactId>
<artifactId>wicket-tool-9</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down Expand Up @@ -160,7 +160,7 @@
<artifactId>chartjs</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>
</dependencies>
<build>
<sourceDirectory>src/java</sourceDirectory>
<scriptSourceDirectory>src/webapp</scriptSourceDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import org.apache.wicket.core.request.handler.RenderPageRequestHandler;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.cycle.AbstractRequestCycleListener;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.resource.PackageResourceReference;
import org.apache.wicket.settings.IRequestCycleSettings.RenderStrategy;
import org.apache.wicket.settings.RequestCycleSettings.RenderStrategy;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;

import org.sakaiproject.gradebookng.framework.GradebookNgStringResourceLoader;
Expand Down Expand Up @@ -55,6 +54,9 @@ public void init() {
mountPage("/accessdenied", AccessDeniedPage.class);
mountPage("/error", ErrorPage.class);

// Allow Sakai portal to handle CSP
getCspSettings().blocking().disabled();

// remove the version number from the URL so that browser refreshes re-render the page
getRequestCycleSettings().setRenderStrategy(RenderStrategy.ONE_PASS_RENDER);

Expand All @@ -70,21 +72,6 @@ public void init() {
// Remove the wicket specific tags from the generated markup
getMarkupSettings().setStripWicketTags(true);

// Don't add any extra tags around a disabled link (default is <em></em>)
getMarkupSettings().setDefaultBeforeDisabledLink(null);
getMarkupSettings().setDefaultAfterDisabledLink(null);

// On Wicket session timeout, redirect to main page
// getApplicationSettings().setPageExpiredErrorPage(getHomePage());

// Intercept any unexpected error stacktrace and take to our page
getRequestCycleListeners().add(new AbstractRequestCycleListener() {
@Override
public IRequestHandler onException(final RequestCycle cycle, final Exception e) {
return new RenderPageRequestHandler(new PageProvider(new ErrorPage(e)));
}
});

// Disable Wicket's loading of jQuery - we load Sakai's preferred version in BasePage.java
getJavaScriptLibrarySettings().setJQueryReference(new PackageResourceReference(GradebookNgApplication.class, "empty.js"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ public List<GbStudentGradeInfo> sortGradeMatrix(Map<String, GbStudentGradeInfo>
/**
* Get a list of sections and groups in a site
*
* @return
* @return a list of sections and groups in the current site
*/
public List<GbGroup> getSiteSectionsAndGroups() {
final String siteId = getCurrentSiteId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package org.sakaiproject.gradebookng.business.model;

import java.io.Serializable;
import java.util.Comparator;

import org.apache.commons.lang3.builder.CompareToBuilder;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.Getter;
import lombok.ToString;

Expand All @@ -31,21 +31,17 @@
*
*/

@Getter
@ToString
@AllArgsConstructor
@EqualsAndHashCode
public class GbGroup implements Comparable<GbGroup>, Serializable {

private static final long serialVersionUID = 1L;

@Getter
private final String id;

@Getter
private final String title;

@Getter
private final String reference;

@Getter
private final Type type;

/**
Expand All @@ -57,51 +53,11 @@ public enum Type {
ALL;
}

public GbGroup(final String id, final String title, final String reference, final Type type) {
this.id = id;
this.title = title;
this.reference = reference;
this.type = type;
}

@Override
public int compareTo(final GbGroup other) {
return new CompareToBuilder()
.append(this.title, other.getTitle())
.append(this.type, other.getType())
.toComparison();

}

@Override
public boolean equals(final Object o) {
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (o.getClass() != getClass()) {
return false;
}
final GbGroup other = (GbGroup) o;
return new EqualsBuilder()
.appendSuper(super.equals(o))
.append(this.id, other.id)
.append(this.title, other.title)
.append(this.reference, other.reference)
.append(this.type, other.type)
.isEquals();
}

@Override
public int hashCode() {
return new HashCodeBuilder()
.append(this.id)
.append(this.title)
.append(this.reference)
.append(this.type)
.toHashCode();
public int compareTo(final @NonNull GbGroup other) {
return Comparator.comparing(GbGroup::getTitle)
.thenComparing(GbGroup::getType)
.compare(this, other);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ private String build(final CourseGradeTransferBean courseGrade) {
if (StringUtils.isNotBlank(calculatedGrade)
&& (this.gradebook.getCourseAverageDisplayed() || shouldDisplayFullCourseGrade())) {
if (parts.isEmpty()) {
parts.add(new StringResourceModel("coursegrade.display.percentage-first", null,
new Object[] { calculatedGrade }).getString());
parts.add(new StringResourceModel("coursegrade.display.percentage-first").setParameters(calculatedGrade).getString());
} else {
parts.add(new StringResourceModel("coursegrade.display.percentage-second", null,
new Object[] { calculatedGrade }).getString());
parts.add(new StringResourceModel("coursegrade.display.percentage-second").setParameters(calculatedGrade).getString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,6 @@ public static String formatDate(final Date date, final String ifNull) {
return formatDate(date);
}

/**
* Format a date with a time e.g. MM/dd/yyyy HH:mm
*
* @param date
* @return
*/
public static String formatDateTime(final Date date) {
final String dateTimeFormatString = MessageHelper.getString("format.datetime");
final SimpleDateFormat df = new SimpleDateFormat(dateTimeFormatString);
return df.format(date);
}

/**
* Strips out line breaks
*
Expand Down Expand Up @@ -407,8 +395,8 @@ public static String htmlUnescape(String input){
* @return fully formatted string ready for display
*/
public static String getGradeFromNumber(String newGrade, Map<String, Double> schema, Locale currentUserLocale) {
Double currentGradeValue = new Double(0.0);
Double maxValue = new Double(0.0);
Double currentGradeValue = 0.0;
Double maxValue = 0.0;
String returnGrade = newGrade;
try {
NumberFormat nf = NumberFormat.getInstance(currentUserLocale);
Expand Down Expand Up @@ -467,9 +455,9 @@ public static String transformNewGrade(String newGrade, Locale locale) {
if (parsePosition.getIndex() != newGrade.length()) {
throw new NumberFormatException("Grade has a bad format.");
}
Double dValue = n.doubleValue();
double dValue = n.doubleValue();

return (dValue.toString());
return (Double.toString(dValue));

}
catch (NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public class GradebookNgStringResourceLoader implements IStringResourceLoader {

private ResourceLoader loader = new ResourceLoader("gradebookng");
private final ResourceLoader loader = new ResourceLoader("gradebookng");

@Override
public String loadStringResource(Class<?> clazz, String key, Locale locale, String style, String variation) {
Expand All @@ -43,6 +43,11 @@ private String loadString(Locale locale, String key) {
if (locale != null && sakaiLocale == null) {
loader.setContextLocale(locale);
}
return loader.getString(key);
// Check the validity first because loader.getString will return a "missing key" string if not found
if (loader.getIsValid(key)) {
return loader.getString(key);
}
// Return null so the Wicket default loader can try to load the string
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget
window.setStudentToReturnFocusTo(studentUuid);
content.setOutputMarkupId(true);

final String modalTitle = (new StringResourceModel("heading.studentsummary",
null, new Object[] { student.getDisplayName(), student.getDisplayId() })).getString();
final String modalTitle = (new StringResourceModel("heading.studentsummary")
.setParameters(student.getDisplayName(), student.getDisplayId())).getString();

window.setTitle(modalTitle);
window.show(target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,16 @@ protected GbChartData getData() {

// get all grades for this assignment
final List<Double> allGrades = new ArrayList<>();
for (int i = 0; i < gradeInfo.size(); i++) {
final GbStudentGradeInfo studentGradeInfo = gradeInfo.get(i);
for (final GbStudentGradeInfo studentGradeInfo : gradeInfo) {
final Map<Long, GbGradeInfo> studentGrades = studentGradeInfo.getGrades();
final GbGradeInfo grade = studentGrades.get(this.assignmentId);

final Map<Long, GbGradeInfo> studentGrades = studentGradeInfo.getGrades();
final GbGradeInfo grade = studentGrades.get(this.assignmentId);
if (grade == null || grade.getGrade() == null) {
continue;
}

if (grade == null || grade.getGrade() == null) {
continue;
}

allGrades.add(Double.valueOf(grade.getGrade()));
}
allGrades.add(Double.valueOf(grade.getGrade()));
}
Collections.sort(allGrades);

final GbChartData data = new GbChartData();
Expand Down Expand Up @@ -124,7 +122,7 @@ protected GbChartData getData() {
* @return eg "0-50" as a string, depending on translation
*/
private String buildRangeLabel(final int start, final int end) {
return new StringResourceModel("label.statistics.chart.range", null, start, end).getString();
return new StringResourceModel("label.statistics.chart.range").setParameters(start, end).getString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ protected void onEvent(final AjaxRequestTarget target) {
add(component);
}

@Override
public void renderHead(final IHeaderResponse response) {
final GbGradeTableData gbGradeTableData = (GbGradeTableData) getDefaultModelObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ private List<ColumnDefinition> loadColumns(final List<Assignment> assignments) {
&& (a2 == null || !a1.getCategoryId().equals(a2.getCategoryId()))) {
result.add(new CategoryAverageDefinition(a1.getCategoryId(),
FormatHelper.abbreviateMiddle(a1.getCategoryName()),
(new StringResourceModel("label.gradeitem.categoryaverage", null, new Object[] { a1.getCategoryName() }))
(new StringResourceModel("label.gradeitem.categoryaverage").setParameters(a1.getCategoryName()))
.getString(),
nullable(categoryWeight),
getCategoryPoints(a1.getCategoryId()),
Expand All @@ -617,7 +617,7 @@ private List<ColumnDefinition> loadColumns(final List<Assignment> assignments) {
result.add(new CategoryAverageDefinition(
category.getId(),
FormatHelper.abbreviateMiddle(category.getName()),
(new StringResourceModel("label.gradeitem.categoryaverage", null, new Object[] { category.getName() }))
(new StringResourceModel("label.gradeitem.categoryaverage").setParameters(category.getName()))
.getString(),
nullable(categoryWeight),
category.getTotalPoints(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">

Expand Down Expand Up @@ -55,4 +56,4 @@

</div>
</body>
</html>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ErrorPage(final Exception e) {
final String code = RandomStringUtils.randomAlphanumeric(10);
log.error("User supplied error code for the above stacktrace: {}", code);

final Label error = new Label("error", new StringResourceModel("errorpage.text", null, new Object[] { code }));
final Label error = new Label("error", new StringResourceModel("errorpage.text").setParameters(code));
error.setEscapeModelStrings(false);
add(error);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">

Expand Down Expand Up @@ -73,7 +74,7 @@
<li>
<div class="gb-student-filter">
<label for="studentFilterInput" class="sr-only"><wicket:message key="filter.students"/></label>
<input type="text" id="studentFilterInput" class="form-control" aria-controls="gradeTable" wicket:id="studentFilter" wicket:message="placeholder:filter.students" accesskey="f">
<input type="text" id="studentFilterInput" class="form-control" aria-controls="gradeTable" wicket:id="studentFilter" wicket:message="placeholder:filter.students" accesskey="f" />
<a class="gb-student-filter-clear-button" wicket:message="title:filter.studentsclear" href="javascript:void(0)">
<i class="fa fa-times-circle" aria-hidden="true"></i>
</a>
Expand Down
Loading

0 comments on commit e941491

Please sign in to comment.