Coverage Report - org.kuali.student.lum.lu.ui.course.server.gwt.CourseRpcGwtServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseRpcGwtServlet
0%
0/55
0%
0/23
2.154
CourseRpcGwtServlet$1
0%
0/1
N/A
2.154
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.lum.lu.ui.course.server.gwt;
 17  
 
 18  
 import java.util.Date;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.kuali.student.common.dto.StatusInfo;
 24  
 import org.kuali.student.common.ui.client.service.DataSaveResult;
 25  
 import org.kuali.student.common.ui.server.gwt.DataGwtServlet;
 26  
 import org.kuali.student.core.statement.dto.ReqComponentInfo;
 27  
 import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
 28  
 import org.kuali.student.core.statement.service.StatementService;
 29  
 import org.kuali.student.core.statement.ui.client.widgets.rules.ReqComponentInfoUi;
 30  
 import org.kuali.student.core.statement.ui.client.widgets.rules.RulesUtil;
 31  
 import org.kuali.student.lum.common.server.StatementUtil;
 32  
 import org.kuali.student.lum.course.service.CourseService;
 33  
 import org.kuali.student.lum.lu.ui.course.client.requirements.CourseRequirementsDataModel;
 34  
 import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService;
 35  
 
 36  0
 public class CourseRpcGwtServlet extends DataGwtServlet implements CourseRpcService {
 37  
 
 38  
         private static final long serialVersionUID = 1L;
 39  
 
 40  
     private CourseService courseService;
 41  
         private StatementService statementService;
 42  
         private CourseStateChangeServiceImpl stateChangeService;
 43  
 
 44  
     @Override
 45  
     public List<StatementTreeViewInfo> getCourseStatements(String courseId, String nlUsageTypeKey, String language) throws Exception {
 46  0
         List<StatementTreeViewInfo> rules = courseService.getCourseStatements(courseId, nlUsageTypeKey, language);
 47  0
         if (rules != null) {
 48  0
                 for (StatementTreeViewInfo rule : rules) {
 49  0
                         setReqCompNL(rule);
 50  
                 }
 51  
         }
 52  0
         return rules;
 53  
     }
 54  
 
 55  
     public Map<Integer, StatementTreeViewInfo> storeCourseStatements(String courseId, String courseState, Map<Integer, CourseRequirementsDataModel.requirementState> states,
 56  
                                                                         Map<Integer, StatementTreeViewInfo> rules) throws Exception {
 57  
 
 58  0
         Map<Integer, StatementTreeViewInfo> storedRules = new HashMap<Integer, StatementTreeViewInfo>();
 59  
 
 60  0
         for (Integer key : rules.keySet()) {
 61  0
             StatementTreeViewInfo rule = rules.get(key);
 62  0
             switch (states.get(key)) {
 63  
                 case STORED:
 64  
                     //rule was not changed so continue
 65  0
                     storedRules.put(key, null);
 66  0
                     break;
 67  
                 case ADDED:
 68  0
                     storedRules.put(key, createCourseStatement(courseId, courseState, rule));
 69  0
                     break;
 70  
                 case EDITED:
 71  0
                     storedRules.put(key, updateCourseStatement(courseId, courseState, rule));
 72  0
                     break;
 73  
                 case DELETED:
 74  0
                     storedRules.put(key, null);
 75  0
                     deleteCourseStatement(courseId, rule);
 76  0
                     break;
 77  
                 default:
 78  0
                     break;
 79  
             }
 80  0
         }
 81  0
         return storedRules;
 82  
     }
 83  
 
 84  
     @Override
 85  
     public StatementTreeViewInfo createCourseStatement(String courseId, String courseState, StatementTreeViewInfo statementTreeViewInfo) throws Exception {
 86  0
             StatementUtil.updateStatementTreeViewInfoState(courseState, statementTreeViewInfo);
 87  0
             CourseRequirementsDataModel.stripStatementIds(statementTreeViewInfo);
 88  0
         StatementTreeViewInfo rule = courseService.createCourseStatement(courseId, statementTreeViewInfo);
 89  0
         setReqCompNL(rule);
 90  0
         return rule;
 91  
     }
 92  
 
 93  
     @Override
 94  
     public StatusInfo deleteCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo) throws Exception {
 95  0
         return courseService.deleteCourseStatement(courseId, statementTreeViewInfo);
 96  
     }
 97  
 
 98  
     @Override
 99  
     public StatementTreeViewInfo updateCourseStatement(String courseId, String courseState, StatementTreeViewInfo statementTreeViewInfo) throws Exception {
 100  0
             StatementUtil.updateStatementTreeViewInfoState(courseState, statementTreeViewInfo);
 101  0
             CourseRequirementsDataModel.stripStatementIds(statementTreeViewInfo);
 102  0
         StatementTreeViewInfo rule = courseService.updateCourseStatement(courseId, statementTreeViewInfo);
 103  0
         setReqCompNL(rule);
 104  0
         return rule;
 105  
     }
 106  
 
 107  
         @Override
 108  
         public DataSaveResult createCopyCourse(String originalCluId)
 109  
                         throws Exception {
 110  0
                 throw new UnsupportedOperationException("Copy is not implemented without a proposal.");
 111  
         }
 112  
 
 113  
         @Override
 114  
         public DataSaveResult createCopyCourseProposal(String originalProposalId)
 115  
                         throws Exception {
 116  0
                 throw new UnsupportedOperationException("Copy is not implemented without a proposal.");
 117  
         }
 118  
 
 119  
     
 120  
     public StatusInfo changeState(String courseId, String newState) throws Exception {
 121  0
             return changeState(courseId, newState, null);
 122  
     }
 123  
 
 124  
     public StatusInfo changeState(String courseId, String newState, Date currentVersionStart) throws Exception {
 125  0
             return stateChangeService.changeState(courseId, newState, currentVersionStart);
 126  
     }
 127  
 
 128  
     private void setReqCompNL(StatementTreeViewInfo tree) throws Exception {
 129  0
         List<StatementTreeViewInfo> statements = tree.getStatements();
 130  0
         List<ReqComponentInfo> reqComponentInfos = tree.getReqComponents();
 131  
 
 132  0
          if ((statements != null) && (statements.size() > 0)) {
 133  
             // retrieve all statements
 134  0
             for (StatementTreeViewInfo statement : statements) {
 135  0
                 setReqCompNL(statement); // inside set the children of this statementTreeViewInfo
 136  
             }
 137  0
         } else if ((reqComponentInfos != null) && (reqComponentInfos.size() > 0)) {
 138  
             // retrieve all req. component LEAFS
 139  0
                 for (int i = 0; i < reqComponentInfos.size(); i++) {
 140  0
                         ReqComponentInfoUi reqUi = RulesUtil.clone(reqComponentInfos.get(i));
 141  0
                         reqUi.setNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE", "en"));
 142  0
                         reqUi.setPreviewNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE.PREVIEW", "en"));
 143  0
                         reqComponentInfos.set(i, reqUi);
 144  
                 }
 145  
         }
 146  0
     }
 147  
 
 148  
     public void setCourseService(CourseService courseService) {
 149  0
         this.courseService = courseService;
 150  0
     }
 151  
 
 152  
     public void setStatementService(StatementService statementService) {
 153  0
         this.statementService = statementService;
 154  0
     }
 155  
 
 156  
         public void setStateChangeService(
 157  
                         CourseStateChangeServiceImpl stateChangeService) {
 158  0
                 this.stateChangeService = stateChangeService;
 159  0
         }
 160  
 }