Coverage Report - org.kuali.rice.kim.impl.jaxb.RolePermissionsXmlDTO
 
Classes in this File Line Coverage Branch Coverage Complexity
RolePermissionsXmlDTO
0%
0/6
N/A
1.588
RolePermissionsXmlDTO$OutsideOfRole
0%
0/10
N/A
1.588
RolePermissionsXmlDTO$WithinRole
0%
0/31
0%
0/10
1.588
 
 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.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 implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kim.impl.jaxb;
 17  
 
 18  
 import java.io.Serializable;
 19  
 import java.util.ArrayList;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.xml.bind.Marshaller;
 23  
 import javax.xml.bind.UnmarshalException;
 24  
 import javax.xml.bind.Unmarshaller;
 25  
 import javax.xml.bind.annotation.XmlAccessType;
 26  
 import javax.xml.bind.annotation.XmlAccessorType;
 27  
 import javax.xml.bind.annotation.XmlElement;
 28  
 import javax.xml.bind.annotation.XmlTransient;
 29  
 import javax.xml.bind.annotation.XmlType;
 30  
 
 31  
 import org.kuali.rice.core.util.jaxb.RiceXmlExportList;
 32  
 import org.kuali.rice.core.util.jaxb.RiceXmlImportList;
 33  
 import org.kuali.rice.core.util.jaxb.RiceXmlListAdditionListener;
 34  
 import org.kuali.rice.core.util.jaxb.RiceXmlListGetterListener;
 35  
 import org.kuali.rice.kim.api.permission.PermissionContract;
 36  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 37  
 
 38  
 /**
 39  
  * Base class representing an unmarshalled <rolePermissions> element.
 40  
  * Refer to the static inner classes for more information about the specific contexts.
 41  
  * 
 42  
  * TODO: Alter the role/permission service APIs so that finding all the permissions assigned to a role is possible; the
 43  
  * current lack of such an API method prevents role permissions from being exported.
 44  
  * 
 45  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 46  
  */
 47  
 @XmlTransient
 48  0
 public abstract class RolePermissionsXmlDTO<T extends RolePermissionXmlDTO> implements RiceXmlListAdditionListener<T>, Serializable {
 49  
     
 50  
     private static final long serialVersionUID = 1L;
 51  
 
 52  
     public abstract List<T> getRolePermissions();
 53  
     
 54  
     public abstract void setRolePermissions(List<T> rolePermissions);
 55  
     
 56  
     void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) throws UnmarshalException {
 57  0
         setRolePermissions(new RiceXmlImportList<T>(this));
 58  0
     }
 59  
     
 60  
     void afterUnmarshal(Unmarshaller unmarshaller, Object parent) throws UnmarshalException {
 61  0
         setRolePermissions(null);
 62  0
     }
 63  
     
 64  
     // =======================================================================================================
 65  
     
 66  
     /**
 67  
      * This class represents a &lt;rolePermissions&gt; element that is not a child of a &lt;role&gt; element.
 68  
      * 
 69  
      * @author Kuali Rice Team (rice.collab@kuali.org)
 70  
      */
 71  0
     @XmlAccessorType(XmlAccessType.FIELD)
 72  
     @XmlType(name="StandaloneRolePermissionsType", propOrder={"rolePermissions"})
 73  0
     public static class OutsideOfRole extends RolePermissionsXmlDTO<RolePermissionXmlDTO.OutsideOfRole> {
 74  
         
 75  
         private static final long serialVersionUID = 1L;
 76  
         
 77  
         @XmlElement(name="rolePermission")
 78  
         private List<RolePermissionXmlDTO.OutsideOfRole> rolePermissions;
 79  
         
 80  
         public List<RolePermissionXmlDTO.OutsideOfRole> getRolePermissions() {
 81  0
             return rolePermissions;
 82  
         }
 83  
 
 84  
         public void setRolePermissions(List<RolePermissionXmlDTO.OutsideOfRole> rolePermissions) {
 85  0
             this.rolePermissions = rolePermissions;
 86  0
         }
 87  
         
 88  
         public void newItemAdded(RolePermissionXmlDTO.OutsideOfRole item) {
 89  
             try {
 90  0
                 RoleXmlUtil.validateAndPersistNewRolePermission(item);
 91  0
             } catch (UnmarshalException e) {
 92  0
                 throw new RuntimeException(e);
 93  0
             }
 94  0
         }
 95  
         
 96  
     }
 97  
     
 98  
     // =======================================================================================================
 99  
     
 100  
     /**
 101  
      * This class represents a &lt;rolePermissions&gt; element that is a child of a &lt;role&gt; element.
 102  
      * 
 103  
      * @author Kuali Rice Team (rice.collab@kuali.org)
 104  
      */
 105  0
     @XmlAccessorType(XmlAccessType.FIELD)
 106  
     @XmlType(name="RolePermissionsType", propOrder={"rolePermissions"})
 107  
     public static class WithinRole extends RolePermissionsXmlDTO<RolePermissionXmlDTO.WithinRole>
 108  
             implements RiceXmlListGetterListener<RolePermissionXmlDTO.WithinRole,String> {
 109  
         
 110  
         private static final long serialVersionUID = 1L;
 111  
 
 112  
         @XmlElement(name="rolePermission")
 113  
         private List<RolePermissionXmlDTO.WithinRole> rolePermissions;
 114  
         
 115  
         @XmlTransient
 116  
         private String roleId;
 117  
         
 118  0
         public WithinRole() {}
 119  
         
 120  0
         public WithinRole(String roleId) {
 121  0
             this.roleId = roleId;
 122  0
         }
 123  
         
 124  
         public List<RolePermissionXmlDTO.WithinRole> getRolePermissions() {
 125  0
             return rolePermissions;
 126  
         }
 127  
 
 128  
         public void setRolePermissions(List<RolePermissionXmlDTO.WithinRole> rolePermissions) {
 129  0
             this.rolePermissions = rolePermissions;
 130  0
         }
 131  
         
 132  
         public String getRoleId() {
 133  0
             return roleId;
 134  
         }
 135  
         
 136  
         @Override
 137  
         void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) throws UnmarshalException {
 138  0
             if (parent instanceof RoleXmlDTO) {
 139  
                 // Obtain the role ID from the enclosing role, and persist the role if it has not been persisted yet.
 140  0
                 RoleXmlDTO parentRole = (RoleXmlDTO) parent;
 141  0
                 if (!parentRole.isAlreadyPersisted()) {
 142  0
                     RoleXmlUtil.validateAndPersistNewRole(parentRole);
 143  
                 }
 144  0
                 roleId = parentRole.getRoleId();
 145  
             }
 146  0
             super.beforeUnmarshal(unmarshaller, parent);
 147  0
         }
 148  
         
 149  
         public void newItemAdded(RolePermissionXmlDTO.WithinRole item) {
 150  
             try {
 151  0
                 RoleXmlUtil.validateAndPersistNewRolePermission(item);
 152  0
             } catch (UnmarshalException e) {
 153  0
                 throw new RuntimeException(e);
 154  0
             }
 155  0
         }
 156  
         
 157  
         void beforeMarshal(Marshaller marshaller) {
 158  
             // TODO: Use new API method once it becomes available!!!!
 159  0
             List<String> permissionIds = new ArrayList<String>();// KIMServiceLocator.getPermissionService().getRoleIdsForPermissionId(permissionId);
 160  0
             if (permissionIds != null && !permissionIds.isEmpty()) {
 161  0
                 setRolePermissions(new RiceXmlExportList<RolePermissionXmlDTO.WithinRole,String>(permissionIds, this));
 162  
             }
 163  0
         }
 164  
         
 165  
         void afterMarshal(Marshaller marshaller) {
 166  0
             setRolePermissions(null);
 167  0
         }
 168  
 
 169  
         public RolePermissionXmlDTO.WithinRole gettingNextItem(String nextItem, int index) {
 170  0
             PermissionContract permission = KimApiServiceLocator.getPermissionService().getPermission(nextItem);
 171  0
             if (permission == null) {
 172  0
                 throw new RuntimeException("Cannot find permission with ID \"" + nextItem + "\"");
 173  
             }
 174  0
             return new RolePermissionXmlDTO.WithinRole(permission, false);
 175  
         }
 176  
     }
 177  
 }