Coverage Report - org.kuali.student.lum.service.assembler.LumServiceMethodInvoker
 
Classes in this File Line Coverage Branch Coverage Complexity
LumServiceMethodInvoker
76%
123/160
68%
84/122
8
LumServiceMethodInvoker$1
100%
1/1
N/A
8
 
 1  
 package org.kuali.student.lum.service.assembler;
 2  
 
 3  
 import java.util.List;
 4  
 
 5  
 import org.apache.log4j.Logger;
 6  
 import org.kuali.student.common.assembly.BaseDTOAssemblyNode;
 7  
 import org.kuali.student.common.assembly.BaseDTOAssemblyNode.NodeOperation;
 8  
 import org.kuali.student.common.assembly.BusinessServiceMethodInvoker;
 9  
 import org.kuali.student.common.assembly.data.AssemblyException;
 10  
 import org.kuali.student.common.exceptions.AlreadyExistsException;
 11  
 import org.kuali.student.common.exceptions.CircularReferenceException;
 12  
 import org.kuali.student.common.exceptions.CircularRelationshipException;
 13  
 import org.kuali.student.common.exceptions.DataValidationErrorException;
 14  
 import org.kuali.student.common.exceptions.DependentObjectsExistException;
 15  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 16  
 import org.kuali.student.common.exceptions.InvalidParameterException;
 17  
 import org.kuali.student.common.exceptions.MissingParameterException;
 18  
 import org.kuali.student.common.exceptions.OperationFailedException;
 19  
 import org.kuali.student.common.exceptions.PermissionDeniedException;
 20  
 import org.kuali.student.common.exceptions.UnsupportedActionException;
 21  
 import org.kuali.student.common.exceptions.VersionMismatchException;
 22  
 import org.kuali.student.core.atp.service.AtpService;
 23  
 import org.kuali.student.core.statement.dto.RefStatementRelationInfo;
 24  
 import org.kuali.student.core.statement.dto.ReqComponentInfo;
 25  
 import org.kuali.student.core.statement.dto.StatementInfo;
 26  
 import org.kuali.student.core.statement.dto.StatementTreeViewInfo;
 27  
 import org.kuali.student.core.statement.service.StatementService;
 28  
 import org.kuali.student.lum.course.service.assembler.LoCategoryRelationInfo;
 29  
 import org.kuali.student.lum.lo.dto.LoInfo;
 30  
 import org.kuali.student.lum.lo.dto.LoLoRelationInfo;
 31  
 import org.kuali.student.lum.lo.service.LearningObjectiveService;
 32  
 import org.kuali.student.lum.lrc.dto.ResultComponentInfo;
 33  
 import org.kuali.student.lum.lrc.service.LrcService;
 34  
 import org.kuali.student.lum.lu.dto.CluCluRelationInfo;
 35  
 import org.kuali.student.lum.lu.dto.CluInfo;
 36  
 import org.kuali.student.lum.lu.dto.CluLoRelationInfo;
 37  
 import org.kuali.student.lum.lu.dto.CluPublicationInfo;
 38  
 import org.kuali.student.lum.lu.dto.CluResultInfo;
 39  
 import org.kuali.student.lum.lu.service.LuService;
 40  
 
 41  2
 public class LumServiceMethodInvoker implements BusinessServiceMethodInvoker {
 42  2
         final Logger LOG = Logger.getLogger(LumServiceMethodInvoker.class);
 43  
         private LuService luService;
 44  
         private StatementService statementService;
 45  
         private LearningObjectiveService loService;
 46  
         private AtpService atpService;
 47  
         private LrcService lrcService;
 48  
 
 49  
         @SuppressWarnings("unchecked")
 50  
         public final void invokeServiceCalls(BaseDTOAssemblyNode results)
 51  
                         throws AlreadyExistsException, DataValidationErrorException,
 52  
                         DoesNotExistException, InvalidParameterException,
 53  
                         MissingParameterException, OperationFailedException,
 54  
                         PermissionDeniedException, VersionMismatchException,
 55  
                         DependentObjectsExistException, CircularRelationshipException,
 56  
                         AssemblyException, UnsupportedActionException, UnsupportedOperationException, CircularReferenceException {
 57  
 
 58  
             // For Delete operation process the tree from bottom up
 59  3352
             if(NodeOperation.DELETE == results.getOperation()) {
 60  130
             for(BaseDTOAssemblyNode childNode: (List<BaseDTOAssemblyNode>) results.getChildNodes()){
 61  112
                 invokeServiceCalls(childNode);
 62  
             }
 63  
             }
 64  
 
 65  3352
             invokeServiceCallOnResult(results);
 66  
 
 67  
                 // For create/update process the child nodes from top to bottom
 68  3351
                 if(NodeOperation.DELETE != results.getOperation()) {
 69  3221
                     for(BaseDTOAssemblyNode childNode: (List<BaseDTOAssemblyNode>) results.getChildNodes()){
 70  3187
                         invokeServiceCalls(childNode);
 71  
                     }
 72  
                 }
 73  3351
         }
 74  
 
 75  
         /**
 76  
          * @param results
 77  
          * @throws AlreadyExistsException
 78  
          * @throws DataValidationErrorException
 79  
          * @throws DoesNotExistException
 80  
          * @throws InvalidParameterException
 81  
          * @throws MissingParameterException
 82  
          * @throws OperationFailedException
 83  
          * @throws PermissionDeniedException
 84  
          * @throws AssemblyException
 85  
          * @throws VersionMismatchException
 86  
          * @throws DependentObjectsExistException
 87  
          * @throws CircularRelationshipException
 88  
          * @throws UnsupportedActionException
 89  
          * @throws UnsupportedOperationException
 90  
          * @throws CircularReferenceException
 91  
          */
 92  
         protected void invokeServiceCallOnResult(BaseDTOAssemblyNode results)
 93  
                         throws AlreadyExistsException, DataValidationErrorException,
 94  
                         DoesNotExistException, InvalidParameterException,
 95  
                         MissingParameterException, OperationFailedException,
 96  
                         PermissionDeniedException, AssemblyException,
 97  
                         VersionMismatchException, DependentObjectsExistException,
 98  
                         CircularRelationshipException, UnsupportedActionException,
 99  
                         UnsupportedOperationException, CircularReferenceException {
 100  3352
                 Object nodeData = results.getNodeData();
 101  3352
                 if (nodeData == null) {
 102  9
                         return;
 103  
                 }
 104  
 
 105  3343
                 if (LOG.isDebugEnabled()) {
 106  0
                         LOG.debug(results.getOperation() + ": " + nodeData);
 107  
                 }
 108  
 
 109  3343
                 if(nodeData instanceof CluInfo){
 110  230
                         CluInfo clu = (CluInfo) nodeData;
 111  230
                         switch(results.getOperation()){
 112  
                         case CREATE:
 113  169
                                 CluInfo newClu = luService.createClu(clu.getType(), clu);
 114  169
                                 if(results.getAssembler() != null) {
 115  169
                                         results.getAssembler().assemble(newClu, results.getBusinessDTORef(), true);
 116  
                                 }
 117  
                                 break;
 118  
                         case UPDATE:
 119  48
                                 CluInfo updatedClu = luService.updateClu(clu.getId(), clu);
 120  47
                                 if(results.getAssembler() != null) {
 121  47
                                         results.getAssembler().assemble(updatedClu, results.getBusinessDTORef(), true);
 122  
                                 }
 123  
                                 break;
 124  
                         case DELETE:
 125  13
                                 luService.deleteClu(clu.getId());
 126  
                                 break;
 127  
                         }
 128  229
                 }else if(nodeData instanceof CluCluRelationInfo){
 129  197
                         CluCluRelationInfo  relation = (CluCluRelationInfo) nodeData;
 130  197
                         switch(results.getOperation()){
 131  
                         case CREATE:
 132  177
                                 CluCluRelationInfo newCluRel = luService.createCluCluRelation(relation.getCluId(), relation.getRelatedCluId(), relation.getType(), relation);
 133  
                                 // Update the businessDTO if one exists for the cluclurelation (for e.g. CourseJointInfo)
 134  177
                                 if(null != results.getBusinessDTORef()) {
 135  0
                                         results.getAssembler().assemble(newCluRel, results.getBusinessDTORef(), true);
 136  
                                 }
 137  
                                 break;
 138  
                         case UPDATE:
 139  1
                                 CluCluRelationInfo updatedCluRel = luService.updateCluCluRelation(relation.getId(), relation);
 140  
                                 // Update the businessDTO if one exists for the cluclurelation (for e.g. CourseJointInfo)
 141  1
                                 if(null != results.getBusinessDTORef()) {
 142  0
                                         results.getAssembler().assemble(updatedCluRel, results.getBusinessDTORef(), true);
 143  
                                 }
 144  
                                 break;
 145  
                         case DELETE:
 146  19
                                 luService.deleteCluCluRelation(relation.getId());
 147  
                                 break;
 148  
                         }
 149  197
                 }else if(nodeData instanceof CluResultInfo){
 150  109
                         CluResultInfo cluResult = (CluResultInfo) nodeData;
 151  109
                         switch(results.getOperation()){
 152  
                         case CREATE:
 153  86
                                 luService.createCluResult(cluResult.getCluId(), cluResult.getType(), cluResult);
 154  86
                                 break;
 155  
                         case UPDATE:
 156  19
                                 luService.updateCluResult(cluResult.getId(), cluResult);
 157  19
                                 break;
 158  
                         case DELETE:
 159  4
                                 luService.deleteCluResult(cluResult.getId());
 160  
                                 break;
 161  
                         }
 162  109
                 }else if(nodeData instanceof LoCategoryRelationInfo){
 163  1331
                         LoCategoryRelationInfo loCategoryRelation = (LoCategoryRelationInfo) nodeData;
 164  1331
                         switch(results.getOperation()){
 165  
                         case CREATE:
 166  1289
                                 loService.addLoCategoryToLo(loCategoryRelation.getCategoryId(), loCategoryRelation.getLoId());
 167  1289
                                 break;
 168  
                         case UPDATE:
 169  0
                                 throw new UnsupportedOperationException("Can't call update on lo category relations, just add and remove");
 170  
                         case DELETE:
 171  42
                                 loService.removeLoCategoryFromLo(loCategoryRelation.getCategoryId(), loCategoryRelation.getLoId());
 172  
                                 break;
 173  
                         }
 174  1331
                 }else if(nodeData instanceof LoInfo){
 175  695
                         LoInfo lo = (LoInfo) nodeData;
 176  695
                         switch(results.getOperation()){
 177  
                         case CREATE:
 178  651
                                 LoInfo createdLo = loService.createLo(lo.getLoRepositoryKey(), lo.getType(), lo);
 179  651
                                 if(null != results.getBusinessDTORef()) {
 180  651
                                         results.getAssembler().assemble(createdLo, results.getBusinessDTORef(), true);
 181  
                                 }
 182  
                                 break;
 183  
                         case UPDATE:
 184  21
                                 LoInfo updatedLo = loService.updateLo(lo.getId(), lo);
 185  21
                                 if(null != results.getBusinessDTORef()) {
 186  21
                                         results.getAssembler().assemble(updatedLo, results.getBusinessDTORef(), true);
 187  
                                 }
 188  
                                 break;
 189  
                         case DELETE:
 190  23
                                 loService.deleteLo(lo.getId());
 191  
                                 break;
 192  
                         }
 193  695
                 }else if(nodeData instanceof LoLoRelationInfo){
 194  570
                         LoLoRelationInfo loRelation = (LoLoRelationInfo) nodeData;
 195  570
                         switch(results.getOperation()){
 196  
                         case CREATE:
 197  552
                                 loService.createLoLoRelation(loRelation.getLoId(), loRelation.getRelatedLoId(), loRelation.getType(), loRelation);
 198  552
                                 break;
 199  
                         case UPDATE:
 200  0
                                 loService.updateLoLoRelation(loRelation.getId(), loRelation);
 201  0
                                  break;
 202  
                         case DELETE:
 203  18
                                 loService.deleteLoLoRelation(loRelation.getId());
 204  
                                 break;
 205  
                         }
 206  570
                 }else if(nodeData instanceof CluLoRelationInfo){
 207  104
                         CluLoRelationInfo cluLoRelation = (CluLoRelationInfo) nodeData;
 208  104
                         switch(results.getOperation()){
 209  
                         case CREATE:
 210  99
                                 luService.createCluLoRelation(cluLoRelation.getCluId(), cluLoRelation.getLoId(), cluLoRelation.getType(), cluLoRelation);
 211  99
                                 break;
 212  
                         case UPDATE:
 213  0
                                 luService.updateCluLoRelation(cluLoRelation.getLoId(), cluLoRelation);
 214  0
                                 break;
 215  
                         case DELETE:
 216  5
                                 luService.deleteCluLoRelation(cluLoRelation.getId());
 217  
                                 break;
 218  
                         }
 219  104
                 }else if(nodeData instanceof ResultComponentInfo){
 220  4
                         ResultComponentInfo resultComponent = (ResultComponentInfo) nodeData;
 221  4
                         switch(results.getOperation()){
 222  
                         case CREATE:
 223  4
                                 ResultComponentInfo createdResultComponent = lrcService.createResultComponent(resultComponent.getType(), resultComponent);
 224  
                                 //Copy the created back to the reference Should there be an assembler for this?
 225  4
                                 if(results.getBusinessDTORef()!=null&& results.getBusinessDTORef() instanceof ResultComponentInfo){
 226  4
                                         ResultComponentInfo resultComponentToUpdate = (ResultComponentInfo) results.getBusinessDTORef();
 227  4
                                         resultComponentToUpdate.setId(createdResultComponent.getId());
 228  4
                                         resultComponentToUpdate.setType(createdResultComponent.getType());
 229  4
                                         resultComponentToUpdate.setDesc(createdResultComponent.getDesc());
 230  4
                                         resultComponentToUpdate.setEffectiveDate(createdResultComponent.getEffectiveDate());
 231  4
                                         resultComponentToUpdate.setExpirationDate(createdResultComponent.getExpirationDate());
 232  4
                                         resultComponentToUpdate.setMetaInfo(createdResultComponent.getMetaInfo());
 233  4
                                         resultComponentToUpdate.setName(createdResultComponent.getName());
 234  4
                                         resultComponentToUpdate.setResultValues(createdResultComponent.getResultValues());
 235  4
                                         resultComponentToUpdate.setState(createdResultComponent.getState());
 236  4
                                 }
 237  
                                 break;
 238  
                         case UPDATE:
 239  0
                                 lrcService.updateResultComponent(resultComponent.getId(), resultComponent);
 240  0
                                 break;
 241  
                         case DELETE:
 242  0
                                 lrcService.deleteResultComponent(resultComponent.getId());
 243  
                                 break;
 244  
                         }
 245  4
                 } else if(nodeData instanceof RefStatementRelationInfo){
 246  9
                         RefStatementRelationInfo relation = (RefStatementRelationInfo) nodeData;
 247  9
                         switch(results.getOperation()){
 248  
                         case CREATE:
 249  6
                                 RefStatementRelationInfo created = statementService.createRefStatementRelation(relation);
 250  6
                                 relation.setMetaInfo(created.getMetaInfo());
 251  6
                                 break;
 252  
                         case UPDATE:
 253  1
                                 RefStatementRelationInfo updated = statementService.updateRefStatementRelation(relation.getId(), relation);
 254  1
                                 relation.setMetaInfo(updated.getMetaInfo());
 255  1
                                 break;
 256  
                         case DELETE:
 257  2
                                 statementService.deleteRefStatementRelation(relation.getId());
 258  
                                 break;
 259  
                         }
 260  9
                 } else if(nodeData instanceof StatementInfo){
 261  0
                         StatementInfo statement = (StatementInfo) nodeData;
 262  0
                         switch(results.getOperation()){
 263  
                         case CREATE:
 264  0
                                 StatementInfo created = statementService.createStatement(statement.getType(), statement);
 265  0
                                 if(results.getAssembler() != null && results.getBusinessDTORef() != null) {
 266  0
                                         results.getAssembler().assemble(created, results.getBusinessDTORef(), true);
 267  
                                 }
 268  
                                 break;
 269  
                         case UPDATE:
 270  0
                                 StatementInfo updated = statementService.updateStatement(statement.getId(), statement);
 271  0
                                 if(results.getAssembler() != null && results.getBusinessDTORef() != null) {
 272  0
                                         results.getAssembler().assemble(updated, results.getBusinessDTORef(), true);
 273  
                                 }
 274  
                                 break;
 275  
                         case DELETE:
 276  0
                                 statementService.deleteStatement(statement.getId());
 277  
                                 break;
 278  
                         }
 279  0
                 } else if(nodeData instanceof ReqComponentInfo){
 280  0
                         ReqComponentInfo reqComp = (ReqComponentInfo) nodeData;
 281  0
                         switch(results.getOperation()){
 282  
                         case CREATE:
 283  0
                                 ReqComponentInfo created = statementService.createReqComponent(reqComp.getType(), reqComp);
 284  0
                                 reqComp.setMetaInfo(created.getMetaInfo());
 285  0
                                 break;
 286  
                         case UPDATE:
 287  0
                                 ReqComponentInfo updated = statementService.updateReqComponent(reqComp.getId(), reqComp);
 288  0
                                 reqComp.setMetaInfo(updated.getMetaInfo());
 289  0
                                 break;
 290  
                         case DELETE:
 291  0
                                 statementService.deleteReqComponent(reqComp.getId());
 292  
                                 break;
 293  
                         }
 294  0
                 }else if(nodeData instanceof StatementTreeViewInfo){
 295  9
                         StatementTreeViewInfo treeView = (StatementTreeViewInfo) nodeData;
 296  9
                         switch(results.getOperation()){
 297  
                         case CREATE:
 298  6
                                 StatementTreeViewInfo created = statementService.createStatementTreeView(treeView);
 299  6
                                 if(results.getAssembler() != null && results.getBusinessDTORef() != null) {
 300  6
                                         results.getAssembler().assemble(created, results.getBusinessDTORef(), true);
 301  
                                 }
 302  
                                 break;
 303  
                         case UPDATE:
 304  1
                                 StatementTreeViewInfo updated = statementService.updateStatementTreeView(treeView.getId(), treeView);
 305  1
                                 if(results.getAssembler() != null && results.getBusinessDTORef() != null) {
 306  1
                                         results.getAssembler().assemble(updated, results.getBusinessDTORef(), true);
 307  
                                 }
 308  
                                 break;
 309  
                         case DELETE:
 310  2
                                 statementService.deleteStatementTreeView(treeView.getId());
 311  
                                 break;
 312  
                         }
 313  9
                    }else if(nodeData instanceof CluPublicationInfo){
 314  85
                         CluPublicationInfo cluPublication = (CluPublicationInfo) nodeData;
 315  85
                         switch(results.getOperation()){
 316  
                         case CREATE:
 317  55
                                 luService.createCluPublication(cluPublication.getCluId(), cluPublication.getType(), cluPublication);
 318  55
                                 break;
 319  
                         case UPDATE:
 320  30
                                 luService.updateCluPublication(cluPublication.getId(), cluPublication);
 321  30
                                 break;
 322  
                         case DELETE:
 323  0
                                 luService.deleteCluPublication(cluPublication.getId());
 324  
                                 break;
 325  
                         }
 326  85
                 }else{
 327  0
                         throw new UnsupportedActionException("This service invoker does not know how to handle nodeData for "+nodeData.getClass().getName());
 328  
                 }
 329  
 
 330  3342
         }
 331  
 
 332  
         public LuService getLuService() {
 333  0
                 return luService;
 334  
         }
 335  
 
 336  
         public void setLuService(LuService luService) {
 337  2
                 this.luService = luService;
 338  2
         }
 339  
 
 340  
         public StatementService getStatementService() {
 341  0
                 return statementService;
 342  
         }
 343  
 
 344  
         public void setStatementService(StatementService statementService) {
 345  2
                 this.statementService = statementService;
 346  2
         }
 347  
 
 348  
         public LearningObjectiveService getLoService() {
 349  0
                 return loService;
 350  
         }
 351  
 
 352  
         public void setLoService(LearningObjectiveService loService) {
 353  2
                 this.loService = loService;
 354  2
         }
 355  
 
 356  
         public AtpService getAtpService() {
 357  0
                 return atpService;
 358  
         }
 359  
 
 360  
         public void setAtpService(AtpService atpService) {
 361  1
                 this.atpService = atpService;
 362  1
         }
 363  
 
 364  
         public void setLrcService(LrcService lrcService) {
 365  1
                 this.lrcService = lrcService;
 366  1
         }
 367  
 
 368  
 }