73
73
import org .sakaiproject .entity .api .ResourceProperties ;
74
74
import org .sakaiproject .event .cover .UsageSessionService ;
75
75
import org .sakaiproject .exception .IdUnusedException ;
76
+ import org .sakaiproject .exception .PermissionException ;
76
77
import org .sakaiproject .grading .api .model .Gradebook ;
77
78
import org .sakaiproject .linktool .LinkToolUtil ;
78
79
import org .sakaiproject .lti .api .LTIService ;
@@ -633,7 +634,8 @@ public static String getCurrentUserSakaiRole(User user, String context) {
633
634
}
634
635
if (StringUtils .isNotBlank (sakaiRole )) return sakaiRole ;
635
636
} catch (GroupNotDefinedException e ) {
636
- log .error ("site realm not found {}" , e .getMessage ());
637
+ log .error ("site realm not found {}" , e .toString ());
638
+ log .debug ("Stacktrace:" , e );
637
639
}
638
640
return null ;
639
641
}
@@ -834,6 +836,7 @@ public static boolean sakaiInfo(Properties props, String context, String placeme
834
836
site = SiteService .getSite (context );
835
837
} catch (IdUnusedException e ) {
836
838
log .error ("No site/page associated with Launch context={}" , context );
839
+ log .debug ("Stacktrace:" , e );
837
840
return false ;
838
841
}
839
842
@@ -1165,6 +1168,7 @@ public static String[] postLaunchHTML(Map<String, Object> content, Map<String, O
1165
1168
site = SiteService .getSite (context );
1166
1169
} catch (IdUnusedException e ) {
1167
1170
log .error ("No site/page associated with Launch context={}" , context );
1171
+ log .debug ("Stacktrace:" , e );
1168
1172
return postError ("<p>" + getRB (rb , "error.site.missing" , "Cannot load site." ) + context + "</p>" );
1169
1173
}
1170
1174
@@ -1421,9 +1425,10 @@ public static Key getPublicKey(Map<String, Object> tool, String id_token)
1421
1425
try {
1422
1426
publicKey = LTI13KeySetUtil .getKeyFromKeySet (incoming_kid , tool_keyset );
1423
1427
} catch (Exception e ) {
1424
- log .error (e .getMessage (), e );
1428
+ log .error (e .toString (), e );
1429
+ log .debug ("Stacktrace:" , e );
1425
1430
// Sorry - too many exceptions to explain here - lets keep it simple after logging it
1426
- throw new RuntimeException ("Unable to retrieve kid=" +incoming_kid +" from " +tool_keyset +" detail=" +e .getMessage ());
1431
+ throw new RuntimeException ("Unable to retrieve kid=" +incoming_kid +" from " +tool_keyset +" detail=" +e .toString ());
1427
1432
}
1428
1433
// TODO: Store in Earle's super-cluster-cache one day - SAK-43700
1429
1434
@@ -1565,6 +1570,7 @@ public static String[] postContentItemSelectionRequest(Long toolKey, Map<String,
1565
1570
site = SiteService .getSite (context );
1566
1571
} catch (IdUnusedException e ) {
1567
1572
log .error ("No site/page associated with Launch context={}" , context );
1573
+ log .debug ("Stacktrace:" , e );
1568
1574
return postError ("<p>" + getRB (rb , "error.site.missing" , "Cannot load site." ) + context + "</p>" );
1569
1575
}
1570
1576
@@ -1919,7 +1925,7 @@ public static String[] postLaunchJWT(Properties toolProps, Properties ltiProps,
1919
1925
lj .email = ltiProps .getProperty (LTIConstants .LIS_PERSON_CONTACT_EMAIL_PRIMARY );
1920
1926
1921
1927
lj .nonce = toolProps .getProperty ("nonce" );
1922
- lj .issued = new Long (System .currentTimeMillis () / 1000L );
1928
+ lj .issued = Long . valueOf (System .currentTimeMillis () / 1000L );
1923
1929
lj .expires = lj .issued + 3600L ;
1924
1930
lj .deployment_id = getDeploymentId (context_id );
1925
1931
@@ -2356,7 +2362,8 @@ private static String getExternalRealmId(String siteId) {
2356
2362
AuthzGroup realm = ComponentManager .get (AuthzGroupService .class ).getAuthzGroup (realmId );
2357
2363
rv = realm .getProviderGroupId ();
2358
2364
} catch (GroupNotDefinedException e ) {
2359
- log .error ("SiteParticipantHelper.getExternalRealmId: site realm not found {}" , e .getMessage ());
2365
+ log .error ("SiteParticipantHelper.getExternalRealmId: site realm not found {}" , e .toString ());
2366
+ log .debug ("Stacktrace:" , e );
2360
2367
}
2361
2368
return rv ;
2362
2369
} // getExternalRealmId
@@ -2519,7 +2526,7 @@ private static Object handleGradebook(String sourcedid, HttpServletRequest reque
2519
2526
2520
2527
// If we are not supposed to lookup or set the grade, we are done
2521
2528
if (isRead == false && isDelete == false && scoreGiven == null ) {
2522
- return new Boolean (matched );
2529
+ return Boolean . valueOf (matched );
2523
2530
}
2524
2531
2525
2532
// Look up the gradebook column so we can find the max points
@@ -2592,7 +2599,7 @@ private static Object handleGradebook(String sourcedid, HttpServletRequest reque
2592
2599
String actualGrade = gradingService .getAssignmentScoreString (gradebookUid , siteId , gradebookColumn .getId (), user_id );
2593
2600
Double dGrade = null ;
2594
2601
if (StringUtils .isNotBlank (actualGrade )) {
2595
- dGrade = new Double (actualGrade );
2602
+ dGrade = Double . valueOf (actualGrade );
2596
2603
dGrade = dGrade / gradebookColumn .getPoints ();
2597
2604
}
2598
2605
CommentDefinition commentDef = gradingService .getAssignmentScoreComment (gradebookUid , gradebookColumn .getId (), user_id );
@@ -2622,7 +2629,7 @@ private static Object handleGradebook(String sourcedid, HttpServletRequest reque
2622
2629
retval = Boolean .TRUE ;
2623
2630
}
2624
2631
} catch (Exception e ) {
2625
- retval = "Grade failure " + e .getMessage () + " siteId=" + siteId ;
2632
+ retval = "Grade failure " + e .toString () + " siteId=" + siteId ;
2626
2633
log .warn ("handleGradebook Grade failure in site: {}, error: {}" , siteId , e );
2627
2634
} finally {
2628
2635
sess .invalidate (); // Make sure to leave no traces
@@ -2642,6 +2649,8 @@ public static Object handleGradebookLTI13(Site site, Long tool_id, Map<String,
2642
2649
Object retval ;
2643
2650
String title ;
2644
2651
2652
+ log .debug ("siteid: {} tool_id: {} lineitem_key: {} userId: {} scoreObj: {}" , site .getId (), tool_id , lineitem_key , userId , scoreObj );
2653
+
2645
2654
// An empty / null score given means to delete the score
2646
2655
SakaiLineItem lineItem = new SakaiLineItem ();
2647
2656
String siteId = site .getId ();
@@ -2668,6 +2677,29 @@ public static Object handleGradebookLTI13(Site site, Long tool_id, Map<String,
2668
2677
log .error ("Could not determine assignment_name title {}" , content .get (LTIService .LTI_ID ));
2669
2678
return "Unable to load column for lineitem_key=" +lineitem_key ;
2670
2679
}
2680
+
2681
+ // Check if this is a gradebook column that is owned by assignments
2682
+ String external_id = gradebookColumn .getExternalId ();
2683
+ log .debug ("external_id: {} {}" , external_id );
2684
+ if ( external_id != null && LineItemUtil .isAssignmentColumn (external_id ) ) {
2685
+ org .sakaiproject .assignment .api .AssignmentService assignmentService = ComponentManager .get (org .sakaiproject .assignment .api .AssignmentService .class );
2686
+ org .sakaiproject .assignment .api .model .Assignment assignment ;
2687
+ try {
2688
+ org .sakaiproject .assignment .api .AssignmentReferenceReckoner .AssignmentReference assignmentReference = org .sakaiproject .assignment .api .AssignmentReferenceReckoner .reckoner ().reference (external_id ).reckon ();
2689
+ log .debug ("assignmentReference.id {}" , assignmentReference .getId ());
2690
+ assignment = assignmentService .getAssignment (assignmentReference .getId ());
2691
+ } catch (Exception e ) {
2692
+ assignment = null ;
2693
+ log .error ("Unexpected error getting assignment: {}" , e .toString ());
2694
+ log .debug ("Stacktrace:" , e );
2695
+ }
2696
+
2697
+ if ( assignment != null ) {
2698
+ log .debug ("Gradebook column is owned by assignment: {}" , assignment .getId ());
2699
+ retval = handleAssignment (assignment , userId , scoreObj );
2700
+ return retval ;
2701
+ }
2702
+ }
2671
2703
title = gradebookColumn .getName ();
2672
2704
}
2673
2705
@@ -2677,10 +2709,9 @@ public static Object handleGradebookLTI13(Site site, Long tool_id, Map<String,
2677
2709
}
2678
2710
2679
2711
// Send the grades to the gradebook
2680
- Double scoreGiven = scoreObj .scoreGiven ;
2712
+ Double scoreGiven = scoreObj .getScoreGiven () ;
2681
2713
String comment = scoreObj .comment ;
2682
- if ( scoreObj .scoreMaximum == null ) scoreObj .scoreMaximum = lineItem .scoreMaximum != null ? lineItem .scoreMaximum : 100D ;
2683
- Double scoreMaximum = scoreObj .scoreMaximum ;
2714
+ Double scoreMaximum = scoreObj .getScoreMaximum ();
2684
2715
log .debug ("scoreGiven={} scoreMaximum={} userId={} comment={}" , scoreGiven , scoreMaximum , userId , comment );
2685
2716
2686
2717
// Look up the gradebook column so we can find the max points
@@ -2731,7 +2762,7 @@ public static Object handleGradebookLTI13(Site site, Long tool_id, Map<String,
2731
2762
return Boolean .TRUE ;
2732
2763
}
2733
2764
} catch (NumberFormatException | AssessmentNotFoundException e ) {
2734
- retval = "Grade failure " + e .getMessage () + " siteId=" + siteId ;
2765
+ retval = "Grade failure " + e .toString () + " siteId=" + siteId ;
2735
2766
log .warn ("handleGradebook Grade failure in site: {}, error: {}" , siteId , e );
2736
2767
} finally {
2737
2768
sess .invalidate (); // Make sure to leave no traces
@@ -2757,15 +2788,20 @@ public static org.sakaiproject.assignment.api.model.Assignment getAssignment(Sit
2757
2788
return a ;
2758
2789
}
2759
2790
return null ;
2760
- } finally {
2791
+ } catch (Exception e ) {
2792
+ log .error ("Unexpected error getting assignment: {}" , e .toString ());
2793
+ log .debug ("Stacktrace:" , e );
2794
+ } finally {
2761
2795
popAdvisor ();
2762
2796
}
2797
+ return null ;
2763
2798
}
2764
2799
2765
2800
public static Object handleAssignment (org .sakaiproject .assignment .api .model .Assignment a , String userId , Score scoreObj ) {
2766
2801
2767
2802
Integer scaledGrade = null ;
2768
2803
String stringGrade = null ;
2804
+ log .debug ("handleAssignment assignment: {} {} user: {} {}" , a .getId (), a .getTitle (), userId , scoreObj .getScoreGiven ());
2769
2805
2770
2806
// Scale up the score if appropriate
2771
2807
if (scoreObj .scoreGiven != null ) {
@@ -2774,12 +2810,11 @@ public static Object handleAssignment(org.sakaiproject.assignment.api.model.Assi
2774
2810
// Sanity check - don't ever divide by zero
2775
2811
if ( assignmentScale == 0 ) assignmentScale = 1 ;
2776
2812
2777
- Integer incomingScoreGiven = new Double (scoreObj .scoreGiven * assignmentScale ).intValue ();
2778
- Integer incomingScoreMax = new Double (scoreObj .scoreMaximum * assignmentScale ).intValue ();
2813
+ Integer incomingScoreGiven = Double . valueOf (scoreObj .getScoreGiven () * assignmentScale ).intValue ();
2814
+ Integer incomingScoreMax = Double . valueOf (scoreObj .getScoreMaximum () * assignmentScale ).intValue ();
2779
2815
if ( incomingScoreMax == 0 ) incomingScoreMax = assignmentMax ;
2780
2816
if ( incomingScoreMax == 0 ) incomingScoreMax = 100 * assignmentScale ;
2781
2817
2782
-
2783
2818
if ( incomingScoreMax .equals (assignmentMax ) ) {
2784
2819
scaledGrade = incomingScoreGiven ;
2785
2820
} else {
@@ -2794,11 +2829,13 @@ public static Object handleAssignment(org.sakaiproject.assignment.api.model.Assi
2794
2829
2795
2830
String activityProgress = scoreObj .activityProgress != null ? scoreObj .activityProgress : Score .ACTIVITY_COMPLETED ;
2796
2831
String gradingProgress = scoreObj .gradingProgress != null ? scoreObj .gradingProgress : Score .GRADING_FULLYGRADED ;
2832
+ log .debug ("activityProgress: {} gradingProgress: {}" , activityProgress , gradingProgress );
2797
2833
2798
2834
User user ;
2799
2835
try {
2800
2836
user = UserDirectoryService .getUser (userId );
2801
2837
} catch (org .sakaiproject .user .api .UserNotDefinedException e ) {
2838
+ log .debug ("Could not look up user {} {}" , userId , e .toString ());
2802
2839
return "Could not look up user " +userId ;
2803
2840
}
2804
2841
@@ -2808,6 +2845,7 @@ public static Object handleAssignment(org.sakaiproject.assignment.api.model.Assi
2808
2845
if ( submission == null ) {
2809
2846
submission = assignmentService .addSubmission (a .getId (), user .getId ());
2810
2847
}
2848
+ log .debug ("submission: {} {} {}" , scaledGrade , user .getId (), submission );
2811
2849
2812
2850
StringBuilder logEntry = new StringBuilder ();
2813
2851
DateTimeFormatter dtf = DateTimeFormatter .RFC_1123_DATE_TIME
@@ -2867,7 +2905,7 @@ public static Object handleAssignment(org.sakaiproject.assignment.api.model.Assi
2867
2905
2868
2906
try {
2869
2907
assignmentService .updateSubmission (submission );
2870
- log .info ("Submitted submission={} userId={} log={}" , submission .getId (), userId , logEntry .toString ());
2908
+ log .debug ("Submitted submission={} userId={} log={}" , submission .getId (), userId , logEntry .toString ());
2871
2909
} catch (org .sakaiproject .exception .PermissionException e ) {
2872
2910
log .warn ("Could not update submission: {}, {}" , submission .getId (), e );
2873
2911
return "Could not update submission=" +submission .getId ()+" " +e ;
@@ -2886,7 +2924,7 @@ private static String getNextSubmissionLogKey(org.sakaiproject.assignment.api.mo
2886
2924
Map <String , String > properties = submission .getProperties ();
2887
2925
List <Integer > keys = properties .keySet ().stream ()
2888
2926
.filter (k -> k .startsWith ("log" ))
2889
- .map (k -> new Integer (StringUtils .split (k , "log" )[0 ]))
2927
+ .map (k -> Integer . valueOf (StringUtils .split (k , "log" )[0 ]))
2890
2928
.sorted ()
2891
2929
.collect (Collectors .toList ());
2892
2930
int next = keys .isEmpty () ? 0 : keys .get (keys .size () - 1 ) + 1 ;
@@ -2945,10 +2983,10 @@ public static org.sakaiproject.grading.api.Assignment getGradebookColumn(Site si
2945
2983
returnColumn .setGradebookUid (returnGradebookUid );
2946
2984
log .info ("Added gradebook column: {} with Id: {}" , title , gradebookColumnId );
2947
2985
} catch (ConflictingAssignmentNameException e ) {
2948
- log .warn ("ConflictingAssignmentNameException while adding gradebook column {}" , e .getMessage ());
2986
+ log .warn ("ConflictingAssignmentNameException while adding gradebook column {}" , e .toString ());
2949
2987
returnColumn = null ; // Just to make sure
2950
2988
} catch (Exception e ) {
2951
- log .warn ("Exception (may be because GradeBook has not yet been added to the Site) {}" , e .getMessage ());
2989
+ log .warn ("Exception (may be because GradeBook has not yet been added to the Site) {}" , e .toString ());
2952
2990
returnColumn = null ; // Just to make double sure
2953
2991
} finally {
2954
2992
popAdvisor ();
@@ -2966,7 +3004,7 @@ public static org.sakaiproject.grading.api.Assignment getGradebookColumn(Site si
2966
3004
// Returns scoreGiven * points rounded to 2 digits (as a String)
2967
3005
// Used for testing and to avoid precision problems
2968
3006
public static String getRoundedGrade (Double scoreGiven , Double points ) throws Exception {
2969
- if (scoreGiven < 0.0 || scoreGiven > 1.0 ) {
3007
+ if (scoreGiven == null || scoreGiven < 0.0 || scoreGiven > 1.0 ) {
2970
3008
throw new Exception ("Grade out of range" );
2971
3009
}
2972
3010
scoreGiven = scoreGiven * points ;
0 commit comments