This project has retired. For details please refer to its Attic page.
MultiFilingServiceImpl 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.atompub;
20  
21  import java.io.OutputStream;
22  
23  import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
24  import org.apache.chemistry.opencmis.client.bindings.spi.http.HttpUtils;
25  import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
26  import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
27  import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
28  import org.apache.chemistry.opencmis.commons.impl.Constants;
29  import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
30  import org.apache.chemistry.opencmis.commons.spi.MultiFilingService;
31  
32  /**
33   * MultiFiling Service AtomPub client.
34   */
35  public class MultiFilingServiceImpl extends AbstractAtomPubService implements MultiFilingService {
36  
37      /**
38       * Constructor.
39       */
40      public MultiFilingServiceImpl(BindingSession session) {
41          setSession(session);
42      }
43  
44      public void addObjectToFolder(String repositoryId, String objectId, String folderId, Boolean allVersions,
45              ExtensionsData extension) {
46          if (objectId == null) {
47              throw new CmisInvalidArgumentException("Object id must be set!");
48          }
49  
50          // find the link
51          String link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
52  
53          if (link == null) {
54              throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
55          }
56  
57          UrlBuilder url = new UrlBuilder(link);
58          url.addParameter(Constants.PARAM_ALL_VERSIONS, allVersions);
59  
60          // set up object and writer
61          final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId));
62  
63          // post addObjectToFolder request
64          post(url, Constants.MEDIATYPE_ENTRY, new HttpUtils.Output() {
65              public void write(OutputStream out) throws Exception {
66                  entryWriter.write(out);
67              }
68          });
69      }
70  
71      public void removeObjectFromFolder(String repositoryId, String objectId, String folderId, ExtensionsData extension) {
72          if (objectId == null) {
73              throw new CmisInvalidArgumentException("Object id must be set!");
74          }
75  
76          // find the link
77          String link = loadCollection(repositoryId, Constants.COLLECTION_UNFILED);
78  
79          if (link == null) {
80              throw new CmisObjectNotFoundException("Unknown repository or unfiling not supported!");
81          }
82  
83          UrlBuilder url = new UrlBuilder(link);
84          url.addParameter(Constants.PARAM_REMOVE_FROM, folderId);
85  
86          // set up object and writer
87          final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId));
88  
89          // post removeObjectFromFolder request
90          post(url, Constants.MEDIATYPE_ENTRY, new HttpUtils.Output() {
91              public void write(OutputStream out) throws Exception {
92                  entryWriter.write(out);
93              }
94          });
95      }
96  }