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