1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.client.bindings.spi.atompub;
20
21 import java.io.IOException;
22 import java.io.OutputStream;
23
24 import javax.xml.stream.XMLStreamException;
25
26 import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
27 import org.apache.chemistry.opencmis.client.bindings.spi.http.Output;
28 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
29 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
30 import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
31 import org.apache.chemistry.opencmis.commons.impl.Constants;
32 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
33 import org.apache.chemistry.opencmis.commons.spi.MultiFilingService;
34
35
36
37
38 public class MultiFilingServiceImpl extends AbstractAtomPubService implements MultiFilingService {
39
40
41
42
43 public MultiFilingServiceImpl(BindingSession session) {
44 setSession(session);
45 }
46
47 @Override
48 public void addObjectToFolder(String repositoryId, String objectId, String folderId, Boolean allVersions,
49 ExtensionsData extension) {
50 if (objectId == null) {
51 throw new CmisInvalidArgumentException("Object id must be set!");
52 }
53
54
55 String link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
56
57 if (link == null) {
58 throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
59 }
60
61 UrlBuilder url = new UrlBuilder(link);
62 url.addParameter(Constants.PARAM_ALL_VERSIONS, allVersions);
63
64
65 final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId), getCmisVersion(repositoryId));
66
67
68 postAndConsume(url, Constants.MEDIATYPE_ENTRY, new Output() {
69 @Override
70 public void write(OutputStream out) throws XMLStreamException, IOException {
71 entryWriter.write(out);
72 }
73 });
74 }
75
76 @Override
77 public void removeObjectFromFolder(String repositoryId, String objectId, String folderId, ExtensionsData extension) {
78 if (objectId == null) {
79 throw new CmisInvalidArgumentException("Object id must be set!");
80 }
81
82
83 String link = loadCollection(repositoryId, Constants.COLLECTION_UNFILED);
84
85 if (link == null) {
86 throw new CmisObjectNotFoundException("Unknown repository or unfiling not supported!");
87 }
88
89 UrlBuilder url = new UrlBuilder(link);
90 url.addParameter(Constants.PARAM_REMOVE_FROM, folderId);
91
92
93 final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId), getCmisVersion(repositoryId));
94
95
96 postAndConsume(url, Constants.MEDIATYPE_ENTRY, new Output() {
97 @Override
98 public void write(OutputStream out) throws XMLStreamException, IOException {
99 entryWriter.write(out);
100 }
101 });
102 }
103 }