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.math.BigInteger;
22 import java.util.ArrayList;
23
24 import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
25 import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomElement;
26 import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomEntry;
27 import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomFeed;
28 import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomLink;
29 import org.apache.chemistry.opencmis.client.bindings.spi.http.Response;
30 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
31 import org.apache.chemistry.opencmis.commons.data.ObjectData;
32 import org.apache.chemistry.opencmis.commons.data.ObjectList;
33 import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection;
34 import org.apache.chemistry.opencmis.commons.impl.Constants;
35 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
36 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl;
37 import org.apache.chemistry.opencmis.commons.spi.RelationshipService;
38
39
40
41
42 public class RelationshipServiceImpl extends AbstractAtomPubService implements RelationshipService {
43
44
45
46
47 public RelationshipServiceImpl(BindingSession session) {
48 setSession(session);
49 }
50
51 @Override
52 public ObjectList getObjectRelationships(String repositoryId, String objectId, Boolean includeSubRelationshipTypes,
53 RelationshipDirection relationshipDirection, String typeId, String filter, Boolean includeAllowableActions,
54 BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
55 ObjectListImpl result = new ObjectListImpl();
56
57
58 String link = loadLink(repositoryId, objectId, Constants.REL_RELATIONSHIPS, Constants.MEDIATYPE_FEED);
59
60 if (link == null) {
61 throwLinkException(repositoryId, objectId, Constants.REL_RELATIONSHIPS, Constants.MEDIATYPE_FEED);
62 }
63
64 UrlBuilder url = new UrlBuilder(link);
65 url.addParameter(Constants.PARAM_SUB_RELATIONSHIP_TYPES, includeSubRelationshipTypes);
66 url.addParameter(Constants.PARAM_RELATIONSHIP_DIRECTION, relationshipDirection);
67 url.addParameter(Constants.PARAM_TYPE_ID, typeId);
68 url.addParameter(Constants.PARAM_FILTER, filter);
69 url.addParameter(Constants.PARAM_ALLOWABLE_ACTIONS, includeAllowableActions);
70 url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
71 url.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
72
73
74 Response resp = read(url);
75 AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
76
77
78 for (AtomElement element : feed.getElements()) {
79 if (element.getObject() instanceof AtomLink) {
80 if (isNextLink(element)) {
81 result.setHasMoreItems(Boolean.TRUE);
82 }
83 } else if (isInt(NAME_NUM_ITEMS, element)) {
84 result.setNumItems((BigInteger) element.getObject());
85 }
86 }
87
88
89 if (!feed.getEntries().isEmpty()) {
90 result.setObjects(new ArrayList<ObjectData>(feed.getEntries().size()));
91
92 for (AtomEntry entry : feed.getEntries()) {
93 ObjectData relationship = null;
94
95 lockLinks();
96 try {
97
98 removeLinks(repositoryId, entry.getId());
99
100
101 for (AtomElement element : entry.getElements()) {
102 if (element.getObject() instanceof AtomLink) {
103 addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
104 } else if (element.getObject() instanceof ObjectData) {
105 relationship = (ObjectData) element.getObject();
106 }
107 }
108 } finally {
109 unlockLinks();
110 }
111
112 if (relationship != null) {
113 result.getObjects().add(relationship);
114 }
115 }
116
117 }
118
119 return result;
120 }
121 }