| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 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 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 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 | |
|
| 68 | |
|
| 69 | |
|
| 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 | |
|
| 102 | |
|
| 103 | |
|
| 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 | |
|
| 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 | |
|
| 159 | 0 | List<String> permissionIds = new ArrayList<String>(); |
| 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 | |
} |