1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.server.impl.webservices;
20
21 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
22 import org.apache.chemistry.opencmis.commons.data.ObjectData;
23 import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
24 import static org.apache.chemistry.opencmis.commons.impl.Converter.convertExtensionHolder;
25 import static org.apache.chemistry.opencmis.commons.impl.Converter.setExtensionValues;
26 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
27 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisExtensionType;
28 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
29 import org.apache.chemistry.opencmis.commons.impl.jaxb.PolicyServicePort;
30 import org.apache.chemistry.opencmis.commons.server.CmisService;
31
32 import java.util.ArrayList;
33 import java.util.List;
34
35 import javax.annotation.Resource;
36
37 import javax.jws.WebService;
38
39 import javax.xml.ws.Holder;
40 import javax.xml.ws.WebServiceContext;
41 import javax.xml.ws.soap.MTOM;
42
43
44
45
46
47 @MTOM
48 @WebService( endpointInterface = "org.apache.chemistry.opencmis.commons.impl.jaxb.PolicyServicePort" )
49 public class PolicyService extends AbstractService implements PolicyServicePort
50 {
51 @Resource
52 public WebServiceContext wsContext;
53
54 public void applyPolicy( String repositoryId, String policyId, String objectId, Holder<CmisExtensionType> extension )
55 throws CmisException
56 {
57 CmisService service = null;
58
59 try
60 {
61 service = getService( wsContext, repositoryId );
62
63 ExtensionsData extData = convertExtensionHolder( extension );
64
65 service.applyPolicy( repositoryId, policyId, objectId, extData );
66
67 setExtensionValues( extData, extension );
68 }
69 catch ( Exception e )
70 {
71 throw convertException( e );
72 }
73 finally
74 {
75 closeService( service );
76 }
77 }
78
79 public List<CmisObjectType> getAppliedPolicies( String repositoryId, String objectId, String filter,
80 CmisExtensionType extension ) throws CmisException
81 {
82 CmisService service = null;
83
84 try
85 {
86 service = getService( wsContext, repositoryId );
87
88 List<ObjectData> policies = service.getAppliedPolicies( repositoryId, objectId, filter, convert( extension ) );
89
90 if ( policies == null )
91 {
92 return null;
93 }
94
95 List<CmisObjectType> result = new ArrayList<CmisObjectType>( );
96
97 for ( ObjectData object : policies )
98 {
99 result.add( convert( object ) );
100 }
101
102 return result;
103 }
104 catch ( Exception e )
105 {
106 throw convertException( e );
107 }
108 finally
109 {
110 closeService( service );
111 }
112 }
113
114 public void removePolicy( String repositoryId, String policyId, String objectId, Holder<CmisExtensionType> extension )
115 throws CmisException
116 {
117 CmisService service = null;
118
119 try
120 {
121 service = getService( wsContext, repositoryId );
122
123 ExtensionsData extData = convertExtensionHolder( extension );
124
125 service.removePolicy( repositoryId, policyId, objectId, extData );
126
127 setExtensionValues( extData, extension );
128 }
129 catch ( Exception e )
130 {
131 throw convertException( e );
132 }
133 finally
134 {
135 closeService( service );
136 }
137 }
138 }