]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
cbfaeef69f0109d9dca49ebc32c72fd55f0e4afd
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.nuxeo.client.java;
2
3 import java.security.Principal;
4
5 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
6 import org.nuxeo.ecm.core.api.ClientException;
7 import org.nuxeo.ecm.core.api.DocumentModel;
8 import org.nuxeo.ecm.core.api.DocumentModelList;
9 import org.nuxeo.ecm.core.api.DocumentRef;
10 import org.nuxeo.ecm.core.api.Filter;
11 import org.nuxeo.ecm.core.api.IterableQueryResult;
12 import org.nuxeo.ecm.core.api.NoRollbackOnException;
13 import org.nuxeo.ecm.core.api.event.DocumentEventTypes;
14 import org.nuxeo.ecm.core.api.impl.LifeCycleFilter;
15 import org.nuxeo.ecm.core.api.CoreSession;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class CoreSessionWrapper implements CoreSessionInterface {
20
21         private CoreSession repoSession;
22         
23     /** The logger. */
24     private static Logger logger = LoggerFactory.getLogger(CoreSessionWrapper.class);
25     
26     private void logQuery(String query) {
27         logger.debug(String.format("NXQL: %s", query));
28     }
29     
30     private void logQuery(String query, String queryType) {
31         logger.debug(String.format("Query Type: '%s' NXQL: %s", queryType, query));
32     }
33     
34     private void logQuery(String query, Filter filter, long limit,
35                 long offset, boolean countTotal) {
36         logger.debug(String.format("Filter: '%s', Limit: '%d', Offset: '%d', Count Total?: %b, NXQL: %s",
37                         filter != null ? filter.toString() : "none", limit, offset, countTotal, query));
38     }
39     
40         
41         public CoreSessionWrapper(CoreSession repoSession) {
42                 this.repoSession = repoSession;
43         }
44
45         @Override
46         public  CoreSession getCoreSession() {
47                 return repoSession;
48         }
49         
50         @Override
51     public String getSessionId() {
52         return repoSession.getSessionId();
53     }
54     
55     @Override
56     public void close() throws Exception {
57         repoSession.close();
58     }
59
60     /**
61      * Gets the root document of this repository.
62      *
63      * @return the root document. cannot be null
64      * @throws ClientException
65      * @throws SecurityException
66      */
67         @Override
68     public DocumentModel getRootDocument() throws ClientException {
69         return repoSession.getRootDocument();
70     }
71     
72     /**
73      * Returns the repository name against which this core session is bound.
74      *
75      * @return the repository name used currently used as an identifier
76      */
77         @Override
78     public String getRepositoryName() {
79                 return repoSession.getRepositoryName();
80         }
81     
82     /**
83      * Gets the principal that created the client session.
84      *
85      * @return the principal
86      */
87         @Override
88         public Principal getPrincipal() {
89                 return repoSession.getPrincipal();
90         }
91
92         @Override
93         public IterableQueryResult queryAndFetch(String query, String queryType,
94             Object... params) throws ClientException {
95                 logQuery(query, queryType);
96                 return repoSession.queryAndFetch(query, queryType, params);
97         }
98
99         @Override
100         public DocumentModelList query(String query, Filter filter, long limit,
101             long offset, boolean countTotal) throws ClientException {
102                 logQuery(query, filter, limit, offset, countTotal);
103                 return repoSession.query(query, filter, limit, offset, countTotal);
104         }
105
106         @Override
107     public DocumentModelList query(String query, int max) throws ClientException {
108                 logQuery(query);
109         return repoSession.query(query, max);
110     }
111     
112         @Override
113         public DocumentModelList query(String query) throws ClientException {
114                 logQuery(query);
115                 return repoSession.query(query);
116         }
117         
118         @Override
119         public DocumentModelList query(String query, LifeCycleFilter workflowStateFilter) {
120                 return repoSession.query(query, workflowStateFilter);
121         }
122
123     /**
124      * Gets a document model given its reference.
125      * <p>
126      * The default schemas are used to populate the returned document model.
127      * Default schemas are configured via the document type manager.
128      * <p>
129      * Any other data model not part of the default schemas will be lazily
130      * loaded as needed.
131      *
132      * @param docRef the document reference
133      * @return the document
134      * @throws ClientException
135      * @throws SecurityException
136      */
137     @NoRollbackOnException
138     @Override
139     public DocumentModel getDocument(DocumentRef docRef) throws ClientException {
140             return repoSession.getDocument(docRef);
141     }
142
143     @Override
144     public DocumentModel saveDocument(DocumentModel docModel) throws ClientException {
145         return repoSession.saveDocument(docModel);
146     }
147
148     @Override
149     public void save() throws ClientException {
150         repoSession.save();
151     }
152
153     /**
154      * Bulk document saving.
155      *
156      * @param docModels the document models that needs to be saved
157      * @throws ClientException
158      */
159     @Override
160     public void saveDocuments(DocumentModel[] docModels) throws ClientException {
161         repoSession.saveDocuments(docModels);
162     }
163
164     /**
165      * Removes this document and all its children, if any.
166      *
167      * @param docRef the reference to the document to remove
168      * @throws ClientException
169      */
170     @Override
171     public void removeDocument(DocumentRef docRef) throws ClientException {
172         repoSession.removeDocument(docRef);
173     }
174
175     /**
176      * Creates a document model using required information.
177      * <p>
178      * Used to fetch initial datamodels from the type definition.
179      * <p>
180      * DocumentModel creation notifies a
181      * {@link DocumentEventTypes.EMPTY_DOCUMENTMODEL_CREATED} so that core event
182      * listener can initialize its content with computed properties.
183      *
184      * @param parentPath
185      * @param id
186      * @param typeName
187      * @return the initial document model
188      * @throws ClientException
189      */
190     @Override
191     public DocumentModel createDocumentModel(String parentPath, String id,
192             String typeName) throws ClientException {
193         return repoSession.createDocumentModel(parentPath, id, typeName);
194     }
195     
196     /**
197      * Creates a document using given document model for initialization.
198      * <p>
199      * The model contains path of the new document, its type and optionally the
200      * initial data models of the document.
201      * <p>
202      *
203      * @param model the document model to use for initialization
204      * @return the created document
205      * @throws ClientException
206      */
207     @Override
208     public DocumentModel createDocument(DocumentModel model) throws ClientException {
209         return repoSession.createDocument(model);
210     }
211     
212     /**
213      * Gets the children of the given parent.
214      *
215      * @param parent the parent reference
216      * @return the children if any, an empty list if no children or null if the
217      *         specified parent document is not a folder
218      * @throws ClientException
219      */
220     @NoRollbackOnException
221     @Override
222     public DocumentModelList getChildren(DocumentRef parent) throws ClientException {
223         return repoSession.getChildren(parent);
224     }
225
226     
227         
228 }