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  
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
27  import org.apache.chemistry.opencmis.commons.data.Ace;
28  import org.apache.chemistry.opencmis.commons.data.Acl;
29  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
30  import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
31  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
32  import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl;
33  import org.apache.chemistry.opencmis.commons.impl.jaxb.ACLServicePort;
34  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
35  import org.apache.chemistry.opencmis.commons.impl.jaxb.EnumACLPropagation;
36  import org.apache.chemistry.opencmis.commons.spi.AclService;
37  import org.apache.chemistry.opencmis.commons.spi.ExtendedAclService;
38  
39  /**
40   * ACL Service Web Services client.
41   */
42  public class AclServiceImpl extends AbstractWebServicesService implements AclService, ExtendedAclService {
43  
44      private final AbstractPortProvider portProvider;
45  
46      /**
47       * Constructor.
48       */
49      public AclServiceImpl(BindingSession session, AbstractPortProvider portProvider) {
50          setSession(session);
51          this.portProvider = portProvider;
52      }
53  
54      @Override
55      public Acl applyAcl(String repositoryId, String objectId, Acl addACEs, Acl removeACEs,
56              AclPropagation aclPropagation, ExtensionsData extension) {
57          ACLServicePort port = portProvider.getACLServicePort(getCmisVersion(repositoryId), "applyACL");
58  
59          try {
60              return convert(port.applyACL(repositoryId, objectId, convert(addACEs), convert(removeACEs),
61                      convert(EnumACLPropagation.class, aclPropagation), convert(extension)));
62          } catch (CmisException e) {
63              throw convertException(e);
64          } catch (Exception e) {
65              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
66          } finally {
67              portProvider.endCall(port);
68          }
69      }
70  
71      @Override
72      public Acl getAcl(String repositoryId, String objectId, Boolean onlyBasicPermissions, ExtensionsData extension) {
73          ACLServicePort port = portProvider.getACLServicePort(getCmisVersion(repositoryId), "getACL");
74  
75          try {
76              return convert(port.getACL(repositoryId, objectId, onlyBasicPermissions, convert(extension)));
77          } catch (CmisException e) {
78              throw convertException(e);
79          } catch (Exception e) {
80              throw new CmisRuntimeException("Error: " + e.getMessage(), e);
81          } finally {
82              portProvider.endCall(port);
83          }
84      }
85  
86      @Override
87      public Acl setAcl(String repositoryId, String objectId, Acl aces) {
88          Acl currentAcl = getAcl(repositoryId, objectId, false, null);
89  
90          List<Ace> removeAces = new ArrayList<Ace>();
91          if (currentAcl.getAces() != null) {
92              for (Ace ace : currentAcl.getAces()) {
93                  if (ace.isDirect()) {
94                      removeAces.add(ace);
95                  }
96              }
97          }
98  
99          return applyAcl(repositoryId, objectId, aces, new AccessControlListImpl(removeAces), AclPropagation.OBJECTONLY,
100                 null);
101     }
102 }