/** @return The comma-separated list of css styles to use in displaying the rows */ public String getRowStyles() { StringBuilder sb = new StringBuilder(); for (Iterator iter = gradebookItemList.iterator(); iter.hasNext(); ) { Object gradebookItem = iter.next(); if (gradebookItem instanceof GradableObject) { GradableObject go = (GradableObject) gradebookItem; if (go.isCourseGrade()) { sb.append("internal"); break; } else { Assignment asn = (Assignment) go; if (asn.isExternallyMaintained()) { sb.append("external,"); } else { sb.append("internal,"); } } } else { sb.append("internal,"); } } return sb.toString(); }
protected void init() { gradebookItemList = new ArrayList(); courseGrade = new CourseGrade(); if (getCategoriesEnabled()) { /* if categories are enabled, we need to display a table that includes * categories, assignments, and the course grade. */ List categoryListWithCG = getGradebookManager() .getCategoriesWithStats( getGradebookId(), getAssignmentSortColumn(), isAssignmentSortAscending(), getCategorySortColumn(), isCategorySortAscending()); List<Category> categoryList = new ArrayList<Category>(); // first, remove the CourseGrade from the Category list for (Iterator catIter = categoryListWithCG.iterator(); catIter.hasNext(); ) { Object catOrCourseGrade = catIter.next(); if (catOrCourseGrade instanceof Category) { categoryList.add((Category) catOrCourseGrade); } else if (catOrCourseGrade instanceof CourseGrade) { courseGrade = (CourseGrade) catOrCourseGrade; } } // then, we need to check for special grader permissions that may limit which categories may // be viewed if (!isUserAbleToGradeAll() && isUserHasGraderPermissions()) { // SAK-19896, eduservice's can't share the same "Category" class, so just pass the ID's List<Long> catIds = new ArrayList<Long>(); for (Category category : (List<Category>) categoryList) { catIds.add(category.getId()); } List<Long> viewableCats = getGradebookPermissionService() .getCategoriesForUser(getGradebookId(), getUserUid(), catIds); List<Category> tmpCatList = new ArrayList<Category>(); for (Category category : (List<Category>) categoryList) { if (viewableCats.contains(category.getId())) { tmpCatList.add(category); } } categoryList = tmpCatList; } if (categoryList != null && !categoryList.isEmpty()) { Comparator catComparator = null; if (Assignment.SORT_BY_MEAN.equals(getAssignmentSortColumn())) { catComparator = Category.averageScoreComparator; } else if (Category.SORT_BY_WEIGHT.equals(getAssignmentSortColumn())) { catComparator = Category.weightComparator; } else if (Category.SORT_BY_NAME.equals(getAssignmentSortColumn())) { catComparator = Category.nameComparator; } if (catComparator != null) { Collections.sort(categoryList, catComparator); if (!isAssignmentSortAscending()) { Collections.reverse(categoryList); } } Iterator catIter = categoryList.iterator(); while (catIter.hasNext()) { Category myCat = (Category) catIter.next(); gradebookItemList.add(myCat); List assignmentList = myCat.getAssignmentList(); if (assignmentList != null && !assignmentList.isEmpty()) { Iterator assignIter = assignmentList.iterator(); while (assignIter.hasNext()) { Assignment assign = (Assignment) assignIter.next(); if (assign.isExternallyMaintained()) displayGradeEditorCol = true; gradebookItemList.add(assign); } ensureAssignmentsSorted(assignmentList, GradableObject.sortingComparator, false); } } } if (!isUserAbleToGradeAll() && (isUserHasGraderPermissions() && !getGradebookPermissionService() .getPermissionForUserForAllAssignment(getGradebookId(), getUserUid()))) { // is not authorized to view the "Unassigned" Category } else { List unassignedList = getGradebookManager() .getAssignmentsWithNoCategoryWithStats( getGradebookId(), getAssignmentSortColumn(), isAssignmentSortAscending()); if (unassignedList != null && !unassignedList.isEmpty()) { Category unassignedCat = new Category(); unassignedCat.setGradebook(getGradebook()); unassignedCat.setAverageScore(new Double(0)); unassignedCat.setName(getLocalizedString("cat_unassigned")); unassignedCat.setAssignmentList(unassignedList); if (!getWeightingEnabled()) unassignedCat.calculateStatistics(unassignedList); gradebookItemList.add(unassignedCat); Iterator unassignedIter = unassignedList.iterator(); while (unassignedIter.hasNext()) { Assignment assignWithNoCat = (Assignment) unassignedIter.next(); if (assignWithNoCat.isExternallyMaintained()) displayGradeEditorCol = true; gradebookItemList.add(assignWithNoCat); } } ensureAssignmentsSorted(unassignedList, GradableObject.sortingComparator, false); } } else { // Get the list of assignments for this gradebook, sorted as defined in the overview page. List goList = getGradebookManager() .getAssignmentsAndCourseGradeWithStats( getGradebookId(), getAssignmentSortColumn(), isAssignmentSortAscending()); if (goList != null && !goList.isEmpty()) { Iterator goIter = goList.iterator(); while (goIter.hasNext()) { GradableObject go = (GradableObject) goIter.next(); if (go.isCourseGrade()) { courseGrade = (CourseGrade) go; } else { Assignment assign = (Assignment) go; if (assign.isExternallyMaintained()) displayGradeEditorCol = true; gradebookItemList.add(assign); } } ensureAssignmentsSorted(goList, GradableObject.sortingComparator, false); } } // Set up navigation ToolSession session = SessionManager.getCurrentToolSession(); session.setAttribute("breadcrumbPage", "overview"); session.removeAttribute("adding"); session.removeAttribute("editing"); session.removeAttribute("middle"); }
public void testCreateExternalAssessmentWithCategory() throws Exception { String categoryName = "My favorite category"; Long gbId = gradebookManager.getGradebook(GRADEBOOK_UID).getId(); Long catId = gradebookManager.createCategory(gbId, categoryName, new Double(0), 0, 0, 0, false); Assert.assertTrue(gradebookFrameworkService.isGradebookDefined(GRADEBOOK_UID)); // Make sure the service knows that the external id has not been defined Assert.assertFalse( gradebookExternalAssessmentService.isExternalAssignmentDefined(GRADEBOOK_UID, EXT_ID_1)); gradebookExternalAssessmentService.addExternalAssessment( GRADEBOOK_UID, EXT_ID_1, null, EXT_TITLE_1, new Double(10), new Date(), "Samigo", new Boolean(false), catId); // Make sure the service knows that the external id has been defined Assert.assertTrue( gradebookExternalAssessmentService.isExternalAssignmentDefined(GRADEBOOK_UID, EXT_ID_1)); // let's retrieve the assignment and double check the category setting // due to security in GradebookService, we need to retrieve all assign and then iterate through // to find this one List<Assignment> allAssigns = gradebookManager.getAssignments(gbId); boolean assignFound = false; for (Assignment assign : allAssigns) { if (assign.isExternallyMaintained() && EXT_ID_1.equals(assign.getExternalId())) { assignFound = true; // double check the category if (assign.getCategory() == null || !catId.equals(assign.getCategory().getId())) { fail("Category was not saved via addExternalAssessment"); } } } if (!assignFound) { fail("Could not retrieve newly added external assignment"); } // double check that leaving category null leaves category unassigned String externalId2 = "external ID 2"; String externalTitle = "Another externally maintained one"; gradebookExternalAssessmentService.addExternalAssessment( GRADEBOOK_UID, externalId2, null, externalTitle, new Double(10), new Date(), "Samigo", new Boolean(false), null); // Make sure the service knows that the external id has been defined Assert.assertTrue( gradebookExternalAssessmentService.isExternalAssignmentDefined(GRADEBOOK_UID, externalId2)); // let's retrieve the assignment and double check the category setting // due to security in GradebookService, we need to retrieve all assign and then iterate through // to find this one allAssigns = gradebookManager.getAssignments(gbId); assignFound = false; for (Assignment assign : allAssigns) { if (assign.isExternallyMaintained() && externalId2.equals(assign.getExternalId())) { assignFound = true; // double check the category if (assign.getCategory() != null) { fail("Category should be null for external assignment added via addExternalAssessment"); } } } if (!assignFound) { fail("Could not retrieve newly added external assignment without a category"); } // Make sure that internal name conflicts are detected try { gradebookExternalAssessmentService.addExternalAssessment( GRADEBOOK_UID, "A unique external id", null, ASN_1, new Double(10), new Date(), "Samigo", new Boolean(false), catId); fail(); } catch (ConflictingAssignmentNameException e) { } // Make sure that external name conflicts are detected try { gradebookExternalAssessmentService.addExternalAssessment( GRADEBOOK_UID, "Another unique external id", null, EXT_TITLE_1, new Double(10), new Date(), "Samigo", new Boolean(false), catId); fail(); } catch (ConflictingAssignmentNameException e) { } // Make sure that external id conflicts are detected try { gradebookExternalAssessmentService.addExternalAssessment( GRADEBOOK_UID, EXT_ID_1, null, "A unique title", new Double(10), new Date(), "Samigo", new Boolean(false), catId); fail(); } catch (ConflictingExternalIdException e) { } // Test a floating value. double floatingPoints = 10.66666; String floatingExtId = "Just another external ID"; gradebookExternalAssessmentService.addExternalAssessment( GRADEBOOK_UID, floatingExtId, null, "AFractionalAssessment", new Double(floatingPoints), new Date(), "Samigo", new Boolean(false), catId); // Find the assessment and ensure that it has been updated Assignment asn = null; List assignments = gradebookManager.getAssignments(gbId); for (Iterator iter = assignments.iterator(); iter.hasNext(); ) { Assignment tmp = (Assignment) iter.next(); if (tmp.getExternalId() != null && tmp.getExternalId().equals(floatingExtId)) { asn = tmp; break; } } Assert.assertEquals(asn.getPointsPossible(), new Double(floatingPoints)); }