List of usage examples for org.apache.wicket.markup.html.panel Panel error
@Override public final void error(final Serializable message)
From source file:org.sakaiproject.gradebookng.business.util.ImportGradesHelper.java
License:Educational Community License
/** * Validates and processes the spreadsheet provided by importWizardModel.getSpreadsheetWrapper(); prepares an ImportWizardModel appropriate for the selection step * @param sourcePage the ImportExportPage * @param sourcePanel panel on which to invoke error(), etc. with localized messages should we encounter any issues * @param importWizardModel/*from w ww . ja va 2s. c om*/ * @param businessService * @param target * @return true if the model was successfully set up without errors; in case of errors, the feedback panels will be updated and false will be returned */ public static boolean setupImportWizardModelForSelectionStep(ImportExportPage sourcePage, Panel sourcePanel, ImportWizardModel importWizardModel, GradebookNgBusinessService businessService, AjaxRequestTarget target) { ImportedSpreadsheetWrapper spreadsheetWrapper = importWizardModel.getSpreadsheetWrapper(); if (spreadsheetWrapper == null) { sourcePanel.error(MessageHelper.getString("importExport.error.unknown")); sourcePage.updateFeedback(target); return false; } // If there are duplicate headings, tell the user now boolean hasValidationErrors = false; HeadingValidationReport headingReport = spreadsheetWrapper.getHeadingReport(); SortedSet<String> duplicateHeadings = headingReport.getDuplicateHeadings(); if (!duplicateHeadings.isEmpty()) { String duplicates = StringUtils.join(duplicateHeadings, ", "); sourcePanel.error(MessageHelper.getString("importExport.error.duplicateColumns", duplicates)); hasValidationErrors = true; } // If there are invalid headings, tell the user now SortedSet<String> invalidHeadings = headingReport.getInvalidHeadings(); if (!invalidHeadings.isEmpty()) { String invalids = StringUtils.join(invalidHeadings, ", "); sourcePanel.error(MessageHelper.getString("importExport.error.invalidColumns", invalids)); hasValidationErrors = true; } // If there are blank headings, tell the user now int blankHeadings = headingReport.getBlankHeaderTitleCount(); if (blankHeadings > 0) { sourcePanel.error(MessageHelper.getString("importExport.error.blankHeadings", blankHeadings)); hasValidationErrors = true; } // If there are duplicate student entries, tell the user now (we can't make the decision about which entry takes precedence) UserIdentificationReport userReport = spreadsheetWrapper.getUserIdentifier().getReport(); SortedSet<GbUser> duplicateStudents = userReport.getDuplicateUsers(); if (!duplicateStudents.isEmpty()) { String duplicates = StringUtils.join(duplicateStudents, ", "); sourcePanel.error(MessageHelper.getString("importExport.error.duplicateStudents", duplicates)); hasValidationErrors = true; } // Perform grade validation; present error message with invalid grades on current page List<ImportedColumn> columns = spreadsheetWrapper.getColumns(); List<ImportedRow> rows = spreadsheetWrapper.getRows(); GradeValidationReport gradeReport = new GradeValidator(businessService).validate(rows, columns); // maps columnTitle -> (userEid -> grade) SortedMap<String, SortedMap<String, String>> invalidGradesMap = gradeReport.getInvalidNumericGrades(); if (!invalidGradesMap.isEmpty()) { Collection<SortedMap<String, String>> invalidGrades = invalidGradesMap.values(); List<String> badGradeEntries = new ArrayList<>(invalidGrades.size()); for (SortedMap<String, String> invalidGradeEntries : invalidGrades) { badGradeEntries.add(StringUtils.join(invalidGradeEntries.entrySet(), ", ")); } String badGrades = StringUtils.join(badGradeEntries, ", "); sourcePanel.error(MessageHelper.getString("importExport.error.invalidGradeData", MessageHelper.getString("grade.notifications.invalid"), badGrades)); hasValidationErrors = true; } // Perform comment validation; present error message with invalid gradebook items and corresponding student identifiers on current page CommentValidationReport commentReport = new CommentValidator().validate(rows, columns, businessService.getServerConfigService()); SortedMap<String, List<String>> invalidCommentsMap = commentReport.getInvalidComments(); if (!invalidCommentsMap.isEmpty()) { List<String> badCommentEntries = new ArrayList<>(); for (String columnTitle : invalidCommentsMap.keySet()) { for (String student : invalidCommentsMap.get(columnTitle)) { badCommentEntries.add(columnTitle + ":" + student); } } String badComments = StringUtils.join(badCommentEntries, ", "); sourcePanel.error(MessageHelper.getString("importExport.error.invalidComments", CommentValidator.getMaxCommentLength(businessService.getServerConfigService()), badComments)); hasValidationErrors = true; } // get existing data final List<Assignment> assignments = businessService.getGradebookAssignments(); final List<GbStudentGradeInfo> grades = businessService.buildGradeMatrixForImportExport(assignments, null); // process file List<ProcessedGradeItem> processedGradeItems = processImportedGrades(spreadsheetWrapper, assignments, grades); // If the file has orphaned comment columns, tell the user now SortedSet<String> orphanedCommentColumns = headingReport.getOrphanedCommentHeadings(); if (!orphanedCommentColumns.isEmpty()) { String invalids = StringUtils.join(orphanedCommentColumns, ", "); sourcePanel.error(MessageHelper.getString("importExport.error.orphanedComments", invalids)); hasValidationErrors = true; } // if the file has no valid users, tell the user now if (userReport.getIdentifiedUsers().isEmpty()) { hasValidationErrors = true; sourcePanel.error(MessageHelper.getString("importExport.error.noValidStudents")); } // if empty there are no grade columns, tell the user now if (processedGradeItems.isEmpty() && !userReport.getIdentifiedUsers().isEmpty()) { hasValidationErrors = true; sourcePanel.error(MessageHelper.getString("importExport.error.noValidGrades")); } boolean hasChanges = false; for (ProcessedGradeItem item : processedGradeItems) { if (item.getStatus() == ProcessedGradeItem.Status.MODIFIED || item.getStatus() == ProcessedGradeItem.Status.NEW || item.getStatus() == ProcessedGradeItem.Status.UPDATE) { hasChanges = true; break; } } if ((!hasChanges && !processedGradeItems.isEmpty()) && !userReport.getIdentifiedUsers().isEmpty()) { hasValidationErrors = true; sourcePanel.error(MessageHelper.getString("importExport.error.noChanges")); } // Return errors before processing further if (hasValidationErrors) { sourcePage.updateFeedback(target); return false; } // No validation errors were encountered; clear out previous errors and continue to the next step in the wizard sourcePage.clearFeedback(); sourcePage.updateFeedback(target); // Setup and return the model importWizardModel.setProcessedGradeItems(processedGradeItems); importWizardModel.setUserReport(userReport); return true; }