This project has retired. For details please refer to its Attic page.
PolicyService 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.server.impl.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 javax.annotation.Resource;
29  import javax.jws.WebService;
30  import javax.xml.ws.Holder;
31  import javax.xml.ws.WebServiceContext;
32  import javax.xml.ws.soap.MTOM;
33  
34  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
35  import org.apache.chemistry.opencmis.commons.data.ObjectData;
36  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
37  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisExtensionType;
38  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
39  import org.apache.chemistry.opencmis.commons.impl.jaxb.PolicyServicePort;
40  import org.apache.chemistry.opencmis.commons.server.CmisService;
41  
42  /**
43   * CMIS Policy Service.
44   */
45  @MTOM
46  @WebService(endpointInterface = "org.apache.chemistry.opencmis.commons.impl.jaxb.PolicyServicePort")
47  public class PolicyService extends AbstractService implements PolicyServicePort {
48      @Resource
49      public WebServiceContext wsContext;
50  
51      public void applyPolicy(String repositoryId, String policyId, String objectId, Holder<CmisExtensionType> extension)
52              throws CmisException {
53          CmisService service = null;
54          try {
55              service = getService(wsContext, repositoryId);
56  
57              ExtensionsData extData = convertExtensionHolder(extension);
58  
59              service.applyPolicy(repositoryId, policyId, objectId, extData);
60  
61              setExtensionValues(extData, extension);
62          } catch (Exception e) {
63              throw convertException(e);
64          } finally {
65              closeService(service);
66          }
67      }
68  
69      public List<CmisObjectType> getAppliedPolicies(String repositoryId, String objectId, String filter,
70              CmisExtensionType extension) throws CmisException {
71          CmisService service = null;
72          try {
73              service = getService(wsContext, repositoryId);
74  
75              List<ObjectData> policies = service.getAppliedPolicies(repositoryId, objectId, filter, convert(extension));
76  
77              if (policies == null) {
78                  return null;
79              }
80  
81              List<CmisObjectType> result = new ArrayList<CmisObjectType>();
82              for (ObjectData object : policies) {
83                  result.add(convert(object));
84              }
85  
86              return result;
87          } catch (Exception e) {
88              throw convertException(e);
89          } finally {
90              closeService(service);
91          }
92      }
93  
94      public void removePolicy(String repositoryId, String policyId, String objectId, Holder<CmisExtensionType> extension)
95              throws CmisException {
96          CmisService service = null;
97          try {
98              service = getService(wsContext, repositoryId);
99  
100             ExtensionsData extData = convertExtensionHolder(extension);
101 
102             service.removePolicy(repositoryId, policyId, objectId, extData);
103 
104             setExtensionValues(extData, extension);
105         } catch (Exception e) {
106             throw convertException(e);
107         } finally {
108             closeService(service);
109         }
110     }
111 }