introduced servicecontext factory to free up abstractresource from assumption that
it is used only to process multipart remote requests. affected services are fixed.
mvn test passes. account is not yet plugged into service build. account build fails.
M services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
M services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java
M services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResource.java
A services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java
M services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContext.java
M services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java
M services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java
A services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContext.java
M services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java
A services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java
A services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextFactory.java
A services/common/src/main/java/org/collectionspace/services/common/storage/jpa
A services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java
M services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandler.java
A services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandler.java
M services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java
A services/common/src/main/java/org/collectionspace/services/common/document/MultipartDocumentHandler.java
M services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java
M services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java
M services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
M services/common/pom.xml
M services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java
_M services/account/service
M services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java
M services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java
M services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java
M services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java
M services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java
import javax.ws.rs.core.UriInfo;
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.RemoteServiceContextImpl;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.util.HttpResponseCodes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Path("/accounts")
-@Consumes("multipart/mixed")
-@Produces("multipart/mixed")
+@Consumes("application/xml")
+@Produces("application/xml")
public class AccountResource
extends AbstractCollectionSpaceResource {
return serviceName;
}
+ private <T> ServiceContext createServiceContext(T obj) {
+ ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
+ ctx.setInput(obj);
+ return ctx;
+ }
+
@Override
- public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+ public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
throw new IllegalStateException();
}
@POST
- public Response createAccount(MultipartInput input) {
+ public Response createAccount(AccountsCommon input) {
try {
- RemoteServiceContext ctx = createServiceContext(input);
+ ServiceContext ctx = createServiceContext(input);
String csid = "";
UriBuilder path = UriBuilder.fromResource(AccountResource.class);
path.path("" + csid);
@GET
@Path("{csid}")
- public MultipartOutput getAccount(
+ public AccountsCommon getAccount(
@PathParam("csid") String csid) {
if (logger.isDebugEnabled()) {
logger.debug("getAccount with csid=" + csid);
"text/plain").build();
throw new WebApplicationException(response);
}
- MultipartOutput result = null;
+ AccountsCommon result = null;
try {
- RemoteServiceContext ctx = createServiceContext(null);
+ ServiceContext ctx = createServiceContext((AccountsCommon)null);
- result = ctx.getOutput();
+ result = (AccountsCommon) ctx.getOutput();
} catch (DocumentNotFoundException dnfe) {
if (logger.isDebugEnabled()) {
logger.debug("getAccount", dnfe);
public AccountsCommonList getAccountList(@Context UriInfo ui) {
AccountsCommonList accountList = new AccountsCommonList();
try {
- RemoteServiceContext ctx = createServiceContext(null);
+ ServiceContext ctx = createServiceContext((AccountsCommonList)null);
accountList = null;
} catch (Exception e) {
@PUT
@Path("{csid}")
- public MultipartOutput updateAccount(
+ public AccountsCommon updateAccount(
@PathParam("csid") String csid,
- MultipartInput theUpdate) {
+ AccountsCommon theUpdate) {
if (logger.isDebugEnabled()) {
logger.debug("updateAccount with csid=" + csid);
}
"text/plain").build();
throw new WebApplicationException(response);
}
- MultipartOutput result = null;
+ AccountsCommon result = null;
try {
- RemoteServiceContext ctx = createServiceContext(theUpdate);
+ ServiceContext ctx = createServiceContext(theUpdate);
- result = ctx.getOutput();
+ result = (AccountsCommon)ctx.getOutput();
} catch (DocumentNotFoundException dnfe) {
if (logger.isDebugEnabled()) {
logger.debug("caugth exception in updateAccount", dnfe);
throw new WebApplicationException(response);
}
try {
- ServiceContext ctx = createServiceContext(null);
+ ServiceContext ctx = createServiceContext((AccountsCommon)null);
return Response.status(HttpResponseCodes.SC_OK).build();
} catch (DocumentNotFoundException dnfe) {
*/
package org.collectionspace.services.account.storage;
+import java.util.UUID;
import org.collectionspace.services.account.AccountsCommon;
import org.collectionspace.services.account.AccountsCommonList;
import org.collectionspace.services.common.document.AbstractDocumentHandler;
* @author
*/
public class AccountDocumentHandler
- extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList> {
+ extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList, AccountsCommon, AccountsCommonList> {
@Override
- public void handleCreate(DocumentWrapper wrapDoc) throws Exception {
+ public void handleCreate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
+ String id = UUID.randomUUID().toString();
+ AccountsCommon account = wrapDoc.getWrappedObject();
+ account.setCsid(id);
}
@Override
- public void handleUpdate(DocumentWrapper wrapDoc) throws Exception {
+ public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
}
@Override
- public void handleGet(DocumentWrapper wrapDoc) throws Exception {
+ public void handleGet(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
}
@Override
- public void handleGetAll(DocumentWrapper wrapDoc) throws Exception {
+ public void handleGetAll(DocumentWrapper< AccountsCommonList> wrapDoc) throws Exception {
}
@Override
- public void extractAllParts(DocumentWrapper wrapDoc)
- throws Exception {
- }
-
- @Override
- public void fillAllParts(DocumentWrapper wrapDoc)
- throws Exception {
- }
-
- @Override
- public AccountsCommon extractCommonPart(DocumentWrapper wrapDoc)
+ public AccountsCommon extractCommonPart(DocumentWrapper<AccountsCommon> wrapDoc)
throws Exception {
return null;
}
@Override
- public void fillCommonPart(AccountsCommon obj, DocumentWrapper wrapDoc)
+ public void fillCommonPart(AccountsCommon obj, DocumentWrapper<AccountsCommon> wrapDoc)
throws Exception {
}
@Override
- public AccountsCommonList extractCommonPartList(DocumentWrapper wrapDoc)
+ public AccountsCommonList extractCommonPartList(DocumentWrapper<AccountsCommonList> wrapDoc)
throws Exception {
return null;
}
import org.collectionspace.services.acquisition.nuxeo.AcquisitionHandlerFactory;
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
}
@Override
- public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+ public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
DocumentHandler docHandler = AcquisitionHandlerFactory.getInstance().getHandler(
ctx.getRepositoryClientType().toString());
docHandler.setServiceContext(ctx);
- if(ctx.getInput() != null){
- Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), AcquisitionsCommon.class);
- if(obj != null){
+ if (ctx.getInput() != null) {
+ Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), AcquisitionsCommon.class);
+ if (obj != null) {
docHandler.setCommonPart((AcquisitionsCommon) obj);
}
}
@POST
public Response createAcquisition(MultipartInput input) {
- try{
- RemoteServiceContext ctx = createServiceContext(input);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
String csid = getRepositoryClient(ctx).create(ctx, handler);
UriBuilder path = UriBuilder.fromResource(AcquisitionResource.class);
path.path("" + csid);
Response response = Response.created(path.build()).build();
return response;
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("Caught exception in createAcquisition", e);
}
Response response = Response.status(
@Path("{csid}")
public MultipartOutput getAcquisition(
@PathParam("csid") String csid) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("getAcquisition with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("getAcquisition: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"get failed on Acquisition csid=" + csid).type(
throw new WebApplicationException(response);
}
MultipartOutput result = null;
- try{
- RemoteServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).get(ctx, csid, handler);
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("getAcquisition", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Get failed on Acquisition csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("getAcquisition", e);
}
Response response = Response.status(
throw new WebApplicationException(response);
}
- if(result == null){
+ if (result == null) {
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Get failed, the requested Acquisition CSID:" + csid + ": was not found.").type(
"text/plain").build();
@Produces("application/xml")
public AcquisitionsCommonList getAcquisitionList(@Context UriInfo ui) {
AcquisitionsCommonList acquisitionObjectList = new AcquisitionsCommonList();
- try{
- RemoteServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).getAll(ctx, handler);
acquisitionObjectList = (AcquisitionsCommonList) handler.getCommonPartList();
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("Caught exception in getAcquisitionList", e);
}
Response response = Response.status(
public MultipartOutput updateAcquisition(
@PathParam("csid") String csid,
MultipartInput theUpdate) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("updateAcquisition with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("updateAcquisition: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"update failed on Acquisition csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
}
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("updateAcquisition with input: ", theUpdate);
}
MultipartOutput result = null;
- try{
- RemoteServiceContext ctx = createServiceContext(theUpdate);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).update(ctx, csid, handler);
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("caugth exception in updateAcquisition", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Update failed on Acquisition csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
+ } catch (Exception e) {
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
throw new WebApplicationException(response);
@Path("{csid}")
public Response deleteAcquisition(@PathParam("csid") String csid) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("deleteAcquisition with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("deleteAcquisition: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"delete failed on Acquisition csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
}
- try{
- ServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
getRepositoryClient(ctx).delete(ctx, csid);
return Response.status(HttpResponseCodes.SC_OK).build();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("caught exception in deleteAcquisition", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Delete failed on Acquisition csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
+ } catch (Exception e) {
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
throw new WebApplicationException(response);
}
}
-
}
import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectHandlerFactory;
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
}
@Override
- public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+ public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
DocumentHandler docHandler = CollectionObjectHandlerFactory.getInstance().getHandler(
ctx.getRepositoryClientType().toString());
docHandler.setServiceContext(ctx);
- if(ctx.getInput() != null){
- Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), CollectionobjectsCommon.class);
- if(obj != null){
+ if (ctx.getInput() != null) {
+ Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), CollectionobjectsCommon.class);
+ if (obj != null) {
docHandler.setCommonPart((CollectionobjectsCommon) obj);
}
}
@POST
public Response createCollectionObject(MultipartInput input) {
- try{
- RemoteServiceContext ctx = createServiceContext(input);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
String csid = getRepositoryClient(ctx).create(ctx, handler);
UriBuilder path = UriBuilder.fromResource(CollectionObjectResource.class);
path.path("" + csid);
Response response = Response.created(path.build()).build();
return response;
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("Caught exception in createCollectionObject", e);
}
Response response = Response.status(
@Path("{csid}")
public MultipartOutput getCollectionObject(
@PathParam("csid") String csid) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("getCollectionObject with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("getCollectionObject: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"get failed on CollectionObject csid=" + csid).type(
throw new WebApplicationException(response);
}
MultipartOutput result = null;
- try{
- RemoteServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).get(ctx, csid, handler);
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("getCollectionObject", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Get failed on CollectionObject csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("getCollectionObject", e);
}
Response response = Response.status(
throw new WebApplicationException(response);
}
- if(result == null){
+ if (result == null) {
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Get failed, the requested CollectionObject CSID:" + csid + ": was not found.").type(
"text/plain").build();
@Produces("application/xml")
public CollectionobjectsCommonList getCollectionObjectList(@Context UriInfo ui) {
CollectionobjectsCommonList collectionObjectList = new CollectionobjectsCommonList();
- try{
- RemoteServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).getAll(ctx, handler);
collectionObjectList = (CollectionobjectsCommonList) handler.getCommonPartList();
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("Caught exception in getCollectionObjectList", e);
}
Response response = Response.status(
public MultipartOutput updateCollectionObject(
@PathParam("csid") String csid,
MultipartInput theUpdate) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("updateCollectionObject with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("updateCollectionObject: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"update failed on CollectionObject csid=" + csid).type(
throw new WebApplicationException(response);
}
MultipartOutput result = null;
- try{
- RemoteServiceContext ctx = createServiceContext(theUpdate);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).update(ctx, csid, handler);
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("caugth exception in updateCollectionObject", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Update failed on CollectionObject csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
+ } catch (Exception e) {
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
throw new WebApplicationException(response);
@Path("{csid}")
public Response deleteCollectionObject(@PathParam("csid") String csid) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("deleteCollectionObject with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("deleteCollectionObject: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"delete failed on CollectionObject csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
}
- try{
- ServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
getRepositoryClient(ctx).delete(ctx, csid);
return Response.status(HttpResponseCodes.SC_OK).build();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("caught exception in deleteCollectionObject", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Delete failed on CollectionObject csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
+ } catch (Exception e) {
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
throw new WebApplicationException(response);
<dependency>\r
<groupId>com.sun.xml.bind</groupId>\r
<artifactId>jaxb-impl</artifactId>\r
- </dependency>\r
+ </dependency>\r
<dependency>\r
<groupId>org.jvnet.jaxb2-commons</groupId>\r
<artifactId>property-listener-injector</artifactId>\r
<scope>provided</scope>\r
</dependency>\r
-->\r
- \r
+ <dependency>\r
+ <groupId>javax.persistence</groupId>\r
+ <artifactId>persistence-api</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.hibernate</groupId>\r
+ <artifactId>hibernate-entitymanager</artifactId>\r
+ </dependency>\r
<!-- jboss -->\r
<dependency>\r
<groupId>jboss</groupId>\r
*/\r
package org.collectionspace.services.common;\r
\r
-import org.collectionspace.services.common.context.RemoteServiceContext;\r
import org.collectionspace.services.common.context.ServiceContext;\r
-import org.collectionspace.services.common.context.RemoteServiceContextImpl;\r
import org.collectionspace.services.common.document.DocumentHandler;\r
import org.collectionspace.services.common.repository.RepositoryClient;\r
import org.collectionspace.services.common.repository.RepositoryClientFactory;\r
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.collectionspace.services.common.storage.StorageClient;\r
+import org.collectionspace.services.common.storage.jpa.JpaStorageClient;\r
\r
public abstract class AbstractCollectionSpaceResource\r
implements CollectionSpaceResource {\r
// Fields for default client factory and client\r
private RepositoryClientFactory repositoryClientFactory;\r
private RepositoryClient repositoryClient;\r
+ private StorageClient storageClient;\r
\r
public AbstractCollectionSpaceResource() {\r
repositoryClientFactory = RepositoryClientFactory.getInstance();\r
@Override\r
abstract public String getServiceName();\r
\r
- @Override\r
- public RepositoryClientFactory getRepositoryClientFactory() {\r
- return repositoryClientFactory;\r
- }\r
\r
@Override\r
synchronized public RepositoryClient getRepositoryClient(ServiceContext ctx) {\r
}\r
\r
@Override\r
- public RemoteServiceContext createServiceContext(MultipartInput input) throws Exception {\r
- return createServiceContext(input,getServiceName());\r
- }\r
-\r
- @Override\r
- public RemoteServiceContext createServiceContext(MultipartInput input, String serviceName) throws Exception {\r
- RemoteServiceContext ctx = new RemoteServiceContextImpl(serviceName);\r
- ctx.setInput(input);\r
- return ctx;\r
+ synchronized public StorageClient getStorageClient(ServiceContext ctx) {\r
+ if(storageClient != null) {\r
+ return storageClient;\r
+ }\r
+ storageClient = new JpaStorageClient();\r
+ return storageClient;\r
}\r
\r
@Override\r
- abstract public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception ;\r
+ abstract public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception ;\r
}\r
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.collectionspace.services.common;
-import org.collectionspace.services.common.context.RemoteServiceContext;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentHandler;
import org.collectionspace.services.common.repository.RepositoryClient;
-import org.collectionspace.services.common.repository.RepositoryClientFactory;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.collectionspace.services.common.storage.StorageClient;
/**
* CollectionSpaceResource is a resource interface implemented by every
* getServiceName returns the name of the service
*/
public String getServiceName();
-
- /**
- * getRepositoryClientFactory
- * @return
- */
- public RepositoryClientFactory getRepositoryClientFactory();
+
/**
* getRepositoryClient
public RepositoryClient getRepositoryClient(ServiceContext ctx);
/**
- * createServiceContext is a factory method to create a service context
- * a service context is created on every service request call
- * This form uses the serviceName as the default context
- * @param input
- * @return
- */
- public RemoteServiceContext createServiceContext(MultipartInput input) throws Exception;
-
- /**
- * createServiceContext is a factory method to create a service context
- * a service context is created on every service request call
- * @param input
- * @param serviceName which service/repository context to use
- * @return
+ * getStorageClient
+ * @param ctx service context
*/
- public RemoteServiceContext createServiceContext(MultipartInput input, String serviceName) throws Exception;
-
+ public StorageClient getStorageClient(ServiceContext ctx);
+
/**
* createDocumentHandler creates a document handler and populates it with given
* service context. document handler should never be used
* @param ctx
* @return
*/
- public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception ;
+ public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception;
}
public abstract IT getInput();
@Override
- public abstract void setInput(IT input) throws Exception;
+ public abstract void setInput(IT input);
@Override
public abstract OT getOutput();
@Override
- public abstract void setOutput(OT output) throws Exception;
+ public abstract void setOutput(OT output);
@Override
public String toString() {
--- /dev/null
+/**
+ * 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.common.context;
+
+import java.io.IOException;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.w3c.dom.Document;
+
+/**
+ * RemoteServiceContext is used to encapsulate the service context of a
+ * remotely invokable service
+ */
+public interface MultipartServiceContext
+ extends RemoteServiceContext<MultipartInput, MultipartOutput> {
+
+ /**
+ * Get input parts as received over the wire from service consumer
+ * @return the input
+ */
+ @Override
+ public MultipartInput getInput();
+
+ /**
+ * setInput is used to set request input before starting to
+ * process input data
+ * @param input
+ */
+ @Override
+ public void setInput(MultipartInput input);
+
+ /**
+ * Get output parts to send over the wire to service consumer
+ * @return the output
+ */
+ @Override
+ public MultipartOutput getOutput();
+
+ /**
+ * Set output parts to send over the wire to service consumer
+ * @return the output
+ */
+ @Override
+ public void setOutput(MultipartOutput output);
+
+ /**
+ * getInputPart returns part for given label from input
+ * @param label
+ * @param clazz class of the object
+ * @return part
+ */
+ public Object getInputPart(String label, Class clazz) throws IOException;
+
+ /**
+ * addOutputPart adds given XML part with given label and content type to output
+ * @param label
+ * @param document
+ * @param contentType media type
+ */
+ public void addOutputPart(String label, Document doc, String contentType) throws Exception;
+}
--- /dev/null
+/**
+ * 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.common.context;
+
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+
+/**
+ *
+ * MultipartRemoteServiceContextFactory creates a service context for
+ * a service processing multipart messages
+ *
+ */
+public class MultipartServiceContextFactory
+ implements ServiceContextFactory<MultipartInput> {
+
+ final private static MultipartServiceContextFactory self = new MultipartServiceContextFactory();
+
+ private MultipartServiceContextFactory() {
+ }
+
+ public static MultipartServiceContextFactory get() {
+ return self;
+ }
+
+ /**
+ * createServiceContext is a factory method to create a service context
+ * a service context is created on every service request call
+ * @param input
+ * @param serviceName which service/repository context to use
+ * @return
+ */
+ @Override
+ public ServiceContext createServiceContext(MultipartInput input, String serviceName) throws Exception {
+ MultipartServiceContext ctx = new MultipartServiceContextImpl(serviceName);
+ ctx.setInput(input);
+ return ctx;
+ }
+}
--- /dev/null
+/**
+ * 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.common.context;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import javax.ws.rs.core.MediaType;
+import org.collectionspace.services.common.document.DocumentUtils;
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+/**
+ * RemoteServiceContextImpl
+ *
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ */
+public class MultipartServiceContextImpl
+ extends RemoteServiceContextImpl<MultipartInput, MultipartOutput>
+ implements MultipartServiceContext {
+
+ final Logger logger = LoggerFactory.getLogger(MultipartServiceContextImpl.class);
+
+ public MultipartServiceContextImpl(String serviceName) {
+ super(serviceName);
+ setOutput(new MultipartOutput());
+ }
+
+
+ @Override
+ public Object getInputPart(String label, Class clazz) throws IOException {
+ Object obj = null;
+ if(getInput() != null){
+ MultipartInput fdip = getInput();
+
+ for(InputPart part : fdip.getParts()){
+ String partLabel = part.getHeaders().getFirst("label");
+ if(label.equalsIgnoreCase(partLabel)){
+ if(logger.isDebugEnabled()){
+ logger.debug("received part label=" + partLabel +
+ "\npayload=" + part.getBodyAsString());
+ }
+ obj = part.getBody(clazz, null);
+ break;
+ }
+ }
+ }
+ return obj;
+ }
+
+ @Override
+ public void addOutputPart(String label, Document doc, String contentType) throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try{
+ DocumentUtils.writeDocument(doc, baos);
+ baos.close();
+ OutputPart part = getOutput().addPart(new String(baos.toByteArray()),
+ MediaType.valueOf(contentType));
+ part.getHeaders().add("label", label);
+ }finally{
+ if(baos != null){
+ try{
+ baos.close();
+ }catch(Exception e){
+ }
+ }
+ }
+ }
+
+ @Override
+ public ServiceContext getLocalContext(String localContextClassName) throws Exception {
+ ClassLoader cloader = Thread.currentThread().getContextClassLoader();
+ Class ctxClass = cloader.loadClass(localContextClassName);
+ if(!ServiceContext.class.isAssignableFrom(ctxClass)) {
+ throw new IllegalArgumentException("getLocalContext requires " +
+ " implementation of " + ServiceContext.class.getName());
+ }
+
+ Constructor ctor = ctxClass.getConstructor(java.lang.String.class);
+ ServiceContext ctx = (ServiceContext)ctor.newInstance(getServiceName());
+ return ctx;
+ }
+}
*/
package org.collectionspace.services.common.context;
-import java.io.IOException;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
-import org.w3c.dom.Document;
-
/**
* RemoteServiceContext is used to encapsulate the service context of a
* remotely invokable service
*/
-public interface RemoteServiceContext
- extends ServiceContext<MultipartInput, MultipartOutput> {
+public interface RemoteServiceContext<IT, OT>
+ extends ServiceContext<IT, OT> {
/**
* Get input parts as received over the wire from service consumer
* @return the input
*/
@Override
- public MultipartInput getInput();
+ public IT getInput();
/**
* setInput is used to set request input before starting to
* @exception IOException
*/
@Override
- public void setInput(MultipartInput input) throws Exception;
+ public void setInput(IT input);
/**
* Get output parts to send over the wire to service consumer
* @return the output
*/
@Override
- public MultipartOutput getOutput();
+ public OT getOutput();
/**
* Set output parts to send over the wire to service consumer
* @return the output
*/
@Override
- public void setOutput(MultipartOutput output) throws Exception;
-
- /**
- * getInputPart returns part for given label from input
- * @param label
- * @param clazz class of the object
- * @return part
- */
- public Object getInputPart(String label, Class clazz) throws IOException;
+ public void setOutput(OT output);
- /**
- * addOutputPart adds given XML part with given label and content type to output
- * @param label
- * @param document
- * @param contentType media type
- */
- public void addOutputPart(String label, Document doc, String contentType) throws Exception;
/**
* getLocalContext clones the remote context minus remote messaging data parts
*/
package org.collectionspace.services.common.context;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.lang.reflect.Constructor;
-import javax.ws.rs.core.MediaType;
-import org.collectionspace.services.common.document.DocumentUtils;
-import org.jboss.resteasy.plugins.providers.multipart.InputPart;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
-import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
/**
* RemoteServiceContextImpl
* $LastChangedRevision: $
* $LastChangedDate: $
*/
-public class RemoteServiceContextImpl
- extends AbstractServiceContext<MultipartInput, MultipartOutput>
- implements RemoteServiceContext {
+public class RemoteServiceContextImpl<IT, OT>
+ extends AbstractServiceContext<IT, OT>
+ implements RemoteServiceContext<IT, OT> {
final Logger logger = LoggerFactory.getLogger(RemoteServiceContextImpl.class);
//input stores original content as received over the wire
- private MultipartInput input;
- private MultipartOutput output;
+ private IT input;
+ private OT output;
public RemoteServiceContextImpl(String serviceName) {
super(serviceName);
- output = new MultipartOutput();
}
@Override
- public MultipartInput getInput() {
+ public IT getInput() {
return input;
}
@Override
- public void setInput(MultipartInput input) throws IOException {
+ public void setInput(IT input){
this.input = input;
}
@Override
- public MultipartOutput getOutput() {
+ public OT getOutput() {
return output;
}
@Override
- public void setOutput(MultipartOutput output) throws Exception {
+ public void setOutput(OT output){
this.output = output;
}
- @Override
- public Object getInputPart(String label, Class clazz) throws IOException {
- Object obj = null;
- if(getInput() != null){
- MultipartInput fdip = getInput();
-
- for(InputPart part : fdip.getParts()){
- String partLabel = part.getHeaders().getFirst("label");
- if(label.equalsIgnoreCase(partLabel)){
- if(logger.isDebugEnabled()){
- logger.debug("received part label=" + partLabel +
- "\npayload=" + part.getBodyAsString());
- }
- obj = part.getBody(clazz, null);
- break;
- }
- }
- }
- return obj;
- }
-
- @Override
- public void addOutputPart(String label, Document doc, String contentType) throws Exception {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try{
- DocumentUtils.writeDocument(doc, baos);
- baos.close();
- OutputPart part = output.addPart(new String(baos.toByteArray()),
- MediaType.valueOf(contentType));
- part.getHeaders().add("label", label);
- }finally{
- if(baos != null){
- try{
- baos.close();
- }catch(Exception e){
- }
- }
- }
- }
@Override
public ServiceContext getLocalContext(String localContextClassName) throws Exception {
* setInput is used to set request input before starting to
* process input data
* @param input
- * @exception Exception
*/
- public void setInput(IT input) throws Exception;
+ public void setInput(IT input);
/**
* Get output parts to send over the wire to service consumer
* setOutput set output
* @param output
*/
- public void setOutput(OT output) throws Exception;
+ public void setOutput(OT output);
/**
* getPartsMetadata returns metadata for object parts used by the service
--- /dev/null
+/**
+ * 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.common.context;
+
+/**
+ *
+ * ServiceContextFactory creates a service context
+ *
+ */
+public interface ServiceContextFactory<T> {
+
+
+ /**
+ * createServiceContext is a factory method to create a service context
+ * a service context is created on every service request call
+ * @param input
+ * @param serviceName which service/repository context to use
+ * @return
+ */
+ public ServiceContext createServiceContext(T input, String serviceName) throws Exception;
+
+}
//no specific action needed
}
- @Override
- public abstract void extractAllParts(DocumentWrapper<WT> wrapDoc)
- throws Exception;
-
- @Override
- public abstract void fillAllParts(DocumentWrapper<WT> wrapDoc)
- throws Exception;
-
@Override
public abstract T extractCommonPart(DocumentWrapper<WT> wrapDoc)
throws Exception;
--- /dev/null
+/**
+ * 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.common.document;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import java.util.StringTokenizer;
+import org.collectionspace.services.common.context.ServiceContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * AbstractMultipartDocumentHandler
+ *
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ */
+public abstract class AbstractMultipartDocumentHandler<T, TL, WT, WTL>
+ extends AbstractDocumentHandler<T, TL, WT, WTL>
+ implements MultipartDocumentHandler<T, TL, WT, WTL> {
+
+ private final Logger logger = LoggerFactory.getLogger(AbstractMultipartDocumentHandler.class);
+
+ public AbstractMultipartDocumentHandler() {
+ }
+
+ @Override
+ public abstract void handleCreate(DocumentWrapper<WT> wrapDoc) throws Exception;
+
+ @Override
+ public abstract void handleUpdate(DocumentWrapper<WT> wrapDoc) throws Exception;
+
+ @Override
+ public abstract void handleGet(DocumentWrapper<WT> wrapDoc) throws Exception;
+
+ @Override
+ public abstract void handleGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception;
+
+ @Override
+ public abstract void extractAllParts(DocumentWrapper<WT> wrapDoc)
+ throws Exception;
+
+ @Override
+ public abstract void fillAllParts(DocumentWrapper<WT> wrapDoc)
+ throws Exception;
+
+ @Override
+ public abstract T extractCommonPart(DocumentWrapper<WT> wrapDoc)
+ throws Exception;
+
+ @Override
+ public abstract void fillCommonPart(T obj, DocumentWrapper<WT> wrapDoc)
+ throws Exception;
+
+ @Override
+ public abstract TL extractCommonPartList(DocumentWrapper<WTL> wrapDoc)
+ throws Exception;
+
+ @Override
+ public abstract T getCommonPart();
+
+ @Override
+ public abstract void setCommonPart(T obj);
+
+ @Override
+ public abstract TL getCommonPartList();
+
+ @Override
+ public abstract void setCommonPartList(TL obj);
+
+ @Override
+ public abstract String getQProperty(String prop);
+
+}
* repository client calls prepare on the handler
* The repository client then calls handle on the handler
*
+ * T - Entity Type (e.g. CollectionObjectsCommon)
+ * TL - Entity List Type (e.g. CollectionObjectsCommonList)
+ * WT - Wrapped Type (e.g. DocumentModel)
+ * WTL - Wrapped List Type (e.g. DocumentModelList)
+ *
*/
public interface DocumentHandler<T, TL, WT, WTL> {
*/
public void completeUpdate(DocumentWrapper<WT> wrapDoc) throws Exception;
- /**
- * extractAllParts extracts all parts of a CS object from given document.
- * this is usually called AFTER the get operation is invoked on the repository
- * Called in handle GET/GET_ALL actions.
- * @param docWrap document
- * @throws Exception
- */
- public void extractAllParts(DocumentWrapper<WT> docWrap) throws Exception;
-
- /**
- * fillAllParts sets parts of CS object into given document
- * this is usually called BEFORE create/update operations are invoked on the
- * repository. Called in handle CREATE/UPDATE actions.
- * @param obj input object
- * @param docWrap target document
- * @throws Exception
- */
- public void fillAllParts(DocumentWrapper<WT> docWrap) throws Exception;
-
/**
* extractCommonPart extracts common part of a CS object from given document.
* this is usually called AFTER the get operation is invoked on the repository.
--- /dev/null
+/**
+ * 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
+ */
+package org.collectionspace.services.common.document;
+
+/**
+ * MultipartDocumentHandler is a DocumentHandler provides document processing
+ * methods for entities using schema extension that are mapped to multipart
+ * request and response.
+ * @author
+ * @param <T>
+ * @param <TL>
+ * @param <WT>
+ * @param <WTL>
+ */
+public interface MultipartDocumentHandler<T, TL, WT, WTL>
+ extends DocumentHandler<T, TL, WT, WTL> {
+
+ /**
+ * extractAllParts extracts all parts of a CS object from given document.
+ * this is usually called AFTER the get operation is invoked on the repository
+ * Called in handle GET/GET_ALL actions.
+ * @param docWrap document
+ * @throws Exception
+ */
+ public void extractAllParts(DocumentWrapper<WT> docWrap) throws Exception;
+
+ /**
+ * fillAllParts sets parts of CS object into given document
+ * this is usually called BEFORE create/update operations are invoked on the
+ * repository. Called in handle CREATE/UPDATE actions.
+ * @param obj input object
+ * @param docWrap target document
+ * @throws Exception
+ */
+ public void fillAllParts(DocumentWrapper<WT> docWrap) throws Exception;
+}
\ No newline at end of file
--- /dev/null
+/**
+ * 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
+ */
+package org.collectionspace.services.common.storage.jpa;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.persistence.Query;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.BadRequestException;
+import org.collectionspace.services.common.document.DocumentException;
+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.document.DocumentHandler.Action;
+import org.collectionspace.services.common.document.DocumentWrapper;
+import org.collectionspace.services.common.document.DocumentWrapperImpl;
+import org.collectionspace.services.common.storage.StorageClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * JpaStorageClient is used to perform CRUD operations on documents in Nuxeo
+ * repository using Remote Java APIs. It uses @see DocumentHandler as IOHandler
+ * with the client.
+ *
+ * $LastChangedRevision: $ $LastChangedDate: $
+ */
+public class JpaStorageClient implements StorageClient {
+
+ private final Logger logger = LoggerFactory.getLogger(JpaStorageClient.class);
+
+ public JpaStorageClient() {
+ }
+
+ @Override
+ public String create(ServiceContext ctx,
+ DocumentHandler handler) throws BadRequestException,
+ DocumentException {
+
+ String docType = ctx.getDocumentType();
+ if (docType == null) {
+ throw new DocumentNotFoundException(
+ "Unable to find DocumentType for service " + ctx.getServiceName());
+ }
+ if (handler == null) {
+ throw new IllegalArgumentException(
+ "JpaStorageClient.create: handler is missing");
+ }
+ EntityManagerFactory emf = null;
+ EntityManager em = null;
+ try {
+ handler.prepare(Action.CREATE);
+ Object po = handler.getCommonPart();
+ DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(po);
+ handler.handle(Action.CREATE, wrapDoc);
+ emf = getEntityManagerFactory(docType);
+ em = emf.createEntityManager();
+ em.getTransaction().begin();
+ em.persist(po);
+ em.getTransaction().commit();
+ handler.complete(Action.CREATE, wrapDoc);
+ return getCsid(po);
+ } catch (Exception e) {
+ if (em != null) {
+ em.getTransaction().rollback();
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ } finally {
+ if (em != null) {
+ releaseEntityManagerFactory(emf);
+ }
+ }
+
+ }
+
+ @Override
+ public void get(ServiceContext ctx, String id, DocumentHandler handler)
+ throws DocumentNotFoundException, DocumentException {
+ if (handler == null) {
+ throw new IllegalArgumentException(
+ "JpaStorageClient.get: handler is missing");
+ }
+ DocumentFilter docFilter = handler.getDocumentFilter();
+ if (docFilter == null) {
+ throw new IllegalArgumentException(
+ "JpaStorageClient.get: handler has no Filter specified");
+ }
+ String docType = ctx.getDocumentType();
+ if (docType == null) {
+ throw new DocumentNotFoundException(
+ "Unable to find DocumentType for service " + ctx.getServiceName());
+ }
+ EntityManagerFactory emf = null;
+ EntityManager em = null;
+ try {
+ handler.prepare(Action.GET);
+ StringBuilder queryStr = new StringBuilder("SELECT * FROM ");
+ queryStr.append(docType);
+ queryStr.append(" WHERE csid = :csid");
+ //TODO: add tenant id
+ String where = docFilter.getWhereClause();
+ if ((null != where) && (where.length() > 0)) {
+ queryStr.append(" AND " + where);
+ }
+ emf = getEntityManagerFactory(docType);
+ em = emf.createEntityManager();
+ Query q = em.createQuery(queryStr.toString());
+ q.setParameter("csid", id);
+ //TODO: add tenant id
+
+ //TODO: get page
+ if ((docFilter.getOffset() > 0) || (docFilter.getPageSize() > 0)) {
+ } else {
+ }
+ //require transaction for get?
+ em.getTransaction().begin();
+ Object o = q.getSingleResult();
+ em.getTransaction().commit();
+ DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(o);
+ handler.handle(Action.GET, wrapDoc);
+ handler.complete(Action.GET, wrapDoc);
+ } catch (IllegalArgumentException iae) {
+ throw iae;
+ } catch (DocumentException de) {
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ } finally {
+ if (emf != null) {
+ releaseEntityManagerFactory(emf);
+ }
+ }
+ }
+
+ @Override
+ public void getAll(ServiceContext ctx, DocumentHandler handler)
+ throws DocumentNotFoundException, DocumentException {
+ throw new UnsupportedOperationException("use getFiltered instead");
+ }
+
+ /**
+ * getFiltered get all documents for an entity service from the Document repository,
+ * given filter parameters specified by the handler.
+ * @param ctx service context under which this method is invoked
+ * @param handler should be used by the caller to provide and transform the document
+ * @throws DocumentNotFoundException if workspace not found
+ * @throws DocumentException
+ */
+ public void getFiltered(ServiceContext ctx, DocumentHandler handler)
+ throws DocumentNotFoundException, DocumentException {
+ if (handler == null) {
+ throw new IllegalArgumentException(
+ "JpaStorageClient.getFiltered: handler is missing");
+ }
+ DocumentFilter docFilter = handler.getDocumentFilter();
+ if (docFilter == null) {
+ throw new IllegalArgumentException(
+ "JpaStorageClient.getFiltered: handler has no Filter specified");
+ }
+ String docType = ctx.getDocumentType();
+ if (docType == null) {
+ throw new DocumentNotFoundException(
+ "Unable to find DocumentType for service " + ctx.getServiceName());
+ }
+
+ EntityManagerFactory emf = null;
+ EntityManager em = null;
+ try {
+ handler.prepare(Action.GET_ALL);
+
+ StringBuilder queryStr = new StringBuilder("SELECT * FROM ");
+ queryStr.append(docType);
+ //TODO: add tenant id
+ String where = docFilter.getWhereClause();
+ if ((null != where) && (where.length() > 0)) {
+ queryStr.append(" AND " + where);
+ }
+ emf = getEntityManagerFactory(docType);
+ em = emf.createEntityManager();
+ Query q = em.createQuery(queryStr.toString());
+ //TODO: add tenant id
+ //TODO: get page
+ if ((docFilter.getOffset() > 0) || (docFilter.getPageSize() > 0)) {
+ } else {
+ }
+ //FIXME is transaction required for get?
+ em.getTransaction().begin();
+ List list = q.getResultList();
+ em.getTransaction().commit();
+ DocumentWrapper<List> wrapDoc = new DocumentWrapperImpl<List>(list);
+ handler.handle(Action.GET_ALL, wrapDoc);
+ handler.complete(Action.GET_ALL, wrapDoc);
+ } catch (DocumentException de) {
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ } finally {
+ if (emf != null) {
+ releaseEntityManagerFactory(emf);
+ }
+ }
+ }
+
+ @Override
+ public void update(ServiceContext ctx, String id, DocumentHandler handler)
+ throws BadRequestException, DocumentNotFoundException,
+ DocumentException {
+ String docType = ctx.getDocumentType();
+ if (docType == null) {
+ throw new DocumentNotFoundException(
+ "Unable to find DocumentType for service " + ctx.getServiceName());
+ }
+ if (handler == null) {
+ throw new IllegalArgumentException(
+ "JpaStorageClient.update: handler is missing");
+ }
+ EntityManagerFactory emf = null;
+ EntityManager em = null;
+ try {
+ handler.prepare(Action.UPDATE);
+ Object po = handler.getCommonPart();
+ setCsid(po, id);
+ DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(po);
+ handler.handle(Action.UPDATE, wrapDoc);
+ emf = getEntityManagerFactory(docType);
+ em = emf.createEntityManager();
+ em.getTransaction().begin();
+ em.merge(po);
+ em.getTransaction().commit();
+ handler.complete(Action.UPDATE, wrapDoc);
+ } catch (DocumentException de) {
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ } finally {
+ }
+ }
+
+ /**
+ * delete a document from the Nuxeo repository
+ * @param ctx service context under which this method is invoked
+ * @param id
+ * of the document
+ * @throws DocumentException
+ */
+ @Override
+ public void delete(ServiceContext ctx, String id) throws DocumentNotFoundException,
+ DocumentException {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleting document with id=" + id);
+ }
+ String docType = ctx.getDocumentType();
+ if (docType == null) {
+ throw new DocumentNotFoundException(
+ "Unable to find DocumentType for service " + ctx.getServiceName());
+ }
+ EntityManagerFactory emf = null;
+ EntityManager em = null;
+ try {
+ StringBuilder deleteStr = new StringBuilder("DELETE FROM ");
+ deleteStr.append(docType);
+ deleteStr.append(" WHERE csid = :csid");
+ //TODO: add tenant id
+
+ emf = getEntityManagerFactory(docType);
+ em = emf.createEntityManager();
+ Query q = em.createQuery(deleteStr.toString());
+ q.setParameter("csid", id);
+ //TODO: add tenant id
+ em.getTransaction().begin();
+ int rcount = q.executeUpdate();
+ em.getTransaction().commit();
+ if (rcount != 1) {
+ throw new DocumentException("failed to delete " + docType +
+ " csid=" + id);
+ }
+ } catch (DocumentException de) {
+ if (em != null) {
+ em.getTransaction().rollback();
+ }
+ throw de;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ if (em != null) {
+ em.getTransaction().rollback();
+ }
+ throw new DocumentException(e);
+ } finally {
+ if (emf != null) {
+ releaseEntityManagerFactory(emf);
+ }
+ }
+ }
+
+ private EntityManagerFactory getEntityManagerFactory(String persistenceUnit) {
+ return Persistence.createEntityManagerFactory(persistenceUnit);
+
+ }
+
+ private void releaseEntityManagerFactory(EntityManagerFactory emf) {
+ if (emf != null) {
+ emf.close();
+ }
+ }
+
+ private String getCsid(Object o) throws Exception {
+ Class c = o.getClass();
+ Method m = c.getMethod("getCsid");
+ if (m == null) {
+ String msg = "Could not find csid in object of class=" + o.getClass().getCanonicalName();
+ logger.error(msg);
+ throw new IllegalArgumentException(msg);
+ }
+ Object r = m.invoke(o);
+ if (logger.isDebugEnabled()) {
+ logger.debug("getCsid returned csid=" + r.toString() +
+ " for " + c.getName());
+ }
+ return (String) r;
+ }
+
+ private void setCsid(Object o, String csid) throws Exception {
+ //verify csid
+ String id = getCsid(o);
+ if (id != null) {
+ if (!id.equals(csid)) {
+ String msg = "Csids do not match!";
+ logger.error(msg);
+ throw new BadRequestException(msg);
+ } else {
+ //no need to set
+ return;
+ }
+ }
+ //set csid
+ Class c = o.getClass();
+ Method m = c.getMethod("setCsid");
+ if (m == null) {
+ String msg = "Could not find csid in object of class=" + o.getClass().getCanonicalName();
+ logger.error(msg);
+ throw new IllegalArgumentException(msg);
+ }
+ Object r = m.invoke(o, csid);
+ if (logger.isDebugEnabled()) {
+ logger.debug("setCsid returned csid=" + r.toString() +
+ " for " + c.getName());
+ }
+ }
+}
\ No newline at end of file
*/
package org.collectionspace.services.nuxeo.client.java;
+import org.collectionspace.services.common.document.AbstractMultipartDocumentHandler;
import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.common.document.AbstractDocumentHandler;
import org.collectionspace.services.nuxeo.client.*;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentModelList;
* $LastChangedDate: $
*/
public abstract class DocumentModelHandler<T, TL>
- extends AbstractDocumentHandler<T, TL, DocumentModel, DocumentModelList> {
+ extends AbstractMultipartDocumentHandler<T, TL, DocumentModel, DocumentModelList> {
private final Logger logger = LoggerFactory.getLogger(DocumentModelHandler.class);
private RepositoryInstance repositorySession;
import java.util.Map.Entry;
import java.util.Set;
import javax.ws.rs.core.MediaType;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.BadRequestException;
import org.collectionspace.services.common.document.DocumentUtils;
@Override
public void setServiceContext(ServiceContext ctx) {
- if(ctx instanceof RemoteServiceContext){
+ if(ctx instanceof MultipartServiceContext){
super.setServiceContext(ctx);
}else{
throw new IllegalArgumentException("setServiceContext requires instance of " +
- RemoteServiceContext.class.getName());
+ MultipartServiceContext.class.getName());
}
}
DocumentModel docModel = wrapDoc.getWrappedObject();
//return at least those document part(s) that were received
Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
- RemoteServiceContext ctx = (RemoteServiceContext) getServiceContext();
+ MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
List<InputPart> inputParts = ctx.getInput().getParts();
for(InputPart part : inputParts){
String partLabel = part.getHeaders().getFirst("label");
//Nuxeo APIs lack to support stream/byte[] input, get/setting properties is
//not an ideal way of populating objects.
DocumentModel docModel = wrapDoc.getWrappedObject();
- RemoteServiceContext ctx = (RemoteServiceContext) getServiceContext();
+ MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
MultipartInput input = ctx.getInput();
if(input.getParts().isEmpty()){
String msg = "No payload found!";
if(logger.isDebugEnabled()){
DocumentUtils.writeDocument(doc, System.out);
}
- RemoteServiceContext ctx = (RemoteServiceContext) getServiceContext();
+ MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
ctx.addOutputPart(schema, doc, partMeta.getContent().getContentType());
} //TODO: handle other media types
}
if (ctx.getDocumentType() == null) {
throw new IllegalArgumentException(
- "RemoteRepositoryClient.create: docType is missing");
+ "RepositoryJavaClient.create: docType is missing");
}
if (handler == null) {
throw new IllegalArgumentException(
- "RemoteRepositoryClient.create: handler is missing");
+ "RepositoryJavaClient.create: handler is missing");
}
String nuxeoWspaceId = ctx.getRepositoryWorkspaceId();
if (nuxeoWspaceId == null) {
if (handler == null) {
throw new IllegalArgumentException(
- "RemoteRepositoryClient.get: handler is missing");
+ "RepositoryJavaClient.get: handler is missing");
}
RepositoryInstance repoSession = null;
throws DocumentNotFoundException, DocumentException {
if (handler == null) {
throw new IllegalArgumentException(
- "RemoteRepositoryClient.getAll: handler is missing");
+ "RepositoryJavaClient.getAll: handler is missing");
}
String nuxeoWspaceId = ctx.getRepositoryWorkspaceId();
if (nuxeoWspaceId == null) {
throws DocumentNotFoundException, DocumentException {
if (handler == null) {
throw new IllegalArgumentException(
- "RemoteRepositoryClient.getFiltered: handler is missing");
+ "RepositoryJavaClient.getFiltered: handler is missing");
}
DocumentFilter docFilter = handler.getDocumentFilter();
if (docFilter == null) {
throw new IllegalArgumentException(
- "RemoteRepositoryClient.getFiltered: handler has no Filter specified");
+ "RepositoryJavaClient.getFiltered: handler has no Filter specified");
}
String docType = ctx.getDocumentType();
if (docType == null) {
public void update(ServiceContext ctx, String id, DocumentHandler handler)
throws BadRequestException, DocumentNotFoundException,
DocumentException {
- if (id == null) {
- throw new BadRequestException(
- "RemoteRepositoryClient.update: id is missing");
- }
if (handler == null) {
throw new IllegalArgumentException(
- "RemoteRepositoryClient.update: handler is missing");
+ "RepositoryJavaClient.update: handler is missing");
}
RepositoryInstance repoSession = null;
try {
import org.collectionspace.services.intake.nuxeo.IntakeHandlerFactory;
import org.collectionspace.services.common.ClientType;
import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
}
@Override
- public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+ public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
DocumentHandler docHandler = IntakeHandlerFactory.getInstance().getHandler(
ctx.getRepositoryClientType().toString());
docHandler.setServiceContext(ctx);
- if(ctx.getInput() != null){
- Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), IntakesCommon.class);
- if(obj != null){
+ if (ctx.getInput() != null) {
+ Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), IntakesCommon.class);
+ if (obj != null) {
docHandler.setCommonPart((IntakesCommon) obj);
}
}
@POST
public Response createIntake(MultipartInput input) {
- try{
- RemoteServiceContext ctx = createServiceContext(input);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
String csid = getRepositoryClient(ctx).create(ctx, handler);
//intakeObject.setCsid(csid);
path.path("" + csid);
Response response = Response.created(path.build()).build();
return response;
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("Caught exception in createIntake", e);
}
Response response = Response.status(
@Path("{csid}")
public MultipartOutput getIntake(
@PathParam("csid") String csid) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("getIntake with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("getIntake: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"get failed on Intake csid=" + csid).type(
throw new WebApplicationException(response);
}
MultipartOutput result = null;
- try{
- RemoteServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).get(ctx, csid, handler);
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("getIntake", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Get failed on Intake csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("getIntake", e);
}
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
throw new WebApplicationException(response);
}
- if(result == null){
+ if (result == null) {
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Get failed, the requested Intake CSID:" + csid + ": was not found.").type(
"text/plain").build();
@Produces("application/xml")
public IntakesCommonList getIntakeList(@Context UriInfo ui) {
IntakesCommonList intakeObjectList = new IntakesCommonList();
- try{
- RemoteServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).getAll(ctx, handler);
intakeObjectList = (IntakesCommonList) handler.getCommonPartList();
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("Caught exception in getIntakeList", e);
}
Response response = Response.status(
public MultipartOutput updateIntake(
@PathParam("csid") String csid,
MultipartInput theUpdate) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("updateIntake with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("updateIntake: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"update failed on Intake csid=" + csid).type(
throw new WebApplicationException(response);
}
MultipartOutput result = null;
- try{
- RemoteServiceContext ctx = createServiceContext(theUpdate);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).update(ctx, csid, handler);
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("caugth exception in updateIntake", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Update failed on Intake csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
+ } catch (Exception e) {
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
throw new WebApplicationException(response);
@Path("{csid}")
public Response deleteIntake(@PathParam("csid") String csid) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("deleteIntake with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("deleteIntake: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"delete failed on Intake csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
}
- try{
- ServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
getRepositoryClient(ctx).delete(ctx, csid);
return Response.status(HttpResponseCodes.SC_OK).build();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("caught exception in deleteIntake", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Delete failed on Intake csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
+ } catch (Exception e) {
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
throw new WebApplicationException(response);
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.relation.IRelationsManager;
import org.collectionspace.services.common.document.DocumentNotFoundException;
}
@Override
- public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+ public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
DocumentHandler docHandler = RelationHandlerFactory.getInstance().getHandler(
ctx.getRepositoryClientType().toString());
docHandler.setServiceContext(ctx);
- if(ctx.getInput() != null){
- Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), RelationsCommon.class);
- if(obj != null){
+ if (ctx.getInput() != null) {
+ Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), RelationsCommon.class);
+ if (obj != null) {
docHandler.setCommonPart((RelationsCommon) obj);
}
}
@POST
public Response createRelation(MultipartInput input) {
- try{
- RemoteServiceContext ctx = createServiceContext(input);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
String csid = getRepositoryClient(ctx).create(ctx, handler);
UriBuilder path = UriBuilder.fromResource(NewRelationResource.class);
path.path("" + csid);
Response response = Response.created(path.build()).build();
return response;
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("Caught exception in createRelation", e);
}
Response response = Response.status(
@GET
@Path("{csid}")
public MultipartOutput getRelation(@PathParam("csid") String csid) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("getRelation with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("getRelation: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity("get failed on Relation csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
}
MultipartOutput result = null;
- try{
- RemoteServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).get(ctx, csid, handler);
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("getRelation", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity("Get failed on Relation csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("getRelation", e);
}
Response response = Response.status(
throw new WebApplicationException(response);
}
- if(result == null){
+ if (result == null) {
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Get failed, the requested Relation CSID:" + csid + ": was not found.").type("text/plain").build();
throw new WebApplicationException(response);
@Path("{csid}")
public MultipartOutput updateRelation(@PathParam("csid") String csid,
MultipartInput theUpdate) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("updateRelation with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("updateRelation: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity("update failed on Relation csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
}
MultipartOutput result = null;
- try{
- RemoteServiceContext ctx = createServiceContext(theUpdate);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).update(ctx, csid, handler);
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("caugth exception in updateRelation", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity("Update failed on Relation csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
+ } catch (Exception e) {
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity(
"Update failed").type("text/plain").build();
@Path("{csid}")
public Response deleteRelation(@PathParam("csid") String csid) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("deleteRelation with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("deleteRelation: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity("delete failed on Relation csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
}
- try{
- ServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
getRepositoryClient(ctx).delete(ctx, csid);
return Response.status(HttpResponseCodes.SC_OK).build();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("caught exception in deleteRelation", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity("Delete failed on Relation csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
+ } catch (Exception e) {
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity(
"Delete failed").type("text/plain").build();
String objectCsid)
throws WebApplicationException {
RelationsCommonList relationList = new RelationsCommonList();
- try{
- RemoteServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
Map propsFromPath = handler.getProperties();
propsFromPath.put(IRelationsManager.SUBJECT, subjectCsid);
propsFromPath.put(IRelationsManager.OBJECT, objectCsid);
getRepositoryClient(ctx).getAll(ctx, handler);
relationList = (RelationsCommonList) handler.getCommonPartList();
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("Caught exception in getRelationList", e);
}
Response response = Response.status(
*/
package org.collectionspace.services.vocabulary;
-import java.util.List;
-import java.util.Map;
-
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MultivaluedMap;
import org.collectionspace.services.common.AbstractCollectionSpaceResource;
import org.collectionspace.services.common.ClientType;
import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentHandler;
/*
public RemoteServiceContext createItemServiceContext(MultipartInput input) throws Exception {
- RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
- ctx.setInput(input);
- return ctx;
+ RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
+ ctx.setInput(input);
+ return ctx;
}
- */
-
+ */
@Override
- public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+ public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
DocumentHandler docHandler = VocabularyHandlerFactory.getInstance().getHandler(
ctx.getRepositoryClientType().toString());
docHandler.setServiceContext(ctx);
- if(ctx.getInput() != null){
- Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), VocabulariesCommon.class);
- if(obj != null){
+ if (ctx.getInput() != null) {
+ Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), VocabulariesCommon.class);
+ if (obj != null) {
docHandler.setCommonPart((VocabulariesCommon) obj);
}
}
return docHandler;
}
-
+
private DocumentHandler createItemDocumentHandler(
- RemoteServiceContext ctx,
- String inVocabulary) throws Exception {
+ ServiceContext ctx,
+ String inVocabulary) throws Exception {
DocumentHandler docHandler = VocabularyItemHandlerFactory.getInstance().getHandler(
ctx.getRepositoryClientType().toString());
docHandler.setServiceContext(ctx);
- ((VocabularyItemDocumentModelHandler)docHandler).setInVocabulary(inVocabulary);
- if(ctx.getInput() != null){
- Object obj = ctx.getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
- VocabularyitemsCommon.class);
- if(obj != null){
+ ((VocabularyItemDocumentModelHandler) docHandler).setInVocabulary(inVocabulary);
+ if (ctx.getInput() != null) {
+ Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
+ VocabularyitemsCommon.class);
+ if (obj != null) {
docHandler.setCommonPart((VocabularyitemsCommon) obj);
}
}
@POST
public Response createVocabulary(MultipartInput input) {
- try{
- RemoteServiceContext ctx = createServiceContext(input);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
String csid = getRepositoryClient(ctx).create(ctx, handler);
//vocabularyObject.setCsid(csid);
path.path("" + csid);
Response response = Response.created(path.build()).build();
return response;
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("Caught exception in createVocabulary", e);
}
Response response = Response.status(
@GET
@Path("{csid}")
public MultipartOutput getVocabulary(@PathParam("csid") String csid) {
- String idValue = null;
- if(csid == null){
+ String idValue = null;
+ if (csid == null) {
logger.error("getVocabulary: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"get failed on Vocabulary csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
}
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("getVocabulary with path(id)=" + csid);
}
MultipartOutput result = null;
- try{
- RemoteServiceContext ctx = createServiceContext(null);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
- getRepositoryClient(ctx).get(ctx, csid, handler);
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ getRepositoryClient(ctx).get(ctx, csid, handler);
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("getVocabulary", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Get failed on Vocabulary csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("getVocabulary", e);
}
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
throw new WebApplicationException(response);
}
- if(result == null){
+ if (result == null) {
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Get failed, the requested Vocabulary CSID:" + csid + ": was not found.").type(
"text/plain").build();
@Produces("application/xml")
public VocabulariesCommonList getVocabularyList(@Context UriInfo ui) {
VocabulariesCommonList vocabularyObjectList = new VocabulariesCommonList();
- try{
- RemoteServiceContext ctx = createServiceContext(null);
- MultivaluedMap<String,String> queryParams = ui.getQueryParameters();
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+ MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
DocumentHandler handler = createDocumentHandler(ctx);
DocumentFilter myFilter =
DocumentFilter.CreatePaginatedDocumentFilter(queryParams);
handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
vocabularyObjectList = (VocabulariesCommonList) handler.getCommonPartList();
- }catch(Exception e){
- if(logger.isDebugEnabled()){
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
logger.debug("Caught exception in getVocabularyList", e);
}
Response response = Response.status(
public MultipartOutput updateVocabulary(
@PathParam("csid") String csid,
MultipartInput theUpdate) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("updateVocabulary with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("updateVocabulary: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"update failed on Vocabulary csid=" + csid).type(
throw new WebApplicationException(response);
}
MultipartOutput result = null;
- try{
- RemoteServiceContext ctx = createServiceContext(theUpdate);
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).update(ctx, csid, handler);
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ result = (MultipartOutput) ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("caugth exception in updateVocabulary", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Update failed on Vocabulary csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
+ } catch (Exception e) {
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
throw new WebApplicationException(response);
@Path("{csid}")
public Response deleteVocabulary(@PathParam("csid") String csid) {
- if(logger.isDebugEnabled()){
+ if (logger.isDebugEnabled()) {
logger.debug("deleteVocabulary with csid=" + csid);
}
- if(csid == null || "".equals(csid)){
+ if (csid == null || "".equals(csid)) {
logger.error("deleteVocabulary: missing csid!");
Response response = Response.status(Response.Status.BAD_REQUEST).entity(
"delete failed on Vocabulary csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
}
- try{
- ServiceContext ctx = createServiceContext(null);
+ try {
+ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
getRepositoryClient(ctx).delete(ctx, csid);
return Response.status(HttpResponseCodes.SC_OK).build();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
logger.debug("caught exception in deleteVocabulary", dnfe);
}
Response response = Response.status(Response.Status.NOT_FOUND).entity(
"Delete failed on Vocabulary csid=" + csid).type(
"text/plain").build();
throw new WebApplicationException(response);
- }catch(Exception e){
+ } catch (Exception e) {
Response response = Response.status(
Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
throw new WebApplicationException(response);
/*************************************************************************
* VocabularyItem parts - this is a sub-resource of Vocabulary
*************************************************************************/
+ @POST
+ @Path("{csid}/items")
+ public Response createVocabularyItem(@PathParam("csid") String parentcsid, MultipartInput input) {
+ try {
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getItemServiceName());
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
+ UriBuilder path = UriBuilder.fromResource(VocabularyResource.class);
+ path.path(parentcsid + "/items/" + itemcsid);
+ Response response = Response.created(path.build()).build();
+ return response;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception in createVocabularyItem", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ }
- @POST
- @Path("{csid}/items")
- public Response createVocabularyItem(@PathParam("csid") String parentcsid, MultipartInput input) {
- try{
- RemoteServiceContext ctx = createServiceContext(input, getItemServiceName());
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
- UriBuilder path = UriBuilder.fromResource(VocabularyResource.class);
- path.path(parentcsid + "/items/" + itemcsid);
- Response response = Response.created(path.build()).build();
- return response;
- }catch(Exception e){
- if(logger.isDebugEnabled()){
- logger.debug("Caught exception in createVocabularyItem", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- }
-
- @GET
- @Path("{csid}/items/{itemcsid}")
- public MultipartOutput getVocabularyItem(
- @PathParam("csid") String parentcsid,
- @PathParam("itemcsid") String itemcsid) {
- if(logger.isDebugEnabled()){
- logger.debug("getVocabularyItem with parentcsid="
- + parentcsid + " and itemcsid=" + itemcsid);
- }
- if(parentcsid == null || "".equals(parentcsid)){
- logger.error("getVocabularyItem: missing csid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "get failed on VocabularyItem csid=" + parentcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- if(itemcsid == null || "".equals(itemcsid)){
- logger.error("getVocabularyItem: missing itemcsid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "get failed on VocabularyItem itemcsid=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- MultipartOutput result = null;
- try{
- // Note that we have to create the service context for the Items, not the main service
- RemoteServiceContext ctx = createServiceContext(null, getItemServiceName());
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- getRepositoryClient(ctx).get(ctx, itemcsid, handler);
- // TODO should we assert that the item is in the passed vocab?
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
- logger.debug("getVocabularyItem", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Get failed on VocabularyItem csid=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }catch(Exception e){
- if(logger.isDebugEnabled()){
- logger.debug("getVocabularyItem", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- if(result == null){
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Get failed, the requested VocabularyItem CSID:" + itemcsid + ": was not found.").type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- return result;
- }
+ @GET
+ @Path("{csid}/items/{itemcsid}")
+ public MultipartOutput getVocabularyItem(
+ @PathParam("csid") String parentcsid,
+ @PathParam("itemcsid") String itemcsid) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
+ }
+ if (parentcsid == null || "".equals(parentcsid)) {
+ logger.error("getVocabularyItem: missing csid!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "get failed on VocabularyItem csid=" + parentcsid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if (itemcsid == null || "".equals(itemcsid)) {
+ logger.error("getVocabularyItem: missing itemcsid!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "get failed on VocabularyItem itemcsid=" + itemcsid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ MultipartOutput result = null;
+ try {
+ // Note that we have to create the service context for the Items, not the main service
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ getRepositoryClient(ctx).get(ctx, itemcsid, handler);
+ // TODO should we assert that the item is in the passed vocab?
+ result = (MultipartOutput)ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getVocabularyItem", dnfe);
+ }
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed on VocabularyItem csid=" + itemcsid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getVocabularyItem", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if (result == null) {
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Get failed, the requested VocabularyItem CSID:" + itemcsid + ": was not found.").type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return result;
+ }
- @GET
- @Path("{csid}/items")
- @Produces("application/xml")
- public VocabularyitemsCommonList getVocabularyItemList(
- @PathParam("csid") String parentcsid,
- @Context UriInfo ui) {
- VocabularyitemsCommonList vocabularyItemObjectList = new VocabularyitemsCommonList();
- try{
- // Note that docType defaults to the ServiceName, so we're fine with that.
- RemoteServiceContext ctx = createServiceContext(null, getItemServiceName());
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- DocumentFilter myFilter = new DocumentFilter(
- "vocabularyitems_common:inVocabulary='"+parentcsid+"'", 0, 0);
- handler.setDocumentFilter(myFilter);
- getRepositoryClient(ctx).getFiltered(ctx, handler);
- vocabularyItemObjectList = (VocabularyitemsCommonList) handler.getCommonPartList();
- }catch(Exception e){
- if(logger.isDebugEnabled()){
- logger.debug("Caught exception in getVocabularyItemList", e);
- }
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- return vocabularyItemObjectList;
- }
+ @GET
+ @Path("{csid}/items")
+ @Produces("application/xml")
+ public VocabularyitemsCommonList getVocabularyItemList(
+ @PathParam("csid") String parentcsid,
+ @Context UriInfo ui) {
+ VocabularyitemsCommonList vocabularyItemObjectList = new VocabularyitemsCommonList();
+ try {
+ // Note that docType defaults to the ServiceName, so we're fine with that.
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ DocumentFilter myFilter = new DocumentFilter(
+ "vocabularyitems_common:inVocabulary='" + parentcsid + "'", 0, 0);
+ handler.setDocumentFilter(myFilter);
+ getRepositoryClient(ctx).getFiltered(ctx, handler);
+ vocabularyItemObjectList = (VocabularyitemsCommonList) handler.getCommonPartList();
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception in getVocabularyItemList", e);
+ }
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return vocabularyItemObjectList;
+ }
- @PUT
- @Path("{csid}/items/{itemcsid}")
- public MultipartOutput updateVocabularyItem(
- @PathParam("csid") String parentcsid,
- @PathParam("itemcsid") String itemcsid,
- MultipartInput theUpdate) {
- if(logger.isDebugEnabled()){
- logger.debug("updateVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
- }
- if(parentcsid == null || "".equals(parentcsid)){
- logger.error("updateVocabularyItem: missing csid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "update failed on VocabularyItem parentcsid=" + parentcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- if(itemcsid == null || "".equals(itemcsid)){
- logger.error("updateVocabularyItem: missing itemcsid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "update failed on VocabularyItem=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- MultipartOutput result = null;
- try{
- // Note that we have to create the service context for the Items, not the main service
- RemoteServiceContext ctx = createServiceContext(theUpdate, getItemServiceName());
- DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- getRepositoryClient(ctx).update(ctx, itemcsid, handler);
- result = ctx.getOutput();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
- logger.debug("caugth exception in updateVocabularyItem", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Update failed on VocabularyItem csid=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }catch(Exception e){
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
- return result;
- }
+ @PUT
+ @Path("{csid}/items/{itemcsid}")
+ public MultipartOutput updateVocabularyItem(
+ @PathParam("csid") String parentcsid,
+ @PathParam("itemcsid") String itemcsid,
+ MultipartInput theUpdate) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("updateVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
+ }
+ if (parentcsid == null || "".equals(parentcsid)) {
+ logger.error("updateVocabularyItem: missing csid!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "update failed on VocabularyItem parentcsid=" + parentcsid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if (itemcsid == null || "".equals(itemcsid)) {
+ logger.error("updateVocabularyItem: missing itemcsid!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "update failed on VocabularyItem=" + itemcsid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ MultipartOutput result = null;
+ try {
+ // Note that we have to create the service context for the Items, not the main service
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getItemServiceName());
+ DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+ getRepositoryClient(ctx).update(ctx, itemcsid, handler);
+ result = (MultipartOutput)ctx.getOutput();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("caugth exception in updateVocabularyItem", dnfe);
+ }
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Update failed on VocabularyItem csid=" + itemcsid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (Exception e) {
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ return result;
+ }
- @DELETE
- @Path("{csid}/items/{itemcsid}")
- public Response deleteVocabularyItem(
- @PathParam("csid") String parentcsid,
- @PathParam("itemcsid") String itemcsid) {
- if(logger.isDebugEnabled()){
- logger.debug("deleteVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
- }
- if(parentcsid == null || "".equals(parentcsid)){
- logger.error("deleteVocabularyItem: missing csid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "delete failed on VocabularyItem parentcsid=" + parentcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- if(itemcsid == null || "".equals(itemcsid)){
- logger.error("deleteVocabularyItem: missing itemcsid!");
- Response response = Response.status(Response.Status.BAD_REQUEST).entity(
- "delete failed on VocabularyItem=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }
- try{
- // Note that we have to create the service context for the Items, not the main service
- RemoteServiceContext ctx = createServiceContext(null, getItemServiceName());
- getRepositoryClient(ctx).delete(ctx, itemcsid);
- return Response.status(HttpResponseCodes.SC_OK).build();
- }catch(DocumentNotFoundException dnfe){
- if(logger.isDebugEnabled()){
- logger.debug("caught exception in deleteVocabulary", dnfe);
- }
- Response response = Response.status(Response.Status.NOT_FOUND).entity(
- "Delete failed on VocabularyItem itemcsid=" + itemcsid).type(
- "text/plain").build();
- throw new WebApplicationException(response);
- }catch(Exception e){
- Response response = Response.status(
- Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
- throw new WebApplicationException(response);
- }
+ @DELETE
+ @Path("{csid}/items/{itemcsid}")
+ public Response deleteVocabularyItem(
+ @PathParam("csid") String parentcsid,
+ @PathParam("itemcsid") String itemcsid) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("deleteVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
+ }
+ if (parentcsid == null || "".equals(parentcsid)) {
+ logger.error("deleteVocabularyItem: missing csid!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "delete failed on VocabularyItem parentcsid=" + parentcsid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ if (itemcsid == null || "".equals(itemcsid)) {
+ logger.error("deleteVocabularyItem: missing itemcsid!");
+ Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+ "delete failed on VocabularyItem=" + itemcsid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ }
+ try {
+ // Note that we have to create the service context for the Items, not the main service
+ ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+ getRepositoryClient(ctx).delete(ctx, itemcsid);
+ return Response.status(HttpResponseCodes.SC_OK).build();
+ } catch (DocumentNotFoundException dnfe) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("caught exception in deleteVocabulary", dnfe);
+ }
+ Response response = Response.status(Response.Status.NOT_FOUND).entity(
+ "Delete failed on VocabularyItem itemcsid=" + itemcsid).type(
+ "text/plain").build();
+ throw new WebApplicationException(response);
+ } catch (Exception e) {
+ Response response = Response.status(
+ Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
+ throw new WebApplicationException(response);
+ }
- }
+ }
}