Skip to content

Commit

Permalink
GradingService modifications especially around GradeType constants
Browse files Browse the repository at this point in the history
  • Loading branch information
ottenhoff committed Apr 18, 2024
1 parent 5f0d7e0 commit bcaec88
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 170 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sakaiproject.certification</groupId>
<artifactId>certification-base</artifactId>
<version>23-SNAPSHOT</version>
<version>25-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.sakaiproject.certification.api;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* Thrown when creating a certificate definition, but some constraint isn't met
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class InvalidCertificateDefinitionException extends CertificationException {

public static final int REASON_TOO_LONG = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package org.sakaiproject.certification.api.criteria.gradebook;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class CertAssignment extends CertGradebookObject
{
private double pointsPossible;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import java.util.Date;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class CertAssignmentScore extends CertGradeRecordObject
{
Expand Down
2 changes: 1 addition & 1 deletion impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sakaiproject.certification</groupId>
<artifactId>certification-base</artifactId>
<version>23-SNAPSHOT</version>
<version>25-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.sakaiproject.certification.api.criteria.CriteriaTemplateVariable;
import org.sakaiproject.certification.api.criteria.Criterion;
import org.sakaiproject.certification.api.criteria.gradebook.FinalGradeScoreCriterion;
import org.sakaiproject.grading.api.GradingConstants;
import org.sakaiproject.grading.api.GradingService;
import org.sakaiproject.util.ResourceLoader;

Expand All @@ -45,6 +46,11 @@ public class FinalGradeScoreCriteriaTemplate implements CriteriaTemplate {
private final String EXPRESSION_KEY = "final.grade.score.criteria.expression";
private final String VARIABLE_SCORE = "score";

// TODO: Once these are correct in GradingConstants, delete these
public static final int CATEGORY_TYPE_NO_CATEGORY = 1;
public static final int CATEGORY_TYPE_ONLY_CATEGORY = 2;
public static final int CATEGORY_TYPE_WEIGHTED_CATEGORY = 3;

public FinalGradeScoreCriteriaTemplate(final GradebookCriteriaFactory factory) {
this.factory = factory;
gradingService = factory.getGradingService();
Expand Down Expand Up @@ -104,7 +110,7 @@ public String getExpression (Criterion criterion) {

try {
categoryType = (Integer) factory.doSecureGradebookAction(typeCallback);
if(categoryType == GradingService.CATEGORY_TYPE_ONLY_CATEGORY) {
if(categoryType == CATEGORY_TYPE_ONLY_CATEGORY) {
assnPoints = (Map<Long, Double>)factory.doSecureGradebookAction(catOnlyAssnPointsCallback);
} else {
assnPoints = (Map<Long, Double>)factory.doSecureGradebookAction(assnPointsCallback);
Expand All @@ -116,9 +122,9 @@ public String getExpression (Criterion criterion) {

double total = 0;
switch(categoryType) {
case GradingService.CATEGORY_TYPE_NO_CATEGORY:
case GradingService.CATEGORY_TYPE_WEIGHTED_CATEGORY:
case GradingService.CATEGORY_TYPE_ONLY_CATEGORY: {
case CATEGORY_TYPE_NO_CATEGORY:
case CATEGORY_TYPE_WEIGHTED_CATEGORY:
case CATEGORY_TYPE_ONLY_CATEGORY: {
for (Double points : assnPoints.values()) {
total += points;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -60,11 +61,23 @@
@Slf4j
public class GradebookCriteriaFactory implements CriteriaFactory {

private CertificateService certService = null;
@Getter
@Setter
private CertificateService certificateService = null;
@Getter
@Setter
private GradingService gradingService = null;
@Getter
@Setter
private ToolManager toolManager = null;
@Getter
@Setter
private UserDirectoryService userDirectoryService = null;
@Getter
@Setter
private SecurityService securityService = null;
@Getter
@Setter
private SessionManager sessionManager = null;

private final HashMap<String, CriteriaTemplate> criteriaTemplates = new HashMap<>();
Expand All @@ -82,6 +95,8 @@ public class GradebookCriteriaFactory implements CriteriaFactory {
private final Map<Long, Map<String, Double>> itemToUserToGradeMap = new HashMap<>();
private final Map<Long, Map<String, Date>> itemToUserToDateRecordedMap = new HashMap<>();

@Setter
@Getter
private ResourceLoader resourceLoader = null;

private static final String PERM_VIEW_OWN_GRADES = "gradebook.viewOwnGrades";
Expand All @@ -101,6 +116,11 @@ public class GradebookCriteriaFactory implements CriteriaFactory {
private static final String SCORE_REQUIREMENTS = "gradebookItem.requirements";
private static final String COURSE_GRADE_REQUIREMENTS = "courseGrade.requirements";

// TODO: Once these are correct in GradingConstants, delete these
public static final int CATEGORY_TYPE_NO_CATEGORY = 1;;
public static final int CATEGORY_TYPE_ONLY_CATEGORY = 2;
public static final int CATEGORY_TYPE_WEIGHTED_CATEGORY = 3;

public void init() {
gbItemScoreTemplate = new GreaterThanScoreCriteriaTemplate(this);
gbItemScoreTemplate.setResourceLoader(resourceLoader);
Expand All @@ -124,67 +144,11 @@ public void init() {
criterionClasses.add(FinalGradeScoreCriterion.class);
criterionClasses.add(WillExpireCriterion.class);

if (certService != null) {
certService.registerCriteriaFactory(this);
if (certificateService != null) {
certificateService.registerCriteriaFactory(this);
}
}

public CertificateService getCertificateService() {
return certService;
}

public void setCertificateService(CertificateService certService) {
this.certService = certService;
}

public void setGradingService(GradingService gradingService) {
this.gradingService = gradingService;
}

public GradingService getGradingService() {
return gradingService;
}

public void setToolManager(ToolManager tm) {
toolManager = tm;
}

public ToolManager getToolManager() {
return toolManager;
}

public void setUserDirectoryService(UserDirectoryService uds) {
userDirectoryService = uds;
}

public UserDirectoryService getUserDirectoryService() {
return userDirectoryService;
}

public ResourceLoader getResourceLoader() {
return resourceLoader;
}

public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}

public SecurityService getSecurityService() {
return securityService;
}

public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}

public SessionManager getSessionManager() {
return sessionManager;
}

public void setSessionManager(SessionManager sessionManager) {
this.sessionManager = sessionManager;
}

protected final String contextId() {
return getToolManager().getCurrentPlacement().getContext();
}
Expand All @@ -194,9 +158,7 @@ protected final String userId() {
}

public Set<CriteriaTemplate> getCriteriaTemplates() {
HashSet<CriteriaTemplate> values = new HashSet<>();
values.addAll(criteriaTemplates.values());
return values;
return new HashSet<>(criteriaTemplates.values());
}

public CriteriaTemplate getCriteriaTemplate(Criterion criterion) throws UnknownCriterionTypeException {
Expand Down Expand Up @@ -253,7 +215,7 @@ public SecurityAdvice isAllowed(String userId, String function, String reference
securityService.pushAdvisor(yesMan);
return callback.doSecureAction();
} finally {
securityService.popAdvisor();
securityService.popAdvisor(yesMan);
}
}

Expand Down Expand Up @@ -350,23 +312,23 @@ public Object doSecureAction() {
//ignore category weights
// TODO: drop all of this custom processing and use the GradingService!

Map<Long,Double> catWeights = certService.getCategoryWeights(contextId);
Map<Long,Double> assgnScores = certService.getAssignmentScores(contextId, userId);
Map<Long,Double> catWeights = certificateService.getCategoryWeights(contextId);
Map<Long,Double> assgnScores = certificateService.getAssignmentScores(contextId, userId);

double studentTotalScore = 0;
int categoryType = certService.getCategoryType(contextId);
int categoryType = certificateService.getCategoryType(contextId);

switch(categoryType) {
case GradingService.CATEGORY_TYPE_NO_CATEGORY: {
case CATEGORY_TYPE_NO_CATEGORY: {
for(Map.Entry<Long, Double> assgnScore : assgnScores.entrySet()) {
Double score = assgnScore.getValue();
studentTotalScore += score == null ? 0:score;
}

break;
}
case GradingService.CATEGORY_TYPE_WEIGHTED_CATEGORY:
case GradingService.CATEGORY_TYPE_ONLY_CATEGORY: {
case CATEGORY_TYPE_WEIGHTED_CATEGORY:
case CATEGORY_TYPE_ONLY_CATEGORY: {
for(Map.Entry<Long, Double> assgnScore : assgnScores.entrySet()) {
if(catWeights.containsKey(assgnScore.getKey())) {
Double score = assgnScore.getValue();
Expand Down Expand Up @@ -578,23 +540,23 @@ public Criterion createCriterion(CriteriaTemplate template, Map<String, String>
criterion.setCriteriaFactory(this);
String scoreStr = FormatHelper.inputStringToFormatString(bindings.get(KEY_SCORE));

Map<Long,Double> catWeights = certService.getCategoryWeights(contextId);
Map<Long,Double> assgnPoints = certService.getAssignmentPoints(contextId);
Map<Long,Double> catWeights = certificateService.getCategoryWeights(contextId);
Map<Long,Double> assgnPoints = certificateService.getAssignmentPoints(contextId);

double totalAvailable = 0;

int categoryType = certService.getCategoryType(contextId);
int categoryType = certificateService.getCategoryType(contextId);

switch(categoryType) {
case GradingService.CATEGORY_TYPE_NO_CATEGORY: {
case CATEGORY_TYPE_NO_CATEGORY: {
for(Map.Entry<Long, Double> assgnPoint : assgnPoints.entrySet()) {
Double point = assgnPoint.getValue();
totalAvailable += point == null ? 0:point;
}
break;
}
case GradingService.CATEGORY_TYPE_WEIGHTED_CATEGORY:
case GradingService.CATEGORY_TYPE_ONLY_CATEGORY: {
case CATEGORY_TYPE_WEIGHTED_CATEGORY:
case CATEGORY_TYPE_ONLY_CATEGORY: {
for(Map.Entry<Long, Double> assgnPoint : assgnPoints.entrySet()) {
if(catWeights.containsKey(assgnPoint.getKey())) {
Double point = assgnPoint.getValue();
Expand Down Expand Up @@ -788,13 +750,13 @@ public Date getFinalGradeDateRecorded(final String userId,final String contextId
return (Date) doSecureGradebookAction(new SecureGradebookActionCallback() {
public Object doSecureAction() {
//Just following the getFinalScore code, but ignoring grades and looking at dates
Map<Long,Double> catWeights = certService.getCategoryWeights(contextId);
Map<Long,Date> assgnDates = certService.getAssignmentDatesRecorded(contextId, userId);
Map<Long,Double> catWeights = certificateService.getCategoryWeights(contextId);
Map<Long,Date> assgnDates = certificateService.getAssignmentDatesRecorded(contextId, userId);
Date lastDate = null;
int categoryType = certService.getCategoryType(contextId);
int categoryType = certificateService.getCategoryType(contextId);

switch(categoryType) {
case GradingService.CATEGORY_TYPE_NO_CATEGORY: {
case CATEGORY_TYPE_NO_CATEGORY: {
for(Map.Entry<Long, Date> assgnDate : assgnDates.entrySet()) {
if (lastDate==null) {
lastDate = assgnDate.getValue();
Expand All @@ -807,8 +769,8 @@ public Object doSecureAction() {

break;
}
case GradingService.CATEGORY_TYPE_ONLY_CATEGORY:
case GradingService.CATEGORY_TYPE_WEIGHTED_CATEGORY: {
case CATEGORY_TYPE_ONLY_CATEGORY:
case CATEGORY_TYPE_WEIGHTED_CATEGORY: {
for(Map.Entry<Long, Date> assgnDate : assgnDates.entrySet()) {
if(catWeights.containsKey(assgnDate.getKey())) {
if (lastDate==null) {
Expand Down Expand Up @@ -840,9 +802,7 @@ public Date getDateIssued(final String userId, final String contextId, Certifica
//The last date in chronological order will be selected
Date lastDate = null;

Iterator<Criterion> itCriteria = criteria.iterator();
while (itCriteria.hasNext()) {
Criterion crit = itCriteria.next();
for (Criterion crit : criteria) {
try {
if (!isCriterionMet(crit, userId, contextId, useCaching)) {
return null;
Expand Down Expand Up @@ -981,7 +941,7 @@ private Map<String, Map<Criterion, UserProgress>> getFinalGradeScoreProgressForU
UserProgress progress = new UserProgress(userId, criterion, strScore, score >= reqScore, dateRecorded);

// add progress to the user's map of criteria to UserProgress (creates an empty map for the user if it doesn't exist)
Map critProgressMap = getCritProgressMapForUser(userCritProgress, userId);
Map<Criterion, UserProgress> critProgressMap = getCritProgressMapForUser(userCritProgress, userId);
critProgressMap.put(criterion, progress);
}
}
Expand Down
Loading

0 comments on commit bcaec88

Please sign in to comment.