1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.chemistry.opencmis.server.impl.browser;
20  
21  import org.apache.chemistry.opencmis.commons.data.ObjectList;
22  import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection;
23  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
24  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_ALLOWABLE_ACTIONS;
25  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_MAX_ITEMS;
26  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_RELATIONSHIP_DIRECTION;
27  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_RENDITION_FILTER;
28  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_SKIP_COUNT;
29  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_SUB_RELATIONSHIP_TYPES;
30  import static org.apache.chemistry.opencmis.commons.impl.Constants.PARAM_TYPE_ID;
31  import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
32  import org.apache.chemistry.opencmis.commons.impl.TypeCache;
33  import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
34  import org.apache.chemistry.opencmis.commons.impl.server.TypeCacheImpl;
35  import org.apache.chemistry.opencmis.commons.server.CallContext;
36  import org.apache.chemistry.opencmis.commons.server.CmisService;
37  import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.CONTEXT_OBJECT_ID;
38  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBigIntegerParameter;
39  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
40  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getEnumParameter;
41  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
42  
43  import java.math.BigInteger;
44  
45  import javax.servlet.http.HttpServletRequest;
46  import javax.servlet.http.HttpServletResponse;
47  
48  
49  public class RelationshipService
50  {
51      
52  
53  
54      public static void getObjectRelationships( CallContext context, CmisService service, String repositoryId,
55          HttpServletRequest request, HttpServletResponse response )
56          throws Exception
57      {
58          
59          String objectId = (String) context.get( CONTEXT_OBJECT_ID );
60          Boolean includeSubRelationshipTypes = getBooleanParameter( request, PARAM_SUB_RELATIONSHIP_TYPES );
61          RelationshipDirection relationshipDirection = getEnumParameter( request, PARAM_RELATIONSHIP_DIRECTION,
62                  RelationshipDirection.class );
63          String typeId = getStringParameter( request, PARAM_TYPE_ID );
64          String renditionFilter = getStringParameter( request, PARAM_RENDITION_FILTER );
65          Boolean includeAllowableActions = getBooleanParameter( request, PARAM_ALLOWABLE_ACTIONS );
66          BigInteger maxItems = getBigIntegerParameter( request, PARAM_MAX_ITEMS );
67          BigInteger skipCount = getBigIntegerParameter( request, PARAM_SKIP_COUNT );
68  
69          
70          ObjectList relationships = service.getObjectRelationships( repositoryId, objectId, includeSubRelationshipTypes,
71                  relationshipDirection, typeId, renditionFilter, includeAllowableActions, maxItems, skipCount, null );
72  
73          if ( relationships == null )
74          {
75              throw new CmisRuntimeException( "Relationships are null!" );
76          }
77  
78          TypeCache typeCache = new TypeCacheImpl( repositoryId, service );
79          JSONObject jsonChildren = JSONConverter.convert( relationships, typeCache, false );
80  
81          response.setStatus( HttpServletResponse.SC_OK );
82          BrowserBindingUtils.writeJSON( jsonChildren, request, response );
83      }
84  }