Coverage Report - org.kuali.student.enrollment.lpr.service.adapter.config.LuiPersonRelationAdapterStacker
 
Classes in this File Line Coverage Branch Coverage Complexity
LuiPersonRelationAdapterStacker
0%
0/76
0%
0/38
2
 
 1  
 /*
 2  
  * Copyright 2009 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the
 5  
  * "License"); you may not use this file except in compliance with the
 6  
  * License.  You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 13  
  * implied.  See the License for the specific language governing
 14  
  * permissions and limitations under the License.
 15  
  */
 16  
 package org.kuali.student.enrollment.lpr.service.adapter.config;
 17  
 
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 import org.kuali.rice.kim.service.IdentityService;
 22  
 import org.kuali.rice.kim.service.PermissionService;
 23  
 import org.kuali.student.common.infc.HoldsIdentityService;
 24  
 import org.kuali.student.common.infc.HoldsLprService;
 25  
 import org.kuali.student.common.infc.HoldsLuiService;
 26  
 import org.kuali.student.common.infc.HoldsPermissionService;
 27  
 import org.kuali.student.enrollment.lpr.mock.LuiPersonRelationServiceAdapter;
 28  
 import org.kuali.student.enrollment.lpr.service.LuiPersonRelationService;
 29  
 import org.kuali.student.enrollment.lui.service.LuiService;
 30  
 
 31  
 /**
 32  
  * A example of an adapter that might sit at the top of the stack and converts any
 33  
  * runtime exceptions into the formal OperationFailedException
 34  
  * <p/>
 35  
  * This could be genrated automatically from the contract definitions too.
 36  
  *
 37  
  * @Author Norm
 38  
  */
 39  0
 public class LuiPersonRelationAdapterStacker extends LuiPersonRelationServiceAdapter
 40  
                 implements HoldsLprService,
 41  
                 HoldsIdentityService,
 42  
                 HoldsPermissionService {
 43  
 
 44  
         private LuiService luiService;
 45  
         private IdentityService identityService;
 46  
         private PermissionService permissionService;
 47  
         private List<LuiPersonRelationService> cleanupImpls;
 48  
         private List<LuiPersonRelationService> calculationImpls;
 49  
         private List<LuiPersonRelationService> authorizationImpls;
 50  
         private List<LuiPersonRelationService> validaitonImpls;
 51  
         private List<LuiPersonRelationService> sideEffectImpls;
 52  
         private List<LuiPersonRelationService> persistenceImpls;
 53  
 
 54  
         public void init() {
 55  
 
 56  0
                 List<LuiPersonRelationService> allImpls = new ArrayList<LuiPersonRelationService>();
 57  0
                 if (cleanupImpls != null) {
 58  0
                         allImpls.addAll(cleanupImpls);
 59  
                 }
 60  0
                 if (calculationImpls != null) {
 61  0
                         allImpls.addAll(calculationImpls);
 62  
                 }
 63  0
                 if (authorizationImpls != null) {
 64  0
                         allImpls.addAll(authorizationImpls);
 65  
                 }
 66  0
                 if (validaitonImpls != null) {
 67  0
                         allImpls.addAll(validaitonImpls);
 68  
                 }
 69  0
                 if (sideEffectImpls != null) {
 70  0
                         allImpls.addAll(sideEffectImpls);
 71  
                 }
 72  0
                 if (persistenceImpls != null) {
 73  0
                         allImpls.addAll(persistenceImpls);
 74  
                 }
 75  0
                 validateConfiguration(allImpls);
 76  
 
 77  0
                 int i = 0;
 78  0
                 LuiPersonRelationService top = allImpls.get(i);
 79  0
                 setLprService(top);
 80  0
                 LuiPersonRelationService current = top;
 81  0
                 for (i = 1; i < allImpls.size(); i++) {
 82  0
                         LuiPersonRelationService next = allImpls.get(i);
 83  0
                         configure(current, next);
 84  0
                         current = allImpls.get(i);
 85  
                 }
 86  0
             current = allImpls.get(allImpls.size() - 1);
 87  0
                 configure(current, null);
 88  0
         }
 89  
 
 90  
         private void configure(LuiPersonRelationService current, LuiPersonRelationService next) {
 91  0
                 if (current instanceof HoldsLprService) {
 92  0
                         HoldsLprService holder = (HoldsLprService) current;
 93  0
                         if (holder.getLprService() == null) {
 94  0
                                 holder.setLprService(next);
 95  
                         }
 96  
                 }
 97  0
                 if (current instanceof HoldsLuiService) {
 98  0
                         HoldsLuiService holder = (HoldsLuiService) current;
 99  0
                         if (holder.getLuiService() == null) {
 100  0
                                 holder.setLuiService(this.getLuiService());
 101  
                         }
 102  
                 }
 103  0
                 if (current instanceof HoldsIdentityService) {
 104  0
                         HoldsIdentityService holder = (HoldsIdentityService) current;
 105  0
                         if (holder.getIdentityService() == null) {
 106  0
                                 holder.setIdentityService(this.getIdentityService());
 107  
                         }
 108  
                 }
 109  0
                 if (current instanceof HoldsPermissionService) {
 110  0
                         HoldsPermissionService holder = (HoldsPermissionService) current;
 111  0
                         if (holder.getPermissionService() == null) {
 112  0
                                 holder.setPermissionService(this.getPermissionService());
 113  
                         }
 114  
                 }
 115  0
         }
 116  
 
 117  
         private void validateConfiguration(List<LuiPersonRelationService> allImpls) {
 118  0
                 if (this.persistenceImpls == null || this.persistenceImpls.isEmpty()) {
 119  0
                         throw new IllegalArgumentException("No persistence layers defined");
 120  
                 }
 121  0
                 for (int i = 0; i < allImpls.size() - 1; i++) {
 122  0
                         if (!(allImpls.get(i) instanceof HoldsLprService)) {
 123  0
                                 throw new IllegalArgumentException(allImpls.get(i).getClass().getName()
 124  
                                   + " does not impelment HoldsLprService so it cannot call the next impl in the stack");
 125  
                         }
 126  
                 }
 127  
                 // TODO: other validation
 128  0
         }
 129  
 
 130  
         public List<LuiPersonRelationService> getAuthorizationImpls() {
 131  0
                 return authorizationImpls;
 132  
         }
 133  
 
 134  
         public void setAuthorizationImpls(List<LuiPersonRelationService> authorizationImpls) {
 135  0
                 this.authorizationImpls = authorizationImpls;
 136  0
         }
 137  
 
 138  
         public List<LuiPersonRelationService> getCalculationImpls() {
 139  0
                 return calculationImpls;
 140  
         }
 141  
 
 142  
         public void setCalculationImpls(List<LuiPersonRelationService> calculationImpls) {
 143  0
                 this.calculationImpls = calculationImpls;
 144  0
         }
 145  
 
 146  
         public List<LuiPersonRelationService> getCleanupImpls() {
 147  0
                 return cleanupImpls;
 148  
         }
 149  
 
 150  
         public void setCleanupImpls(List<LuiPersonRelationService> cleanupImpls) {
 151  0
                 this.cleanupImpls = cleanupImpls;
 152  0
         }
 153  
 
 154  
         public List<LuiPersonRelationService> getPersistenceImpls() {
 155  0
                 return persistenceImpls;
 156  
         }
 157  
 
 158  
         public void setPersistenceImpls(List<LuiPersonRelationService> persistenceImpls) {
 159  0
                 this.persistenceImpls = persistenceImpls;
 160  0
         }
 161  
 
 162  
         public List<LuiPersonRelationService> getSideEffectImpls() {
 163  0
                 return sideEffectImpls;
 164  
         }
 165  
 
 166  
         public void setSideEffectImpls(List<LuiPersonRelationService> sideEffectImpls) {
 167  0
                 this.sideEffectImpls = sideEffectImpls;
 168  0
         }
 169  
 
 170  
         public List<LuiPersonRelationService> getValidaitonImpls() {
 171  0
                 return validaitonImpls;
 172  
         }
 173  
 
 174  
         public void setValidaitonImpls(List<LuiPersonRelationService> validaitonImpls) {
 175  0
                 this.validaitonImpls = validaitonImpls;
 176  0
         }
 177  
 
 178  
         public IdentityService getIdentityService() {
 179  0
                 return identityService;
 180  
         }
 181  
 
 182  
         public void setIdentityService(IdentityService identityService) {
 183  0
                 this.identityService = identityService;
 184  0
         }
 185  
 
 186  
         public LuiService getLuiService() {
 187  0
                 return luiService;
 188  
         }
 189  
 
 190  
         public void setLuiService(LuiService luiService) {
 191  0
                 this.luiService = luiService;
 192  0
         }
 193  
 
 194  
         public PermissionService getPermissionService() {
 195  0
                 return permissionService;
 196  
         }
 197  
 
 198  
         public void setPermissionService(PermissionService permissionService) {
 199  0
                 this.permissionService = permissionService;
 200  0
         }
 201  
 }