Coverage Report - org.kuali.student.lum.lu.ui.course.server.gwt.CourseRpcGwtServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseRpcGwtServlet
0%
0/69
0%
0/23
2
CourseRpcGwtServlet$1
0%
0/1
N/A
2
 
 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.ArrayList;
 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.search.dto.SearchRequest;
 25  
 import org.kuali.student.common.search.dto.SearchResult;
 26  
 import org.kuali.student.common.ui.client.service.DataSaveResult;
 27  
 import org.kuali.student.common.ui.server.gwt.DataGwtServlet;
 28  
 import org.kuali.student.core.statement.dto.ReqComponentInfo;
 29  
 import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
 30  
 import org.kuali.student.core.statement.service.StatementService;
 31  
 import org.kuali.student.core.statement.ui.client.widgets.rules.ReqComponentInfoUi;
 32  
 import org.kuali.student.core.statement.ui.client.widgets.rules.RulesUtil;
 33  
 import org.kuali.student.lum.common.server.StatementUtil;
 34  
 import org.kuali.student.lum.course.service.CourseService;
 35  
 import org.kuali.student.lum.lu.service.LuService;
 36  
 import org.kuali.student.lum.lu.ui.course.client.requirements.CourseRequirementsDataModel;
 37  
 import org.kuali.student.lum.lu.ui.course.client.service.CourseRpcService;
 38  
 
 39  0
 public class CourseRpcGwtServlet extends DataGwtServlet implements CourseRpcService {
 40  
 
 41  
         private static final long serialVersionUID = 1L;
 42  
 
 43  
     private CourseService courseService;
 44  
     private LuService luService;
 45  
         private StatementService statementService;
 46  
         private CourseStateChangeServiceImpl stateChangeService;
 47  
 
 48  
     @Override
 49  
     public List<StatementTreeViewInfo> getCourseStatements(String courseId, String nlUsageTypeKey, String language) throws Exception {
 50  0
         List<StatementTreeViewInfo> rules = courseService.getCourseStatements(courseId, nlUsageTypeKey, language);
 51  0
         if (rules != null) {
 52  0
                 for (StatementTreeViewInfo rule : rules) {
 53  0
                         setReqCompNL(rule);
 54  
                 }
 55  
         }
 56  0
         return rules;
 57  
     }
 58  
 
 59  
     public Map<Integer, StatementTreeViewInfo> storeCourseStatements(String courseId, String courseState, Map<Integer, CourseRequirementsDataModel.requirementState> states,
 60  
                                                                         Map<Integer, StatementTreeViewInfo> rules) throws Exception {
 61  
 
 62  0
         Map<Integer, StatementTreeViewInfo> storedRules = new HashMap<Integer, StatementTreeViewInfo>();
 63  
 
 64  0
         for (Integer key : rules.keySet()) {
 65  0
             StatementTreeViewInfo rule = rules.get(key);
 66  0
             switch (states.get(key)) {
 67  
                 case STORED:
 68  
                     //rule was not changed so continue
 69  0
                     storedRules.put(key, null);
 70  0
                     break;
 71  
                 case ADDED:
 72  0
                     storedRules.put(key, createCourseStatement(courseId, courseState, rule));
 73  0
                     break;
 74  
                 case EDITED:
 75  0
                     storedRules.put(key, updateCourseStatement(courseId, courseState, rule));
 76  0
                     break;
 77  
                 case DELETED:
 78  0
                     storedRules.put(key, null);
 79  0
                     deleteCourseStatement(courseId, rule);
 80  0
                     break;
 81  
                 default:
 82  0
                     break;
 83  
             }
 84  0
         }
 85  0
         return storedRules;
 86  
     }
 87  
 
 88  
     @Override
 89  
     public StatementTreeViewInfo createCourseStatement(String courseId, String courseState, StatementTreeViewInfo statementTreeViewInfo) throws Exception {
 90  0
             StatementUtil.updateStatementTreeViewInfoState(courseState, statementTreeViewInfo);
 91  0
             CourseRequirementsDataModel.stripStatementIds(statementTreeViewInfo);
 92  0
         StatementTreeViewInfo rule = courseService.createCourseStatement(courseId, statementTreeViewInfo);
 93  0
         setReqCompNL(rule);
 94  0
         return rule;
 95  
     }
 96  
 
 97  
     @Override
 98  
     public StatusInfo deleteCourseStatement(String courseId, StatementTreeViewInfo statementTreeViewInfo) throws Exception {
 99  0
         return courseService.deleteCourseStatement(courseId, statementTreeViewInfo);
 100  
     }
 101  
 
 102  
     @Override
 103  
     public StatementTreeViewInfo updateCourseStatement(String courseId, String courseState, StatementTreeViewInfo statementTreeViewInfo) throws Exception {
 104  0
             StatementUtil.updateStatementTreeViewInfoState(courseState, statementTreeViewInfo);
 105  0
             CourseRequirementsDataModel.stripStatementIds(statementTreeViewInfo);
 106  0
         StatementTreeViewInfo rule = courseService.updateCourseStatement(courseId, statementTreeViewInfo);
 107  0
         setReqCompNL(rule);
 108  0
         return rule;
 109  
     }
 110  
 
 111  
         @Override
 112  
         public DataSaveResult createCopyCourse(String originalCluId)
 113  
                         throws Exception {
 114  0
                 throw new UnsupportedOperationException("Copy is not implemented without a proposal.");
 115  
         }
 116  
 
 117  
         @Override
 118  
         public DataSaveResult createCopyCourseProposal(String originalProposalId)
 119  
                         throws Exception {
 120  0
                 throw new UnsupportedOperationException("Copy is not implemented without a proposal.");
 121  
         }
 122  
 
 123  
         @Override  
 124  
     public StatusInfo changeState(String courseId, String newState) throws Exception {
 125  0
             return changeState(courseId, newState, null);
 126  
     }
 127  
         
 128  
         @Override
 129  
     public StatusInfo changeState(String courseId, String newState, String prevEndTerm) throws Exception {
 130  0
             return stateChangeService.changeState(courseId, newState, prevEndTerm);
 131  
     }
 132  
 
 133  
     private void setReqCompNL(StatementTreeViewInfo tree) throws Exception {
 134  0
         List<StatementTreeViewInfo> statements = tree.getStatements();
 135  0
         List<ReqComponentInfo> reqComponentInfos = tree.getReqComponents();
 136  
 
 137  0
          if ((statements != null) && (statements.size() > 0)) {
 138  
             // retrieve all statements
 139  0
             for (StatementTreeViewInfo statement : statements) {
 140  0
                 setReqCompNL(statement); // inside set the children of this statementTreeViewInfo
 141  
             }
 142  0
         } else if ((reqComponentInfos != null) && (reqComponentInfos.size() > 0)) {
 143  
             // retrieve all req. component LEAFS
 144  0
                 for (int i = 0; i < reqComponentInfos.size(); i++) {
 145  0
                         ReqComponentInfoUi reqUi = RulesUtil.clone(reqComponentInfos.get(i));
 146  0
                         reqUi.setNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE", "en"));
 147  0
                         reqUi.setPreviewNaturalLanguageTranslation(statementService.translateReqComponentToNL(reqUi, "KUALI.RULE.PREVIEW", "en"));
 148  0
                         reqComponentInfos.set(i, reqUi);
 149  
                 }
 150  
         }
 151  0
     }
 152  
 
 153  
     @Override
 154  
         public Boolean isLatestVersion(String versionIndId, Long versionSequenceNumber) throws Exception {
 155  
             //Perform a search to see if there are any new versions of the course that are approved, draft, etc.
 156  
             //We don't want to version if there are
 157  0
             SearchRequest request = new SearchRequest("lu.search.isVersionable");
 158  0
             request.addParam("lu.queryParam.versionIndId", versionIndId);
 159  0
             request.addParam("lu.queryParam.sequenceNumber", versionSequenceNumber.toString());
 160  0
             List<String> states = new ArrayList<String>();
 161  0
             states.add("Approved");
 162  0
             states.add("Active");
 163  0
             states.add("Draft");
 164  0
             states.add("Superseded");
 165  0
             request.addParam("lu.queryParam.luOptionalState", states);
 166  0
             SearchResult result = luService.search(request);
 167  
             
 168  0
             String resultString = result.getRows().get(0).getCells().get(0).getValue();
 169  0
             return "0".equals(resultString);
 170  
         }
 171  
     
 172  
     public void setCourseService(CourseService courseService) {
 173  0
         this.courseService = courseService;
 174  0
     }
 175  
 
 176  
     public void setStatementService(StatementService statementService) {
 177  0
         this.statementService = statementService;
 178  0
     }
 179  
 
 180  
         public void setStateChangeService(
 181  
                         CourseStateChangeServiceImpl stateChangeService) {
 182  0
                 this.stateChangeService = stateChangeService;
 183  0
         }
 184  
 
 185  
         public void setLuService(LuService luService) {
 186  0
                 this.luService = luService;
 187  0
         }
 188  
 }