This project has retired. For details please refer to its Attic page.
MultiFilingService 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.browser;
20  
21  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_FOLDER_ID;
22  import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.RESOURCE_CONTENT;
23  import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileBaseUrl;
24  import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileUrl;
25  import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.CONTEXT_OBJECT_ID;
26  import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.getSimpleObject;
27  import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.setStatus;
28  import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.writeJSON;
29  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
30  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
31  
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.http.HttpServletResponse;
34  
35  import org.apache.chemistry.opencmis.commons.data.ObjectData;
36  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
37  import org.apache.chemistry.opencmis.commons.impl.Constants;
38  import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
39  import org.apache.chemistry.opencmis.commons.impl.TypeCache;
40  import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
41  import org.apache.chemistry.opencmis.commons.impl.server.TypeCacheImpl;
42  import org.apache.chemistry.opencmis.commons.server.CallContext;
43  import org.apache.chemistry.opencmis.commons.server.CmisService;
44  import org.apache.chemistry.opencmis.commons.spi.Holder;
45  
46  /**
47   * MultiFiling Service operations.
48   */
49  public class MultiFilingService {
50  
51      /*
52       * addObjectToFolder.
53       */
54      public static void addObjectToFolder(CallContext context, CmisService service, String repositoryId,
55              HttpServletRequest request, HttpServletResponse response) throws Exception {
56          // get parameters
57          String objectId = (String) context.get(CONTEXT_OBJECT_ID);
58          String folderId = getStringParameter(request, PARAM_FOLDER_ID);
59          Boolean allVersions = getBooleanParameter(request, Constants.PARAM_ALL_VERSIONS);
60  
61          // execute
62          Holder<String> objectIdHolder = new Holder<String>(objectId);
63          service.addObjectToFolder(repositoryId, objectId, folderId, allVersions, null);
64  
65          String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
66  
67          ObjectData object = getSimpleObject(service, repositoryId, newObjectId);
68          if (object == null) {
69              throw new CmisRuntimeException("Object is null!");
70          }
71  
72          // set headers
73          String location = compileUrl(compileBaseUrl(request, repositoryId), RESOURCE_CONTENT, newObjectId);
74  
75          setStatus(request, response, HttpServletResponse.SC_CREATED);
76          response.setHeader("Location", location);
77  
78          // return object
79          TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
80          JSONObject jsonObject = JSONConverter.convert(object, typeCache, false);
81  
82          writeJSON(jsonObject, request, response);
83      }
84  
85      /*
86       * removeObjectFromFolder.
87       */
88      public static void removeObjectFromFolder(CallContext context, CmisService service, String repositoryId,
89              HttpServletRequest request, HttpServletResponse response) throws Exception {
90          // get parameters
91          String objectId = (String) context.get(CONTEXT_OBJECT_ID);
92          String folderId = getStringParameter(request, PARAM_FOLDER_ID);
93  
94          // execute
95          Holder<String> objectIdHolder = new Holder<String>(objectId);
96          service.removeObjectFromFolder(repositoryId, objectId, folderId, null);
97  
98          String newObjectId = (objectIdHolder.getValue() == null ? objectId : objectIdHolder.getValue());
99  
100         ObjectData object = getSimpleObject(service, repositoryId, newObjectId);
101         if (object == null) {
102             throw new CmisRuntimeException("Object is null!");
103         }
104 
105         // set headers
106         String location = compileUrl(compileBaseUrl(request, repositoryId), RESOURCE_CONTENT, newObjectId);
107 
108         setStatus(request, response, HttpServletResponse.SC_CREATED);
109         response.setHeader("Location", location);
110 
111         // return object
112         TypeCache typeCache = new TypeCacheImpl(repositoryId, service);
113         JSONObject jsonObject = JSONConverter.convert(object, typeCache, false);
114 
115         writeJSON(jsonObject, request, response);
116     }
117 }