Coverage Report - org.kuali.student.kim.permission.mock.PermissionServiceMockImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PermissionServiceMockImpl
0%
0/95
0%
0/90
3.4
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may        obtain a copy of the License at
 7  
  *
 8  
  *         http://www.osedu.org/licenses/ECL-2.0
 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 implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.student.kim.permission.mock;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.kuali.rice.core.api.criteria.QueryByCriteria;
 24  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 25  
 import org.kuali.rice.core.api.exception.RiceIllegalStateException;
 26  
 import org.kuali.rice.kim.api.common.assignee.Assignee;
 27  
 import org.kuali.rice.kim.api.common.template.Template;
 28  
 import org.kuali.rice.kim.api.common.template.TemplateQueryResults;
 29  
 import org.kuali.rice.kim.api.permission.Permission;
 30  
 import org.kuali.rice.kim.api.permission.PermissionQueryResults;
 31  
 import org.kuali.rice.kim.api.permission.PermissionService;
 32  
 import org.kuali.rice.kim.api.role.Role;
 33  
 import org.kuali.rice.kim.api.role.RoleMembership;
 34  
 
 35  
 import javax.jws.WebParam;
 36  
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 37  
 
 38  
 /**
 39  
  * @author nwright
 40  
  */
 41  0
 public class PermissionServiceMockImpl implements PermissionService {
 42  
 
 43  0
     private transient Map<String, Template> permissionTemplateCache = new HashMap<String, Template>();
 44  0
     private transient Map<String, Permission> permissionCache = new HashMap<String, Permission>();
 45  0
     private transient Map<String, Role> roleCache = new HashMap<String, Role>();
 46  0
     private transient Map<String, RoleMembership> roleMembershipCache = new HashMap<String, RoleMembership>();
 47  
 
 48  
     @Override
 49  
     public List<Template> getAllTemplates() {
 50  0
         return new ArrayList(this.permissionTemplateCache.values());
 51  
     }
 52  
 
 53  
     @Override
 54  
     public List<Permission> getAuthorizedPermissions(String principalId,
 55  
             String namespaceCode,
 56  
             String permissionName,
 57  
             Map<String, String> qualification) {
 58  0
         List<Permission> list = new ArrayList<Permission>();
 59  0
         for (Permission permission : this.permissionCache.values()) {
 60  0
             if (namespaceCode.equals(permission.getNamespaceCode())) {
 61  0
                 if (permissionName.equals(permission.getName())) {
 62  0
                     if (matchesQualification(permission, qualification)) {
 63  0
                         if (matchesPrincipalId(permission, principalId)) {
 64  0
                             list.add(permission);
 65  
                         }
 66  
                     }
 67  
                 }
 68  
             }
 69  
         }
 70  0
         return list;
 71  
     }
 72  
 
 73  
     private boolean matchesPermissionDetails(Permission permission, Map<String, String> permissionDetails) {
 74  
 //        TODO: implement this check
 75  0
         return true;
 76  
     }
 77  
 
 78  
     private boolean matchesQualification(Permission permission, Map<String, String> qualification) {
 79  
 //        TODO: implement this check
 80  0
         return true;
 81  
     }
 82  
 
 83  
     private boolean matchesPrincipalId(Permission permission, String principalId) {
 84  
 //        TODO: implement this check
 85  0
         return true;
 86  
     }
 87  
 
 88  
     @Override
 89  
     public List<Permission> getAuthorizedPermissionsByTemplate(String principalId,
 90  
             String namespaceCode,
 91  
             String permissionTemplateName,
 92  
             Map<String, String> permissionDetails,
 93  
             Map<String, String> qualification) {
 94  0
         List<Permission> list = new ArrayList<Permission>();
 95  0
         for (Permission permission : this.permissionCache.values()) {
 96  0
             if (permission.getTemplate() != null) {
 97  0
                 if (namespaceCode.equals(permission.getTemplate().getNamespaceCode())) {
 98  0
                     if (permissionTemplateName.equals(permission.getTemplate().getName())) {
 99  0
                         if (matchesPermissionDetails(permission, permissionDetails)) {
 100  0
                             if (matchesQualification(permission, qualification)) {
 101  0
                                 if (matchesPrincipalId(permission, principalId)) {
 102  0
                                     list.add(permission);
 103  
                                 }
 104  
                             }
 105  
                         }
 106  
                     }
 107  
                 }
 108  
             }
 109  
         }
 110  0
         return list;
 111  
     }
 112  
 
 113  
     @Override
 114  
     public Permission getPermission(String permissionId) {
 115  0
         return this.permissionCache.get(permissionId);
 116  
     }
 117  
 
 118  
     @Override
 119  
     public List<Assignee> getPermissionAssignees(String namespaceCode,
 120  
             String permissionName,
 121  
             Map<String, String> qualification) {
 122  0
         List<Assignee> list = new ArrayList<Assignee>();
 123  0
         for (Permission permission : this.permissionCache.values()) {
 124  0
             if (namespaceCode.equals(permission.getNamespaceCode())) {
 125  0
                 if (permissionName.equals(permission.getName())) {
 126  0
                     if (matchesQualification(permission, qualification)) {
 127  0
                         list.addAll(getPermissionAssignees(permission));
 128  
                     }
 129  
                 }
 130  
             }
 131  
         }
 132  0
         return list;
 133  
     }
 134  
 
 135  
     private List<Assignee> getPermissionAssignees(Permission permission) {
 136  0
         List<Assignee> list = new ArrayList<Assignee>();
 137  
 //        TODO: Implement this
 138  0
         return list;
 139  
     }
 140  
 
 141  
     @Override
 142  
     public List<Assignee> getPermissionAssigneesByTemplate(String namespaceCode,
 143  
             String permissionTemplateName,
 144  
             Map<String, String> permissionDetails,
 145  
             Map<String, String> qualification) {
 146  0
         List<Assignee> list = new ArrayList<Assignee>();
 147  0
         for (Permission permission : this.permissionCache.values()) {
 148  0
             if (permission.getTemplate() != null) {
 149  0
                 if (namespaceCode.equals(permission.getTemplate().getNamespaceCode())) {
 150  0
                     if (permissionTemplateName.equals(permission.getTemplate().getName())) {
 151  0
                         if (matchesPermissionDetails(permission, permissionDetails)) {
 152  0
                             if (matchesQualification(permission, qualification)) {
 153  0
                                 list.addAll(getPermissionAssignees(permission));
 154  
                             }
 155  
                         }
 156  
                     }
 157  
                 }
 158  
             }
 159  
         }
 160  0
         return list;
 161  
     }
 162  
 
 163  
     @Override
 164  
     public Template getPermissionTemplate(String permissionTemplateId) {
 165  0
         return this.permissionTemplateCache.get(permissionTemplateId);
 166  
     }
 167  
 
 168  
     @Override
 169  
     public Template findPermTemplateByNamespaceCodeAndName(String namespaceCode,
 170  
             String permissionTemplateName) {
 171  0
         for (Template template : this.permissionTemplateCache.values()) {
 172  0
             if (template.getNamespaceCode().equals(namespaceCode)) {
 173  0
                 if (template.getName().equals(permissionTemplateName)) {
 174  0
                     return template;
 175  
                 }
 176  
             }
 177  
         }
 178  0
         return null;
 179  
     }
 180  
 
 181  
     @Override
 182  
     public Permission findPermByNamespaceCodeAndName(String namespaceCode, String permissionName) {
 183  0
         List<Permission> list = new ArrayList<Permission>();
 184  0
         for (Permission permission : this.permissionCache.values()) {
 185  0
             if (namespaceCode.equals(permission.getNamespaceCode())) {
 186  0
                 if (permissionName.equals(permission.getName())) {
 187  0
                     if (permission.isActive()) {
 188  0
                         list.add(permission);
 189  
                     }
 190  
                 }
 191  
             }
 192  
         }
 193  0
         if (list.isEmpty()) {
 194  0
             return null;
 195  
         }
 196  0
         return list.get(0);
 197  
     }
 198  
 
 199  
     /*
 200  
     
 201  
     // TODO Larry Symms wanted to take a look at this
 202  
     @Override
 203  
     public Permission getPermissionsByNameIncludingInactive(String namespaceCode, String permissionName) {
 204  
     List<Permission> list = new ArrayList<Permission>();
 205  
     for (Permission permission : this.permissionCache.values()) {
 206  
     if (namespaceCode.equals(permission.getNamespaceCode())) {
 207  
     if (permissionName.equals(permission.getName())) {
 208  
     list.add(permission);
 209  
     }
 210  
     }
 211  
     }
 212  
     if (list.isEmpty()) {
 213  
     return null;
 214  
     }
 215  
     return list.get(0);
 216  
     }
 217  
      */
 218  
     @Override
 219  
     public List<Permission> findPermissionsByTemplate(String namespaceCode,
 220  
             String permissionTemplateName) {
 221  0
         List<Permission> list = new ArrayList<Permission>();
 222  0
         for (Permission permission : this.permissionCache.values()) {
 223  0
             if (permission.getTemplate() != null) {
 224  0
                 if (namespaceCode.equals(permission.getTemplate().getNamespaceCode())) {
 225  0
                     if (permissionTemplateName.equals(permission.getTemplate().getName())) {
 226  0
                         list.add(permission);
 227  
                     }
 228  
                 }
 229  
             }
 230  
         }
 231  0
         return list;
 232  
     }
 233  
 
 234  
     @Override
 235  
     public List<String> getRoleIdsForPermission(String namespaceCode,
 236  
             String permissionName) {
 237  0
         throw new UnsupportedOperationException("Not supported yet.");
 238  
     }
 239  
 
 240  
     @Override
 241  
     public boolean hasPermission(String principalId, String namespaceCode,
 242  
             String permissionName) {
 243  0
         throw new UnsupportedOperationException("Not supported yet.");
 244  
     }
 245  
 
 246  
     @Override
 247  
     public boolean hasPermissionByTemplate(String principalId,
 248  
             String namespaceCode,
 249  
             String permissionTemplateName,
 250  
             Map<String, String> permissionDetails) {
 251  0
         throw new UnsupportedOperationException("Not supported yet.");
 252  
     }
 253  
 
 254  
     @Override
 255  
     public boolean isAuthorized(String principalId, String namespaceCode,
 256  
             String permissionName,
 257  
             Map<String, String> qualification) {
 258  0
         if (principalId != null) {
 259  0
             if (principalId.equals("123")) {
 260  0
                 return true;
 261  0
             } else if (principalId.endsWith("TestDataLoader")) {
 262  0
                 return true;
 263  
             }
 264  0
             return false;
 265  
         } else {
 266  0
             return false;
 267  
         }
 268  
     }
 269  
 
 270  
     @Override
 271  
     public boolean isAuthorizedByTemplate(String principalId,
 272  
             String namespaceCode,
 273  
             String permissionTemplateName,
 274  
             Map<String, String> permissionDetails,
 275  
             Map<String, String> qualification) {
 276  0
         throw new UnsupportedOperationException("Not supported yet.");
 277  
     }
 278  
 
 279  
     @Override
 280  
     public boolean isPermissionDefined(String namespaceCode, String permissionName) {
 281  0
         for (Permission permission : this.permissionCache.values()) {
 282  0
             if (namespaceCode.equals(permission.getNamespaceCode())) {
 283  0
                 if (permissionName.equals(permission.getName())) {
 284  0
                     return true;
 285  
                 }
 286  
             }
 287  
         }
 288  
 
 289  0
         return false;
 290  
     }
 291  
 
 292  
     @Override
 293  
     public boolean isPermissionDefinedByTemplate(String namespaceCode,
 294  
             String permissionTemplateName,
 295  
             Map<String, String> permissionDetails) {
 296  0
         for (Permission permission : this.permissionCache.values()) {
 297  0
             if (permission.getTemplate() != null) {
 298  0
                 if (namespaceCode.equals(permission.getTemplate().getNamespaceCode())) {
 299  0
                     if (permissionTemplateName.equals(permission.getTemplate().getName())) {
 300  0
                         if (matchesPermissionDetails(permission, permissionDetails)) {
 301  0
                             return true;
 302  
                         }
 303  
                     }
 304  
                 }
 305  
             }
 306  
         }
 307  0
         return false;
 308  
     }
 309  
 
 310  
     @Override
 311  
     public PermissionQueryResults findPermissions(@WebParam(name = "query") QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException {
 312  0
         throw new UnsupportedOperationException("Not supported yet.");
 313  
     }
 314  
 
 315  
     @Override
 316  
     public Permission createPermission(@WebParam(name = "permission") Permission permission) throws RiceIllegalArgumentException, RiceIllegalStateException {
 317  0
         throw new UnsupportedOperationException("Not supported yet.");
 318  
     }
 319  
 
 320  
     @Override
 321  
     public Permission updatePermission(@WebParam(name = "permission") Permission permission) throws RiceIllegalArgumentException, RiceIllegalStateException {
 322  0
         throw new UnsupportedOperationException("Not supported yet.");
 323  
     }
 324  
 
 325  
     @Override
 326  
     public TemplateQueryResults findPermissionTemplates(@WebParam(name = "query") QueryByCriteria queryByCriteria) throws RiceIllegalArgumentException {
 327  0
         throw new UnsupportedOperationException("Not supported yet.");
 328  
     }
 329  
 }