Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAK-50770 Gradebook Add Osiris Export #13156

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 @@ -1958,6 +1958,10 @@
# DEFAULT: false
# gradebookng.allowColumnResizing=true

# SAK-50770
# DEFAULT: false
# gradebookng.export.enabelOsirisExport=true

# SAK-46075: max upload file size, defined in megabytes
# DEFAULT: 2
# gradebook.import.maxSize=3
Expand Down
4 changes: 4 additions & 0 deletions gradebookng/bundle/src/main/bundle/gradebookng.properties
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ importExport.template.button.fullGradebook = Export Gradebook
importExport.template.button.customGradebook = Download Custom Export
importExport.template.button.advancedOptions = Custom Export

importExport.export.osiris.heading = Export to Osiris
importExport.export.osiris.description = Export final grades in a format compatible with the Osiris SIS platform
importExport.template.button.export.osiris = Osiris export

importExport.selection.heading = Gradebook Item Import Selection
importExport.selection.description = The system has analyzed the contents of your file upload and has identified new/updated information where applicable. Please select from the desired items below.
importExport.selection.note = <strong>Note:</strong> Selecting "Update" items will override existing values for that item.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,20 @@ public static void postStudentViewEvent(Gradebook gradebook, String studentUid)


public static void postExportEvent(Gradebook gradebook, boolean isCustomExport) {
postExportEvent(gradebook, isCustomExport ? "custom" : "full");
}


public static void postOsirisExportEvent(Gradebook gradebook) {
postExportEvent(gradebook, "osiris");
}


private static void postExportEvent(Gradebook gradebook, String exportType) {
String[] bits = new String[] {
EVENT_REF_PREFIX,
String.valueOf(gradebook.getId()),
isCustomExport ? "custom" : "full"
exportType
};

postEvent(createEvent(GbEvent.EXPORT, String.join("/", bits), false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public abstract class BasePanel extends Panel {
protected static final String SAK_PROP_ALLOW_COMPARE_GRADES = "gradebookng.allowStudentsToCompareGradesWithClassmates";
protected static final Boolean SAK_PROP_ALLOW_COMPARE_GRADES_DEFAULT = Boolean.FALSE;

protected static final String SAK_PROP_ENABLE_OSIRIS_EXPORT = "gradebookng.export.enabelOsirisExport";
protected static final Boolean SAK_PROP_ENABLE_OSIRIS_EXPORT_DEFAULT = Boolean.FALSE;

public BasePanel(final String id) {
super(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,26 @@ <h5 class="modal-title" id="customExportModalTitle"><wicket:message key="importE
</div>
</div>
</div>

<div wicket:id="osirisExportContainer">
<h2><wicket:message key="importExport.export.osiris.heading" /></h2>
ottenhoff marked this conversation as resolved.
Show resolved Hide resolved

<div class="row">
<div class="col-sm-12">
<p><wicket:message key="importExport.export.osiris.description" /></p>
</div>
</div>

<div class="row">
<div class="col-sm-12">
<p>
<button type="button" class="button_color" wicket:id="downloadOsirisExport">
Copy link

Choose a reason for hiding this comment

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

Looks like this element is missing an accessible name or label. That makes it hard for people using screen readers or voice control to use the control.

<wicket:message key="importExport.template.button.export.osiris"/>
</button>
</p>
</div>
</div>
</div>
</section>

</wicket:panel>
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,28 @@

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormatSymbols;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.link.DownloadLink;
Expand All @@ -42,6 +50,7 @@
import org.sakaiproject.gradebookng.business.model.GbGradeInfo;
import org.sakaiproject.gradebookng.business.model.GbGroup;
import org.sakaiproject.gradebookng.business.model.GbStudentGradeInfo;
import org.sakaiproject.gradebookng.business.model.GbUser;
import org.sakaiproject.gradebookng.business.util.EventHelper;
import org.sakaiproject.gradebookng.business.util.FormatHelper;
import org.sakaiproject.gradebookng.tool.model.GradebookUiSettings;
Expand All @@ -54,6 +63,9 @@
import org.sakaiproject.util.Validator;
import org.sakaiproject.util.api.FormattedText;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ExportPanel extends BasePanel {

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -282,6 +294,24 @@ protected File load() {

this.customDownloadLink = buildCustomDownloadLink();
add(this.customDownloadLink);

// Add Osiris export components if enabled
boolean osirisExportEnabled =this.serverConfigService.getBoolean(SAK_PROP_ENABLE_OSIRIS_EXPORT,
SAK_PROP_ENABLE_OSIRIS_EXPORT_DEFAULT);

WebMarkupContainer osirisExportContainer = new WebMarkupContainer("osirisExportContainer");
osirisExportContainer.setVisible(osirisExportEnabled);
add(osirisExportContainer);
osirisExportContainer.add(new DownloadLink("downloadOsirisExport", new LoadableDetachableModel<File>() {
private static final long serialVersionUID = 2L;

@Override
protected File load() {
return buildOsirisExportFile();
}

}, buildOsirisExportFileName()).setCacheDuration(Duration.ZERO).setDeleteAfterDownload(true));

}

private Component buildCustomDownloadLink() {
Expand Down Expand Up @@ -535,4 +565,63 @@ private String buildFileName(final boolean customDownload) {

return String.format("%s.%s", cleanFilename, extension);
}

private File buildOsirisExportFile() {
List<String> userIds = this.businessService.getGradeableUsers();

Map<String, String> userEids = this.businessService.getGbUsers(userIds).stream()
.collect(Collectors.toMap(GbUser::getUserUuid, GbUser::getDisplayId));

Map<String, CourseGradeTransferBean> courseGrades = this.businessService.getCourseGrades(userIds);

try {
File tempFile = File.createTempFile("gradebookExport", ".txt");

try (PrintWriter writer = new PrintWriter(new FileWriter(tempFile))) {
for (String userId : userIds) {
String userEid = userEids.get(userId);
if (StringUtils.isEmpty(userEid)) {
log.debug("Skipping user {} from export, beacuse eid is empty", userId);
continue;
}

CourseGradeTransferBean courseGrade = courseGrades.get(userId);
if (courseGrade == null || StringUtils.isEmpty(courseGrade.getCalculatedGrade())) {
log.debug("Skipping user {} from export, beacuse display grade is empty", userId);
continue;
}

DecimalFormatSymbols.getInstance(Locale.US);
String grade = NumberUtils.toScaledBigDecimal(courseGrade.getCalculatedGrade(), 0, RoundingMode.HALF_UP).toString();

writer.println(StringUtils.trim(userEid) + " " + grade);
}
}

EventHelper.postOsirisExportEvent(getGradebook());

return tempFile;
} catch (IOException e) {
throw new RuntimeException("Failed to create Osiris export", e);
}
}

private String buildOsirisExportFileName() {
final String prefix = getString("importExport.download.filenameprefix");

final List<String> fileNameComponents = new ArrayList<>();
fileNameComponents.add(prefix);

// Add gradebook name/site id to filename
final String gradebookName = this.businessService.getGradebook().getName();
if (StringUtils.isNotBlank(gradebookName)) {
fileNameComponents.add(StringUtils.replace(gradebookName, " ", "_"));
}

fileNameComponents.add("osiris");

final String cleanFilename = Validator.cleanFilename(StringUtils.join(fileNameComponents, "-"));

return cleanFilename + ".txt";
}
}
Loading