This project has retired. For details please refer to its Attic page.
PolicyServiceImpl xref

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.Converter.convert;
22  import static org.apache.chemistry.opencmis.commons.impl.Converter.convertExtensionHolder;
23  import static org.apache.chemistry.opencmis.commons.impl.Converter.setExtensionValues;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
29  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
30  import org.apache.chemistry.opencmis.commons.data.ObjectData;
31  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
32  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
33  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisExtensionType;
34  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
35  import org.apache.chemistry.opencmis.commons.impl.jaxb.PolicyServicePort;
36  import org.apache.chemistry.opencmis.commons.spi.PolicyService;
37  
38  import javax.xml.ws.Holder;
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      public void applyPolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
56          PolicyServicePort port = portProvider.getPolicyServicePort();
57  
58          try {
59              Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension);
60  
61              port.applyPolicy(repositoryId, policyId, objectId, portExtension);
62  
63              setExtensionValues(portExtension, extension);
64          } catch (CmisException e) {
65              throw convertException(e);
66          } catch (Exception e) {
67              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
68          } finally {
69              portProvider.endCall(port);
70          }
71      }
72  
73      public void removePolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
74          PolicyServicePort port = portProvider.getPolicyServicePort();
75  
76          try {
77              Holder<CmisExtensionType> portExtension = convertExtensionHolder(extension);
78  
79              port.removePolicy(repositoryId, policyId, objectId, portExtension);
80  
81              setExtensionValues(portExtension, extension);
82          } catch (CmisException e) {
83              throw convertException(e);
84          } catch (Exception e) {
85              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
86          } finally {
87              portProvider.endCall(port);
88          }
89      }
90  
91      public List<ObjectData> getAppliedPolicies(String repositoryId, String objectId, String filter,
92              ExtensionsData extension) {
93          PolicyServicePort port = portProvider.getPolicyServicePort();
94  
95          try {
96              List<CmisObjectType> policyList = port.getAppliedPolicies(repositoryId, objectId, filter,
97                      convert(extension));
98  
99              List<ObjectData> result = new ArrayList<ObjectData>();
100 
101             // no list?
102             if (policyList == null) {
103                 return result;
104             }
105 
106             // convert list
107             for (CmisObjectType policy : policyList) {
108                 result.add(convert(policy));
109             }
110 
111             return result;
112         } catch (CmisException e) {
113             throw convertException(e);
114         } catch (Exception e) {
115             throw new CmisRuntimeException("Error: " + e.getMessage(), e);
116         } finally {
117             portProvider.endCall(port);
118         }
119     }
120 }