From: Patrick Schmitz Date: Tue, 28 Feb 2012 20:09:58 +0000 (-0800) Subject: CSPACE-4875 Adding support for keyword search across a range of services. This has... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=551ca94e920e10d25e9a9edb6da865db679bde9c;p=tmp%2Fjakarta-migration.git CSPACE-4875 Adding support for keyword search across a range of services. This has the service structure in place, and a stub to list groups. --- diff --git a/services/servicegroup/build.xml b/services/servicegroup/build.xml new file mode 100644 index 000000000..90d068fd9 --- /dev/null +++ b/services/servicegroup/build.xml @@ -0,0 +1,118 @@ + + + + servicegroup service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/servicegroup/client/pom.xml b/services/servicegroup/client/pom.xml new file mode 100644 index 000000000..c4ff91db4 --- /dev/null +++ b/services/servicegroup/client/pom.xml @@ -0,0 +1,95 @@ + + + + org.collectionspace.services + org.collectionspace.services.servicegroup + 2.2-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.servicegroup.client + services.servicegroup.client + + + + + org.slf4j + slf4j-api + test + + + org.slf4j + slf4j-log4j12 + test + + + + org.collectionspace.services + org.collectionspace.services.authority.jaxb + true + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.common + true + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.servicegroup.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.person.client + ${project.version} + + + + org.testng + testng + + + org.jboss.resteasy + resteasy-jaxrs + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + commons-httpclient + commons-httpclient + 3.1 + + + + + collectionspace-services-servicegroup-client + + diff --git a/services/servicegroup/client/src/main/java/org/collectionspace/services/client/ServiceGroupClient.java b/services/servicegroup/client/src/main/java/org/collectionspace/services/client/ServiceGroupClient.java new file mode 100644 index 000000000..1359961c6 --- /dev/null +++ b/services/servicegroup/client/src/main/java/org/collectionspace/services/client/ServiceGroupClient.java @@ -0,0 +1,48 @@ +/** + * 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 (c) 2009 Regents of the University of California + * + * 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 + */ +package org.collectionspace.services.client; + +/** + * ServiceGroupClient.java + * + * $LastChangedRevision: 2108 $ + * $LastChangedDate: 2010-05-17 18:25:37 -0700 (Mon, 17 May 2010) $ + * + */ +public class ServiceGroupClient extends AbstractCommonListPoxServiceClientImpl { + + public static final String SERVICE_NAME = "servicegroups"; + public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; + public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; + public static final String SERVICE_PATH_PROXY = SERVICE_PATH + "/"; + public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME; + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + @Override + public Class getProxyClass() { + return ServiceGroupProxy.class; + } +} diff --git a/services/servicegroup/client/src/main/java/org/collectionspace/services/client/ServiceGroupProxy.java b/services/servicegroup/client/src/main/java/org/collectionspace/services/client/ServiceGroupProxy.java new file mode 100644 index 000000000..09a195f71 --- /dev/null +++ b/services/servicegroup/client/src/main/java/org/collectionspace/services/client/ServiceGroupProxy.java @@ -0,0 +1,40 @@ +/** + * ServiceGroupProxy.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + * 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 © 2011 U.C. 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 + */ +package org.collectionspace.services.client; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +/** + * @version $Revision: 2108 $ + */ +@Path(ServiceGroupClient.SERVICE_PATH_PROXY) +@Produces({"application/xml"}) +@Consumes({"application/xml"}) +public interface ServiceGroupProxy extends CollectionSpaceCommonListPoxProxy { +} diff --git a/services/servicegroup/client/src/test/java/org/collectionspace/services/client/test/ServiceGroupServiceTest.java b/services/servicegroup/client/src/test/java/org/collectionspace/services/client/test/ServiceGroupServiceTest.java new file mode 100644 index 000000000..26ef6c287 --- /dev/null +++ b/services/servicegroup/client/src/test/java/org/collectionspace/services/client/test/ServiceGroupServiceTest.java @@ -0,0 +1,130 @@ +/** + * 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 Regents of the University of California + * + * 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.client.test; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.client.AbstractCommonListUtils; +import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.client.ServiceGroupClient; +import org.collectionspace.services.client.ServiceGroupProxy; +import org.collectionspace.services.client.PayloadOutputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.servicegroup.ServicegroupsCommon; + +import org.jboss.resteasy.client.ClientResponse; + +import org.testng.Assert; +import org.testng.annotations.Test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ServiceGroupServiceTest, carries out tests against a deployed and running ServiceGroup Service.

+ * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class ServiceGroupServiceTest extends AbstractPoxServiceTestImpl { + + private final String CLASS_NAME = ServiceGroupServiceTest.class.getName(); + private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + final String SERVICE_PATH_COMPONENT = "servicegroups"; + private String knownResourceId = null; + + @Override + public String getServicePathComponent() { + return ServiceGroupClient.SERVICE_PATH_COMPONENT; + } + + @Override + protected String getServiceName() { + return ServiceGroupClient.SERVICE_NAME; + } + + @Override + protected CollectionSpaceClient getClientInstance() { + return new ServiceGroupClient(); + } + + @Override + protected AbstractCommonList getCommonList(ClientResponse response) { + return response.getEntity(AbstractCommonList.class); + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + + @Override + protected PoxPayloadOut createInstance(String identifier) { + ServiceGroupClient client = new ServiceGroupClient(); + return createInstance(client.getCommonPartName(), identifier); + } + + @Override + protected PoxPayloadOut createInstance(String commonPartName, + String identifier) { + return createServiceGroupInstance(identifier); + } + + private PoxPayloadOut createServiceGroupInstance(String uid) { + String identifier = "name-" + uid; + ServicegroupsCommon servicegroup = new ServicegroupsCommon(); + servicegroup.setName(identifier); + PoxPayloadOut multipart = new PoxPayloadOut(ServiceGroupClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = multipart.addPart(servicegroup, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(new ServiceGroupClient().getCommonPartName()); + + if (logger.isDebugEnabled()) { + logger.debug("to be created, servicegroup common"); + logger.debug(objectAsXmlString(servicegroup, ServicegroupsCommon.class)); + } + + return multipart; + } + + @Override + public void CRUDTests(String testName) { + // TODO Auto-generated method stub + + } + + @Override + protected ServicegroupsCommon updateInstance(ServicegroupsCommon servicegroupsCommon) { + ServicegroupsCommon result = new ServicegroupsCommon(); + + result.setName("updated-" + servicegroupsCommon.getName()); + + return result; + } + + @Override + protected void compareUpdatedInstances(ServicegroupsCommon original, + ServicegroupsCommon updated) throws Exception { + Assert.assertEquals(updated.getName(), original.getName()); + } +} diff --git a/services/servicegroup/client/src/test/resources/log4j.properties b/services/servicegroup/client/src/test/resources/log4j.properties new file mode 100644 index 000000000..148a3e865 --- /dev/null +++ b/services/servicegroup/client/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +log4j.rootLogger=debug, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=target/test-client.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +#packages +log4j.logger.org.collectionspace=DEBUG +log4j.logger.org.apache=INFO +log4j.logger.httpclient=INFO +log4j.logger.org.jboss.resteasy=INFO diff --git a/services/servicegroup/jaxb/pom.xml b/services/servicegroup/jaxb/pom.xml new file mode 100644 index 000000000..a20b40498 --- /dev/null +++ b/services/servicegroup/jaxb/pom.xml @@ -0,0 +1,35 @@ + + + + org.collectionspace.services.servicegroup + org.collectionspace.services + 2.2-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.servicegroup.jaxb + services.servicegroup.jaxb + + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + + + collectionspace-services-servicegroup-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + + diff --git a/services/servicegroup/jaxb/src/main/java/org/collectionspace/services/ServiceGroupJAXBSchema.java b/services/servicegroup/jaxb/src/main/java/org/collectionspace/services/ServiceGroupJAXBSchema.java new file mode 100644 index 000000000..58ef4e2b6 --- /dev/null +++ b/services/servicegroup/jaxb/src/main/java/org/collectionspace/services/ServiceGroupJAXBSchema.java @@ -0,0 +1,9 @@ +/** + * + */ +package org.collectionspace.services; + +public interface ServiceGroupJAXBSchema { + final static String SERVICE_CLASS_NAME = "name"; + final static String SERVICE_CLASS_URI = "uri"; +} diff --git a/services/servicegroup/jaxb/src/main/java/org/collectionspace/services/ServiceGroupListItemJAXBSchema.java b/services/servicegroup/jaxb/src/main/java/org/collectionspace/services/ServiceGroupListItemJAXBSchema.java new file mode 100644 index 000000000..48fd0e1cb --- /dev/null +++ b/services/servicegroup/jaxb/src/main/java/org/collectionspace/services/ServiceGroupListItemJAXBSchema.java @@ -0,0 +1,6 @@ +package org.collectionspace.services; + +public interface ServiceGroupListItemJAXBSchema { + final static String NAME = "name"; + final static String URI = "url"; +} diff --git a/services/servicegroup/pom.xml b/services/servicegroup/pom.xml new file mode 100644 index 000000000..00e1bf1d7 --- /dev/null +++ b/services/servicegroup/pom.xml @@ -0,0 +1,23 @@ + + + + + org.collectionspace.services + org.collectionspace.services.main + 2.2-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.servicegroup + services.servicegroup + pom + + + jaxb + service + client + + + + diff --git a/services/servicegroup/service/pom.xml b/services/servicegroup/service/pom.xml new file mode 100644 index 000000000..1a87ab720 --- /dev/null +++ b/services/servicegroup/service/pom.xml @@ -0,0 +1,101 @@ + + + + + org.collectionspace.services + org.collectionspace.services.servicegroup + 2.2-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.servicegroup.service + services.servicegroup.service + jar + + + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.servicegroup.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.servicegroup.jaxb + ${project.version} + + + + junit + junit + 4.1 + test + + + org.testng + testng + + + + + + javax.security + jaas + 1.0.01 + provided + + + + dom4j + dom4j + 1.6.1 + provided + + + + + + org.jboss.resteasy + resteasy-jaxrs + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + ${nuxeo.core.version} + + + jboss-remoting + jboss + + + + + + + + collectionspace-services-servicegroup + + + diff --git a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java new file mode 100644 index 000000000..b8f7a08d6 --- /dev/null +++ b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java @@ -0,0 +1,160 @@ +/** + * 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.servicegroup; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.collectionspace.services.ServiceGroupListItemJAXBSchema; +import org.collectionspace.services.client.IQueryManager; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.client.ServiceGroupClient; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; +import org.collectionspace.services.common.ServiceMessages; +import org.collectionspace.services.common.api.Tools; +import org.collectionspace.services.common.context.RemoteServiceContextFactory; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.context.ServiceContextFactory; +import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.document.DocumentNotFoundException; +import org.collectionspace.services.common.query.QueryManager; +import org.collectionspace.services.nuxeo.client.java.CommonList; +import org.collectionspace.services.nuxeo.util.NuxeoUtils; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +@Path(ServiceGroupClient.SERVICE_PATH) +@Produces({"application/xml"}) +@Consumes({"application/xml"}) +public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl { + + @Override + public String getServiceName(){ + return ServiceGroupClient.SERVICE_NAME; + } + + @Override + protected String getVersionString() { + final String lastChangeRevision = "$LastChangedRevision: 2108 $"; + return lastChangeRevision; + } + + @Override + //public Class getCommonPartClass() { + public Class getCommonPartClass() { + try { + return Class.forName("org.collectionspace.services.servicegroup.ServicegroupsCommon");//.class; + } catch (ClassNotFoundException e){ + return null; + } + } + + @Override + public ServiceContextFactory getServiceContextFactory() { + return RemoteServiceContextFactory.get(); + } + + + //======================= GET ==================================================== + /* + @GET + @Path("{groupname}") + public byte[] get( + @Context UriInfo ui, + @PathParam("csid") String csid) { + PoxPayloadOut result = null; + ensureCSID(csid, READ); + try { + MultivaluedMap queryParams = ui.getQueryParameters(); + ServiceContext ctx = createServiceContext(queryParams); + result = Need to fetch info and prepare it. + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build(); + throw new WebApplicationException(response); + } + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.READ_FAILED, csid); + } + + return result.getBytes(); + } + */ + + + //======================= GET without specifier: List ===================================== + @GET + public AbstractCommonList getList(@Context UriInfo ui) { + try { + CommonList commonList = new CommonList(); + AbstractCommonList list = (AbstractCommonList)commonList; + ServiceContext ctx = createServiceContext(); + String commonSchema = ctx.getCommonPartLabel(); + ArrayList svcGroups = new ArrayList(); + svcGroups.add("procedure"); + svcGroups.add("object"); + svcGroups.add("authority"); + // Fetch the list of groups from the tenant-bindings config, and prepare a list item + // for each one. + // We always declare this a full list, of the size that we are returning. + // Not quite in the spirit of what paging means, but tells callers not to ask for more. + list.setPageNum(0); + list.setPageSize(svcGroups.size()); + list.setItemsInPage(svcGroups.size()); + list.setTotalItems(svcGroups.size()); + String fields[] = new String[2]; + fields[0] = ServiceGroupListItemJAXBSchema.NAME; + fields[1] = ServiceGroupListItemJAXBSchema.URI; + commonList.setFieldsReturned(fields); + HashMap item = new HashMap(); + for(String groupName:svcGroups){ + item.put(ServiceGroupListItemJAXBSchema.NAME, groupName); + String uri = "/" + getServiceName().toLowerCase() + "/" + groupName; + item.put(ServiceGroupListItemJAXBSchema.URI, uri); + commonList.addItem(item); + item.clear(); + } + return list; + } catch (Exception e) { + throw bigReThrow(e, ServiceMessages.LIST_FAILED); + } + + } + + +} diff --git a/services/servicegroup/service/src/test/java/org/collectionspace/services/test/ServiceGroupServiceTest.java b/services/servicegroup/service/src/test/java/org/collectionspace/services/test/ServiceGroupServiceTest.java new file mode 100644 index 000000000..307ed28a3 --- /dev/null +++ b/services/servicegroup/service/src/test/java/org/collectionspace/services/test/ServiceGroupServiceTest.java @@ -0,0 +1,13 @@ +package org.collectionspace.services.test; + +//import org.collectionspace.services.servicegroup.ServiceGroup; +//import org.collectionspace.services.servicegroup.ServiceGroupList; + +/** + * Placeholder for server-side testing of ServiceGroup service code. + * + * @version $Revision: 2108 $ + */ +public class ServiceGroupServiceTest { + //empty +} diff --git a/services/servicegroup/service/src/test/resources/log4j.xml b/services/servicegroup/service/src/test/resources/log4j.xml new file mode 100644 index 000000000..52121cb83 --- /dev/null +++ b/services/servicegroup/service/src/test/resources/log4j.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +