1 package org.collectionspace.services.nuxeo.client.java;
3 import java.security.Principal;
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;
19 public class CoreSessionWrapper implements CoreSessionInterface {
21 private CoreSession repoSession;
24 private static Logger logger = LoggerFactory.getLogger(CoreSessionWrapper.class);
26 private void logQuery(String query) {
27 logger.debug(String.format("NXQL: %s", query));
30 private void logQuery(String query, String queryType) {
31 logger.debug(String.format("Query Type: '%s' NXQL: %s", queryType, query));
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));
41 public CoreSessionWrapper(CoreSession repoSession) {
42 this.repoSession = repoSession;
46 public CoreSession getCoreSession() {
51 public String getSessionId() {
52 return repoSession.getSessionId();
56 public void close() throws Exception {
61 * Gets the root document of this repository.
63 * @return the root document. cannot be null
64 * @throws ClientException
65 * @throws SecurityException
68 public DocumentModel getRootDocument() throws ClientException {
69 return repoSession.getRootDocument();
73 * Returns the repository name against which this core session is bound.
75 * @return the repository name used currently used as an identifier
78 public String getRepositoryName() {
79 return repoSession.getRepositoryName();
83 * Gets the principal that created the client session.
85 * @return the principal
88 public Principal getPrincipal() {
89 return repoSession.getPrincipal();
93 public IterableQueryResult queryAndFetch(String query, String queryType,
94 Object... params) throws ClientException {
95 logQuery(query, queryType);
96 return repoSession.queryAndFetch(query, queryType, params);
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);
107 public DocumentModelList query(String query, int max) throws ClientException {
109 return repoSession.query(query, max);
113 public DocumentModelList query(String query) throws ClientException {
115 return repoSession.query(query);
119 public DocumentModelList query(String query, LifeCycleFilter workflowStateFilter) {
120 return repoSession.query(query, workflowStateFilter);
124 * Gets a document model given its reference.
126 * The default schemas are used to populate the returned document model.
127 * Default schemas are configured via the document type manager.
129 * Any other data model not part of the default schemas will be lazily
132 * @param docRef the document reference
133 * @return the document
134 * @throws ClientException
135 * @throws SecurityException
137 @NoRollbackOnException
139 public DocumentModel getDocument(DocumentRef docRef) throws ClientException {
140 return repoSession.getDocument(docRef);
144 public DocumentModel saveDocument(DocumentModel docModel) throws ClientException {
145 return repoSession.saveDocument(docModel);
149 public void save() throws ClientException {
154 * Bulk document saving.
156 * @param docModels the document models that needs to be saved
157 * @throws ClientException
160 public void saveDocuments(DocumentModel[] docModels) throws ClientException {
161 repoSession.saveDocuments(docModels);
165 * Removes this document and all its children, if any.
167 * @param docRef the reference to the document to remove
168 * @throws ClientException
171 public void removeDocument(DocumentRef docRef) throws ClientException {
172 repoSession.removeDocument(docRef);
176 * Creates a document model using required information.
178 * Used to fetch initial datamodels from the type definition.
180 * DocumentModel creation notifies a
181 * {@link DocumentEventTypes.EMPTY_DOCUMENTMODEL_CREATED} so that core event
182 * listener can initialize its content with computed properties.
187 * @return the initial document model
188 * @throws ClientException
191 public DocumentModel createDocumentModel(String parentPath, String id,
192 String typeName) throws ClientException {
193 return repoSession.createDocumentModel(parentPath, id, typeName);
197 * Creates a document using given document model for initialization.
199 * The model contains path of the new document, its type and optionally the
200 * initial data models of the document.
203 * @param model the document model to use for initialization
204 * @return the created document
205 * @throws ClientException
208 public DocumentModel createDocument(DocumentModel model) throws ClientException {
209 return repoSession.createDocument(model);
213 * Gets the children of the given parent.
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
220 @NoRollbackOnException
222 public DocumentModelList getChildren(DocumentRef parent) throws ClientException {
223 return repoSession.getChildren(parent);