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.api.common.template.Template;
26
27
28
29
30
31
32 public class NameAndNamespacePairToPermTemplateIdAdapter extends XmlAdapter<NameAndNamespacePair,String> {
33
34
35
36
37 @Override
38 public String unmarshal(NameAndNamespacePair v) throws Exception {
39 if (v != null) {
40 Template permissionTemplate = KimApiServiceLocator.getPermissionService().findPermTemplateByNamespaceCodeAndName(
41 v.getNamespaceCode(), new NormalizedStringAdapter().unmarshal(v.getName()));
42 if (permissionTemplate == null) {
43 throw new UnmarshalException("Cannot find permission template with namespace \"" + v.getNamespaceCode() + "\" and name \"" + v.getName() + "\"");
44 }
45 return permissionTemplate.getId();
46 }
47 return null;
48 }
49
50
51
52
53 @Override
54 public NameAndNamespacePair marshal(String v) throws Exception {
55 if (v != null) {
56 Template permissionTemplate = KimApiServiceLocator.getPermissionService().getPermissionTemplate(v);
57 if (permissionTemplate == null) {
58 throw new MarshalException("Cannot find permission template with ID \"" + v + "\"");
59 }
60 return new NameAndNamespacePair(permissionTemplate.getNamespaceCode(), permissionTemplate.getName());
61 }
62 return null;
63 }
64
65 }