2 * QueryManagerNuxeoImpl.java
\r
4 * {Purpose of This Class}
\r
6 * {Other Notes Relating to This Class (Optional)}
\r
9 * $LastChangedRevision: $
\r
10 * $LastChangedDate: $
\r
12 * This document is a part of the source code and related artifacts
\r
13 * for CollectionSpace, an open source collections management system
\r
14 * for museums and related institutions:
\r
16 * http://www.collectionspace.org
\r
17 * http://wiki.collectionspace.org
\r
19 * Copyright © 2009 {Contributing Institution}
\r
21 * Licensed under the Educational Community License (ECL), Version 2.0.
\r
22 * You may not use this file except in compliance with this License.
\r
24 * You may obtain a copy of the ECL 2.0 License at
\r
25 * https://source.collectionspace.org/collection-space/LICENSE.txt
\r
27 package org.collectionspace.services.common.query.nuxeo;
\r
29 import java.util.StringTokenizer;
\r
31 import org.slf4j.Logger;
\r
32 import org.slf4j.LoggerFactory;
\r
34 import java.util.Map;
\r
35 import java.util.HashMap;
\r
36 import java.util.StringTokenizer;
\r
38 import org.nuxeo.ecm.core.api.DocumentModel;
\r
39 import org.nuxeo.ecm.core.api.DocumentModelList;
\r
40 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
\r
41 import org.nuxeo.ecm.core.client.NuxeoClient;
\r
43 import org.collectionspace.services.nuxeo.client.java.NuxeoConnector;
\r
44 import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClientImpl;
\r
45 import org.collectionspace.services.common.document.DocumentFilter;
\r
46 import org.collectionspace.services.common.query.IQueryManager;
\r
48 public class QueryManagerNuxeoImpl implements IQueryManager {
\r
50 private final Logger logger = LoggerFactory
\r
51 .getLogger(RepositoryJavaClientImpl.class);
\r
53 //TODO: This is currently just an example fixed query. This should eventually be
\r
54 // removed or replaced with a more generic method.
\r
56 * @see org.collectionspace.services.common.query.IQueryManager#execQuery(java.lang.String)
\r
58 public void execQuery(String queryString) {
\r
59 NuxeoClient client = null;
\r
61 client = NuxeoConnector.getInstance().getClient();
\r
62 RepositoryInstance repoSession = client.openRepository();
\r
64 DocumentModelList docModelList = repoSession.query("SELECT * FROM Relation WHERE relation:relationtype.documentId1='updated-Subject-1'");
\r
65 // DocumentModelList docModelList = repoSession.query("SELECT * FROM Relation");
\r
66 // DocumentModelList docModelList = repoSession.query("SELECT * FROM CollectionObject WHERE collectionobject:objectNumber='objectNumber-1251305545865'");
\r
67 for (DocumentModel docModel : docModelList) {
\r
68 System.out.println("--------------------------------------------");
\r
69 System.out.println(docModel.getPathAsString());
\r
70 System.out.println(docModel.getName());
\r
71 System.out.println(docModel.getPropertyValue("dc:title"));
\r
72 // System.out.println("documentId1=" + docModel.getProperty("relation", "relationtype/documentId1").toString());
\r
75 } catch (Exception e) {
\r
76 // TODO Auto-generated catch block
\r
77 e.printStackTrace();
\r
82 * @see org.collectionspace.services.common.query.IQueryManager#createWhereClauseFromKeywords(java.lang.String)
\r
84 public String createWhereClauseFromKeywords(String keywords) {
\r
85 String result = null;
\r
86 StringBuffer whereClause = new StringBuffer();
\r
87 StringTokenizer stringTokenizer = new StringTokenizer(keywords);
\r
88 while (stringTokenizer.hasMoreElements() == true) {
\r
89 whereClause.append(ECM_FULLTEXT_LIKE + "'" +
\r
90 stringTokenizer.nextToken() + "'");
\r
91 if (stringTokenizer.hasMoreElements() == true) {
\r
92 whereClause.append(SEARCH_TERM_SEPARATOR +
\r
93 SEARCH_QUALIFIER_OR +
\r
94 SEARCH_TERM_SEPARATOR);
\r
96 if (logger.isDebugEnabled() == true) {
\r
97 logger.debug("Current built whereClause is: " + whereClause.toString());
\r
101 result = whereClause.toString();
\r
102 if (logger.isDebugEnabled()) {
\r
103 logger.debug("Final built WHERE clause is: " + result);
\r