Coverage Report - org.kuali.student.enrollment.class2.courseregistration.service.impl.CourseRegistrationServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseRegistrationServiceImpl
0%
0/1
N/A
0
 
 1  
 package org.kuali.student.enrollment.class2.courseregistration.service.impl;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.HashMap;
 5  
 import java.util.List;
 6  
 import java.util.Map;
 7  
 
 8  
 import org.apache.commons.lang.StringUtils;
 9  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 10  
 import org.kuali.rice.krms.api.engine.EngineResults;
 11  
 import org.kuali.student.common.util.krms.RulesExecutionConstants;
 12  
 import org.kuali.student.core.statement.dto.ReqComponentInfo;
 13  
 import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
 14  
 import org.kuali.student.core.statement.service.StatementService;
 15  
 import org.kuali.student.core.statement.util.PropositionBuilder;
 16  
 import org.kuali.student.core.statement.util.RulesEvaluationUtil;
 17  
 
 18  
 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
 19  
 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
 20  
 import org.kuali.student.enrollment.courseoffering.dto.RegistrationGroupInfo;
 21  
 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
 22  
 import org.kuali.student.enrollment.courseregistration.dto.ActivityRegistrationInfo;
 23  
 import org.kuali.student.enrollment.courseregistration.dto.CourseRegistrationInfo;
 24  
 import org.kuali.student.enrollment.courseregistration.dto.RegistrationRequestInfo;
 25  
 import org.kuali.student.enrollment.courseregistration.dto.RegistrationRequestItemInfo;
 26  
 import org.kuali.student.enrollment.courseregistration.dto.RegistrationResponseInfo;
 27  
 import org.kuali.student.enrollment.courseregistration.service.CourseRegistrationService;
 28  
 import org.kuali.student.enrollment.grading.dto.LoadInfo;
 29  
 import org.kuali.student.enrollment.lpr.dto.LprTransactionInfo;
 30  
 import org.kuali.student.enrollment.lpr.dto.LprTransactionItemInfo;
 31  
 import org.kuali.student.enrollment.lpr.dto.LprInfo;
 32  
 import org.kuali.student.enrollment.lpr.service.LprService;
 33  
 import org.kuali.student.enrollment.roster.dto.LprRosterEntryInfo;
 34  
 import org.kuali.student.enrollment.roster.dto.LprRosterInfo;
 35  
 import org.kuali.student.enrollment.roster.service.LprRosterService;
 36  
 import org.kuali.student.lum.course.service.CourseService;
 37  
 import org.kuali.student.r2.common.assembler.AssemblyException;
 38  
 import org.kuali.student.r2.common.dto.ContextInfo;
 39  
 import org.kuali.student.r2.common.dto.OperationStatusInfo;
 40  
 import org.kuali.student.r2.common.dto.StatusInfo;
 41  
 import org.kuali.student.r2.common.dto.ValidationResultInfo;
 42  
 import org.kuali.student.r2.common.exceptions.AlreadyExistsException;
 43  
 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
 44  
 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
 45  
 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
 46  
 import org.kuali.student.r2.common.exceptions.MissingParameterException;
 47  
 import org.kuali.student.r2.common.exceptions.OperationFailedException;
 48  
 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
 49  
 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
 50  
 import org.kuali.student.r2.common.exceptions.VersionMismatchException;
 51  
 import org.kuali.student.r2.common.infc.ValidationResult;
 52  
 import org.kuali.student.r2.common.util.constants.LprServiceConstants;
 53  
 import org.kuali.student.r2.common.util.constants.LrcServiceConstants;
 54  
 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
 55  
 
 56  
 import org.kuali.student.r2.core.process.service.ProcessService;
 57  
 import org.kuali.student.r2.lum.lrc.dto.ResultScaleInfo;
 58  
 import org.kuali.student.r2.lum.lrc.infc.ResultValuesGroup;
 59  
 import org.kuali.student.r2.lum.lrc.service.LRCService;
 60  
 
 61  
 
 62  0
 public class CourseRegistrationServiceImpl 
 63  
     extends AbstractCourseRegistrationService
 64  
     implements CourseRegistrationService {
 65  
 
 66  
     private LprService lprService;
 67  
     private LprRosterService lprRosterService;
 68  
     private CourseOfferingService courseOfferingService;
 69  
     /*    private RegRequestAssembler regRequestAssembler;
 70  
     private RegResponseAssembler regResponseAssembler;
 71  
     private CourseRegistrationAssembler courseRegistrationAssembler;*/
 72  
     private StatementService statementService;
 73  
     private CourseService courseService;
 74  
     private PropositionBuilder propositionBuilder;
 75  
     private RulesEvaluationUtil rulesEvaluationUtil;
 76  
     private ProcessService processService;
 77  
     private LRCService lrcService;
 78  
 
 79  
     /*************
 80  
      Core-slice code
 81  
 
 82  
     public ProcessService getProcessService() {
 83  
         return processService;
 84  
     }
 85  
 
 86  
     public void setProcessService(ProcessService processService) {
 87  
         this.processService = processService;
 88  
     }
 89  
 
 90  
     public LRCService getLrcService() {
 91  
         return lrcService;
 92  
     }
 93  
 
 94  
     public void setLrcService(LRCService lrcService) {
 95  
         this.lrcService = lrcService;
 96  
     }
 97  
 
 98  
     public LprService getLprService() {
 99  
         return lprService;
 100  
     }
 101  
 
 102  
     public void setLprService(LprService lprService) {
 103  
         this.lprService = lprService;
 104  
     }
 105  
 
 106  
     public CourseOfferingService getCourseOfferingService() {
 107  
         return courseOfferingService;
 108  
     }
 109  
 
 110  
     public void setCourseOfferingService(CourseOfferingService courseOfferingService) {
 111  
         this.courseOfferingService = courseOfferingService;
 112  
     }
 113  
 
 114  
     public RegRequestAssembler getRegRequestAssembler() {
 115  
         return regRequestAssembler;
 116  
     }
 117  
 
 118  
     public void setRegRequestAssembler(RegRequestAssembler regRequestAssembler) {
 119  
         this.regRequestAssembler = regRequestAssembler;
 120  
     }
 121  
 
 122  
     public RegResponseAssembler getRegResponseAssembler() {
 123  
         return regResponseAssembler;
 124  
     }
 125  
 
 126  
     public void setRegResponseAssembler(RegResponseAssembler regResponseAssembler) {
 127  
         this.regResponseAssembler = regResponseAssembler;
 128  
     }
 129  
 
 130  
     public CourseRegistrationAssembler getCourseRegistrationAssembler() {
 131  
         return courseRegistrationAssembler;
 132  
     }
 133  
 
 134  
     public void setCourseRegistrationAssembler(CourseRegistrationAssembler courseRegistrationAssembler) {
 135  
         this.courseRegistrationAssembler = courseRegistrationAssembler;
 136  
     }
 137  
 
 138  
     public StatementService getStatementService() {
 139  
         return statementService;
 140  
     }
 141  
 
 142  
     public void setStatementService(StatementService statementService) {
 143  
         this.statementService = statementService;
 144  
     }
 145  
 
 146  
     public CourseService getCourseService() {
 147  
         return courseService;
 148  
     }
 149  
 
 150  
     public void setCourseService(CourseService courseService) {
 151  
         this.courseService = courseService;
 152  
     }
 153  
 
 154  
     public PropositionBuilder getPropositionBuilder() {
 155  
         return propositionBuilder;
 156  
     }
 157  
 
 158  
     public void setPropositionBuilder(PropositionBuilder propositionBuilder) {
 159  
         this.propositionBuilder = propositionBuilder;
 160  
     }
 161  
 
 162  
     public RulesEvaluationUtil getRulesEvaluationUtil() {
 163  
         return rulesEvaluationUtil;
 164  
     }
 165  
 
 166  
     public void setRulesEvaluationUtil(RulesEvaluationUtil rulesEvaluationUtil) {
 167  
         this.rulesEvaluationUtil = rulesEvaluationUtil;
 168  
     }
 169  
 
 170  
     private List<LprTransactionItemInfo> createModifiedLprTransactionItemsForNew(RegRequestItemInfo regRequestItem, ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 171  
             MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException {
 172  
 
 173  
         List<LprTransactionItemInfo> newTransactionItems = new ArrayList<LprTransactionItemInfo>();
 174  
 
 175  
         String regGroupId = regRequestItem.getNewRegGroupId();
 176  
         RegistrationGroupInfo regGroup = courseOfferingService.getRegistrationGroup(regGroupId, context);
 177  
         LprTransactionItemInfo lprTransactionItem = regRequestAssembler.disassembleItem(regRequestItem, null, context);
 178  
         if (getAvailableSeatsForStudentInRegGroup(regRequestItem.getStudentId(), regGroupId, context) > 0) {
 179  
             List<LprTransactionItemInfo> lprActivityTransactionItems = new ArrayList<LprTransactionItemInfo>();
 180  
             for (String activityOfferingId : regGroup.getActivityOfferingIds()) {
 181  
                 LprTransactionItemInfo activtyItemInfo = regRequestAssembler.disassembleItem(regRequestItem, null, context);
 182  
                 activtyItemInfo.setId(null);
 183  
                 activtyItemInfo.setNewLuiId(activityOfferingId);
 184  
                 newTransactionItems.add(activtyItemInfo);
 185  
             }
 186  
 
 187  
             String courseOfferingId = regGroup.getCourseOfferingId();
 188  
             LprTransactionItemInfo courseOfferingItemInfo = regRequestAssembler.disassembleItem(regRequestItem, null, context);
 189  
             courseOfferingItemInfo.setNewLuiId(courseOfferingId);
 190  
             courseOfferingItemInfo.setId(null);
 191  
             ArrayList<String> rvgs = new ArrayList<String>();
 192  
             rvgs.add(LrcServiceConstants.RESULT_GROUP_KEY_GRADE_LETTER);
 193  
             courseOfferingItemInfo.setResultValuesGroupKeys(rvgs);
 194  
             newTransactionItems.add(courseOfferingItemInfo);
 195  
 
 196  
         } else {
 197  
             // TODO: copy the transaction item and change the type
 198  
             // of the new one to be ADD TO WAITLIST
 199  
             // and then on that item mark the original with a state
 200  
             // of failed
 201  
 
 202  
             lprTransactionItem.setTypeKey(LprServiceConstants.LPRTRANS_ITEM_ADD_TO_WAITLIST_TYPE_KEY);
 203  
             lprTransactionItem.setStateKey(LprServiceConstants.LPRTRANS_ITEM_NEW_STATE_KEY);
 204  
         }
 205  
         newTransactionItems.add(lprTransactionItem);
 206  
         return newTransactionItems;
 207  
 
 208  
     }
 209  
 
 210  
     private List<LprTransactionItemInfo> createModifiedLprTransactionItemsForDrop(RegRequestItemInfo regRequestItem, ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 211  
             MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException {
 212  
         List<LprTransactionItemInfo> newTransactionItems = new ArrayList<LprTransactionItemInfo>();
 213  
 
 214  
         String regGroupId = regRequestItem.getExistingRegGroupId();
 215  
         RegistrationGroupInfo regGroup = courseOfferingService.getRegistrationGroup(regGroupId, context);
 216  
         List<LprTransactionItemInfo> lprActivityTransactionItems = new ArrayList<LprTransactionItemInfo>();
 217  
         for (String activityOfferingId : regGroup.getActivityOfferingIds()) {
 218  
             LprTransactionItemInfo activtyItemInfo = regRequestAssembler.disassembleItem(regRequestItem, null, context);
 219  
             activtyItemInfo.setId(null);
 220  
             activtyItemInfo.setExistingLuiId(activityOfferingId);
 221  
 //            activtyItemInfo.setGroupId(regRequestItem.getId());
 222  
             newTransactionItems.add(activtyItemInfo);
 223  
 
 224  
         }
 225  
 
 226  
         String courseOfferingId = regGroup.getCourseOfferingId();
 227  
         LprTransactionItemInfo courseOfferingItemInfo = regRequestAssembler.disassembleItem(regRequestItem, null, context);
 228  
         courseOfferingItemInfo.setId(null);
 229  
         courseOfferingItemInfo.setExistingLuiId(courseOfferingId);
 230  
 //        courseOfferingItemInfo.setGroupId(regRequestItem.getId());
 231  
         lprActivityTransactionItems.add(courseOfferingItemInfo);
 232  
         newTransactionItems.add(courseOfferingItemInfo);
 233  
         // regRequestAssembler.disassembleItem(regRequestItem, null, context);
 234  
         return newTransactionItems;
 235  
 
 236  
     }
 237  
 
 238  
     private LprTransactionInfo createModifiedTransactionItems(LprTransactionInfo storedLprTransaction, RegRequestInfo storedRegRequest, ContextInfo context) throws DoesNotExistException,
 239  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, DataValidationErrorException, VersionMismatchException {
 240  
         List<LprTransactionItemInfo> newTransactionItems = new ArrayList<LprTransactionItemInfo>();
 241  
         List<RegRequestItemInfo> regRequestItems = storedRegRequest.getRegRequestItems();
 242  
         for (RegRequestItemInfo regRequestItem : regRequestItems) {
 243  
             if (regRequestItem.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_ADD_TYPE_KEY)
 244  
                     || regRequestItem.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_DROP_TYPE_KEY)
 245  
                     || regRequestItem.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_UPDATE_TYPE_KEY)) {
 246  
                 if (regRequestItem.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_ADD_TYPE_KEY)) {
 247  
 
 248  
                     newTransactionItems.addAll(createModifiedLprTransactionItemsForNew(regRequestItem, context));
 249  
 
 250  
                 } else if (regRequestItem.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_DROP_TYPE_KEY)) {
 251  
 
 252  
                     newTransactionItems.addAll(createModifiedLprTransactionItemsForDrop(regRequestItem, context));
 253  
                 }
 254  
 
 255  
             }
 256  
 
 257  
         }
 258  
         storedLprTransaction.setLprTransactionItems(newTransactionItems);
 259  
 
 260  
         storedLprTransaction = lprService.updateLprTransaction(storedLprTransaction.getId(), storedLprTransaction, context);
 261  
         return lprService.getLprTransaction(storedLprTransaction.getId(), context);
 262  
 
 263  
     }
 264  
 
 265  
     @Override
 266  
     public List<ValidationResultInfo> checkStudentEligibility(String studentId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 267  
             PermissionDeniedException {
 268  
 
 269  
 //        String matchingProcessKey = null;
 270  
 //        List<ProcessInfo> studentElgibilityProcesses = processService.getProcessesForProcessCategory(ProcessServiceConstants.PROCESS_CATEGORY_STUDENT_ELIGIBILITY, context);
 271  
 //
 272  
 //        for (ProcessInfo processInfo : studentElgibilityProcesses) {
 273  
 //            if (processInfo.getOwnerOrgId().equals(ProcessServiceConstants.PROCESS_OWNING_ORG_GRAD_SCHOOL)) {
 274  
 //                matchingProcessKey = processInfo.getKey();
 275  
 //                break;
 276  
 //            }
 277  
 //        }
 278  
 
 279  
         return null;
 280  
     }
 281  
 
 282  
     @Override
 283  
     public List<ValidationResultInfo> checkStudentEligibilityForTerm(String studentId, String termKey, ContextInfo context) throws InvalidParameterException, MissingParameterException,
 284  
             OperationFailedException, PermissionDeniedException {
 285  
         return null;
 286  
     }
 287  
 
 288  
     @Override
 289  
     public List<ValidationResultInfo> checkStudentEligibiltyForCourseOffering(String studentId, String courseOfferingId, ContextInfo context) throws InvalidParameterException,
 290  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 291  
 
 292  
         CourseOfferingInfo courseOffering = null;
 293  
         try {
 294  
             courseOffering = courseOfferingService.getCourseOffering(courseOfferingId, context);
 295  
         } catch (DoesNotExistException e) {
 296  
             throw new InvalidParameterException("Invalid courseOfferingId, no course offering found with id of: " + courseOfferingId);
 297  
         }
 298  
 
 299  
         List<StatementTreeViewInfo> statements;
 300  
 
 301  
         try {
 302  
             // TODO fill in nlUsageType and language parameters once the
 303  
             // implementation actually uses them
 304  
             statements = courseService.getCourseStatements(courseOffering.getCourseId(), null, null);
 305  
         } catch (Exception e) {
 306  
             throw new OperationFailedException(e.getMessage(), e);
 307  
         }
 308  
 
 309  
         List<ValidationResultInfo> resultInfos = new ArrayList<ValidationResultInfo>();
 310  
 
 311  
         // find and process statements that the PropositionBuilder can handle
 312  
         for (StatementTreeViewInfo statementTree : statements) {
 313  
             if (PropositionBuilder.TRANSLATABLE_STATEMENT_TYPES.contains(statementTree.getType())) {
 314  
                 PropositionBuilder.TranslationResults translationResults = null;
 315  
                 try {
 316  
                     translationResults = propositionBuilder.translateStatement(statementTree, null);
 317  
                 } catch (org.kuali.student.common.exceptions.InvalidParameterException e) {
 318  
                     throw new OperationFailedException("Exception thrown attempting statement translation for statement: " + statementTree.getId(), e);
 319  
                 }
 320  
 
 321  
                 Map<String, Object> executionFacts = new HashMap<String, Object>();
 322  
                 executionFacts.put(RulesExecutionConstants.STUDENT_ID_TERM_NAME, studentId);
 323  
                 executionFacts.put(RulesExecutionConstants.COURSE_ID_TO_ENROLL_TERM_NAME, courseOffering.getCourseId());
 324  
                 executionFacts.put(RulesExecutionConstants.CONTEXT_INFO_TERM_NAME, context);
 325  
 
 326  
                 EngineResults engineResults = rulesEvaluationUtil.executeAgenda(translationResults.agenda, executionFacts);
 327  
 
 328  
                 List<ReqComponentInfo> failedRequirements = rulesEvaluationUtil.getFailedRequirementsFromEngineResults(engineResults, translationResults.reqComponentPropositionMap);
 329  
 
 330  
                 if (!failedRequirements.isEmpty()) {
 331  
                     for (ReqComponentInfo failedRequirement : failedRequirements) {
 332  
                         ValidationResultInfo resultInfo = new ValidationResultInfo();
 333  
                         resultInfo.setLevel(ValidationResult.ErrorLevel.ERROR);
 334  
                         resultInfo.setElement(failedRequirement.getId());
 335  
                         try {
 336  
                             resultInfo.setMessage(statementService.getNaturalLanguageForReqComponent(failedRequirement.getId(), "KUALI.RULE", "en"));
 337  
                         } catch (Exception e) {
 338  
                             throw new OperationFailedException(e.getMessage(), e);
 339  
                         }
 340  
 
 341  
                         resultInfos.add(resultInfo);
 342  
                     }
 343  
                 }
 344  
             }
 345  
         }
 346  
 
 347  
         if (resultInfos.isEmpty()) {
 348  
             ValidationResultInfo resultInfo = new ValidationResultInfo();
 349  
             resultInfo.setLevel(ValidationResult.ErrorLevel.OK);
 350  
 
 351  
             resultInfos.add(resultInfo);
 352  
         }
 353  
 
 354  
         return resultInfos;
 355  
     }
 356  
 
 357  
     @Override
 358  
     public List<org.kuali.student.r2.common.dto.ValidationResultInfo> checkStudentEligibiltyForRegGroup(String studentId, String regGroupId, ContextInfo context) throws InvalidParameterException,
 359  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 360  
         // TODO sambit - THIS METHOD NEEDS JAVADOCS
 361  
         return null;
 362  
     }
 363  
 
 364  
     @Override
 365  
     public List<RegistrationGroupInfo> getEligibleRegGroupsForStudentInCourseOffering(String studentId, String courseOfferingId, ContextInfo context) throws InvalidParameterException,
 366  
             MissingParameterException, OperationFailedException, PermissionDeniedException {
 367  
         // TODO sambit - THIS METHOD NEEDS JAVADOCS
 368  
         return null;
 369  
     }
 370  
 
 371  
     @Override
 372  
     public LoadInfo calculateCreditLoadForTerm(String studentId, String termKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 373  
             PermissionDeniedException {
 374  
         // TODO sambit - THIS METHOD NEEDS JAVADOCS
 375  
         return null;
 376  
     }
 377  
 
 378  
     @Override
 379  
     public LoadInfo calculateCreditLoadForRegRequest(String studentId, RegRequestInfo regRequestInfo, ContextInfo context) throws InvalidParameterException, MissingParameterException,
 380  
             OperationFailedException, PermissionDeniedException {
 381  
         // TODO sambit - THIS METHOD NEEDS JAVADOCS
 382  
         return null;
 383  
     }
 384  
 
 385  
     @Override
 386  
     public Integer getAvailableSeatsForCourseOffering(String courseOfferingId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 387  
             PermissionDeniedException {
 388  
         // TODO sambit - THIS METHOD NEEDS JAVADOCS
 389  
         return null;
 390  
     }
 391  
 
 392  
     @Override
 393  
     public Integer getAvailableSeatsForRegGroup(String regGroupId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException,
 394  
             PermissionDeniedException {
 395  
         // TODO sambit - THIS METHOD NEEDS JAVADOCS
 396  
         return null;
 397  
     }
 398  
 
 399  
     @Override
 400  
     public Integer getAvailableSeatsForStudentInRegGroup(String studentId, String regGroupId, ContextInfo context) throws InvalidParameterException, MissingParameterException,
 401  
             OperationFailedException, PermissionDeniedException {
 402  
         // TODO - rules and waitlist implementation needed
 403  
         return new Integer(3);
 404  
 
 405  
     }
 406  
 
 407  
     @Override
 408  
     public Integer getAvailableSeatsInSeatPool(String seatpoolId, ContextInfo context) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 409  
         // TODO sambit - THIS METHOD NEEDS JAVADOCS
 410  
         return null;
 411  
     }
 412  
 
 413  
     @Override
 414  
     public RegRequestInfo updateRegRequest(String regRequestId, RegRequestInfo regRequestInfo, ContextInfo context) throws DataValidationErrorException, DoesNotExistException,
 415  
             InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException {
 416  
         RegRequestInfo rrInfo;
 417  
         try {
 418  
             LprTransactionInfo lprTransactionInfo = regRequestAssembler.disassemble(regRequestInfo, context);
 419  
             rrInfo = regRequestAssembler.assemble(lprService.updateLprTransaction(regRequestId, lprTransactionInfo, context), context);
 420  
         } catch (AssemblyException e) {
 421  
             throw new OperationFailedException("AssemblyException : " + e.getMessage());
 422  
         }
 423  
 
 424  
         return rrInfo;
 425  
     }
 426  
 
 427  
     @Override
 428  
     public StatusInfo deleteRegRequest(String regRequestId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 429  
             PermissionDeniedException {
 430  
         return lprService.deleteLprTransaction(regRequestId, context);
 431  
     }
 432  
 
 433  
   
 434  
 
 435  
     @Override
 436  
         public RegRequestInfo createRegRequest(String regRequestTypeKey,
 437  
                         RegRequestInfo regRequestInfo, ContextInfo context)
 438  
                         throws AlreadyExistsException, DoesNotExistException, DataValidationErrorException,
 439  
                         InvalidParameterException, MissingParameterException,
 440  
                         OperationFailedException, PermissionDeniedException,
 441  
                         ReadOnlyException {
 442  
         LprTransactionInfo lprTransaction = null;
 443  
         try {
 444  
             lprTransaction = regRequestAssembler.disassemble(regRequestInfo, context);
 445  
         } catch (AssemblyException e) {
 446  
             throw new OperationFailedException("AssemblyException in disassembling: " + e.getMessage());
 447  
         }
 448  
 
 449  
         LprTransactionInfo newLprTransaction = lprService.createLprTransaction(lprTransaction.getTypeKey(), lprTransaction, context);
 450  
         try {
 451  
             newLprTransaction = lprService.getLprTransaction(newLprTransaction.getId(), context);
 452  
         } catch (DoesNotExistException e) {
 453  
             return null;
 454  
         }
 455  
 
 456  
         RegRequestInfo createdRegRequestInfo = null;
 457  
         try {
 458  
             createdRegRequestInfo = regRequestAssembler.assemble(newLprTransaction, context);
 459  
         } catch (AssemblyException e) {
 460  
             throw new OperationFailedException("AssemblyException in assembling: " + e.getMessage());
 461  
         }
 462  
 
 463  
         return createdRegRequestInfo;
 464  
     }
 465  
 
 466  
     @Override
 467  
     public RegRequestInfo createRegRequestFromExisting(String existingRegRequestId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 468  
             OperationFailedException, DataValidationErrorException, PermissionDeniedException {
 469  
 
 470  
         LprTransactionInfo newLprTransaction = lprService.createLprTransactionFromExisting(existingRegRequestId, context);
 471  
         RegRequestInfo createdRegRequestInfo = null;
 472  
         try {
 473  
             createdRegRequestInfo = regRequestAssembler.assemble(newLprTransaction, context);
 474  
         } catch (AssemblyException e) {
 475  
             throw new OperationFailedException("AssemblyException in assembling: " + e.getMessage());
 476  
         }
 477  
         return createdRegRequestInfo;
 478  
     }
 479  
 
 480  
     @Override
 481  
     public RegResponseInfo submitRegRequest(String regRequestId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 482  
             OperationFailedException, PermissionDeniedException, AlreadyExistsException {
 483  
         LprTransactionInfo storedLprTransaction = lprService.getLprTransaction(regRequestId, context);
 484  
 
 485  
         RegRequestInfo storedRegRequest = null;
 486  
         try {
 487  
             storedRegRequest = regRequestAssembler.assemble(storedLprTransaction, context);
 488  
         } catch (AssemblyException e) {
 489  
             throw new OperationFailedException("AssemblyException in assembling: " + e.getMessage());
 490  
         }
 491  
 
 492  
         try {
 493  
            
 494  
             List<ValidationResultInfo> verificationResultList = verifyRegRequestForSubmission(regRequestId, context);
 495  
             for (ValidationResultInfo verificationResult : verificationResultList) {
 496  
                 if (!verificationResult.isOk()) {
 497  
                     throw new DataValidationErrorException("Error while verifying registration request: " + verificationResult.getMessage());
 498  
                 }
 499  
             }
 500  
         } catch (DataValidationErrorException dataValidException) {
 501  
             throw new OperationFailedException(dataValidException.getMessage(), dataValidException);
 502  
         }
 503  
 
 504  
         // check eligibility requirements
 505  
         for (RegRequestItemInfo item : storedRegRequest.getRegRequestItems()) {
 506  
             if (!StringUtils.equals(LprServiceConstants.LPRTRANS_ITEM_DROP_TYPE_KEY, item.getTypeKey())) {
 507  
                 RegistrationGroupInfo regGroup = courseOfferingService.getRegistrationGroup(item.getNewRegGroupId(), context);
 508  
 
 509  
                 List<ValidationResultInfo> validations = checkStudentEligibiltyForCourseOffering(storedLprTransaction.getRequestingPersonId(), regGroup.getCourseOfferingId(), context);
 510  
                 List<String> errorMessages = new ArrayList<String>();
 511  
                 for (ValidationResultInfo validation : validations) {
 512  
                     if (validation.isError()) {
 513  
                         errorMessages.add(validation.getMessage());
 514  
                     }
 515  
                 }
 516  
 
 517  
                 if (!errorMessages.isEmpty()) {
 518  
                     RegResponseInfo errorResponse = new RegResponseInfo();
 519  
                     errorResponse.setOperationStatus(new OperationStatusInfo());
 520  
                     errorResponse.getOperationStatus().setErrors(errorMessages);
 521  
                     errorResponse.getOperationStatus().setStatus("FAILURE");
 522  
 
 523  
                     return errorResponse;
 524  
                 }
 525  
             }
 526  
         }
 527  
 
 528  
         LprTransactionInfo multipleItemsTransaction;
 529  
                 try {
 530  
                         multipleItemsTransaction = createModifiedTransactionItems(storedLprTransaction, storedRegRequest, context);
 531  
                 } catch (DataValidationErrorException dataValidException) {
 532  
                          throw new OperationFailedException(dataValidException.getMessage(), dataValidException);
 533  
                 }catch (VersionMismatchException ex) {
 534  
                          throw new OperationFailedException(ex.getMessage(), ex);
 535  
                 }
 536  
 
 537  
         LprTransactionInfo submittedLprTransaction = lprService.processLprTransaction(multipleItemsTransaction.getId(), context);
 538  
 
 539  
         RegResponseInfo returnRegResponse = null;
 540  
         try {
 541  
             returnRegResponse = regResponseAssembler.assemble(submittedLprTransaction, context);
 542  
         } catch (AssemblyException e) {
 543  
             throw new OperationFailedException("AssemblyException in assembling: " + e.getMessage());
 544  
         }
 545  
 
 546  
         if (checkSuccessfulRegCriteria(returnRegResponse)) {
 547  
 
 548  
             try {
 549  
                 createGradeRosterEntryForRegisteredStudent(submittedLprTransaction, context);
 550  
             } catch (DataValidationErrorException dataValidException) {
 551  
                 throw new OperationFailedException(dataValidException.getMessage(), dataValidException);
 552  
             }catch (ReadOnlyException dataValidException) {
 553  
                 throw new OperationFailedException(dataValidException.getMessage(), dataValidException);
 554  
             }
 555  
 
 556  
         }
 557  
 
 558  
         return returnRegResponse;
 559  
 
 560  
     }
 561  
 
 562  
     private boolean checkSuccessfulRegCriteria(RegResponseInfo returnRegResponse) {
 563  
         return true;
 564  
     }
 565  
 
 566  
     private void createGradeRosterEntryForRegisteredStudent(LprTransactionInfo submittedLprTransaction, ContextInfo context) throws DataValidationErrorException, AlreadyExistsException,
 567  
             InvalidParameterException, MissingParameterException, DoesNotExistException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
 568  
 
 569  
         // TODO: since we're creating at a minimum 3 lprs per course reg we
 570  
         // shouldn't loop through all of them. need a way to get directly to the
 571  
         // grade roster
 572  
         for (LprTransactionItemInfo lprItem : submittedLprTransaction.getLprTransactionItems()) {
 573  
             if (lprItem.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_ADD_TYPE_KEY)) {
 574  
                 LprRosterEntryInfo newLprRosterEntry = new LprRosterEntryInfo();
 575  
                 newLprRosterEntry.setLprId(lprItem.getLprTransactionItemResult().getResultingLprId());
 576  
                 newLprRosterEntry.setTypeKey(LprServiceConstants.LPRROSTER_COURSE_FINAL_GRADE_TYPE_KEY);
 577  
                 newLprRosterEntry.setStateKey(LprServiceConstants.LPRROSTER_COURSE_FINAL_GRADEROSTER_READY_STATE_KEY);
 578  
 
 579  
                 List<LprRosterInfo> lprRosters = lprRosterService.getLprRostersByTypeAndLui(LprServiceConstants.LPRROSTER_COURSE_FINAL_GRADEROSTER_TYPE_KEY, 
 580  
                         lprItem.getNewLuiId(), context);
 581  
                 if (lprRosters.size() == 1) {
 582  
                     newLprRosterEntry.setLprRosterId(lprRosters.get(0).getId());
 583  
                     lprRosterService.createLprRosterEntry(
 584  
                             newLprRosterEntry.getLprRosterId(),
 585  
                             newLprRosterEntry.getLprId(), 
 586  
                             newLprRosterEntry.getTypeKey(),
 587  
                             newLprRosterEntry, context);
 588  
                 }
 589  
 
 590  
             }
 591  
 
 592  
         }
 593  
 
 594  
     }
 595  
 
 596  
     @Override
 597  
     public CourseRegistrationInfo getCourseRegistration(String courseRegistrationId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 598  
             OperationFailedException, PermissionDeniedException {
 599  
         return new CourseRegistrationInfo();
 600  
 
 601  
     }
 602  
 
 603  
     @Override
 604  
         public List<CourseRegistrationInfo> getCourseRegistrationsByIds(
 605  
                         List<String> courseRegistrationIds, ContextInfo context)
 606  
                         throws DoesNotExistException, InvalidParameterException,
 607  
                         MissingParameterException, OperationFailedException,
 608  
                         PermissionDeniedException {
 609  
             
 610  
              List<CourseRegistrationInfo> courseRegistrationInfos = new ArrayList<CourseRegistrationInfo>();
 611  
        ResultValuesGroup rvGroup = null;
 612  
        List<LprInfo> lprs = lprService.getLprsByIds(courseRegistrationIds, context);
 613  
        for (LprInfo lpr : lprs) {
 614  
            for (String rvGroupKey : lpr.getResultValuesGroupKeys()) {
 615  
                rvGroup = lrcService.getResultValuesGroup(rvGroupKey, context);
 616  
                if (rvGroup != null) {
 617  
                    ResultScaleInfo resScale = lrcService.getResultScale(rvGroup.getResultScaleKey(), context);
 618  
                    if (resScale != null) {
 619  
                        if (StringUtils.equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED, resScale.getTypeKey())) {
 620  
                            courseRegistrationInfos.add(courseRegistrationAssembler.assemble(lpr, rvGroup, context));
 621  
                            break;
 622  
                        }
 623  
                    }
 624  
                }
 625  
 
 626  
            }
 627  
        }
 628  
 
 629  
        return courseRegistrationInfos;
 630  
         }
 631  
 
 632  
         // TODO - post core slice need to ensure that the list has one
 633  
     private List<LprInfo> filterLprByState(List<LprInfo> lprInfoList, String stateKey) {
 634  
         List<LprInfo> filteredLprInfoList = new ArrayList<LprInfo>();
 635  
         for (LprInfo lprInfo : filteredLprInfoList) {
 636  
             if (lprInfo.getStateKey().equals(stateKey)) {
 637  
                 filteredLprInfoList.add(lprInfo);
 638  
             }
 639  
         }
 640  
         return filteredLprInfoList;
 641  
     }
 642  
 
 643  
    
 644  
 
 645  
     @Override
 646  
     public List<CourseRegistrationInfo> getCourseRegistrationsByStudentAndTerm(String studentId, String termKey, ContextInfo context) throws DoesNotExistException, InvalidParameterException,
 647  
                                                                                                                                              MissingParameterException, OperationFailedException, PermissionDeniedException {
 648  
 
 649  
         List<CourseRegistrationInfo> courseRegistrationList = new ArrayList<CourseRegistrationInfo>();
 650  
 
 651  
         List<LprInfo> courseLprList = lprService.getLprsByPersonForAtpAndLuiType(studentId, termKey, LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, context);
 652  
 
 653  
         List<LprInfo> regGroupLprList = lprService.getLprsByPersonForAtpAndLuiType(studentId, termKey, LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY, context);
 654  
 
 655  
         getCourseRegistration(studentId, courseRegistrationList, courseLprList, regGroupLprList, context);
 656  
 
 657  
         return courseRegistrationList;
 658  
     }
 659  
 
 660  
     private void getCourseRegistration(String studentId, List<CourseRegistrationInfo> courseRegistrationList, List<LprInfo> courseLprList, List<LprInfo> regGroupLprList,
 661  
                                        ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
 662  
         if (courseLprList != null && !courseLprList.isEmpty()) {
 663  
             for (LprInfo courseOfferinglprInfo : courseLprList) {
 664  
 
 665  
                 if (courseOfferinglprInfo.getTypeKey().equals(LprServiceConstants.REGISTRANT_TYPE_KEY)) {
 666  
                     CourseOfferingInfo courseOfferingInfo = courseOfferingService.getCourseOffering(courseOfferinglprInfo.getLuiId(), context);
 667  
 
 668  
                     List<RegistrationGroupInfo> regGroupList = courseOfferingService.getRegistrationGroupsForCourseOffering(courseOfferinglprInfo.getLuiId(), context);
 669  
 
 670  
                     for (RegistrationGroupInfo regGroup : regGroupList) {
 671  
 
 672  
                         RegistrationGroupInfo reg = new RegistrationGroupInfo();
 673  
 
 674  
                         Map<LprInfo, ActivityOfferingInfo> activtiesLprInfoMap = new HashMap<LprInfo, ActivityOfferingInfo>();
 675  
 
 676  
                         for (LprInfo regGroupLprInfo : regGroupLprList) {
 677  
 
 678  
                             if (regGroup.getId().equals(regGroupLprInfo.getLuiId()) && regGroupLprInfo.getTypeKey().equals(LprServiceConstants.REGISTRANT_TYPE_KEY)) {
 679  
 
 680  
                                 reg = courseOfferingService.getRegistrationGroup(regGroup.getId(), context);
 681  
 
 682  
                                 for (String activityOfferingId : regGroup.getActivityOfferingIds()) {
 683  
 
 684  
                                     List<LprInfo> lprsForActivity = lprService.getLprsByPersonAndLui(studentId, activityOfferingId, context);
 685  
 
 686  
                                     for (LprInfo activityLpr : lprsForActivity) {
 687  
 
 688  
                                         if (activityLpr.getTypeKey().equals(LprServiceConstants.REGISTRANT_TYPE_KEY) && activityLpr.getStateKey().equals(regGroupLprInfo.getStateKey())) {
 689  
 
 690  
                                             ActivityOfferingInfo activityOffering = courseOfferingService.getActivityOffering(activityOfferingId, context);
 691  
 
 692  
                                             activtiesLprInfoMap.put(activityLpr, activityOffering);
 693  
                                         }
 694  
                                     }
 695  
 
 696  
                                 }
 697  
 
 698  
                                 courseRegistrationList.add(courseRegistrationAssembler.assemble(courseOfferinglprInfo, courseOfferingInfo, activtiesLprInfoMap, regGroupLprInfo, reg, context));
 699  
                             }
 700  
 
 701  
                         }
 702  
 
 703  
                     }
 704  
                 }
 705  
 
 706  
             }
 707  
         }
 708  
     }
 709  
 
 710  
     
 711  
     @Override
 712  
     public List<RegRequestItemInfo> getRegRequestItemsByCourseRegistration(
 713  
             String courseRegistrationId, ContextInfo context)
 714  
             throws DoesNotExistException, InvalidParameterException,
 715  
             MissingParameterException, OperationFailedException,
 716  
             PermissionDeniedException {
 717  
 
 718  
         List<RegRequestItemInfo> regrequests = new ArrayList<RegRequestItemInfo>();
 719  
         List<LprTransactionItemInfo> lprTransactionItems = lprService.getLprTransactionItemsByResultingLpr(
 720  
                 courseRegistrationId, context);
 721  
         for (LprTransactionItemInfo lprTransactionItem : lprTransactionItems) {
 722  
             regrequests.add(regRequestAssembler.assembleItem(
 723  
                     lprTransactionItem, context));
 724  
         }
 725  
         return regrequests;
 726  
     }
 727  
 
 728  
   
 729  
 
 730  
 
 731  
     @Override
 732  
     public RegRequestInfo getRegRequest(String regRequestId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException,
 733  
             PermissionDeniedException {
 734  
         LprTransactionInfo lprTransaction = lprService.getLprTransaction(regRequestId, context);
 735  
         RegRequestInfo regRequest = null;
 736  
         try {
 737  
             regRequest = regRequestAssembler.assemble(lprTransaction, context);
 738  
         } catch (AssemblyException e) {
 739  
             throw new OperationFailedException("AssemblyException in assembling: " + e.getMessage());
 740  
         }
 741  
         return regRequest;
 742  
     }
 743  
    
 744  
     @Override
 745  
     public List<CourseRegistrationInfo> getCourseRegistrationsByStudent(String studentId, ContextInfo context) throws DoesNotExistException, InvalidParameterException, MissingParameterException,
 746  
                                                                                                                       OperationFailedException, PermissionDeniedException {
 747  
         List<CourseRegistrationInfo> courseRegistrationList = new ArrayList<CourseRegistrationInfo>();
 748  
 
 749  
         List<LprInfo> courseLprList = lprService.getLprsByPersonAndLuiType(studentId, LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, context);
 750  
 
 751  
         List<LprInfo> regGroupLprList = lprService.getLprsByPersonAndLuiType(studentId, LuiServiceConstants.REGISTRATION_GROUP_TYPE_KEY, context);
 752  
 
 753  
         getCourseRegistration(studentId, courseRegistrationList, courseLprList, regGroupLprList, context);
 754  
 
 755  
         return courseRegistrationList;
 756  
     }
 757  
 
 758  
         @Override
 759  
         public List<ValidationResultInfo> verifyRegRequestForSubmission(
 760  
                         String regRequestId, ContextInfo context)
 761  
                         throws DataValidationErrorException, InvalidParameterException,
 762  
                         MissingParameterException, OperationFailedException,
 763  
                         PermissionDeniedException {
 764  
                 // TODO Auto-generated method stub
 765  
                 return null;
 766  
         }
 767  
 
 768  
         @Override
 769  
         public List<ValidationResultInfo> validateRegRequest(
 770  
                         String validationTypeKey, String regRequestTypeKey,
 771  
                         RegRequestInfo regRequestInfo, ContextInfo context)
 772  
                         throws DataValidationErrorException, InvalidParameterException,
 773  
                         MissingParameterException, OperationFailedException,
 774  
                         PermissionDeniedException {
 775  
                 // TODO Auto-generated method stub
 776  
                 return null;
 777  
         }
 778  
 
 779  
         @Override
 780  
         public List<RegRequestInfo> getRegRequestsByIds(List<String> regRequestIds,
 781  
                         ContextInfo context) throws DoesNotExistException,
 782  
                         InvalidParameterException, MissingParameterException,
 783  
                         OperationFailedException, PermissionDeniedException {
 784  
                 // TODO Auto-generated method stub
 785  
                 return null;
 786  
         }
 787  
 
 788  
         @Override
 789  
         public List<RegRequestInfo> getUnsubmittedRegRequestsByRequestorAndTerm(
 790  
                         String requestorId, String termId, ContextInfo context)
 791  
                         throws InvalidParameterException, MissingParameterException,
 792  
                         OperationFailedException, PermissionDeniedException {
 793  
                 // TODO Auto-generated method stub
 794  
                 return null;
 795  
         }
 796  
 
 797  
         @Override
 798  
         public List<String> getCourseRegistrationIdsByType(
 799  
                         String courseRegistrationTypeKey, ContextInfo context)
 800  
                         throws InvalidParameterException, MissingParameterException,
 801  
                         OperationFailedException, PermissionDeniedException {
 802  
                 // TODO Auto-generated method stub
 803  
                 return null;
 804  
         }
 805  
 
 806  
         @Override
 807  
         public List<CourseRegistrationInfo> getCourseRegistrationsByStudentAndCourseOffering(
 808  
                         String studentId, String courseOfferingId, ContextInfo context)
 809  
                         throws InvalidParameterException, MissingParameterException,
 810  
                                OperationFailedException, PermissionDeniedException {
 811  
                 // TODO Auto-generated method stub
 812  
                 return null;
 813  
         }
 814  
 
 815  
         
 816  
 
 817  
         @Override
 818  
         public List<CourseRegistrationInfo> getCourseRegistrationsByCourseOffering(
 819  
                         String courseOfferingId, ContextInfo context)
 820  
                         throws DoesNotExistException, InvalidParameterException,
 821  
                         MissingParameterException, OperationFailedException,
 822  
                         PermissionDeniedException {
 823  
                 // TODO Auto-generated method stub
 824  
                 return null;
 825  
         }
 826  
 
 827  
         @Override
 828  
         public List<CourseRegistrationInfo> searchForCourseRegistrations(
 829  
                         QueryByCriteria criteria, ContextInfo context)
 830  
                         throws InvalidParameterException, MissingParameterException,
 831  
                         OperationFailedException, PermissionDeniedException {
 832  
                 // TODO Auto-generated method stub
 833  
                 return null;
 834  
         }
 835  
 
 836  
         @Override
 837  
         public List<RegRequestItemInfo> getRegRequestItemsByCourseOfferingAndStudent(
 838  
                         String courseOfferingId, String studentId, ContextInfo context)
 839  
                         throws DoesNotExistException, InvalidParameterException,
 840  
                         MissingParameterException, OperationFailedException,
 841  
                         PermissionDeniedException {
 842  
                 // TODO Auto-generated method stub
 843  
                 return null;
 844  
         }
 845  
 
 846  
         @Override
 847  
         public List<String> searchForCourseRegistrationIds(
 848  
                         QueryByCriteria criteria, ContextInfo context)
 849  
                         throws InvalidParameterException, MissingParameterException,
 850  
                         OperationFailedException, PermissionDeniedException {
 851  
                 // TODO Auto-generated method stub
 852  
                 return null;
 853  
         }
 854  
 
 855  
         @Override
 856  
         public List<ActivityRegistrationInfo> searchForActivityRegistrations(
 857  
                         QueryByCriteria criteria, ContextInfo context)
 858  
                         throws InvalidParameterException, MissingParameterException,
 859  
                         OperationFailedException, PermissionDeniedException {
 860  
                 // TODO Auto-generated method stub
 861  
                 return null;
 862  
         }
 863  
 
 864  
         @Override
 865  
         public List<String> searchForActivityRegistrationIds(
 866  
                         QueryByCriteria criteria, ContextInfo context)
 867  
                         throws InvalidParameterException, MissingParameterException,
 868  
                         OperationFailedException, PermissionDeniedException {
 869  
                 // TODO Auto-generated method stub
 870  
                 return null;
 871  
         }
 872  
     **********/
 873  
 }