View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   *
20   */
21  package org.apache.chemistry.opencmis.client.bindings.spi.local;
22  
23  import java.util.List;
24  
25  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
26  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
27  import org.apache.chemistry.opencmis.commons.data.ObjectData;
28  import org.apache.chemistry.opencmis.commons.server.CmisService;
29  import org.apache.chemistry.opencmis.commons.server.CmisServiceFactory;
30  import org.apache.chemistry.opencmis.commons.spi.PolicyService;
31  
32  public class PolicyServiceImpl extends AbstractLocalService implements PolicyService {
33  
34      /**
35       * Constructor.
36       */
37      public PolicyServiceImpl(BindingSession session, CmisServiceFactory factory) {
38          setSession(session);
39          setServiceFactory(factory);
40      }
41  
42      @Override
43      public void applyPolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
44          CmisService service = getService(repositoryId);
45  
46          try {
47              if (stopBeforeService(service)) {
48                  return;
49              }
50  
51              service.applyPolicy(repositoryId, policyId, objectId, extension);
52  
53              if (stopAfterService(service)) {
54                  return;
55              }
56          } finally {
57              service.close();
58          }
59      }
60  
61      @Override
62      public List<ObjectData> getAppliedPolicies(String repositoryId, String objectId, String filter,
63              ExtensionsData extension) {
64          CmisService service = getService(repositoryId);
65  
66          try {
67              if (stopBeforeService(service)) {
68                  return null;
69              }
70              List<ObjectData> serviceResut = service.getAppliedPolicies(repositoryId, objectId, filter, extension);
71  
72              if (stopAfterService(service)) {
73                  return null;
74              }
75  
76              return serviceResut;
77          } finally {
78              service.close();
79          }
80      }
81  
82      @Override
83      public void removePolicy(String repositoryId, String policyId, String objectId, ExtensionsData extension) {
84          CmisService service = getService(repositoryId);
85  
86          try {
87              if (stopBeforeService(service)) {
88                  return;
89              }
90  
91              service.removePolicy(repositoryId, policyId, objectId, extension);
92  
93              if (stopAfterService(service)) {
94                  return;
95              }
96          } finally {
97              service.close();
98          }
99      }
100 }