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.client.bindings.spi.webservices;
20  
21  import static org.apache.chemistry.opencmis.commons.impl.WSConverter.convert;
22  import static org.apache.chemistry.opencmis.commons.impl.WSConverter.convertExtensionHolder;
23  import static org.apache.chemistry.opencmis.commons.impl.WSConverter.setExtensionValues;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  import javax.xml.ws.Holder;
29  
30  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
31  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
32  import org.apache.chemistry.opencmis.commons.data.ObjectData;
33  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
34  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
35  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisExtensionType;
36  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
37  import org.apache.chemistry.opencmis.commons.impl.jaxb.PolicyServicePort;
38  import org.apache.chemistry.opencmis.commons.spi.PolicyService;
39  
40  /**
41   * Policy Service Web Services client.
42   */
43  public class PolicyServiceImpl extends AbstractWebServicesService implements PolicyService {
44  
45      private final AbstractPortProvider portProvider;
46  
47      /**
48       * Constructor.
49       */
50      public PolicyServiceImpl(BindingSession session, AbstractPortProvider portProvider) {
51          setSession(session);
52          this.portProvider = portProvider;
53      }
54  
55      @Override
56      public void applyPolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
57          PolicyServicePort port = portProvider.getPolicyServicePort(getCmisVersion(repositoryId), "applyPolicy");
58  
59          try {
60              Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension);
61  
62              port.applyPolicy(repositoryId, policyId, objectId, portExtension);
63  
64              setExtensionValues(portExtension, extension);
65          } catch (CmisException e) {
66              throw convertException(e);
67          } catch (Exception e) {
68              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
69          } finally {
70              portProvider.endCall(port);
71          }
72      }
73  
74      @Override
75      public void removePolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
76          PolicyServicePort port = portProvider.getPolicyServicePort(getCmisVersion(repositoryId), "removePolicy");
77  
78          try {
79              Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension);
80  
81              port.removePolicy(repositoryId, policyId, objectId, portExtension);
82  
83              setExtensionValues(portExtension, extension);
84          } catch (CmisException e) {
85              throw convertException(e);
86          } catch (Exception e) {
87              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
88          } finally {
89              portProvider.endCall(port);
90          }
91      }
92  
93      @Override
94      public List<ObjectData> getAppliedPolicies(String repositoryId, String objectId, String filter,
95              ExtensionsData extension) {
96          PolicyServicePort port = portProvider.getPolicyServicePort(getCmisVersion(repositoryId), "getAppliedPolicies");
97  
98          try {
99              List<CmisObjectType> policyList = port.getAppliedPolicies(repositoryId, objectId, filter,
100                     convert(extension));
101 
102             List<ObjectData> result = new ArrayList<ObjectData>();
103 
104             // no list?
105             if (policyList == null) {
106                 return result;
107             }
108 
109             // convert list
110             for (CmisObjectType policy : policyList) {
111                 result.add(convert(policy));
112             }
113 
114             return result;
115         } catch (CmisException e) {
116             throw convertException(e);
117         } catch (Exception e) {
118             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
119         } finally {
120             portProvider.endCall(port);
121         }
122     }
123 }