@Override public int getGradeEntryType(final String gradebookUid) { if (gradebookUid == null) { throw new IllegalArgumentException("null gradebookUid passed to getGradeEntryType"); } try { final Gradebook gradebook = getGradebook(gradebookUid); return gradebook.getGrade_type(); } catch (final GradebookNotFoundException gnfe) { throw new GradebookNotFoundException("No gradebook exists with the given gradebookUid: " + gradebookUid); } }
public void updateGradebook(final Gradebook gradebook) throws StaleObjectModificationException { HibernateCallback hc = session -> { // Get the gradebook and selected mapping from persistence Gradebook gradebookFromPersistence = (Gradebook)session.load(gradebook.getClass(), gradebook.getId()); GradeMapping mappingFromPersistence = gradebookFromPersistence.getSelectedGradeMapping(); // If the mapping has changed, and there are explicitly entered // course grade records, disallow this update. if (!mappingFromPersistence.getId().equals(gradebook.getSelectedGradeMapping().getId())) { if(isExplicitlyEnteredCourseGradeRecords(gradebook.getId())) { throw new IllegalStateException("Selected grade mapping can not be changed, since explicit course grades exist."); } } // Evict the persisted objects from the session and update the gradebook // so the new grade mapping is used in the sort column update //session.evict(mappingFromPersistence); for(Iterator iter = gradebookFromPersistence.getGradeMappings().iterator(); iter.hasNext();) { session.evict(iter.next()); } session.evict(gradebookFromPersistence); try { session.update(gradebook); session.flush(); } catch (StaleObjectStateException e) { throw new StaleObjectModificationException(e); } return null; }; getHibernateTemplate().execute(hc); }
@Override public boolean equals(Object other) { if (!(other instanceof Gradebook)) { return false; } Gradebook gb = (Gradebook)other; return new EqualsBuilder(). append(uid, gb.getUid()).isEquals(); }
Gradebook gradebook = new Gradebook(name); gradebook.setUid(uid); session.save(gradebook); gradebook.setAssignmentsDisplayed(propAssignmentsDisplayed); gradebook.setCourseGradeDisplayed(propCourseGradeDisplayed); gradebook.setCoursePointsDisplayed(propCoursePointsDisplayed); if (log.isWarnEnabled()) log.warn("No default GradeMapping found for new Gradebook=" + gradebook.getUid() + "; will set default to " + defaultGradeMapping.getName()); gradebook.setSelectedGradeMapping(defaultGradeMapping); gradebook.setGradeMappings(gradeMappings); gradebook.setGrade_type(GradebookService.GRADE_TYPE_POINTS); gradebook.setCategory_type(GradebookService.CATEGORY_TYPE_NO_CATEGORY); gradebook.setCourseLetterGradeDisplayed(true); gradebook.setCourseAverageDisplayed(true);
rval.setGradeMappings(getGradebookGradeMappings(gradebook.getGradeMappings())); final GradeMapping selectedGradeMapping = gradebook.getSelectedGradeMapping(); if (selectedGradeMapping != null) { rval.setGradeType(gradebook.getGrade_type()); rval.setCategoryType(gradebook.getCategory_type()); rval.setDisplayReleasedGradeItemsToStudents(gradebook.isAssignmentsDisplayed()); rval.setCourseGradeDisplayed(gradebook.isCourseGradeDisplayed()); rval.setCourseLetterGradeDisplayed(gradebook.isCourseLetterGradeDisplayed()); rval.setCoursePointsDisplayed(gradebook.isCoursePointsDisplayed()); rval.setCourseAverageDisplayed(gradebook.isCourseAverageDisplayed());
final Set<GradeMapping> gradeMappings = gradebook.getGradeMappings(); gradeMappings.forEach(gradeMapping -> { if(StringUtils.equals(Long.toString(gradeMapping.getId()), gbInfo.getSelectedGradeMappingId())) { gradebook.setSelectedGradeMapping(gradeMapping); gradebook.setGrade_type(gbInfo.getGradeType()); gradebook.setCategory_type(gbInfo.getCategoryType()); gradebook.setAssignmentsDisplayed(gbInfo.isDisplayReleasedGradeItemsToStudents()); gradebook.setCourseGradeDisplayed(gbInfo.isCourseGradeDisplayed()); gradebook.setCourseLetterGradeDisplayed(gbInfo.isCourseLetterGradeDisplayed()); gradebook.setCoursePointsDisplayed(gbInfo.isCoursePointsDisplayed()); gradebook.setCourseAverageDisplayed(gbInfo.isCourseAverageDisplayed()); if(gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY) { double totalWeight = 0; for(final CategoryDefinition newDef: newCategoryDefinitions) { final List<Category> currentCategories = getCategories(gradebook.getId()); final Map<Long,Category> currentCategoryMap = new HashMap<>(); for(final Category c: currentCategories) { this.createCategory(gradebook.getId(), newCat.getName(), newCat.getWeight(), newCat.getDropLowest(), newCat.getDropHighest(), newCat.getKeepHighest(), newCat.isExtraCredit(), entry.getValue()); if(gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY) { excludeUncategorisedItemsFromCourseGradeCalculations(gradebook);
gradebook.setCategory_type(gradebookInformation.getCategoryType()); gradebook.setGrade_type(gradebookInformation.getGradeType()); categoryId = createCategory(gradebook.getId(), c.getName(), a.getWeight(), 0, 0, 0, a.isCategoryExtraCredit()); } catch (final ConflictingCategoryNameException e) { final List<CategoryDefinition> existingCategories = getCategoryDefinitions(gradebook.getUid()); categoryId = existingCategories.stream().filter(e -> StringUtils.equals(e.getName(), c.getName())).findFirst().get().getId(); createAssignmentForCategory(gradebook.getId(), categoriesCreated.get(c.getName()), a.getName(), a.getPoints(), a.getDueDate(), true, false, a.isExtraCredit()); } catch (final ConflictingAssignmentNameException e) { categories.forEach(c -> { try { createCategory(gradebook.getId(), c.getName(), c.getWeight(), c.getDropLowest(), c.getDropHighest(), c.getKeepHighest(), c.isExtraCredit()); } catch (final ConflictingCategoryNameException e) { assignments.forEach(a -> { try { createAssignment(gradebook.getId(), a.getName(), a.getPoints(), a.getDueDate(), true, false, a.isExtraCredit()); } catch (final ConflictingAssignmentNameException e) { for (final GradeMapping gradeMapping : gradebook.getGradeMappings()) { if (gradeMapping.getGradingScale().getUid().equals(fromGradingScaleUid)) { gradebook.setSelectedGradeMapping(gradeMapping); updateGradebook(gradebook); log.info("Merge to gradebook {} updated grade mapping", toGradebookUid);
@Override public String getGradebookDefinitionXml(final String gradebookUid) { final Long gradebookId = getGradebook(gradebookUid).getId(); final Gradebook gradebook = getGradebook(gradebookUid); final GradebookDefinition gradebookDefinition = new GradebookDefinition(); final GradeMapping selectedGradeMapping = gradebook.getSelectedGradeMapping(); gradebookDefinition.setSelectedGradingScaleUid(selectedGradeMapping.getGradingScale().getUid()); gradebookDefinition.setSelectedGradingScaleBottomPercents(new HashMap<>(selectedGradeMapping.getGradeMap())); gradebookDefinition.setAssignments(getAssignments(gradebookUid)); gradebookDefinition.setGradeType(gradebook.getGrade_type()); gradebookDefinition.setCategoryType(gradebook.getCategory_type()); gradebookDefinition.setCategory(getCategories(gradebookId)); return VersionedExternalizable.toXml(gradebookDefinition); }
final Gradebook gradebook = gbItem.getGradebook(); if (!this.authz.isUserAbleToGrade(gradebook.getUid())) { log.error("User {} attempted to access grade information without permission in gb {} using gradebookService.getGradesForStudentsForItem", this.authn.getUserUid(), gradebook.getUid()); throw new GradebookSecurityException(); final Map enrRecFunctionMap = this.authz.findMatchingEnrollmentsForItem(gradebook.getUid(), categoryId, gradebook.getCategory_type(), null, null); final Set enrRecs = enrRecFunctionMap.keySet(); final Map studentIdEnrRecMap = new HashMap(); final List<AssignmentGradeRecord> gradeRecs = getAllAssignmentGradeRecordsForGbItem(gradableObjectId, studentIds); if (gradeRecs != null) { if (gradebook.getGrade_type() == GradebookService.GRADE_TYPE_LETTER) { convertPointsToLetterGrade(gradebook, gradeRecs); } else if (gradebook.getGrade_type() == GradebookService.GRADE_TYPE_PERCENTAGE) { convertPointsToPercentage(gradebook, gradeRecs);
final Gradebook thisGradebook = getGradebook(gradebookUid); final Long gradebookId = thisGradebook.getId(); final CourseGrade courseGrade = getCourseGrade(gradebookId); .findMatchingEnrollmentsForViewableCourseGrade(gradebookUid, thisGradebook.getCategory_type(), null, null); enrollmentMap = new HashMap();
final List assignList = getAssignmentsCounted(thisGradebook.getId()); boolean nonAssignment = false; if (assignList == null || assignList.size() < 1) { final Long gradebookId = thisGradebook.getId(); final CourseGrade courseGrade = getCourseGrade(gradebookId); thisGradebook.getCategory_type(), null, null); final Map<String, EnrollmentRecord> enrollmentMap = new HashMap<>(); final CourseGradeRecord gradeRecord = (CourseGradeRecord) iter.next(); final GradeMapping gradeMap = thisGradebook.getSelectedGradeMapping();
gradeDef.setGraderUid(gradeRecord.getGraderId()); gradeDef.setDateRecorded(gradeRecord.getDateRecorded()); final int gradeEntryType = gradebook.getGrade_type(); gradeDef.setGradeEntryType(gradeEntryType); String grade = null; gradeDef.setGradeReleased(gradebook.isAssignmentsDisplayed() && gbo.isReleased());
protected void finalizeNullGradeRecords(final Gradebook gradebook) { final Set<String> studentUids = getAllStudentUids(gradebook.getUid()); final Date now = new Date(); final String graderId = getAuthn().getUserUid(); final List<GradebookAssignment> countedAssignments = session .createQuery("from GradebookAssignment as asn where asn.gradebook.id = :gb and asn.removed is false and asn.notCounted is false and asn.ungraded is false") .setLong("gb", gradebook.getId()) .list();
final Map<String, Double> gradingSchema = gb.getSelectedGradeMapping().getGradeMap(); if (gb.getGrade_type() == GradebookService.GRADE_TYPE_PERCENTAGE) { grade = calculateEquivalentPointValueForPercent(pointsPossible, NumberUtils.createDouble(rawGrade)); } else if (gb.getGrade_type() == GradebookService.GRADE_TYPE_LETTER) { grade = gradingSchema.get(rawGrade); } else {
@SuppressWarnings({ "rawtypes", "unchecked" }) private List getTotalPointsEarnedInternal(final String studentId, final Gradebook gradebook, final List categories, final List<AssignmentGradeRecord> gradeRecs, final List<GradebookAssignment> countedAssigns) { final int gbGradeType = gradebook.getGrade_type(); if (gbGradeType != GradebookService.GRADE_TYPE_POINTS && gbGradeType != GradebookService.GRADE_TYPE_PERCENTAGE) { if (log.isErrorEnabled()) { if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_NO_CATEGORY) { if (!excused) { totalPointsEarned += pointsEarned; } else if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_ONLY_CATEGORY && go != null) { if (!excused) { totalPointsEarned += pointsEarned; } else if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY && go != null && categories != null) { for (int i = 0; i < categories.size(); i++) { if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY && categories != null) { final Iterator assgnsIter = countedAssigns.iterator(); while (assgnsIter.hasNext()) { if (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY) { for (int i = 0; i < categories.size(); i++) { final Category cate = (Category) categories.get(i);
public Map getAvailableItemsForStudent(String gradebookUid, String userId, String studentId, Collection courseSections) throws IllegalArgumentException { if(gradebookUid == null || userId == null || studentId == null) throw new IllegalArgumentException("Null parameter(s) in GradebookPermissionServiceImpl.getAvailableItemsForStudent"); Long gradebookId = getGradebook(gradebookUid).getId(); return getAvailableItemsForStudent(gradebookId, userId, studentId, courseSections); }
if(gradebook != null && (gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_ONLY_CATEGORY || gradebook.getCategory_type() == GradebookService.CATEGORY_TYPE_WEIGHTED_CATEGORY))
final Gradebook gradebook = getGradebook(gradebookUid); if (gradebook != null) { final CourseGrade courseGrade = getCourseGrade(gradebook.getId()); final Set<String> studentUids = getAllStudentUids(gradebookUid); courseGradeLetter = gradebook.getSelectedGradeMapping().getMappedGrade(courseGrade.getMean());
.setLong("gradebookid", gradebook.getId()) .list()); createAssignment(gradebook.getId(), assignmentDef.getName(), assignmentDef.getPoints(), assignmentDef.getDueDate(), true, false, assignmentDef.isExtraCredit()); assignmentsAddedCount++; for (final GradeMapping gradeMapping : gradebook.getGradeMappings()) { if (gradeMapping.getGradingScale().getUid().equals(fromGradingScaleUid)) { gradeMapping.getGradeMap().put(gradeCode, inputGradePercents.get(gradeCode)); gradebook.setSelectedGradeMapping(gradeMapping); updateGradebook(gradebook); if (log.isInfoEnabled()) {
@Override public Map<String, org.sakaiproject.service.gradebook.shared.CourseGrade> getCourseGradeForStudents(final String gradebookUid, final List<String> userUuids) { final Map<String, org.sakaiproject.service.gradebook.shared.CourseGrade> rval = new HashMap<>(); try { final Gradebook gradebook = getGradebook(gradebookUid); final GradeMapping gradeMap = gradebook.getSelectedGradeMapping(); rval.putAll(this.getCourseGradeForStudents(gradebookUid, userUuids, gradeMap.getGradeMap())); } catch (final Exception e) { log.error("Error in getCourseGradeForStudents", e); } return rval; }