This project has retired. For details please refer to its Attic page.
AclServiceImpl 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.browser;
20  
21  import java.io.OutputStream;
22  import java.util.Map;
23  
24  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
25  import org.apache.chemistry.opencmis.client.bindings.spi.http.HttpUtils;
26  import org.apache.chemistry.opencmis.commons.data.Acl;
27  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
28  import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
29  import org.apache.chemistry.opencmis.commons.impl.Constants;
30  import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
31  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
32  import org.apache.chemistry.opencmis.commons.spi.AclService;
33  
34  /**
35   * ACL Service Browser Binding client.
36   */
37  public class AclServiceImpl extends AbstractBrowserBindingService implements AclService {
38  
39      /**
40       * Constructor.
41       */
42      public AclServiceImpl(BindingSession session) {
43          setSession(session);
44      }
45  
46      public Acl getAcl(String repositoryId, String objectId, Boolean onlyBasicPermissions, ExtensionsData extension) {
47          // build URL
48          UrlBuilder url = getObjectUrl(repositoryId, objectId, Constants.SELECTOR_ACL);
49          url.addParameter(Constants.PARAM_ONLY_BASIC_PERMISSIONS, onlyBasicPermissions);
50  
51          // read and parse
52          HttpUtils.Response resp = read(url);
53          Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
54  
55          return JSONConverter.convertAcl(json, null);
56      }
57  
58      public Acl applyAcl(String repositoryId, String objectId, Acl addAces, Acl removeAces,
59              AclPropagation aclPropagation, ExtensionsData extension) {
60          // build URL
61          UrlBuilder url = getObjectUrl(repositoryId, objectId);
62  
63          // prepare form data
64          final FormDataWriter formData = new FormDataWriter(Constants.CMISACTION_APPLY_ACL);
65          formData.addAddAcesParameters(addAces);
66          formData.addRemoveAcesParameters(removeAces);
67          formData.addParameter(Constants.PARAM_ACL_PROPAGATION, aclPropagation);
68  
69          // send and parse
70          HttpUtils.Response resp = post(url, formData.getContentType(), new HttpUtils.Output() {
71              public void write(OutputStream out) throws Exception {
72                  formData.write(out);
73              }
74          });
75          Map<String, Object> json = parseObject(resp.getStream(), resp.getCharset());
76  
77          return JSONConverter.convertAcl(json, null);
78      }
79  }