Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,17 @@ public class SimpleAssignment {
*/
private boolean allowResubmission;

/**
* Number of allowed re-submissions, using the current
* function in AssignmentAction assignment_resubmission_option_into_context()
*/
private String resubmissionNumber = "0";

/**
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resubmissionNumber is modeled as a String and is later set to a localized label for the unlimited case. This makes the entity response locale-dependent and hard to consume programmatically (clients can’t reliably parse/compare the value). Prefer returning a numeric value (e.g., int/Integer with -1 for unlimited) and/or a separate boolean like resubmissionUnlimited, and let the UI localize the label.

Suggested change
/**
/**
* Machine-readable number of allowed re-submissions.
* <ul>
* <li>0 when resubmissions are not allowed or the value is blank</li>
* <li>Parsed integer value when {@code resubmissionNumber} is numeric</li>
* <li>-1 when {@code resubmissionNumber} is non-numeric (e.g. a localized "unlimited" label)</li>
* </ul>
*/
public Integer getResubmissionNumberValue() {
if (!allowResubmission) {
return 0;
}
if (StringUtils.isBlank(resubmissionNumber)) {
return 0;
}
String trimmed = resubmissionNumber.trim();
if (StringUtils.isNumeric(trimmed)) {
try {
return Integer.valueOf(trimmed);
} catch (NumberFormatException e) {
// Fall through to treat as unlimited
}
}
// Non-numeric or unparsable values are treated as "unlimited"
return -1;
}
/**
* Indicates whether the number of allowed re-submissions is unlimited.
*/
public boolean isResubmissionUnlimited() {
Integer value = getResubmissionNumberValue();
return value != null && value.intValue() < 0;
}
/**

Copilot uses AI. Check for mistakes.
* Honor Pledge is set or not
*/
private boolean honorPledge;

/**
* Supplement items: model answer text
*/
Expand Down Expand Up @@ -1977,6 +1988,8 @@ public SimpleAssignment(Assignment a, boolean hydrate) {
// Translate grade scale from its numeric value to its description.
this.gradeScale = a.getTypeOfGrade().toString();

this.honorPledge = a.getHonorPledge();

// If grade scale is "points" we also capture the maximum points allowed.
if (a.getTypeOfGrade() == Assignment.GradeType.SCORE_GRADE_TYPE) {
Integer scaleFactor = a.getScaleFactor() != null ? a.getScaleFactor() : assignmentService.getScaleFactor();
Expand All @@ -1985,6 +1998,15 @@ public SimpleAssignment(Assignment a, boolean hydrate) {

// Use the number of submissions allowed as an indicator that re-submission is permitted.
if (a.getProperties().get(ALLOW_RESUBMIT_NUMBER) != null && a.getTypeOfSubmission() != Assignment.SubmissionType.NON_ELECTRONIC_ASSIGNMENT_SUBMISSION) {
Integer allowResubmitNumber = Integer.parseInt(
a.getProperties().get(ALLOW_RESUBMIT_NUMBER)
);

this.resubmissionNumber =
allowResubmitNumber == -1
? rb.getString("allow.resubmit.number.unlimited")
: allowResubmitNumber.toString();

this.allowResubmission = true;
Comment on lines 2000 to 2010
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integer.parseInt(a.getProperties().get(ALLOW_RESUBMIT_NUMBER)) can throw NumberFormatException if the stored property is blank or non-numeric (e.g., because setGrade accepts resubmitNumber as an unchecked String). This would break the /direct/assignment/... responses. Parse defensively (validate/try-catch) and fall back to a safe default (and optionally log).

Suggested change
if (a.getProperties().get(ALLOW_RESUBMIT_NUMBER) != null && a.getTypeOfSubmission() != Assignment.SubmissionType.NON_ELECTRONIC_ASSIGNMENT_SUBMISSION) {
Integer allowResubmitNumber = Integer.parseInt(
a.getProperties().get(ALLOW_RESUBMIT_NUMBER)
);
this.resubmissionNumber =
allowResubmitNumber == -1
? rb.getString("allow.resubmit.number.unlimited")
: allowResubmitNumber.toString();
this.allowResubmission = true;
String allowResubmitStr = a.getProperties().get(ALLOW_RESUBMIT_NUMBER);
if (StringUtils.isNotBlank(allowResubmitStr)
&& a.getTypeOfSubmission() != Assignment.SubmissionType.NON_ELECTRONIC_ASSIGNMENT_SUBMISSION) {
try {
Integer allowResubmitNumber = Integer.parseInt(allowResubmitStr);
this.resubmissionNumber =
allowResubmitNumber == -1
? rb.getString("allow.resubmit.number.unlimited")
: allowResubmitNumber.toString();
this.allowResubmission = true;
} catch (NumberFormatException nfe) {
log.warn("Invalid value for {} on assignment {}: '{}'", ALLOW_RESUBMIT_NUMBER, a.getId(), allowResubmitStr);
}

Copilot uses AI. Check for mistakes.
}
this.submissionType = a.getTypeOfSubmission().toString();
Expand Down
Loading