1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.api.jaxb; |
17 | |
|
18 | |
import javax.xml.bind.MarshalException; |
19 | |
import javax.xml.bind.UnmarshalException; |
20 | |
import javax.xml.bind.annotation.adapters.NormalizedStringAdapter; |
21 | |
import javax.xml.bind.annotation.adapters.XmlAdapter; |
22 | |
|
23 | |
import org.kuali.rice.core.util.jaxb.NameAndNamespacePair; |
24 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
25 | |
import org.kuali.rice.kim.bo.role.KimPermissionTemplate; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | 0 | public class NameAndNamespacePairToPermTemplateIdAdapter extends XmlAdapter<NameAndNamespacePair,String> { |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
@Override |
38 | |
public String unmarshal(NameAndNamespacePair v) throws Exception { |
39 | 0 | if (v != null) { |
40 | 0 | KimPermissionTemplate permissionTemplate = KimApiServiceLocator.getPermissionService().getPermissionTemplateByName( |
41 | |
v.getNamespaceCode(), new NormalizedStringAdapter().unmarshal(v.getName())); |
42 | 0 | if (permissionTemplate == null) { |
43 | 0 | throw new UnmarshalException("Cannot find permission template with namespace \"" + v.getNamespaceCode() + "\" and name \"" + v.getName() + "\""); |
44 | |
} |
45 | 0 | return permissionTemplate.getPermissionTemplateId(); |
46 | |
} |
47 | 0 | return null; |
48 | |
} |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
@Override |
54 | |
public NameAndNamespacePair marshal(String v) throws Exception { |
55 | 0 | if (v != null) { |
56 | 0 | KimPermissionTemplate permissionTemplate = KimApiServiceLocator.getPermissionService().getPermissionTemplate(v); |
57 | 0 | if (permissionTemplate == null) { |
58 | 0 | throw new MarshalException("Cannot find permission template with ID \"" + v + "\""); |
59 | |
} |
60 | 0 | return new NameAndNamespacePair(permissionTemplate.getNamespaceCode(), permissionTemplate.getName()); |
61 | |
} |
62 | 0 | return null; |
63 | |
} |
64 | |
|
65 | |
} |