Coverage Report - org.kuali.student.enrollment.lpr.service.adapter.calculations.LuiPersonRelationDefaultContextFromRequestAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
LuiPersonRelationDefaultContextFromRequestAdapter
0%
0/27
0%
0/10
1.556
 
 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.calculations;
 17  
 
 18  
 import org.kuali.student.common.exceptions.*;
 19  
 import javax.servlet.http.HttpServletRequest;
 20  
 import java.util.List;
 21  
 import org.kuali.rice.kim.bo.entity.dto.KimPrincipalInfo;
 22  
 import org.kuali.rice.kim.service.IdentityService;
 23  
 import org.kuali.student.common.dto.ContextInfo;
 24  
 import org.kuali.student.common.dto.StatusInfo;
 25  
 import org.kuali.student.common.infc.HoldsIdentityService;
 26  
 import org.kuali.student.enrollment.lpr.dto.LuiPersonRelationInfo;
 27  
 import org.kuali.student.enrollment.lpr.service.decorators.LuiPersonRelationServiceDecorator;
 28  
 
 29  
 /**
 30  
  * A example of an adaptor that will default the context if not supplied based
 31  
  * on the requset.
 32  
  * <p/>
 33  
  * This could be generated from the contract definitions as well.
 34  
  *
 35  
  * @Author Norm
 36  
  */
 37  0
 public class LuiPersonRelationDefaultContextFromRequestAdapter
 38  
                 extends LuiPersonRelationServiceDecorator
 39  
                 implements HoldsIdentityService {
 40  
 
 41  
         private HttpServletRequest request;
 42  
         private IdentityService identityService;
 43  
 
 44  
         // TODO: add logic to the servlet to actually set this variable because it cannot be configured
 45  
         public HttpServletRequest getRequest() {
 46  0
                 return request;
 47  
         }
 48  
 
 49  
         public void setRequest(HttpServletRequest request) {
 50  0
                 this.request = request;
 51  0
         }
 52  
 
 53  
         @Override
 54  
         public IdentityService getIdentityService() {
 55  0
                 return identityService;
 56  
         }
 57  
 
 58  
         @Override
 59  
         public void setIdentityService(IdentityService identityService) {
 60  0
                 this.identityService = identityService;
 61  0
         }
 62  
 
 63  
         private ContextInfo defaultContext(ContextInfo context) {
 64  0
                 if (context == null) {
 65  0
                         context = new ContextInfo.Builder().build();
 66  
                 }
 67  0
                 if (context.getPrincipalId() == null) {
 68  0
                         KimPrincipalInfo principalInfo = identityService.getPrincipalByPrincipalName(request.getRemoteUser());
 69  0
                         context = new ContextInfo.Builder(context).principalId(principalInfo.getPrincipalId()).build();
 70  
                 }
 71  0
                 if (context.getLocaleLanguage() == null) {
 72  0
                         context = new ContextInfo.Builder(context).localeLanguage(request.getLocale().getLanguage()).build();
 73  
                 }
 74  
                 // TODO: check if Region and country are supposed to the same thing
 75  0
                 if (context.getLocaleRegion() == null) {
 76  0
                         context = new ContextInfo.Builder(context).localeLanguage(request.getLocale().getCountry()).build();
 77  
                 }
 78  0
                 if (context.getLocaleVariant() == null) {
 79  0
                         context = new ContextInfo.Builder(context).localeLanguage(request.getLocale().getVariant()).build();
 80  
                 }
 81  
                 // TODO: default script from the character set
 82  0
                 return context;
 83  
         }
 84  
 
 85  
         @Override
 86  
         public String createLuiPersonRelation(String personId,
 87  
                         String luiId,
 88  
                         String luiPersonRelationType,
 89  
                         LuiPersonRelationInfo luiPersonRelationInfo,
 90  
                         ContextInfo context)
 91  
                         throws DataValidationErrorException,
 92  
                         AlreadyExistsException,
 93  
                         DoesNotExistException,
 94  
                         DisabledIdentifierException,
 95  
                         ReadOnlyException,
 96  
                         InvalidParameterException,
 97  
                         MissingParameterException, OperationFailedException,
 98  
                         PermissionDeniedException {
 99  0
                 context = defaultContext(context);
 100  0
                 return (getLprService().createLuiPersonRelation(personId,
 101  
                                 luiId,
 102  
                                 luiPersonRelationType,
 103  
                                 luiPersonRelationInfo,
 104  
                                 context));
 105  
         }
 106  
 
 107  
         @Override
 108  
         public List<String> createBulkRelationshipsForPerson(String personId,
 109  
                         List<String> luiIdList,
 110  
                         String relationState,
 111  
                         String luiPersonRelationType,
 112  
                         LuiPersonRelationInfo luiPersonRelationInfo,
 113  
                         ContextInfo context)
 114  
                         throws DataValidationErrorException,
 115  
                         AlreadyExistsException,
 116  
                         DoesNotExistException,
 117  
                         DisabledIdentifierException,
 118  
                         ReadOnlyException,
 119  
                         InvalidParameterException,
 120  
                         MissingParameterException,
 121  
                         OperationFailedException,
 122  
                         PermissionDeniedException {
 123  0
                 context = defaultContext(context);
 124  0
                 return (getLprService().createBulkRelationshipsForPerson(personId, luiIdList,
 125  
                                 relationState,
 126  
                                 luiPersonRelationType,
 127  
                                 luiPersonRelationInfo,
 128  
                                 context));
 129  
         }
 130  
 
 131  
         @Override
 132  
         public LuiPersonRelationInfo updateLuiPersonRelation(
 133  
                         String luiPersonRelationId,
 134  
                         LuiPersonRelationInfo luiPersonRelationInfo,
 135  
                         ContextInfo context)
 136  
                         throws DataValidationErrorException,
 137  
                         DoesNotExistException,
 138  
                         InvalidParameterException,
 139  
                         MissingParameterException,
 140  
                         ReadOnlyException,
 141  
                         OperationFailedException,
 142  
                         PermissionDeniedException,
 143  
                         VersionMismatchException {
 144  0
                 context = defaultContext(context);
 145  0
                 return (getLprService().updateLuiPersonRelation(luiPersonRelationId,
 146  
                                 luiPersonRelationInfo,
 147  
                                 context));
 148  
         }
 149  
 
 150  
         @Override
 151  
         public StatusInfo deleteLuiPersonRelation(String luiPersonRelationId,
 152  
                         ContextInfo context) throws
 153  
                         DoesNotExistException, InvalidParameterException, MissingParameterException,
 154  
                         OperationFailedException,
 155  
                         PermissionDeniedException {
 156  0
                 context = defaultContext(context);
 157  0
                 return (getLprService().deleteLuiPersonRelation(luiPersonRelationId, context));
 158  
         }
 159  
 
 160  
 
 161  
         
 162  
 }