Coverage Report - org.kuali.student.enrollment.class2.grading.service.impl.GradingServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
GradingServiceImpl
0%
0/273
0%
0/90
2.4
 
 1  
 package org.kuali.student.enrollment.class2.grading.service.impl;
 2  
 
 3  
 import org.apache.commons.lang.StringUtils;
 4  
 import org.kuali.rice.krad.util.GlobalVariables;
 5  
 import org.kuali.student.common.util.UUIDHelper;
 6  
 import org.kuali.student.enrollment.class2.grading.assembler.GradeValuesGroupAssembler;
 7  
 import org.kuali.student.enrollment.class2.grading.service.assembler.GradeRosterAssembler;
 8  
 import org.kuali.student.enrollment.class2.grading.service.assembler.GradeRosterEntryAssembler;
 9  
 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
 10  
 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
 11  
 import org.kuali.student.enrollment.courseregistration.service.CourseRegistrationService;
 12  
 import org.kuali.student.enrollment.grading.dto.GradeRosterEntryInfo;
 13  
 import org.kuali.student.enrollment.grading.dto.GradeRosterInfo;
 14  
 import org.kuali.student.enrollment.grading.dto.GradeValuesGroupInfo;
 15  
 import org.kuali.student.enrollment.grading.service.GradingService;
 16  
 import org.kuali.student.enrollment.lpr.dto.LprInfo;
 17  
 import org.kuali.student.enrollment.lpr.service.LprService;
 18  
 import org.kuali.student.enrollment.lrr.dto.LearningResultRecordInfo;
 19  
 import org.kuali.student.enrollment.lrr.service.LearningResultRecordService;
 20  
 import org.kuali.student.enrollment.lui.service.LuiService;
 21  
 import org.kuali.student.r2.common.assembler.AssemblyException;
 22  
 import org.kuali.student.r2.common.dto.*;
 23  
 import org.kuali.student.r2.common.exceptions.*;
 24  
 import org.kuali.student.r2.common.util.constants.LprServiceConstants;
 25  
 import org.kuali.student.r2.common.util.constants.LrcServiceConstants;
 26  
 import org.kuali.student.r2.common.util.constants.LrrServiceConstants;
 27  
 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
 28  
 import org.kuali.student.r2.lum.lrc.dto.ResultValueInfo;
 29  
 import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
 30  
 import org.kuali.student.r2.lum.lrc.service.LRCService;
 31  
 
 32  
 import javax.jws.WebParam;
 33  
 import java.util.*;
 34  
 import org.kuali.student.enrollment.roster.dto.LprRosterEntryInfo;
 35  
 import org.kuali.student.enrollment.roster.dto.LprRosterInfo;
 36  
 import org.kuali.student.enrollment.roster.service.LprRosterService;
 37  
 import org.kuali.student.r2.core.type.dto.TypeInfo;
 38  
 
 39  0
 public class GradingServiceImpl implements GradingService {
 40  
     private LprService lprService;
 41  
     private LprRosterService lprRosterService;
 42  
     private CourseOfferingService courseOfferingService;
 43  
     private LRCService lrcService;
 44  
     private LearningResultRecordService lrrService;
 45  
     private LuiService luiService;
 46  
     private GradeRosterAssembler gradeRosterAssembler;
 47  
     private GradeRosterEntryAssembler gradeRosterEntryAssembler;
 48  
     private GradeValuesGroupAssembler gradeValuesGroupAssembler;
 49  
     private CourseRegistrationService courseRegistrationService;
 50  
 
 51  
     /**
 52  
      * This method returns the TypeInfo for a given grade roster type key.
 53  
      *
 54  
      * @param gradeRosterTypeKey
 55  
      *            Key of the type
 56  
      * @param context
 57  
      *            Context information containing the principalId and locale
 58  
      *            information about the caller of service operation
 59  
      * @return Information about the Type
 60  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 61  
      *             gradeRosterTypeKey not found
 62  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 63  
      *             invalid gradeRosterTypeKey
 64  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 65  
      *             missing gradeRosterTypeKey
 66  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 67  
      *             unable to complete request
 68  
      */
 69  
     @Override
 70  
     public TypeInfo getGradeRosterType(@WebParam(name = "gradeRosterTypeKey") String gradeRosterTypeKey,
 71  
             @WebParam(name = "context") ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 72  
             MissingParameterException, OperationFailedException {
 73  0
         return null; // TODO implement method.
 74  
     }
 75  
 
 76  
     /**
 77  
      * Retrieve information about a grade roster
 78  
      *
 79  
      * @param gradeRosterId
 80  
      * @param context
 81  
      *            Context information containing the principalId and locale
 82  
      *            information about the caller of service operation
 83  
      * @return
 84  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 85  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 86  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 87  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 88  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 89  
      *             authorization failure
 90  
      */
 91  
     @Override
 92  
     public GradeRosterInfo getGradeRoster(@WebParam(name = "gradeRosterId") String gradeRosterId,
 93  
             @WebParam(name = "context") ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 94  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 95  0
         return null; // TODO implement method.
 96  
     }
 97  
 
 98  
     /**
 99  
      * Retrieve information about grade rosters by grader and term
 100  
      *
 101  
      * @param graderId
 102  
      * @param termId
 103  
      * @param context
 104  
      *            Context information containing the principalId and locale
 105  
      *            information about the caller of service operation
 106  
      * @return
 107  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 108  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 109  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 110  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 111  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 112  
      *             authorization failure
 113  
      */
 114  
     @Override
 115  
     public List<GradeRosterInfo> getGradeRostersByGraderAndTerm(@WebParam(name = "graderId") String graderId,
 116  
             @WebParam(name = "termId") String termId, @WebParam(name = "context") ContextInfo context)
 117  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 118  
             OperationFailedException, PermissionDeniedException {
 119  0
         return null; // TODO implement method.
 120  
     }
 121  
 
 122  
     /**
 123  
      * Retrieves rosters of final grades for a course offering
 124  
      *
 125  
      * @param courseOfferingId
 126  
      * @param context
 127  
      *            Context information containing the principalId and locale
 128  
      *            information about the caller of service operation
 129  
      * @return
 130  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 131  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 132  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 133  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 134  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 135  
      *             authorization failure
 136  
      */
 137  
     @Override
 138  
     public List<GradeRosterInfo> getFinalGradeRostersForCourseOffering(
 139  
             @WebParam(name = "courseOfferingId") String courseOfferingId,
 140  
             @WebParam(name = "context") ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 141  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 142  0
         List<GradeRosterInfo> gradeRosterInfos = new ArrayList<GradeRosterInfo>();
 143  
 
 144  0
         List<LprRosterInfo> lprRosters = lprRosterService.getLprRostersByTypeAndLui(LprServiceConstants.LPRROSTER_COURSE_FINAL_GRADEROSTER_TYPE_KEY, courseOfferingId, context);
 145  0
         for (LprRosterInfo lprRoster : lprRosters) {
 146  0
             GradeRosterInfo gradeRosterInfo = assembleGradeRoster(lprRoster, context);
 147  0
             gradeRosterInfos.add(gradeRosterInfo);
 148  0
         }
 149  
 
 150  0
         return gradeRosterInfos;
 151  
     }
 152  
 
 153  
     /**
 154  
      * Retrieves rosters of final grade by actvity offerings
 155  
      *
 156  
      * @param activityOfferingId
 157  
      * @param context
 158  
      *            Context information containing the principalId and locale
 159  
      *            information about the caller of service operation
 160  
      * @return
 161  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 162  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 163  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 164  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 165  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 166  
      *             authorization failure
 167  
      */
 168  
     @Override
 169  
     public List<GradeRosterInfo> getFinalGradeRostersForActivityOffering(
 170  
             @WebParam(name = "activityOfferingId") String activityOfferingId,
 171  
             @WebParam(name = "context") ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 172  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 173  0
         return null; // TODO implement method.
 174  
     }
 175  
 
 176  
     /**
 177  
      * Retrieves all rosters for an activity offering
 178  
      *
 179  
      * @param activityOfferingId
 180  
      * @param context
 181  
      *            Context information containing the principalId and locale
 182  
      *            information about the caller of service operation
 183  
      * @return
 184  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 185  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 186  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 187  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 188  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 189  
      *             authorization failure
 190  
      */
 191  
     @Override
 192  
     public List<GradeRosterInfo> getGradeRostersForActivityOffering(
 193  
             @WebParam(name = "activityOfferingId") String activityOfferingId,
 194  
             @WebParam(name = "context") ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 195  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 196  0
         return null; // TODO implement method.
 197  
     }
 198  
 
 199  
     /**
 200  
      * Build an interim roster of given type. Roster type should be used to
 201  
      * figure out which students from the activity offerings will be in the
 202  
      * roster
 203  
      *
 204  
      * @param activityOfferingIds
 205  
      * @param rosterTypeKey
 206  
      * @param context
 207  
      *            Context information containing the principalId and locale
 208  
      *            information about the caller of service operation
 209  
      * @return
 210  
      * @throws org.kuali.student.r2.common.exceptions.AlreadyExistsException
 211  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 212  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 213  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 214  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 215  
      *             authorization failure
 216  
      */
 217  
     @Override
 218  
     public GradeRosterInfo buildInterimGradeRosterByType(
 219  
             @WebParam(name = "courseOfferingId") String courseOfferingId,
 220  
             @WebParam(name = "activityOfferingIds") List<String> activityOfferingIds,
 221  
             @WebParam(name = "rosterTypeKey") String rosterTypeKey, @WebParam(name = "context") ContextInfo context)
 222  
             throws AlreadyExistsException, InvalidParameterException, MissingParameterException,
 223  
             OperationFailedException, PermissionDeniedException {
 224  0
         return null; // TODO implement method.
 225  
     }
 226  
 
 227  
     /**
 228  
      * Update interim grade roster information
 229  
      *
 230  
      * @param gradeRoster
 231  
      * @param context
 232  
      *            Context information containing the principalId and locale
 233  
      *            information about the caller of service operation
 234  
      * @return
 235  
      * @throws org.kuali.student.r2.common.exceptions.DataValidationErrorException
 236  
      *             One or more values invalid for this operation
 237  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 238  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 239  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 240  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 241  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 242  
      *             authorization failure
 243  
      * @throws org.kuali.student.r2.common.exceptions.VersionMismatchException
 244  
      */
 245  
     @Override
 246  
     public GradeRosterInfo updateInterimGradeRoster(@WebParam(name = "gradeRoster") GradeRosterInfo gradeRoster,
 247  
             @WebParam(name = "context") ContextInfo context) throws DataValidationErrorException,
 248  
             DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 249  
             PermissionDeniedException, VersionMismatchException {
 250  0
         return null; // TODO implement method.
 251  
     }
 252  
 
 253  
     /**
 254  
      * Delete an interim grade roster
 255  
      *
 256  
      * @param gradeRosterId
 257  
      * @param context
 258  
      *            Context information containing the principalId and locale
 259  
      *            information about the caller of service operation
 260  
      * @return
 261  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 262  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 263  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 264  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 265  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 266  
      *             authorization failure
 267  
      */
 268  
     @Override
 269  
     public StatusInfo deleteInterimGradeRoster(@WebParam(name = "gradeRosterId") String gradeRosterId,
 270  
             @WebParam(name = "context") ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 271  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 272  0
         return null; // TODO implement method.
 273  
     }
 274  
 
 275  
     /**
 276  
      * Update state of final grade roster. Only state can be changed for the
 277  
      * final grade roster. Final grade submission is tracked through state
 278  
      * change on the roster.
 279  
      *
 280  
      * @param gradeRosterId
 281  
      * @param stateKey
 282  
      * @param context
 283  
      *            Context information containing the principalId and locale
 284  
      *            information about the caller of service operation
 285  
      * @return
 286  
      * @throws org.kuali.student.r2.common.exceptions.DataValidationErrorException
 287  
      *             One or more values invalid for this operation
 288  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 289  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 290  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 291  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 292  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 293  
      *             authorization failure
 294  
      * @throws org.kuali.student.r2.common.exceptions.VersionMismatchException
 295  
      */
 296  
     @Override
 297  
     public GradeRosterInfo updateFinalGradeRosterState(@WebParam(name = "gradeRosterId") String gradeRosterId,
 298  
             @WebParam(name = "newStateKey") String stateKey, @WebParam(name = "context") ContextInfo context)
 299  
             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException,
 300  
             MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 301  
 
 302  0
         LprRosterInfo lprRosterInfo = lprRosterService.getLprRoster(gradeRosterId,context);
 303  0
         lprRosterInfo.setStateKey(stateKey);
 304  
 
 305  
         GradeRosterInfo returnRoster;
 306  
         try {
 307  0
             LprRosterInfo newRoster = lprRosterService.updateLprRoster(gradeRosterId,lprRosterInfo,context);
 308  0
             returnRoster = assembleGradeRoster(newRoster,context);
 309  0
         } catch (ReadOnlyException e) {
 310  0
             throw new RuntimeException(e);
 311  0
         }
 312  
 
 313  
         //Update LRR State
 314  0
         List<LprRosterEntryInfo> rosterEntryInfoList = lprRosterService.getLprRosterEntriesByLprRoster(lprRosterInfo.getId(),context);
 315  0
         List<String> lprIds = new ArrayList();
 316  0
         for (LprRosterEntryInfo entryInfo : rosterEntryInfoList) {
 317  0
             lprIds.add(entryInfo.getLprId());
 318  
         }
 319  
 
 320  0
         List<LearningResultRecordInfo> learningResultRecordInfoList = lrrService.getLearningResultRecordsForLprIds(lprIds,context);
 321  0
         for (LearningResultRecordInfo learningResultRecordInfo : learningResultRecordInfoList) {
 322  
             //process only saved state entries (Skipping deleted state)
 323  0
             if (StringUtils.equals(learningResultRecordInfo.getStateKey(),LrrServiceConstants.RESULT_RECORD_SAVED_STATE_KEY)){
 324  0
                 learningResultRecordInfo.setStateKey(LrrServiceConstants.RESULT_RECORD_SUBMITTED_STATE_KEY);
 325  0
                 lrrService.updateLearningResultRecord(learningResultRecordInfo.getId(),learningResultRecordInfo,context);
 326  
             }
 327  
         }
 328  
 
 329  0
         return returnRoster;
 330  
     }
 331  
 
 332  
     /**
 333  
      * Validate a grade roster information
 334  
      *
 335  
      * @param gradeRoster
 336  
      * @param context
 337  
      *            Context information containing the principalId and locale
 338  
      *            information about the caller of service operation
 339  
      * @return
 340  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 341  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 342  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 343  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 344  
      */
 345  
     @Override
 346  
     public List<ValidationResultInfo> validateGradeRoster(@WebParam(name = "gradeRoster") GradeRosterInfo gradeRoster,
 347  
             @WebParam(name = "context") ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 348  
             MissingParameterException, OperationFailedException {
 349  0
         return null; // TODO implement method.
 350  
     }
 351  
 
 352  
     /**
 353  
      * Retrieve information about a grade roster entry
 354  
      *
 355  
      * @param gradeRosterEntryId
 356  
      * @param context
 357  
      *            Context information containing the principalId and locale
 358  
      *            information about the caller of service operation
 359  
      * @return
 360  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 361  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 362  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 363  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 364  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 365  
      *             authorization failure
 366  
      */
 367  
     @Override
 368  
     public GradeRosterEntryInfo getGradeRosterEntry(@WebParam(name = "gradeRosterEntryId") String gradeRosterEntryId,
 369  
             @WebParam(name = "context") ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 370  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 371  0
         return null; // TODO implement method.
 372  
     }
 373  
 
 374  
     /**
 375  
      * Retrieve a list of grade roster entries based on their Ids. The method
 376  
      * should fail if there is an error in retrieving any id from the list.
 377  
      *
 378  
      * @param gradeRosterEntryIds
 379  
      * @param context
 380  
      *            Context information containing the principalId and locale
 381  
      *            information about the caller of service operation
 382  
      * @return
 383  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 384  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 385  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 386  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 387  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 388  
      *             authorization failure
 389  
      */
 390  
     @Override
 391  
     public List<GradeRosterEntryInfo> getGradeRosterEntriesByIds(
 392  
             @WebParam(name = "gradeRosterEntryIds") List<String> gradeRosterEntryIds,
 393  
             @WebParam(name = "context") ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 394  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 395  
 
 396  
 
 397  0
         List<LprRosterEntryInfo> entries = lprRosterService.getLprRosterEntriesByIds(gradeRosterEntryIds, context);
 398  0
         return assembleGradeRosterEntries(entries, context);
 399  
     }
 400  
 
 401  
     /**
 402  
      * Retrieve grade roster entries by roster
 403  
      *
 404  
      * @param gradeRosterId
 405  
      * @param context
 406  
      *            Context information containing the principalId and locale
 407  
      *            information about the caller of service operation
 408  
      * @return
 409  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 410  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 411  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 412  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 413  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 414  
      *             authorization failure
 415  
      */
 416  
     @Override
 417  
     public List<GradeRosterEntryInfo> getGradeRosterEntriesByRosterId(
 418  
             @WebParam(name = "gradeRosterId") String gradeRosterId, @WebParam(name = "context") ContextInfo context)
 419  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 420  
             OperationFailedException, PermissionDeniedException {
 421  0
         List<LprRosterEntryInfo> entries = lprRosterService.getLprRosterEntriesByLprRoster(gradeRosterId, context);
 422  0
         return assembleGradeRosterEntries(entries, context);
 423  
     }
 424  
 
 425  
     /**
 426  
      * This method ...
 427  
      *
 428  
      * @param studentId
 429  
      * @param courseOfferingId
 430  
      * @param context
 431  
      *            Context information containing the principalId and locale
 432  
      *            information about the caller of service operation
 433  
      * @return
 434  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 435  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 436  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 437  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 438  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 439  
      *             authorization failure
 440  
      */
 441  
     @Override
 442  
     public GradeRosterEntryInfo getFinalGradeForStudentInCourseOffering(@WebParam(name = "studentId") String studentId,
 443  
             @WebParam(name = "courseOfferingId") String courseOfferingId,
 444  
             @WebParam(name = "context") ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 445  
             MissingParameterException, OperationFailedException, PermissionDeniedException, DisabledIdentifierException {
 446  
 
 447  
 
 448  0
         List<LprRosterInfo> lprRosters = lprRosterService.getLprRostersByTypeAndLui(LprServiceConstants.LPRROSTER_COURSE_FINAL_GRADEROSTER_TYPE_KEY, courseOfferingId, context);
 449  0
         Map<String, LprRosterEntryInfo> lprIdToRosterEntryMap = new HashMap<String, LprRosterEntryInfo>();
 450  0
         for (LprRosterInfo lprRoster : lprRosters) {
 451  0
             String rosterId = lprRoster.getId();
 452  0
             List<LprRosterEntryInfo> rosterEntries = lprRosterService.getLprRosterEntriesByLprRoster(rosterId, context);
 453  0
             for (LprRosterEntryInfo rosterEntry : rosterEntries) {
 454  0
                 String lprId = rosterEntry.getLprId();
 455  0
                 lprIdToRosterEntryMap.put(lprId, rosterEntry);
 456  0
             }
 457  0
         }
 458  
 
 459  0
         List<LprInfo> lprs = lprService.getLprsByPersonAndLui(studentId, courseOfferingId, context);
 460  0
         LprInfo lpr = lprs.get(0); // TODO throw exception if null?
 461  0
         LprRosterEntryInfo entry = lprIdToRosterEntryMap.get(lpr.getId());
 462  
 
 463  0
         return assembleGradeRosterEntry(entry, context);
 464  
     }
 465  
 
 466  
     /**
 467  
      * This method ...
 468  
      *
 469  
      * @param gradeRosterEntry
 470  
      * @param gradeRosterId
 471  
      * @param context
 472  
      *            Context information containing the principalId and locale
 473  
      *            information about the caller of service operation
 474  
      * @return
 475  
      * @throws org.kuali.student.r2.common.exceptions.AlreadyExistsException
 476  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 477  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 478  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 479  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 480  
      *             authorization failure
 481  
      */
 482  
     @Override
 483  
     public GradeRosterEntryInfo addEntrytoInterimRoster(
 484  
             @WebParam(name = "gradeRosterEntry") GradeRosterEntryInfo gradeRosterEntry,
 485  
             @WebParam(name = "gradeRosterId") String gradeRosterId, @WebParam(name = "context") ContextInfo context)
 486  
             throws AlreadyExistsException, InvalidParameterException, MissingParameterException,
 487  
             OperationFailedException, PermissionDeniedException {
 488  0
         return null; // TODO implement method.
 489  
     }
 490  
 
 491  
     /**
 492  
      * This method ...
 493  
      *
 494  
      * @param gradeRosterEntryId
 495  
      * @param gradeRosterId
 496  
      * @param context
 497  
      *            Context information containing the principalId and locale
 498  
      *            information about the caller of service operation
 499  
      * @return
 500  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 501  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 502  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 503  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 504  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 505  
      *             authorization failure
 506  
      */
 507  
     @Override
 508  
     public StatusInfo removeEntryFromInterimRoster(@WebParam(name = "gradeRosterEntryId") String gradeRosterEntryId,
 509  
             @WebParam(name = "gradeRosterId") String gradeRosterId, @WebParam(name = "context") ContextInfo context)
 510  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 511  
             OperationFailedException, PermissionDeniedException {
 512  0
         return null; // TODO implement method.
 513  
     }
 514  
 
 515  
     /**
 516  
      * This method ...
 517  
      *
 518  
      * @param gradeRosterEntryId
 519  
      * @param assignedGradeKey
 520  
      * @param context
 521  
      *            Context information containing the principalId and locale
 522  
      *            information about the caller of service operation
 523  
      * @return
 524  
      * @throws org.kuali.student.r2.common.exceptions.DataValidationErrorException
 525  
      *             One or more values invalid for this operation
 526  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 527  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 528  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 529  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 530  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 531  
      *             authorization failure
 532  
      * @throws org.kuali.student.r2.common.exceptions.VersionMismatchException
 533  
      */
 534  
     @Override
 535  
     public boolean updateGrade(@WebParam(name = "gradeRosterEntryId") String gradeRosterEntryId,
 536  
             @WebParam(name = "assignedGrade") String assignedGradeKey, @WebParam(name = "context") ContextInfo context)
 537  
             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException,
 538  
             MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 539  
 
 540  0
         List<String> lprRosterEntryIds = new ArrayList();
 541  0
         lprRosterEntryIds.add(gradeRosterEntryId);
 542  
 
 543  0
         List<LprRosterEntryInfo> entryInfoList = lprRosterService.getLprRosterEntriesByIds(lprRosterEntryIds,context);
 544  0
         if (entryInfoList.isEmpty()){
 545  0
             throw new DoesNotExistException("Lpr Roster Entry not exists for the id " + gradeRosterEntryId);
 546  
         }
 547  
 
 548  0
         LprRosterEntryInfo entryInfo = entryInfoList.get(0);
 549  0
         List<String> lprIds = new ArrayList();
 550  0
         lprIds.add(entryInfo.getLprId());
 551  
 
 552  0
         List<LearningResultRecordInfo> learningResultRecordInfoList = lrrService.getLearningResultRecordsForLprIds(lprIds,context);
 553  
 
 554  
         //If an entry not exists for a student, create one
 555  0
         if ((learningResultRecordInfoList == null || learningResultRecordInfoList.isEmpty()) && StringUtils.isNotBlank(assignedGradeKey)){
 556  0
             LearningResultRecordInfo lrrInfo = constructLearningResultRecordInfo(entryInfo, assignedGradeKey);
 557  
             try{
 558  0
                 lrrService.createLearningResultRecord(lrrInfo,context);
 559  0
                 return true;
 560  0
             }catch(AlreadyExistsException e){
 561  0
                 throw new OperationFailedException("Someone updated the grade. Please refresh to get the latest",e);
 562  
             }
 563  
         }
 564  
 
 565  0
         for (LearningResultRecordInfo lrrInfo : learningResultRecordInfoList){
 566  0
             if (StringUtils.equals(LrrServiceConstants.RESULT_RECORD_FINAL_GRADE_ASSIGNED_TYPE_KEY, lrrInfo.getTypeKey())){
 567  0
                 if (!StringUtils.equals(LrrServiceConstants.RESULT_RECORD_DELETED_STATE_KEY,lrrInfo.getStateKey())){
 568  0
                      if (StringUtils.isBlank(assignedGradeKey)){
 569  0
                         StatusInfo status = lrrService.deleteLearningResultRecord(lrrInfo.getId(),context);
 570  0
                         return status.getIsSuccess();
 571  
                     }else{
 572  0
                         lrrInfo.setStateKey(LrrServiceConstants.RESULT_RECORD_SAVED_STATE_KEY);//If cancelled before
 573  0
                         lrrInfo.setResultValueKey(assignedGradeKey);
 574  0
                         lrrService.updateLearningResultRecord(lrrInfo.getId(),lrrInfo,context);
 575  0
                         return true;
 576  
                     }
 577  
                 }
 578  
             }
 579  
         }
 580  
 
 581  
         //Create a new LRR as there are no active LRRs found
 582  0
         if (StringUtils.isNotBlank(assignedGradeKey)){
 583  0
             LearningResultRecordInfo newLrr = constructLearningResultRecordInfo(entryInfo, assignedGradeKey);
 584  
             try{
 585  0
                 lrrService.createLearningResultRecord(newLrr,context);
 586  0
                 return true;
 587  0
             }catch(AlreadyExistsException e){
 588  0
                 throw new OperationFailedException("Someone updated the grade. Please refresh to get the latest",e);
 589  
             }
 590  
         }
 591  
 
 592  0
         return false;
 593  
     }
 594  
 
 595  
     private LearningResultRecordInfo constructLearningResultRecordInfo(LprRosterEntryInfo entryInfo, String assignedGradeKey){
 596  0
         LearningResultRecordInfo lrrInfo = new LearningResultRecordInfo();
 597  0
         lrrInfo.setId(UUIDHelper.genStringUUID());
 598  0
         lrrInfo.setLprId(entryInfo.getLprId());
 599  0
         lrrInfo.setName("LRR for " + entryInfo.getLprId());
 600  0
         lrrInfo.setStateKey(LrrServiceConstants.RESULT_RECORD_SAVED_STATE_KEY);
 601  0
         lrrInfo.setTypeKey(LrrServiceConstants.RESULT_RECORD_FINAL_GRADE_ASSIGNED_TYPE_KEY);
 602  
 
 603  
         //FIXME: Hardcoded for core slice
 604  0
         List<String> resultSource = new ArrayList();
 605  0
         resultSource.add("ResultSource-Sample1");
 606  0
         lrrInfo.setResultSourceIds(resultSource);
 607  
 
 608  0
         lrrInfo.setResultValueKey(assignedGradeKey);
 609  0
         MetaInfo meta = new MetaInfo();
 610  0
         meta.setCreateId(GlobalVariables.getUserSession().getPrincipalId());
 611  0
         meta.setCreateTime(new Date());
 612  0
         lrrInfo.setMeta(meta);
 613  
 
 614  0
         return lrrInfo;
 615  
     }
 616  
 
 617  
     /**
 618  
      * This method ...
 619  
      *
 620  
      * @param gradeRosterEntryId
 621  
      * @param assignedGradeKey
 622  
      * @param context
 623  
      *            Context information containing the principalId and locale
 624  
      *            information about the caller of service operation
 625  
      * @return
 626  
      * @throws org.kuali.student.r2.common.exceptions.DataValidationErrorException
 627  
      *             One or more values invalid for this operation
 628  
      * @throws org.kuali.student.r2.common.exceptions.DoesNotExistException
 629  
      * @throws org.kuali.student.r2.common.exceptions.InvalidParameterException
 630  
      * @throws org.kuali.student.r2.common.exceptions.MissingParameterException
 631  
      * @throws org.kuali.student.r2.common.exceptions.OperationFailedException
 632  
      * @throws org.kuali.student.r2.common.exceptions.PermissionDeniedException
 633  
      *             authorization failure
 634  
      * @throws org.kuali.student.r2.common.exceptions.VersionMismatchException
 635  
      */
 636  
     @Override
 637  
     public boolean updateCredit(@WebParam(name = "gradeRosterEntryId") String gradeRosterEntryId,
 638  
             @WebParam(name = "creditsEarned") String assignedGradeKey, @WebParam(name = "context") ContextInfo context)
 639  
             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException,
 640  
             MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 641  0
         return false; // TODO implement method.
 642  
     }
 643  
 
 644  
     @Override
 645  
     public List<GradeValuesGroupInfo> getGradeGroupsByKeyList(List<String> gradeGroupKeyList, ContextInfo context)
 646  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 647  
             OperationFailedException, PermissionDeniedException {
 648  
 
 649  0
         List<ResultValuesGroupInfo> resultValuesGroupInfos = lrcService.getResultValuesGroupsByIds(gradeGroupKeyList, context);
 650  0
         List<GradeValuesGroupInfo> gradeValuesGroupInfos = new ArrayList<GradeValuesGroupInfo>();
 651  
 
 652  0
         for(ResultValuesGroupInfo resultValuesGroupInfo : resultValuesGroupInfos){
 653  0
             List<ResultValueInfo> resultValueInfos = lrcService.getResultValuesByIds(resultValuesGroupInfo.getResultValueKeys(),context);
 654  
             try {
 655  0
                 gradeValuesGroupInfos.add(gradeValuesGroupAssembler.assemble(resultValuesGroupInfo,resultValueInfos,context));
 656  0
             } catch (AssemblyException e) {
 657  0
                 throw new OperationFailedException("AssemblyException : " + e.getMessage());
 658  0
             }
 659  0
         }
 660  
 
 661  0
         return gradeValuesGroupInfos;
 662  
     }
 663  
 
 664  
     @Override
 665  
     public boolean updateNumberGrade(String gradeRosterEntryId, String numberGradeValue, ContextInfo context)
 666  
             throws DataValidationErrorException, DoesNotExistException, InvalidParameterException,
 667  
             MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 668  
         // TODO sambit - THIS METHOD NEEDS JAVADOCS
 669  0
         return false;
 670  
     }
 671  
 
 672  
     private GradeRosterInfo assembleGradeRoster(LprRosterInfo lprRosterInfo, ContextInfo context) throws InvalidParameterException, MissingParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException {
 673  0
         Map<String, LprRosterEntryInfo> lprIdToRosterEntriesMap = new HashMap<String, LprRosterEntryInfo>();
 674  0
         List<String> graderIds = new ArrayList<String>();
 675  0
         List<String> lprRosterEntryIds = new ArrayList<String>();
 676  
 
 677  0
         List<LprRosterEntryInfo> lprRosterEntries = lprRosterService.getLprRosterEntriesByLprRoster(lprRosterInfo.getId(), context);
 678  0
         for (LprRosterEntryInfo lprRosterEntry : lprRosterEntries) {
 679  0
             String lprId = lprRosterEntry.getLprId();
 680  0
             lprIdToRosterEntriesMap.put(lprId, lprRosterEntry);
 681  0
         }
 682  
 
 683  0
         List<String> lprIds = new ArrayList<String>(lprIdToRosterEntriesMap.keySet());
 684  0
         List<LprInfo> lprInfos = lprService.getLprsByIds(lprIds, context);
 685  0
         for (LprInfo lprInfo : lprInfos) {
 686  0
             String lprInfoType = lprInfo.getTypeKey();
 687  0
             if (LprServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY.equals(lprInfoType)) {
 688  0
                 graderIds.add(lprInfo.getPersonId());
 689  0
             } else if (LprServiceConstants.REGISTRANT_TYPE_KEY.equals(lprInfoType)) {
 690  0
                 LprRosterEntryInfo lprRosterEntryInfo = lprIdToRosterEntriesMap.get(lprInfo.getId());
 691  0
                 lprRosterEntryIds.add(lprRosterEntryInfo.getId());
 692  
             }
 693  0
         }
 694  
 
 695  0
         String courseOfferingId = null;
 696  0
         List<String> activityOfferingIds = null;
 697  
 
 698  0
         List<String> associatedLuiIds = lprRosterInfo.getAssociatedLuiIds();
 699  
 
 700  0
         if (associatedLuiIds == null || associatedLuiIds.size() ==  0) {
 701  0
             throw new OperationFailedException("LPR Roster does not contain any associated LUI IDs.");
 702  0
         } else if (associatedLuiIds.size() ==  1) {
 703  0
             CourseOfferingInfo courseOffering = courseOfferingService.getCourseOffering(associatedLuiIds.get(0), context);
 704  0
             courseOfferingId = courseOffering.getId();
 705  0
             activityOfferingIds = new ArrayList<String>();
 706  0
         } else if (associatedLuiIds.size() >  1) {
 707  0
             activityOfferingIds = associatedLuiIds;
 708  
 
 709  0
             List<String> relatedLuis = luiService.getLuiIdsByRelatedLuiAndRelationType(activityOfferingIds.get(0), LuiServiceConstants.LUI_LUI_RELATION_DELIVEREDVIA_TYPE_KEY, context);
 710  0
             if (relatedLuis == null || relatedLuis.size() != 1) {
 711  0
                 throw new OperationFailedException("The provided activity offering is not related to 1 and only 1 course offering.");
 712  
             }
 713  0
             courseOfferingId = relatedLuis.get(0);
 714  
         }
 715  
 
 716  0
         GradeRosterInfo gradeRosterInfo = gradeRosterAssembler.assemble(lprRosterInfo, lprRosterEntryIds, graderIds, courseOfferingId, activityOfferingIds, context);
 717  0
         return gradeRosterInfo;
 718  
     }
 719  
 
 720  
     private List<GradeRosterEntryInfo> assembleGradeRosterEntries(List<LprRosterEntryInfo> entries, ContextInfo context)
 721  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 722  
 
 723  
         //FIXME : This method needs some code refactoring
 724  
 
 725  0
         final String STUDENT_ID = "studentId";
 726  0
         final String ACTIVITY_OFFERING_ID = "activityOfferingId";
 727  0
         final String ASSIGNED_GRADE = "assignedGrade";
 728  0
         final String ADMINISTRATIVE_GRADE = "administrativeGrade";
 729  0
         final String CREDITS_EARNED = "creditsEarned";
 730  0
         final String CALCULATED_GRADE = "calculatedGrade";
 731  0
         final String GRADING_OPTION = "gradingOption";
 732  
 
 733  0
         List<GradeRosterEntryInfo> gradeRosterEntryInfos = new ArrayList<GradeRosterEntryInfo>();
 734  0
         Map<LprRosterEntryInfo, Map<String, String>> entryKeysMap = new HashMap<LprRosterEntryInfo, Map<String, String>>();
 735  
 
 736  0
         Map<String, LprRosterEntryInfo> lprIdToEntryMap = new HashMap<String, LprRosterEntryInfo>();
 737  0
         for (LprRosterEntryInfo lprRosterEntryInfo : entries) {
 738  0
             lprIdToEntryMap.put(lprRosterEntryInfo.getLprId(), lprRosterEntryInfo);
 739  0
             entryKeysMap.put(lprRosterEntryInfo, new HashMap<String, String>());
 740  
         }
 741  
 
 742  0
         List<String> lprIds = new ArrayList(lprIdToEntryMap.keySet());
 743  0
         List<LprInfo> lprs = lprService.getLprsByIds(lprIds, context);
 744  
 
 745  0
         Map<String,List> lprToGradeOptions = new HashMap();
 746  
 
 747  0
         for (LprInfo lpr : lprs) {
 748  0
             Map<String, String> entryAttributes = entryKeysMap.get(lprIdToEntryMap.get(lpr.getId()));
 749  0
             entryAttributes.put(STUDENT_ID, lpr.getPersonId());
 750  0
             entryAttributes.put(ACTIVITY_OFFERING_ID, lpr.getLuiId());
 751  
 
 752  0
             CourseOfferingInfo courseOfferingInfo = courseOfferingService.getCourseOffering(lpr.getLuiId(),context);
 753  
 
 754  0
             if (courseOfferingInfo == null){
 755  0
                 throw new OperationFailedException("Could not find course offering " + lpr.getLuiId());
 756  
             }
 757  
 
 758  0
             lprToGradeOptions.put(lpr.getId(),courseOfferingInfo.getRegistrationGradingOptionIds());
 759  
 
 760  0
         }
 761  
 
 762  0
         List<LearningResultRecordInfo> lrrs = lrrService.getLearningResultRecordsForLprIds(lprIds, context);
 763  0
         Map<LearningResultRecordInfo, String> lrrToLprIdMap = new HashMap<LearningResultRecordInfo, String>();
 764  0
         List<String> resultValueKeys = new ArrayList<String>();
 765  0
         List<LearningResultRecordInfo> filteredLrrs = new ArrayList();
 766  
 
 767  0
         for (LearningResultRecordInfo lrr : lrrs) {
 768  
             //Skip deleted LRR
 769  0
             if (!StringUtils.equals(lrr.getStateKey(),LrrServiceConstants.RESULT_RECORD_DELETED_STATE_KEY)){
 770  0
                 lrrToLprIdMap.put(lrr, lrr.getLprId());
 771  0
                 if (StringUtils.isNotBlank(lrr.getResultValueKey())){
 772  0
                     resultValueKeys.add(lrr.getResultValueKey());
 773  0
                     filteredLrrs.add(lrr);
 774  
                 }
 775  
             }
 776  
         }
 777  
 
 778  0
         List<ResultValueInfo> resultValues = lrcService.getResultValuesByIds(resultValueKeys, context);
 779  0
         for (int i = 0; i < resultValues.size(); i++) {
 780  0
             LearningResultRecordInfo lrr = filteredLrrs.get(i);
 781  0
             ResultValueInfo resultValue = resultValues.get(i);
 782  0
             String lprId = lrrToLprIdMap.get(lrr);
 783  0
             LprRosterEntryInfo entry = lprIdToEntryMap.get(lprId);
 784  0
             Map<String, String> entryAttributes = entryKeysMap.get(entry);
 785  
 
 786  0
             String resultValuetypeKey = resultValue.getTypeKey();
 787  0
             String entryAttributesKey = null;
 788  0
             if (LrcServiceConstants.RESULT_SCALE_TYPE_KEY_GRADE.equals(resultValuetypeKey)) {
 789  0
                 entryAttributesKey = ASSIGNED_GRADE;
 790  0
             } else if (LrcServiceConstants.RESULT_SCALE_TYPE_KEY_ADMIN_GRADE.equals(resultValuetypeKey)) {
 791  0
                 entryAttributesKey = ADMINISTRATIVE_GRADE;
 792  0
             } else if (LrcServiceConstants.RESULT_SCALE_TYPE_KEY_CREDIT.equals(resultValuetypeKey)) {
 793  0
                 entryAttributesKey = CREDITS_EARNED;
 794  
             } else if (false) { //"".equals(resultValuetypeKey)) { // TODO need type value for calculated grade
 795  
                 entryAttributesKey = CALCULATED_GRADE;
 796  
             }
 797  
 
 798  0
             if (entryAttributesKey != null) {
 799  0
                 entryAttributes.put(entryAttributesKey, resultValue.getKey());
 800  
             }
 801  
         }
 802  
 
 803  0
         for (LprRosterEntryInfo lprRosterEntry : entryKeysMap.keySet()) {
 804  0
             Map<String, String> entryAttributes = entryKeysMap.get(lprRosterEntry);
 805  0
             String studentId = entryAttributes.get(STUDENT_ID);
 806  0
             String activityOfferingId = entryAttributes.get(ACTIVITY_OFFERING_ID);
 807  0
             String assignedGradeKey = entryAttributes.get(ASSIGNED_GRADE);
 808  0
             String calculatedGradeKey = entryAttributes.get(CALCULATED_GRADE);
 809  0
             String administrativeGradeKey = entryAttributes.get(ADMINISTRATIVE_GRADE);
 810  0
             String creditsEarnedKey = entryAttributes.get(CREDITS_EARNED);
 811  0
             List gradingOptionKey = lprToGradeOptions.get(lprRosterEntry.getLprId());
 812  
 
 813  0
             GradeRosterEntryInfo gradeRosterEntry = gradeRosterEntryAssembler.assemble(lprRosterEntry, studentId, activityOfferingId, assignedGradeKey, calculatedGradeKey, administrativeGradeKey, creditsEarnedKey, gradingOptionKey , context);
 814  0
             gradeRosterEntryInfos.add(gradeRosterEntry);
 815  0
         }
 816  
 
 817  0
         return gradeRosterEntryInfos;
 818  
     }
 819  
 
 820  
     private GradeRosterEntryInfo assembleGradeRosterEntry(LprRosterEntryInfo lprRosterEntry, ContextInfo context)
 821  
             throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 822  
 
 823  
         String studentId;
 824  
         String activityOfferingId;
 825  0
         String assignedGradeKey = null;
 826  0
         String administrativeGradeKey = null;
 827  0
         String creditsEarnedKey = null;
 828  0
         String calculatedGradeKey = null;
 829  0
         List<String> gradingOptionKeys = new ArrayList<String>();
 830  
 
 831  0
         String lprId = lprRosterEntry.getLprId();
 832  0
         LprInfo lpr = lprService.getLpr(lprId, context);
 833  
 
 834  0
         studentId = lpr.getPersonId();
 835  0
         activityOfferingId = lpr.getLuiId();
 836  
 
 837  
         // TODO Get grading options from courseRegistration instead of courseOffering.
 838  0
         CourseOfferingInfo courseOfferingInfo = courseOfferingService.getCourseOffering(lpr.getLuiId(),context);
 839  0
         gradingOptionKeys.add(courseOfferingInfo.getGradingOptionId());
 840  
 
 841  0
         List<LearningResultRecordInfo> lrrs = lrrService.getLearningResultRecordsForLpr(lprId);
 842  0
         List<String> resultValueKeys = new ArrayList<String>();
 843  
 
 844  0
         for (LearningResultRecordInfo lrr : lrrs) {
 845  
             //Skip deleted LRR
 846  0
             if (StringUtils.isBlank(lrr.getResultValueKey()) ||
 847  
                     StringUtils.equals(lrr.getStateKey(),LrrServiceConstants.RESULT_RECORD_DELETED_STATE_KEY)) {
 848  0
                 lrrs.remove(lrr);
 849  
             } else {
 850  0
                 resultValueKeys.add(lrr.getResultValueKey());
 851  
             }
 852  
         }
 853  
 
 854  0
         List<ResultValueInfo> resultValues = lrcService.getResultValuesByIds(resultValueKeys, context);
 855  0
         for (int i = 0; i < resultValues.size(); i++) {
 856  0
             ResultValueInfo resultValue = resultValues.get(i);
 857  0
             String resultValuetypeKey = resultValue.getTypeKey();
 858  0
             if (LrcServiceConstants.RESULT_SCALE_TYPE_KEY_GRADE.equals(resultValuetypeKey)) {
 859  0
                 assignedGradeKey = resultValue.getKey();
 860  0
             } else if (LrcServiceConstants.RESULT_SCALE_TYPE_KEY_ADMIN_GRADE.equals(resultValuetypeKey)) {
 861  0
                 administrativeGradeKey = resultValue.getKey();
 862  0
             } else if (LrcServiceConstants.RESULT_SCALE_TYPE_KEY_CREDIT.equals(resultValuetypeKey)) {
 863  0
                 creditsEarnedKey = resultValue.getKey();
 864  
             } else if (false) { //"".equals(resultValuetypeKey)) { // TODO need type value for calculated grade
 865  
                 calculatedGradeKey = resultValue.getKey();
 866  
             }
 867  
         }
 868  
 
 869  0
         GradeRosterEntryInfo gradeRosterEntry = gradeRosterEntryAssembler.assemble(lprRosterEntry, studentId, activityOfferingId, assignedGradeKey, calculatedGradeKey, administrativeGradeKey, creditsEarnedKey, gradingOptionKeys , context);
 870  
 
 871  0
         return gradeRosterEntry;
 872  
     }
 873  
 
 874  
     public LprRosterService getLprRosterService() {
 875  0
         return lprRosterService;
 876  
     }
 877  
 
 878  
     public void setLprRosterService(LprRosterService lprRosterService) {
 879  0
         this.lprRosterService = lprRosterService;
 880  0
     }
 881  
 
 882  
     public LprService getLprService() {
 883  0
         return lprService;
 884  
     }
 885  
 
 886  
     public void setLprService(LprService lprService) {
 887  0
         this.lprService = lprService;
 888  0
     }
 889  
 
 890  
     public CourseOfferingService getCourseOfferingService() {
 891  0
         return courseOfferingService;
 892  
     }
 893  
 
 894  
     public void setCourseOfferingService(CourseOfferingService courseOfferingService) {
 895  0
         this.courseOfferingService = courseOfferingService;
 896  0
     }
 897  
 
 898  
     public LRCService getLrcService() {
 899  0
         return lrcService;
 900  
     }
 901  
 
 902  
     public void setLrcService(LRCService lrcService) {
 903  0
         this.lrcService = lrcService;
 904  0
     }
 905  
 
 906  
     public LearningResultRecordService getLrrService() {
 907  0
         return lrrService;
 908  
     }
 909  
 
 910  
     public void setLrrService(LearningResultRecordService lrrService) {
 911  0
         this.lrrService = lrrService;
 912  0
     }
 913  
 
 914  
     public LuiService getLuiService() {
 915  0
         return luiService;
 916  
     }
 917  
 
 918  
     public void setLuiService(LuiService luiService) {
 919  0
         this.luiService = luiService;
 920  0
     }
 921  
 
 922  
     public GradeRosterAssembler getGradeRosterAssembler() {
 923  0
         return gradeRosterAssembler;
 924  
     }
 925  
 
 926  
     public void setGradeRosterAssembler(GradeRosterAssembler gradeRosterAssembler) {
 927  0
         this.gradeRosterAssembler = gradeRosterAssembler;
 928  0
     }
 929  
 
 930  
     public GradeRosterEntryAssembler getGradeRosterEntryAssembler() {
 931  0
         return gradeRosterEntryAssembler;
 932  
     }
 933  
 
 934  
     public void setGradeRosterEntryAssembler(GradeRosterEntryAssembler gradeRosterEntryAssembler) {
 935  0
         this.gradeRosterEntryAssembler = gradeRosterEntryAssembler;
 936  0
     }
 937  
 
 938  
     public GradeValuesGroupAssembler getGradeValuesGroupAssembler() {
 939  0
         return gradeValuesGroupAssembler;
 940  
     }
 941  
 
 942  
     public void setGradeValuesGroupAssembler(GradeValuesGroupAssembler gradeValuesGroupAssembler) {
 943  0
         this.gradeValuesGroupAssembler = gradeValuesGroupAssembler;
 944  0
     }
 945  
 
 946  
     public CourseRegistrationService getCourseRegistrationService() {
 947  0
         return courseRegistrationService;
 948  
     }
 949  
 
 950  
     public void setCourseRegistrationService(CourseRegistrationService courseRegistrationService) {
 951  0
         this.courseRegistrationService = courseRegistrationService;
 952  0
     }
 953  
 }