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.webservices;
20  
21  import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
22  import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
23  import static org.apache.chemistry.opencmis.commons.impl.Converter.convertTypeContainerList;
24  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisException;
25  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisExtensionType;
26  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisRepositoryEntryType;
27  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisRepositoryInfoType;
28  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeContainer;
29  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeDefinitionListType;
30  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisTypeDefinitionType;
31  import org.apache.chemistry.opencmis.commons.impl.jaxb.RepositoryServicePort;
32  import org.apache.chemistry.opencmis.commons.server.CmisService;
33  
34  import java.math.BigInteger;
35  
36  import java.util.ArrayList;
37  import java.util.List;
38  
39  import javax.annotation.Resource;
40  
41  import javax.jws.WebService;
42  
43  import javax.xml.ws.WebServiceContext;
44  import javax.xml.ws.soap.MTOM;
45  
46  
47  
48  
49  
50  @MTOM
51  @WebService( endpointInterface = "org.apache.chemistry.opencmis.commons.impl.jaxb.RepositoryServicePort" )
52  public class RepositoryService extends AbstractService implements RepositoryServicePort
53  {
54      @Resource
55      public WebServiceContext wsContext;
56  
57      public List<CmisRepositoryEntryType> getRepositories( CmisExtensionType extension )
58          throws CmisException
59      {
60          CmisService service = null;
61  
62          try
63          {
64              service = getService( wsContext, null );
65  
66              List<RepositoryInfo> infoDataList = service.getRepositoryInfos( convert( extension ) );
67  
68              if ( infoDataList == null )
69              {
70                  return null;
71              }
72  
73              List<CmisRepositoryEntryType> result = new ArrayList<CmisRepositoryEntryType>(  );
74  
75              for ( RepositoryInfo infoData : infoDataList )
76              {
77                  CmisRepositoryEntryType entry = new CmisRepositoryEntryType(  );
78                  entry.setRepositoryId( infoData.getId(  ) );
79                  entry.setRepositoryName( infoData.getName(  ) );
80  
81                  result.add( entry );
82              }
83  
84              return result;
85          }
86          catch ( Exception e )
87          {
88              throw convertException( e );
89          }
90          finally
91          {
92              closeService( service );
93          }
94      }
95  
96      public CmisRepositoryInfoType getRepositoryInfo( String repositoryId, CmisExtensionType extension )
97          throws CmisException
98      {
99          CmisService service = null;
100 
101         try
102         {
103             service = getService( wsContext, repositoryId );
104 
105             return convert( service.getRepositoryInfo( repositoryId, convert( extension ) ) );
106         }
107         catch ( Exception e )
108         {
109             throw convertException( e );
110         }
111         finally
112         {
113             closeService( service );
114         }
115     }
116 
117     public CmisTypeDefinitionListType getTypeChildren( String repositoryId, String typeId,
118         Boolean includePropertyDefinitions, BigInteger maxItems, BigInteger skipCount, CmisExtensionType extension )
119         throws CmisException
120     {
121         CmisService service = null;
122 
123         try
124         {
125             service = getService( wsContext, repositoryId );
126 
127             return convert( service.getTypeChildren( repositoryId, typeId, includePropertyDefinitions, maxItems,
128                     skipCount, convert( extension ) ) );
129         }
130         catch ( Exception e )
131         {
132             throw convertException( e );
133         }
134         finally
135         {
136             closeService( service );
137         }
138     }
139 
140     public CmisTypeDefinitionType getTypeDefinition( String repositoryId, String typeId, CmisExtensionType extension )
141         throws CmisException
142     {
143         CmisService service = null;
144 
145         try
146         {
147             service = getService( wsContext, repositoryId );
148 
149             return convert( service.getTypeDefinition( repositoryId, typeId, convert( extension ) ) );
150         }
151         catch ( Exception e )
152         {
153             throw convertException( e );
154         }
155         finally
156         {
157             closeService( service );
158         }
159     }
160 
161     public List<CmisTypeContainer> getTypeDescendants( String repositoryId, String typeId, BigInteger depth,
162         Boolean includePropertyDefinitions, CmisExtensionType extension )
163         throws CmisException
164     {
165         CmisService service = null;
166 
167         try
168         {
169             service = getService( wsContext, repositoryId );
170 
171             List<CmisTypeContainer> result = new ArrayList<CmisTypeContainer>(  );
172             convertTypeContainerList( service.getTypeDescendants( repositoryId, typeId, depth,
173                     includePropertyDefinitions, convert( extension ) ), result );
174 
175             return result;
176         }
177         catch ( Exception e )
178         {
179             throw convertException( e );
180         }
181         finally
182         {
183             closeService( service );
184         }
185     }
186 }