From 2f8e43dd0b81672ef85b5130ac7eb9de84efbe62 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Fri, 4 Sep 2009 19:47:13 +0000 Subject: [PATCH] CSPACE-410: Adding stubbed query/search service structure. Requires full clean build. --- services/JaxRsServiceProvider/pom.xml | 8 +- .../CollectionSpaceJaxRsApplication.java | 4 +- .../CollectionObjectServiceNuxeoImpl.java | 277 +++++++++-------- .../services/common/query/IQueryManager.java | 7 + .../services/common/query/QueryManager.java | 11 + .../query/nuxeo/QueryManagerNuxeoImpl.java | 43 +++ ...ationUtils.java => IRelationsManager.java} | 2 +- .../common/relation/RelationsManager.java | 6 +- ...pl.java => RelationsManagerNuxeoImpl.java} | 6 +- .../CollectionSpaceServiceNuxeoImpl.java | 130 ++------ .../intake/IntakeServiceNuxeoImpl.java | 290 +++++++++--------- services/pom.xml | 1 + services/query/.classpath | 6 + services/query/.project | 23 ++ .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 8 + services/query/pom.xml | 65 ++++ services/query/service/.classpath | 8 + services/query/service/.project | 23 ++ services/query/service/pom.xml | 149 +++++++++ .../services/query/QueryResource.java | 122 ++++++++ .../relation/NewRelationResource.java | 5 + .../nuxeo/RelationDocumentModelHandler.java | 8 +- .../nuxeo/RelationNuxeoConstants.java | 4 +- .../nuxeo/RelationServiceNuxeoImpl.java | 38 +-- 25 files changed, 831 insertions(+), 418 deletions(-) create mode 100644 services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java create mode 100644 services/common/src/main/java/org/collectionspace/services/common/query/QueryManager.java create mode 100644 services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java rename services/common/src/main/java/org/collectionspace/services/common/relation/{RelationUtils.java => IRelationsManager.java} (95%) rename services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/{RelationUtilsNuxeoImpl.java => RelationsManagerNuxeoImpl.java} (95%) create mode 100644 services/query/.classpath create mode 100644 services/query/.project create mode 100644 services/query/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/query/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/query/pom.xml create mode 100644 services/query/service/.classpath create mode 100644 services/query/service/.project create mode 100644 services/query/service/pom.xml create mode 100644 services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index b155b43f5..422db5f4d 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -37,12 +37,16 @@ org.collectionspace.services.intake.service 1.0 - org.collectionspace.services org.collectionspace.services.relation.service 1.0 + + org.collectionspace.services + org.collectionspace.services.query.service + 1.0 + commons-io commons-io @@ -169,6 +173,7 @@ 8180 + jboss-undeploy pre-integration-test @@ -193,6 +198,7 @@ + diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java index 413442a02..65c4b42b6 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java @@ -5,6 +5,7 @@ import org.collectionspace.services.id.IDResource; import org.collectionspace.services.intake.IntakeResource; //import org.collectionspace.services.relation.RelationResource; import org.collectionspace.services.relation.NewRelationResource; +import org.collectionspace.services.query.QueryResource; import javax.ws.rs.core.Application; import java.util.HashSet; @@ -21,7 +22,8 @@ public class CollectionSpaceJaxRsApplication extends Application { singletons.add(new IDResource()); singletons.add(new IntakeResource()); // singletons.add(new RelationResource()); - singletons.add(new NewRelationResource()); + singletons.add(new NewRelationResource()); + singletons.add(new QueryResource()); // singletons.add(new DomainIdentifierResource()); // singletons.add(new PingResource()); } diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectServiceNuxeoImpl.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectServiceNuxeoImpl.java index d0d8a9760..e19e56d3a 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectServiceNuxeoImpl.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectServiceNuxeoImpl.java @@ -48,18 +48,20 @@ public class CollectionObjectServiceNuxeoImpl extends public Document deleteCollectionObject(String csid) throws DocumentException, IOException { - NuxeoRESTClient nxClient = getClient(); - List pathParams = new ArrayList(); - Map queryParams = new HashMap(); - - pathParams.add("default"); - pathParams.add(csid); - pathParams.add("deleteDocumentRestlet"); - Representation res = nxClient.get(pathParams, queryParams); - SAXReader reader = new SAXReader(); - Document document = reader.read(res.getStream()); + Document result = null; + +// NuxeoRESTClient nxClient = getClient(); +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// +// pathParams.add("default"); +// pathParams.add(csid); +// pathParams.add("deleteDocumentRestlet"); +// Representation res = nxClient.get(pathParams, queryParams); +// SAXReader reader = new SAXReader(); +// result = reader.read(res.getStream()); - return document; + return result; } public Document getCollectionObject(String csid) throws DocumentException, @@ -69,21 +71,23 @@ public class CollectionObjectServiceNuxeoImpl extends //getCollectionObjectViaJavaAPI(csid); // Return to normal Nuxeo REST call - List pathParams = new ArrayList(); - Map queryParams = new HashMap(); - - pathParams.add("default"); - pathParams.add(csid); - pathParams.add("export"); - queryParams.put("format", "XML"); - - NuxeoRESTClient nxClient = getClient(); - Representation res = nxClient.get(pathParams, queryParams); - - SAXReader reader = new SAXReader(); - Document document = reader.read(res.getStream()); + Document result = null; +// +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// +// pathParams.add("default"); +// pathParams.add(csid); +// pathParams.add("export"); +// queryParams.put("format", "XML"); +// +// NuxeoRESTClient nxClient = getClient(); +// Representation res = nxClient.get(pathParams, queryParams); +// +// SAXReader reader = new SAXReader(); +// result = reader.read(res.getStream()); - return document; + return result; } @@ -91,125 +95,130 @@ public class CollectionObjectServiceNuxeoImpl extends IOException { Document result = null; - NuxeoRESTClient nxClient = getClient(); - List pathParams = new ArrayList(); - Map queryParams = new HashMap(); - pathParams = Arrays.asList("default", - CS_COLLECTIONOBJECT_WORKSPACE_UID, "browse"); - Representation res = nxClient.get(pathParams, queryParams); - SAXReader reader = new SAXReader(); - result = reader.read(res.getStream()); +// NuxeoRESTClient nxClient = getClient(); +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// pathParams = Arrays.asList("default", +// CS_COLLECTIONOBJECT_WORKSPACE_UID, "browse"); +// Representation res = nxClient.get(pathParams, queryParams); +// SAXReader reader = new SAXReader(); +// result = reader.read(res.getStream()); return result; } public Document postCollectionObject(CollectionObject co) throws DocumentException, IOException { - NuxeoRESTClient nxClient = getClient(); - - List pathParams = new ArrayList(); - Map queryParams = new HashMap(); - pathParams.add("default"); - pathParams.add(CS_COLLECTIONOBJECT_WORKSPACE_UID); - pathParams.add("createDocument"); - queryParams.put("docType", CO_NUXEO_DOCTYPE); - - // a default title for the Dublin Core schema - queryParams.put("dublincore:title", CO_NUXEO_DC_TITLE); - - // CollectionObject core values - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.OBJECT_NUMBER, co - .getObjectNumber()); - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.OTHER_NUMBER, co.getOtherNumber()); - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.BRIEF_DESCRIPTION, co - .getBriefDescription()); - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.COMMENTS, co.getComments()); - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.DIST_FEATURES, co - .getDistFeatures()); - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.OBJECT_NAME, co.getObjectName()); - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.RESPONSIBLE_DEPT, co - .getResponsibleDept()); - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.TITLE, co.getTitle()); - - ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); - Representation res = nxClient.post(pathParams, queryParams, bais); - - SAXReader reader = new SAXReader(); - Document document = reader.read(res.getStream()); - - return document; + Document result = null; + +// NuxeoRESTClient nxClient = getClient(); +// +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// pathParams.add("default"); +// pathParams.add(CS_COLLECTIONOBJECT_WORKSPACE_UID); +// pathParams.add("createDocument"); +// queryParams.put("docType", CO_NUXEO_DOCTYPE); +// +// // a default title for the Dublin Core schema +// queryParams.put("dublincore:title", CO_NUXEO_DC_TITLE); +// +// // CollectionObject core values +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.OBJECT_NUMBER, co +// .getObjectNumber()); +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.OTHER_NUMBER, co.getOtherNumber()); +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.BRIEF_DESCRIPTION, co +// .getBriefDescription()); +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.COMMENTS, co.getComments()); +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.DIST_FEATURES, co +// .getDistFeatures()); +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.OBJECT_NAME, co.getObjectName()); +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.RESPONSIBLE_DEPT, co +// .getResponsibleDept()); +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.TITLE, co.getTitle()); +// +// ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); +// Representation res = nxClient.post(pathParams, queryParams, bais); +// +// SAXReader reader = new SAXReader(); +// result = reader.read(res.getStream()); + + return result; } public Document putCollectionObject(String csid, CollectionObject theUpdate) throws DocumentException, IOException { - List pathParams = new ArrayList(); - Map queryParams = new HashMap(); - pathParams.add("default"); - pathParams.add(csid); - pathParams.add("updateDocumentRestlet"); - - // todo: intelligent merge needed - if (theUpdate.getObjectNumber() != null) { - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.OBJECT_NUMBER, theUpdate - .getObjectNumber()); - } - - if (theUpdate.getOtherNumber() != null) { - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.OTHER_NUMBER, theUpdate - .getOtherNumber()); - } - - if (theUpdate.getBriefDescription() != null) { - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.BRIEF_DESCRIPTION, theUpdate - .getBriefDescription()); - } - - if (theUpdate.getComments() != null) { - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.COMMENTS, theUpdate - .getComments()); - } - - if (theUpdate.getDistFeatures() != null) { - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.DIST_FEATURES, theUpdate - .getDistFeatures()); - } - - if (theUpdate.getObjectName() != null) { - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.OBJECT_NAME, theUpdate - .getObjectName()); - } - - if (theUpdate.getResponsibleDept() != null) { - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.RESPONSIBLE_DEPT, theUpdate - .getResponsibleDept()); - } - - if (theUpdate.getTitle() != null) { - queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" - + CollectionObjectJAXBSchema.TITLE, theUpdate.getTitle()); - } - - NuxeoRESTClient nxClient = getClient(); - Representation res = nxClient.get(pathParams, queryParams); - SAXReader reader = new SAXReader(); - Document document = reader.read(res.getStream()); - - return document; + + Document result = null; + +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// pathParams.add("default"); +// pathParams.add(csid); +// pathParams.add("updateDocumentRestlet"); +// +// // todo: intelligent merge needed +// if (theUpdate.getObjectNumber() != null) { +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.OBJECT_NUMBER, theUpdate +// .getObjectNumber()); +// } +// +// if (theUpdate.getOtherNumber() != null) { +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.OTHER_NUMBER, theUpdate +// .getOtherNumber()); +// } +// +// if (theUpdate.getBriefDescription() != null) { +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.BRIEF_DESCRIPTION, theUpdate +// .getBriefDescription()); +// } +// +// if (theUpdate.getComments() != null) { +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.COMMENTS, theUpdate +// .getComments()); +// } +// +// if (theUpdate.getDistFeatures() != null) { +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.DIST_FEATURES, theUpdate +// .getDistFeatures()); +// } +// +// if (theUpdate.getObjectName() != null) { +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.OBJECT_NAME, theUpdate +// .getObjectName()); +// } +// +// if (theUpdate.getResponsibleDept() != null) { +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.RESPONSIBLE_DEPT, theUpdate +// .getResponsibleDept()); +// } +// +// if (theUpdate.getTitle() != null) { +// queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" +// + CollectionObjectJAXBSchema.TITLE, theUpdate.getTitle()); +// } +// +// NuxeoRESTClient nxClient = getClient(); +// Representation res = nxClient.get(pathParams, queryParams); +// SAXReader reader = new SAXReader(); +// result = reader.read(res.getStream()); + + return result; } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java b/services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java new file mode 100644 index 000000000..98c4887b7 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/query/IQueryManager.java @@ -0,0 +1,7 @@ +package org.collectionspace.services.common.query; + +public interface IQueryManager { + + public void execQuery(String queryString); + +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/QueryManager.java b/services/common/src/main/java/org/collectionspace/services/common/query/QueryManager.java new file mode 100644 index 000000000..4cc2bf88f --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/query/QueryManager.java @@ -0,0 +1,11 @@ +package org.collectionspace.services.common.query; + +import org.collectionspace.services.common.query.nuxeo.QueryManagerNuxeoImpl; + +public class QueryManager { + static private final IQueryManager queryManager = new QueryManagerNuxeoImpl(); + + static public void execQuery(String queryString) { + queryManager.execQuery(queryString); + } +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java new file mode 100644 index 000000000..8240ef4b8 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/query/nuxeo/QueryManagerNuxeoImpl.java @@ -0,0 +1,43 @@ +package org.collectionspace.services.common.query.nuxeo; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; +import org.nuxeo.ecm.core.api.repository.RepositoryInstance; +import org.nuxeo.ecm.core.client.NuxeoClient; + +import org.collectionspace.services.nuxeo.client.java.NuxeoConnector; +import org.collectionspace.services.nuxeo.client.java.RepositoryJavaClient; +import org.collectionspace.services.common.query.IQueryManager; + +public class QueryManagerNuxeoImpl implements IQueryManager { + + private final Logger logger = LoggerFactory + .getLogger(RepositoryJavaClient.class); + + public void execQuery(String queryString) { + NuxeoClient client = null; + try { + client = NuxeoConnector.getInstance().getClient(); + RepositoryInstance repoSession = client.openRepository(); + + DocumentModelList docModelList = repoSession.query("SELECT * FROM Relation WHERE relation:relationtype.documentId1='updated-Subject-1'"); +// DocumentModelList docModelList = repoSession.query("SELECT * FROM Relation"); +// DocumentModelList docModelList = repoSession.query("SELECT * FROM CollectionObject WHERE collectionobject:objectNumber='objectNumber-1251305545865'"); + for (DocumentModel docModel : docModelList) { + System.out.println("--------------------------------------------"); + System.out.println(docModel.getPathAsString()); + System.out.println(docModel.getName()); + System.out.println(docModel.getPropertyValue("dc:title")); +// System.out.println("documentId1=" + docModel.getProperty("relation", "relationtype/documentId1").toString()); + } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java b/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java similarity index 95% rename from services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java rename to services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java index 26351b1a7..07e17b35b 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/IRelationsManager.java @@ -37,7 +37,7 @@ import org.nuxeo.ecm.core.api.DocumentModel; /** * The Interface RelationUtils. */ -public interface RelationUtils { +public interface IRelationsManager { /** * Gets the relationships. diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java index a5043c58c..4658e85ce 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationsManager.java @@ -30,9 +30,9 @@ import java.io.IOException; import java.util.List; import org.collectionspace.services.common.repository.DocumentException; -import org.collectionspace.services.common.relation.nuxeo.RelationUtilsNuxeoImpl; +import org.collectionspace.services.common.relation.nuxeo.RelationsManagerNuxeoImpl; import org.collectionspace.services.relation.Relation; -import org.collectionspace.services.common.relation.RelationUtils; +import org.collectionspace.services.common.relation.IRelationsManager; import org.dom4j.Document; import org.nuxeo.ecm.core.api.DocumentModel; @@ -52,7 +52,7 @@ public class RelationsManager { static public final String OBJECT = "objectCsid"; /** The relation utils. */ - static private RelationUtils relationUtils = new RelationUtilsNuxeoImpl(); + static private IRelationsManager relationUtils = new RelationsManagerNuxeoImpl(); /** * Gets the relationships. diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationUtilsNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsManagerNuxeoImpl.java similarity index 95% rename from services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationUtilsNuxeoImpl.java rename to services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsManagerNuxeoImpl.java index 6e4d794e1..aa3effef6 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationUtilsNuxeoImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/nuxeo/RelationsManagerNuxeoImpl.java @@ -35,7 +35,7 @@ import java.util.Map; import org.collectionspace.services.common.relation.RelationJAXBSchema; import org.collectionspace.services.common.relation.RelationListItemJAXBSchema; -import org.collectionspace.services.common.relation.RelationUtils; +import org.collectionspace.services.common.relation.IRelationsManager; import org.collectionspace.services.relation.Relation; import org.collectionspace.services.relation.RelationList; @@ -65,7 +65,7 @@ import org.slf4j.LoggerFactory; /** * The Class RelationUtilsNuxeoImpl. */ -public class RelationUtilsNuxeoImpl implements RelationUtils { +public class RelationsManagerNuxeoImpl implements IRelationsManager { /** The C s_ relatio n_ servic e_ name. */ static public String CS_RELATION_SERVICE_NAME = "relations"; @@ -87,7 +87,7 @@ public class RelationUtilsNuxeoImpl implements RelationUtils { /** The logger. */ private static Logger logger = LoggerFactory - .getLogger(RelationUtilsNuxeoImpl.class); + .getLogger(RelationsManagerNuxeoImpl.class); /** diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java index bcad5ee34..4b49abc02 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/CollectionSpaceServiceNuxeoImpl.java @@ -36,129 +36,41 @@ import org.slf4j.LoggerFactory; */ public abstract class CollectionSpaceServiceNuxeoImpl { - // replace host if not running on localhost - // static String CS_NUXEO_HOST = "173.45.234.217"; - static String CS_NUXEO_HOST = "localhost"; - static String CS_NUXEO_URI = "http://" + CS_NUXEO_HOST + ":8080/nuxeo"; protected Logger logger = LoggerFactory .getLogger(CollectionSpaceServiceNuxeoImpl.class); - public NuxeoRESTClient getClient() { - NuxeoRESTClient nxClient = new NuxeoRESTClient(CS_NUXEO_URI); - - nxClient.setAuthType(NuxeoRESTClient.AUTH_TYPE_BASIC); - nxClient.setBasicAuthentication("Administrator", "Administrator"); - - return nxClient; - } - -// FIXME: Replace this method after integration of the relation code - protected RepositoryInstance getRepositorySession() throws Exception { +// public NuxeoRESTClient getClient() { +// NuxeoRESTClient nxClient = new NuxeoRESTClient(CS_NUXEO_URI); +// +// nxClient.setAuthType(NuxeoRESTClient.AUTH_TYPE_BASIC); +// nxClient.setBasicAuthentication("Administrator", "Administrator"); +// +// return nxClient; +// } + + + protected RepositoryInstance getRepositorySession() throws Exception { // FIXME: is it possible to reuse repository session? // Authentication failures happen while trying to reuse the session - NuxeoConnector nuxeoConnector = NuxeoConnector.getInstance(); - return nuxeoConnector.getRepositorySession(); - } - - protected Document deleteDocument(RepositoryInstance repoSession, String csid) - throws DocumentException, IOException { - Document result = null; - - try { - repoSession = getRepositorySession(); - DocumentRef relDocumentRef = new IdRef(csid); - - try{ - repoSession.removeDocument(relDocumentRef); - }catch(ClientException ce){ - String msg = "could not find document to delete with id=" + csid; - logger.error(msg, ce); - throw new DocumentNotFoundException(msg, ce); - } - repoSession.save(); - } catch (Exception e) { - e.printStackTrace(); + NuxeoClient client = NuxeoConnector.getInstance().getClient(); + RepositoryInstance repoSession = client.openRepository(); + if (logger.isDebugEnabled()) { + logger.debug("getRepository() repository root: " + + repoSession.getRootDocument()); } - - return result; + return repoSession; } - - protected Document listWorkspaceContent(RepositoryInstance repoSession, - String workspaceName) { - - DOMDocumentFactory domfactory = new DOMDocumentFactory(); - DOMDocument result = (DOMDocument) domfactory.createDocument(); + protected void releaseRepositorySession(RepositoryInstance repoSession) { try { - repoSession = getRepositorySession(); - DocumentModel workspaceModel = NuxeoUtils.getWorkspaceModel(repoSession, - workspaceName); - - Element current = result.createElement("document"); - try { - current.setAttribute("title", workspaceModel.getTitle()); - } catch (Exception e) { - e.printStackTrace(); - } - current.setAttribute("type", workspaceModel.getType()); - current.setAttribute("id", workspaceModel.getId()); - current.setAttribute("name", workspaceModel.getName()); - current.setAttribute("url", getRelURL(workspaceName, workspaceModel.getRef().toString())); - result.setRootElement((org.dom4j.Element) current); - - if (workspaceModel.isFolder()) { - // Element childrenElem = result.createElement("children"); - // root.appendChild(childrenElem); - - DocumentModelList children = null; - try { - children = repoSession.getChildren(workspaceModel.getRef()); - } catch (ClientException e) { - e.printStackTrace(); - } - - for (DocumentModel child : children) { - Element el = result.createElement("document"); - try { - el.setAttribute("title", child.getTitle()); - } catch (DOMException e) { - e.printStackTrace(); - } catch (ClientException e) { - e.printStackTrace(); - } - el.setAttribute("type", child.getType()); - el.setAttribute("id", child.getId()); - el.setAttribute("name", child.getName()); - el.setAttribute("url", getRelURL(workspaceName, child.getRef() - .toString())); - current.appendChild(el); - } - } - - } catch (Exception e) { - e.printStackTrace(); - } - - if (logger.isDebugEnabled() == true) { - System.out.println(result.asXML()); - } - - return result; - } - - protected void releaseRepositorySession(RepositoryInstance repoSession) { - try { + NuxeoClient client = NuxeoConnector.getInstance().getClient(); // release session - NuxeoConnector nuxeoConnector = NuxeoConnector.getInstance(); - nuxeoConnector.releaseRepositorySession(repoSession); + client.releaseRepository(repoSession); } catch (Exception e) { logger.error("Could not close the repository session", e); // no need to throw this service specific exception } } - - private static String getRelURL(String repo, String uuid) { - return '/' + repo + '/' + uuid; - } + } diff --git a/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeServiceNuxeoImpl.java b/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeServiceNuxeoImpl.java index 63f5ee55c..003432699 100644 --- a/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeServiceNuxeoImpl.java +++ b/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeServiceNuxeoImpl.java @@ -39,169 +39,177 @@ public class IntakeServiceNuxeoImpl extends public Document deleteIntake(String csid) throws DocumentException, IOException { - NuxeoRESTClient nxClient = getClient(); - List pathParams = new ArrayList(); - Map queryParams = new HashMap(); - - pathParams.add("default"); - pathParams.add(csid); - pathParams.add("deleteDocumentRestlet"); - Representation res = nxClient.get(pathParams, queryParams); - SAXReader reader = new SAXReader(); - Document document = reader.read(res.getStream()); + Document result = null; + +// NuxeoRESTClient nxClient = getClient(); +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// +// pathParams.add("default"); +// pathParams.add(csid); +// pathParams.add("deleteDocumentRestlet"); +// Representation res = nxClient.get(pathParams, queryParams); +// SAXReader reader = new SAXReader(); +// result = reader.read(res.getStream()); - return document; + return result; } public Document getIntake(String csid) throws DocumentException, IOException { - List pathParams = new ArrayList(); - Map queryParams = new HashMap(); - - pathParams.add("default"); - pathParams.add(csid); - pathParams.add("export"); - queryParams.put("format", "XML"); - - NuxeoRESTClient nxClient = getClient(); - Representation res = nxClient.get(pathParams, queryParams); - - SAXReader reader = new SAXReader(); - Document document = reader.read(res.getStream()); + Document result = null; + +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// +// pathParams.add("default"); +// pathParams.add(csid); +// pathParams.add("export"); +// queryParams.put("format", "XML"); +// +// NuxeoRESTClient nxClient = getClient(); +// Representation res = nxClient.get(pathParams, queryParams); +// +// SAXReader reader = new SAXReader(); +// result = reader.read(res.getStream()); - return document; + return result; } public Document getIntakeList() throws DocumentException, IOException { Document result = null; - NuxeoRESTClient nxClient = getClient(); - List pathParams = new ArrayList(); - Map queryParams = new HashMap(); - pathParams = Arrays.asList("default", - CS_INTAKE_WORKSPACE_UID, "browse"); - Representation res = nxClient.get(pathParams, queryParams); - SAXReader reader = new SAXReader(); - result = reader.read(res.getStream()); +// NuxeoRESTClient nxClient = getClient(); +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// pathParams = Arrays.asList("default", +// CS_INTAKE_WORKSPACE_UID, "browse"); +// Representation res = nxClient.get(pathParams, queryParams); +// SAXReader reader = new SAXReader(); +// result = reader.read(res.getStream()); return result; } public Document postIntake(Intake co) throws DocumentException, IOException { - NuxeoRESTClient nxClient = getClient(); - - List pathParams = new ArrayList(); - Map queryParams = new HashMap(); - pathParams.add("default"); - pathParams.add(CS_INTAKE_WORKSPACE_UID); - pathParams.add("createDocument"); - queryParams.put("docType", INTAKE_NUXEO_DOCTYPE); - - // a default title for the Dublin Core schema - queryParams.put("dublincore:title", INTAKE_NUXEO_DC_TITLE); - - // Intake core values - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.CURRENT_OWNER, co - .getCurrentOwner()); - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.DEPOSITOR, co.getDepositor()); - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS, co - .getDepositorsRequirements()); - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.ENTRY_DATE, co.getEntryDate()); - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.ENTRY_METHOD, co - .getEntryMethod()); - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.ENTRY_NOTE, co.getEntryNote()); - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.ENTRY_NUMBER, co - .getEntryNumber()); - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.ENTRY_REASON, co.getEntryReason()); - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.PACKING_NOTE, co.getPackingNote()); - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.RETURN_DATE, co.getReturnDate()); - - ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); - Representation res = nxClient.post(pathParams, queryParams, bais); - - SAXReader reader = new SAXReader(); - Document document = reader.read(res.getStream()); - - return document; + Document result = null; + +// NuxeoRESTClient nxClient = getClient(); +// +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// pathParams.add("default"); +// pathParams.add(CS_INTAKE_WORKSPACE_UID); +// pathParams.add("createDocument"); +// queryParams.put("docType", INTAKE_NUXEO_DOCTYPE); +// +// // a default title for the Dublin Core schema +// queryParams.put("dublincore:title", INTAKE_NUXEO_DC_TITLE); +// +// // Intake core values +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.CURRENT_OWNER, co +// .getCurrentOwner()); +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.DEPOSITOR, co.getDepositor()); +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS, co +// .getDepositorsRequirements()); +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.ENTRY_DATE, co.getEntryDate()); +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.ENTRY_METHOD, co +// .getEntryMethod()); +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.ENTRY_NOTE, co.getEntryNote()); +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.ENTRY_NUMBER, co +// .getEntryNumber()); +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.ENTRY_REASON, co.getEntryReason()); +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.PACKING_NOTE, co.getPackingNote()); +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.RETURN_DATE, co.getReturnDate()); +// +// ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); +// Representation res = nxClient.post(pathParams, queryParams, bais); +// +// SAXReader reader = new SAXReader(); +// result = reader.read(res.getStream()); + + return result; } public Document putIntake(String csid, Intake theUpdate) throws DocumentException, IOException { - List pathParams = new ArrayList(); - Map queryParams = new HashMap(); - pathParams.add("default"); - pathParams.add(csid); - pathParams.add("updateDocumentRestlet"); - - // todo: intelligent merge needed - if (theUpdate.getCurrentOwner() != null) { - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.CURRENT_OWNER, theUpdate.getCurrentOwner()); - } - - if (theUpdate.getDepositor() != null) { - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.DEPOSITOR, theUpdate.getDepositor()); - } - - if (theUpdate.getDepositorsRequirements() != null) { - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS, theUpdate.getDepositorsRequirements()); - } - - if (theUpdate.getEntryDate() != null) { - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.ENTRY_DATE, theUpdate.getEntryDate()); - } - - if (theUpdate.getEntryMethod() != null) { - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.ENTRY_METHOD, theUpdate.getEntryMethod()); - } - - if (theUpdate.getEntryNote() != null) { - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.ENTRY_NOTE, theUpdate.getEntryNote()); - } - - if (theUpdate.getEntryNumber() != null) { - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.ENTRY_NUMBER, theUpdate.getEntryNumber()); - } - - if (theUpdate.getEntryReason() != null) { - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.ENTRY_REASON, theUpdate.getEntryReason()); - } - - if (theUpdate.getPackingNote() != null) { - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.PACKING_NOTE, theUpdate.getPackingNote()); - } - - if (theUpdate.getReturnDate() != null) { - queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" - + IntakeJAXBSchema.RETURN_DATE, theUpdate.getReturnDate()); - } - - NuxeoRESTClient nxClient = getClient(); - Representation res = nxClient.get(pathParams, queryParams); - SAXReader reader = new SAXReader(); - Document document = reader.read(res.getStream()); - - return document; + Document result = null; + +// List pathParams = new ArrayList(); +// Map queryParams = new HashMap(); +// pathParams.add("default"); +// pathParams.add(csid); +// pathParams.add("updateDocumentRestlet"); +// +// // todo: intelligent merge needed +// if (theUpdate.getCurrentOwner() != null) { +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.CURRENT_OWNER, theUpdate.getCurrentOwner()); +// } +// +// if (theUpdate.getDepositor() != null) { +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.DEPOSITOR, theUpdate.getDepositor()); +// } +// +// if (theUpdate.getDepositorsRequirements() != null) { +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.DEPOSITORS_REQUIREMENTS, theUpdate.getDepositorsRequirements()); +// } +// +// if (theUpdate.getEntryDate() != null) { +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.ENTRY_DATE, theUpdate.getEntryDate()); +// } +// +// if (theUpdate.getEntryMethod() != null) { +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.ENTRY_METHOD, theUpdate.getEntryMethod()); +// } +// +// if (theUpdate.getEntryNote() != null) { +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.ENTRY_NOTE, theUpdate.getEntryNote()); +// } +// +// if (theUpdate.getEntryNumber() != null) { +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.ENTRY_NUMBER, theUpdate.getEntryNumber()); +// } +// +// if (theUpdate.getEntryReason() != null) { +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.ENTRY_REASON, theUpdate.getEntryReason()); +// } +// +// if (theUpdate.getPackingNote() != null) { +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.PACKING_NOTE, theUpdate.getPackingNote()); +// } +// +// if (theUpdate.getReturnDate() != null) { +// queryParams.put(INTAKE_NUXEO_SCHEMA_NAME + ":" +// + IntakeJAXBSchema.RETURN_DATE, theUpdate.getReturnDate()); +// } +// +// NuxeoRESTClient nxClient = getClient(); +// Representation res = nxClient.get(pathParams, queryParams); +// SAXReader reader = new SAXReader(); +// result = reader.read(res.getStream()); + + return result; } } diff --git a/services/pom.xml b/services/pom.xml index e60921875..1286b5fae 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -19,6 +19,7 @@ common authentication relation + query id collectionobject intake diff --git a/services/query/.classpath b/services/query/.classpath new file mode 100644 index 000000000..046988541 --- /dev/null +++ b/services/query/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/services/query/.project b/services/query/.project new file mode 100644 index 000000000..0d231bad3 --- /dev/null +++ b/services/query/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.collectionobject + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/query/.settings/org.eclipse.jdt.core.prefs b/services/query/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..b634d9cad --- /dev/null +++ b/services/query/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Thu Apr 30 16:21:29 PDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/services/query/.settings/org.maven.ide.eclipse.prefs b/services/query/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..86c513b9c --- /dev/null +++ b/services/query/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,8 @@ +#Thu Jul 16 13:50:16 PDT 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +version=1 diff --git a/services/query/pom.xml b/services/query/pom.xml new file mode 100644 index 000000000..e054046fc --- /dev/null +++ b/services/query/pom.xml @@ -0,0 +1,65 @@ + + + + org.collectionspace.services.main + org.collectionspace.services + 1.0 + + 4.0.0 + org.collectionspace.services + 1.0 + org.collectionspace.services.query + pom + services.query + + + service + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-site-plugin + + /usr/bin/unzip -o > err.txt + + + + org.apache.maven.plugins + maven-war-plugin + 2.0.1 + + WEB-INF/lib/*.jar + + + true + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + + diff --git a/services/query/service/.classpath b/services/query/service/.classpath new file mode 100644 index 000000000..199bbbbdb --- /dev/null +++ b/services/query/service/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/services/query/service/.project b/services/query/service/.project new file mode 100644 index 000000000..2307d2382 --- /dev/null +++ b/services/query/service/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.collectionobject.service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/query/service/pom.xml b/services/query/service/pom.xml new file mode 100644 index 000000000..f60c5fc4e --- /dev/null +++ b/services/query/service/pom.xml @@ -0,0 +1,149 @@ + + + + + org.collectionspace.services.query + org.collectionspace.services + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.query.service + jar + 1.0 + services.query.service + + + + org.collectionspace.services + org.collectionspace.services.common + 1.0 + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + junit + junit + 4.1 + test + + + org.testng + testng + 5.6 + + + + + commons-beanutils + commons-beanutils + 1.6.1 + + + + commons-logging + commons-logging + 1.1 + + + + + + javax.security + jaas + 1.0.01 + provided + + + + dom4j + dom4j + 1.6.1 + provided + + + + + + org.jboss.resteasy + resteasy-jaxrs + 1.0.2.GA + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.0.2.GA + + + org.jboss.resteasy + resteasy-multipart-provider + 1.0.2.GA + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + ${nuxeo.version.1.5} + + + jboss-remoting + jboss + + + + + + org.restlet + org.restlet + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet.ext.httpclient + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet + 1.0.7 + + + + + + collectionspace-services-query + + + org.codehaus.mojo + jboss-maven-plugin + + ${jboss.dir} + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + + + + + + diff --git a/services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java b/services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java new file mode 100644 index 000000000..e99aeaf79 --- /dev/null +++ b/services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java @@ -0,0 +1,122 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.query; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.PathParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; + +import org.collectionspace.services.common.query.QueryManager; +import org.collectionspace.services.common.NuxeoClientType; +import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.repository.DocumentNotFoundException; +import org.collectionspace.services.common.repository.DocumentHandler; +import org.collectionspace.services.common.repository.RepositoryClient; +import org.collectionspace.services.common.repository.RepositoryClientFactory; +import org.jboss.resteasy.util.HttpResponseCodes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/query") +@Consumes("application/xml") +@Produces("application/xml") +public class QueryResource { + + public final static String SERVICE_NAME = "query"; + final Logger logger = LoggerFactory.getLogger(QueryResource.class); + //FIXME retrieve client type from configuration + final static NuxeoClientType CLIENT_TYPE = ServiceMain.getInstance().getNuxeoClientType(); + + public QueryResource() { + // do nothing + } + + @GET + @Path("{csid}") + public void getQuery( + @PathParam("csid") String csid) { + if(logger.isDebugEnabled()){ + verbose("getQuery with csid=" + csid); + } + if(csid == null || "".equals(csid)){ + logger.error("getQuery: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on getQuery csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + + try { + QueryManager.execQuery(csid); + } catch(Exception e){ + if(logger.isDebugEnabled()){ + logger.debug("getQuery", e); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on query csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + + if(false){ + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested CSID:" + csid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + +// return intakeObject; + } + +// private void verbose(String msg, Intake intakeObject) { +// try{ +// verbose(msg); +// JAXBContext jc = JAXBContext.newInstance( +// Intake.class); +// +// Marshaller m = jc.createMarshaller(); +// m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); +// m.marshal(intakeObject, System.out); +// }catch(Exception e){ +// e.printStackTrace(); +// } +// +// } + + private void verbose(String msg) { + System.out.println("QueryResource. " + msg); + } +} diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java index 2f4f00962..2ec1700ec 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java @@ -113,6 +113,9 @@ public class NewRelationResource extends CollectionSpaceResource { } } + /* + * Prototype for using NXQL -will move away from here once protyping is finished. + */ @GET @Path("query/{queryValue}") public Response getQuery(@PathParam("queryValue") String queryString) { @@ -122,6 +125,8 @@ public class NewRelationResource extends CollectionSpaceResource { if (logger.isDebugEnabled() == true) { logger.debug("Query string is: " + queryString); } + + //getDefaultClient(). result = Response.status(Response.Status.ACCEPTED).entity( "Query performed. Look in $JBOSS_HOME/server/cspace/log/" + diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java index c6b74c1a6..0db9aa602 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.Map; import org.collectionspace.services.common.relation.RelationJAXBSchema; -import org.collectionspace.services.common.relation.nuxeo.RelationUtilsNuxeoImpl; +import org.collectionspace.services.common.relation.nuxeo.RelationsManagerNuxeoImpl; import org.collectionspace.services.common.relation.RelationsManager; import org.collectionspace.services.relation.Relation; @@ -108,7 +108,7 @@ public class RelationDocumentModelHandler DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject(); Relation theRelation = new Relation(); - RelationUtilsNuxeoImpl.fillRelationFromDocModel(theRelation, docModel); + RelationsManagerNuxeoImpl.fillRelationFromDocModel(theRelation, docModel); return theRelation; } @@ -117,7 +117,7 @@ public class RelationDocumentModelHandler public void fillCommonObject(Relation relation, DocumentWrapper wrapDoc) throws Exception { DocumentModel docModel = (DocumentModel) wrapDoc.getWrappedObject(); - RelationUtilsNuxeoImpl.fillDocModelFromRelation(relation, docModel); + RelationsManagerNuxeoImpl.fillDocModelFromRelation(relation, docModel); } @Override @@ -140,7 +140,7 @@ public class RelationDocumentModelHandler if (RelationsManager.isQueryMatch(docModel, subjectCsid, predicate, objectCsid) == true) { RelationListItem coListItem = new RelationListItem(); - RelationUtilsNuxeoImpl.fillRelationListItemFromDocModel( + RelationsManagerNuxeoImpl.fillRelationListItemFromDocModel( coListItem, docModel); list.add(coListItem); } diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationNuxeoConstants.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationNuxeoConstants.java index cc974846f..ca09458d8 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationNuxeoConstants.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationNuxeoConstants.java @@ -1,7 +1,7 @@ package org.collectionspace.services.relation.nuxeo; -import org.collectionspace.services.common.relation.nuxeo.RelationUtilsNuxeoImpl; +import org.collectionspace.services.common.relation.nuxeo.RelationsManagerNuxeoImpl; public class RelationNuxeoConstants { - static String NUXEO_DOCTYPE = RelationUtilsNuxeoImpl.REL_NUXEO_DOCTYPE; + static String NUXEO_DOCTYPE = RelationsManagerNuxeoImpl.REL_NUXEO_DOCTYPE; } \ No newline at end of file diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationServiceNuxeoImpl.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationServiceNuxeoImpl.java index 85273c211..f1e5a9ccb 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationServiceNuxeoImpl.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationServiceNuxeoImpl.java @@ -39,7 +39,7 @@ import java.util.List; import org.collectionspace.services.common.repository.DocumentException; //import org.collectionspace.services.nuxeo.NuxeoRESTClient; import org.collectionspace.services.nuxeo.CollectionSpaceServiceNuxeoImpl; -import org.collectionspace.services.common.relation.nuxeo.RelationUtilsNuxeoImpl; +import org.collectionspace.services.common.relation.nuxeo.RelationsManagerNuxeoImpl; import org.collectionspace.services.relation.Relation; import org.collectionspace.services.relation.RelationService; //import org.collectionspace.services.relation.RelationList; @@ -82,20 +82,20 @@ public class RelationServiceNuxeoImpl extends public Document deleteRelation(String csid) throws DocumentException { Document result = null; - RepositoryInstance repoSession = null; - try { - repoSession = getRepositorySession(); - result = deleteDocument(repoSession, csid); - } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug("Caught exception ", e); - } - throw new DocumentException(e); - } finally { - if (repoSession != null) { - releaseRepositorySession(repoSession); - } - } +// RepositoryInstance repoSession = null; +// try { +// repoSession = getRepositorySession(); +// result = deleteDocument(repoSession, csid); +// } catch (Exception e) { +// if (logger.isDebugEnabled()) { +// logger.debug("Caught exception ", e); +// } +// throw new DocumentException(e); +// } finally { +// if (repoSession != null) { +// releaseRepositorySession(repoSession); +// } +// } return result; } @@ -142,7 +142,7 @@ public class RelationServiceNuxeoImpl extends repoSession = getRepositorySession(); List relationList = RelationsManager.getRelationships(repoSession); - result = RelationUtilsNuxeoImpl.getDocument(relationList); + result = RelationsManagerNuxeoImpl.getDocument(relationList); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Caught exception ", e); @@ -175,7 +175,7 @@ public class RelationServiceNuxeoImpl extends List relationList = RelationsManager.getRelationships(repoSession, subjectCsid, predicate, objectCsid); - result = RelationUtilsNuxeoImpl.getDocument(relationList); + result = RelationsManagerNuxeoImpl.getDocument(relationList); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Caught exception ", e); @@ -205,7 +205,7 @@ public class RelationServiceNuxeoImpl extends try { repoSession = getRepositorySession(); - DocumentModel resultDocModel = RelationUtilsNuxeoImpl.createRelationship(repoSession, co); + DocumentModel resultDocModel = RelationsManagerNuxeoImpl.createRelationship(repoSession, co); repoSession.save(); result = NuxeoUtils.getDocument(repoSession, resultDocModel); } catch (Exception e) { @@ -239,7 +239,7 @@ public class RelationServiceNuxeoImpl extends repoSession = getRepositorySession(); DocumentRef documentRef = new IdRef(csid); DocumentModel documentModel = repoSession.getDocument(documentRef); - RelationUtilsNuxeoImpl.fillDocModelFromRelation(theUpdate, documentModel); + RelationsManagerNuxeoImpl.fillDocModelFromRelation(theUpdate, documentModel); repoSession.saveDocument(documentModel); repoSession.save(); result = NuxeoUtils.getDocument(repoSession, documentModel); -- 2.47.3