Coverage Report - org.kuali.student.common.assembly.old.AssemblerFilterManager
 
Classes in this File Line Coverage Branch Coverage Complexity
AssemblerFilterManager
41%
21/51
N/A
1.25
AssemblerFilterManager$1
0%
0/6
0%
0/2
1.25
AssemblerFilterManager$2
0%
0/6
0%
0/2
1.25
AssemblerFilterManager$3
66%
4/6
50%
1/2
1.25
AssemblerFilterManager$4
0%
0/6
0%
0/2
1.25
AssemblerFilterManager$5
100%
6/6
100%
2/2
1.25
AssemblerFilterManager$6
0%
0/6
0%
0/2
1.25
 
 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.common.assembly.old;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 
 22  
 import org.kuali.student.common.assembly.data.AssemblyException;
 23  
 import org.kuali.student.common.assembly.data.Metadata;
 24  
 import org.kuali.student.common.assembly.old.AssemblerFilter.AssembleFilterChain;
 25  
 import org.kuali.student.common.assembly.old.AssemblerFilter.DisassembleFilterChain;
 26  
 import org.kuali.student.common.assembly.old.AssemblerFilter.FilterParamWrapper;
 27  
 import org.kuali.student.common.assembly.old.AssemblerFilter.GetFilterChain;
 28  
 import org.kuali.student.common.assembly.old.AssemblerFilter.GetMetadataFilterChain;
 29  
 import org.kuali.student.common.assembly.old.AssemblerFilter.SaveFilterChain;
 30  
 import org.kuali.student.common.assembly.old.AssemblerFilter.TypeStateFilterParamWrapper;
 31  
 import org.kuali.student.common.assembly.old.AssemblerFilter.ValidateFilterChain;
 32  
 import org.kuali.student.common.assembly.old.data.SaveResult;
 33  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 34  
 
 35  
 @Deprecated
 36  5
 public class AssemblerFilterManager<TargetType, SourceType> implements Assembler<TargetType, SourceType> {
 37  
 
 38  1
         private List<AssemblerFilter<TargetType, SourceType>> filters = new ArrayList<AssemblerFilter<TargetType, SourceType>>();
 39  
         private Assembler<TargetType, SourceType> target;
 40  
         private AssemblerFilterManager<TargetType, SourceType> self;
 41  
         
 42  
         public void addFilter(AssemblerFilter<TargetType, SourceType> filter){
 43  2
                 filters.add(filter);
 44  2
         }
 45  
         
 46  
         public AssemblerFilterManager(Assembler<TargetType, SourceType> target) {
 47  1
                 super();
 48  1
                 this.target = target;
 49  1
                 self = this;
 50  1
         }
 51  
 
 52  
         @Override
 53  
         public TargetType assemble(SourceType input) throws AssemblyException {
 54  0
                 final Iterator<AssemblerFilter<TargetType, SourceType>> iterator = filters.iterator();
 55  
                 
 56  0
                 FilterParamWrapper<SourceType> request  = new FilterParamWrapper<SourceType>();
 57  0
                 request.setValue(input);
 58  
                 
 59  0
                 FilterParamWrapper<TargetType> response  = new FilterParamWrapper<TargetType>();
 60  
                 
 61  0
                 new AssembleFilterChain<TargetType, SourceType>(){
 62  
                         @Override
 63  
                         public void doAssembleFilter(FilterParamWrapper<SourceType> request,
 64  
                                         FilterParamWrapper<TargetType> response) throws AssemblyException {
 65  0
                                 if(iterator.hasNext()){
 66  0
                                         iterator.next().doAssembleFilter(request, response, this);
 67  
                                 }else{
 68  0
                                         response.setValue(target.assemble(request.getValue()));
 69  
                                 }
 70  0
                         }
 71  
 
 72  
                         @Override
 73  
                         public AssemblerFilterManager<TargetType, SourceType> getManager() {
 74  0
                                 return self;
 75  
                         }
 76  
                         
 77  
                 }.doAssembleFilter(request, response);
 78  
                 
 79  0
                 return response.getValue();
 80  
         }
 81  
 
 82  
         @Override
 83  
         public SourceType disassemble(TargetType input) throws AssemblyException {
 84  0
                 final Iterator<AssemblerFilter<TargetType, SourceType>> iterator = filters.iterator();
 85  
                 
 86  0
                 FilterParamWrapper<TargetType> request  = new FilterParamWrapper<TargetType>();
 87  0
                 request.setValue(input);
 88  
                 
 89  0
                 FilterParamWrapper<SourceType> response  = new FilterParamWrapper<SourceType>();
 90  
                 
 91  0
                 new DisassembleFilterChain<TargetType, SourceType>(){
 92  
                         @Override
 93  
                         public void doDisassembleFilter(FilterParamWrapper<TargetType> request,
 94  
                                         FilterParamWrapper<SourceType> response) throws AssemblyException {
 95  0
                                 if(iterator.hasNext()){
 96  0
                                         iterator.next().doDisassembleFilter(request, response, this);
 97  
                                 }else{
 98  0
                                         response.setValue(target.disassemble(request.getValue()));
 99  
                                 }
 100  0
                         }
 101  
                         @Override
 102  
                         public AssemblerFilterManager<TargetType, SourceType> getManager() {
 103  0
                                 return self;
 104  
                         }
 105  
                 }.doDisassembleFilter(request, response);
 106  
                 
 107  0
                 return response.getValue();
 108  
         }
 109  
 
 110  
         @Override
 111  
         public TargetType get(String id) throws AssemblyException {
 112  2
                 final Iterator<AssemblerFilter<TargetType, SourceType>> iterator = filters.iterator();
 113  
                 
 114  2
                 FilterParamWrapper<String> request  = new FilterParamWrapper<String>();
 115  2
                 request.setValue(id);
 116  
                 
 117  2
                 FilterParamWrapper<TargetType> response  = new FilterParamWrapper<TargetType>();
 118  
                 
 119  2
                 new GetFilterChain<TargetType, SourceType>(){
 120  
                         @Override
 121  
                         public void doGetFilter(FilterParamWrapper<String> request,
 122  
                                         FilterParamWrapper<TargetType> response) throws AssemblyException {
 123  2
                                 if(iterator.hasNext()){
 124  2
                                         iterator.next().doGetFilter(request, response, this);
 125  
                                 }else{
 126  0
                                         response.setValue(target.get(request.getValue()));
 127  
                                 }
 128  2
                         }
 129  
                         @Override
 130  
                         public AssemblerFilterManager<TargetType, SourceType> getManager() {
 131  0
                                 return self;
 132  
                         }
 133  
                 }.doGetFilter(request, response);
 134  
                 
 135  2
                 return response.getValue();
 136  
         }
 137  
 
 138  
         @Override
 139  
         public Metadata getMetadata(final String idType, final String id, String type, String state)
 140  
                         throws AssemblyException {
 141  0
                 final Iterator<AssemblerFilter<TargetType, SourceType>> iterator = filters.iterator();
 142  
                 
 143  0
                 TypeStateFilterParamWrapper request  = new TypeStateFilterParamWrapper();
 144  0
                 request.setType(type);
 145  0
                 request.setState(state);
 146  
                 
 147  0
                 FilterParamWrapper<Metadata> response  = new FilterParamWrapper<Metadata>();
 148  
                 
 149  0
                 new GetMetadataFilterChain<TargetType, SourceType>(){
 150  
                         @Override
 151  
                         public void doGetMetadataFilter(TypeStateFilterParamWrapper request,
 152  
                                         FilterParamWrapper<Metadata> response) throws AssemblyException {
 153  0
                                 if(iterator.hasNext()){
 154  0
                                         iterator.next().doGetMetadataFilter(request, response, this);
 155  
                                 }else{
 156  0
                                         response.setValue(target.getMetadata(idType, id, request.getType(),request.getState()));
 157  
                                 }
 158  0
                         }
 159  
                         @Override
 160  
                         public AssemblerFilterManager<TargetType, SourceType> getManager() {
 161  0
                                 return self;
 162  
                         }
 163  
                 }.doGetMetadataFilter(request, response);
 164  
                 
 165  0
                 return response.getValue();
 166  
         }
 167  
 
 168  
         @Override
 169  
         public SaveResult<TargetType> save(TargetType input)
 170  
                         throws AssemblyException {
 171  
                 
 172  1
                 final Iterator<AssemblerFilter<TargetType, SourceType>> iterator = filters.iterator();
 173  
                 
 174  1
                 FilterParamWrapper<TargetType> request  = new FilterParamWrapper<TargetType>();
 175  1
                 request.setValue(input);
 176  
                 
 177  1
                 FilterParamWrapper<SaveResult<TargetType>> response  = new FilterParamWrapper<SaveResult<TargetType>>();
 178  
                 
 179  1
                 new SaveFilterChain<TargetType, SourceType>(){
 180  
                         @Override
 181  
                         public void doSaveFilter(FilterParamWrapper<TargetType> request,
 182  
                                         FilterParamWrapper<SaveResult<TargetType>> response) throws AssemblyException {
 183  3
                                 if(iterator.hasNext()){
 184  2
                                         iterator.next().doSaveFilter(request, response, this);
 185  
                                 }else{
 186  1
                                         response.setValue(target.save(request.getValue()));
 187  
                                 }
 188  3
                         }
 189  
                         @Override
 190  
                         public AssemblerFilterManager<TargetType, SourceType> getManager() {
 191  4
                                 return self;
 192  
                         }
 193  
                 }.doSaveFilter(request, response);
 194  
                 
 195  1
                 return response.getValue();
 196  
         }
 197  
 
 198  
         @Override
 199  
         public List<ValidationResultInfo> validate(TargetType input)
 200  
                         throws AssemblyException {
 201  0
                 final Iterator<AssemblerFilter<TargetType, SourceType>> iterator = filters.iterator();
 202  
                 
 203  0
                 FilterParamWrapper<TargetType> request  = new FilterParamWrapper<TargetType>();
 204  0
                 request.setValue(input);
 205  
                 
 206  0
                 FilterParamWrapper<List<ValidationResultInfo>> response  = new FilterParamWrapper<List<ValidationResultInfo>>();
 207  
                 
 208  0
                 new ValidateFilterChain<TargetType, SourceType>(){
 209  
                         @Override
 210  
                         public void doValidateFilter(FilterParamWrapper<TargetType> request,
 211  
                                         FilterParamWrapper<List<ValidationResultInfo>> response) throws AssemblyException {
 212  0
                                 if(iterator.hasNext()){
 213  0
                                         iterator.next().doValidateFilter(request, response, this);
 214  
                                 }else{
 215  0
                                         response.setValue(target.validate(request.getValue()));
 216  
                                 }
 217  0
                         }
 218  
                         @Override
 219  
                         public AssemblerFilterManager<TargetType, SourceType> getManager() {
 220  0
                                 return self;
 221  
                         }
 222  
                 }.doValidateFilter(request, response);
 223  
                 
 224  0
                 return response.getValue();
 225  
         }
 226  
 
 227  
         public void setFilters(List<AssemblerFilter<TargetType, SourceType>> filters) {
 228  0
                 this.filters = filters;
 229  0
         }
 230  
 
 231  
         public Assembler<TargetType, SourceType> getTarget() {
 232  2
                 return target;
 233  
         }
 234  
 
 235  
         public void setTarget(Assembler<TargetType, SourceType> target) {
 236  0
                 this.target = target;
 237  0
         }
 238  
 
 239  
         @Override
 240  
         public Metadata getDefaultMetadata() throws AssemblyException {
 241  0
                 return target.getDefaultMetadata();
 242  
         }
 243  
         
 244  
 
 245  
 }