View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * CMIS Policy Service.
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 }