Added validation handler. One or more handlers could configured in service binding. If a handler is configured for the service, the service layer callsback on the handler before create and update operations. Example validatorHandlers could be found in Account and CollectionObject services. Sends 400 (bad request) if validation fails.
Deleted DocumentHandlerFactory.java and moved that code to AbstractServiceContext.java. Service context (that is aware of ther service binding) also acts as a factory for various handlers (validator, document) configured in the binding.
tests: account validation (userid, tenant info), collectionobject (othernumber), all service tests
M services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
A services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectValidatorHandler.java
M services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java
M services/dimension/service/src/main/java/org/collectionspace/services/dimension/DimensionResource.java
M services/common/src/main/java/org/collectionspace/services/common/ServiceException.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
M 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
M services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.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/ValidatorHandler.java
D services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandlerFactory.java
A services/common/src/main/java/org/collectionspace/services/common/document/InvalidDocumentException.java
M services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java
M services/common/src/main/config/tenant-bindings.xml
M services/common/src/main/resources/service.xsd
M services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java
M services/contact/service/src/main/java/org/collectionspace/services/contact/ContactResource.java
A services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountValidatorHandler.java
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/storage/AccountJpaFilter.java
M services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java
M services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java
M services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java
_M services/organization/import
M services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.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
resource2Id = extractId(res);
AccountsCommon account3 =
- createAccountInstance("dj", "hithere10", "dj@dinoland.com", true, true, true);
+ createAccountInstance("mj", "hithere10", "mj@dinoland.com", true, true, true);
res = client.create(account3);
statusCode = res.getStatus();
Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
-import org.collectionspace.services.common.document.DocumentHandlerFactory;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.collectionspace.services.common.storage.StorageClient;
import org.jboss.resteasy.util.HttpResponseCodes;
@Override
public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
docHandler.setCommonPart(ctx.getInput());
return docHandler;
}
public void handleCreate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
String id = UUID.randomUUID().toString();
AccountsCommon account = wrapDoc.getWrappedObject();
- if (account.getUserId() == null || "".equals(account.getUserId())) {
- String msg = "userId is missing";
- logger.error(msg);
- throw new BadRequestException(msg);
- }
- List<AccountsCommon.Tenant> tl = account.getTenant();
- if (tl == null || tl.size() == 0) {
- String msg = "missing tenant information!";
- logger.error(msg);
- throw new BadRequestException(msg);
- }
account.setCsid(id);
account.setStatus(Status.ACTIVE);
}
@Override
public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
- if (account.getPassword() != null
- && (account.getUserId() == null || "".equals(account.getUserId()))) {
- String msg = "userId is missing";
- logger.error(msg);
- throw new BadRequestException(msg);
- }
}
@Override
hasWhere = true;
}
- String email = null;
+ String email = null;
List<String> emailvals = getQueryParam(AccountStorageConstants.Q_EMAIL);
if (emailvals != null) {
email = emailvals.get(0);
--- /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.
+ *//**
+ * 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.
+ */
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.collectionspace.services.account.storage;
+
+import java.util.List;
+import org.collectionspace.services.account.AccountsCommon;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentHandler.Action;
+import org.collectionspace.services.common.document.InvalidDocumentException;
+import org.collectionspace.services.common.document.ValidatorHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author
+ */
+public class AccountValidatorHandler implements ValidatorHandler {
+
+ final Logger logger = LoggerFactory.getLogger(AccountValidatorHandler.class);
+
+ @Override
+ public void validate(Action action, ServiceContext ctx)
+ throws InvalidDocumentException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("validate() action=" + action.name());
+ }
+ try {
+ AccountsCommon account = (AccountsCommon) ctx.getInput();
+ String msg = "validate() ";
+ boolean invalid = false;
+
+ List<AccountsCommon.Tenant> tl = account.getTenant();
+ if (tl == null || tl.size() == 0) {
+ msg += " missing tenant information!";
+ invalid = true;
+ }
+ if (action.equals(Action.CREATE)) {
+ //create specific validation here
+ if (account.getUserId() == null || "".equals(account.getUserId())) {
+ invalid = true;
+ msg += " userId is missing";
+ }
+ } else if (action.equals(Action.UPDATE)) {
+ //update specific validation here
+ if (account.getPassword() != null
+ && (account.getUserId() == null || "".equals(account.getUserId()))) {
+ invalid = true;
+ msg += " userId is needed with password";
+ }
+ }
+ if (invalid) {
+ logger.error(msg);
+ throw new InvalidDocumentException(msg);
+ }
+ } catch (InvalidDocumentException ide) {
+ throw ide;
+ } catch (Exception e) {
+ throw new InvalidDocumentException(e);
+ }
+ }
+}
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
-import org.collectionspace.services.common.document.DocumentHandlerFactory;
import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.common.query.QueryManager;
import org.collectionspace.services.common.security.UnauthorizedException;
@Override
public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
if (ctx.getInput() != null) {
Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), AcquisitionsCommon.class);
if (obj != null) {
// Store the ID returned from the first resource created
// for additional tests below.
- if (knownResourceId == null){
+ if (knownResourceId == null) {
knownResourceId = extractId(res);
if (logger.isDebugEnabled()) {
logger.debug(testName + ": knownResourceId=" + knownResourceId);
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
@Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class)
public void createWithEmptyEntityBody(String testName) throws Exception {
}
@Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class)
public void createWithMalformedXml(String testName) throws Exception {
+ setupCreate(testName);
+
+ CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
+ collectionObject.setTitle("atitle");
+ //don't set objectNumber to check validation
+ collectionObject.setObjectName("some name");
+ MultipartOutput multipart =
+ createCollectionObjectInstance(client.getCommonPartName(), collectionObject, null);
+ ClientResponse<Response> res = client.create(multipart);
+ int statusCode = res.getStatus();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + ": status = " + statusCode);
+ }
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
}
@Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class)
public void createWithWrongXmlSchema(String testName) throws Exception {
}
// Perform setup.
setupUpdate(testName);
- ClientResponse<MultipartInput> res =
- client.read(knownResourceId);
- if (logger.isDebugEnabled()) {
- logger.debug(testName + ": read status = " + res.getStatus());
- }
- Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+ ClientResponse<MultipartInput> res = updateRetrieve(testName, knownResourceId);
if (logger.isDebugEnabled()) {
logger.debug("got object to update with ID: " + knownResourceId);
CollectionobjectsCommon.class));
}
- // Submit the request to the service and store the response.
- MultipartOutput output = new MultipartOutput();
- OutputPart commonPart = output.addPart(collectionObject, MediaType.APPLICATION_XML_TYPE);
- commonPart.getHeaders().add("label", client.getCommonPartName());
+ res = updateSend(testName, knownResourceId, collectionObject);
- res = client.update(knownResourceId, output);
int statusCode = res.getStatus();
// Check the status code of the response: does it match the expected response(s)?
if (logger.isDebugEnabled()) {
}
+ private ClientResponse<MultipartInput> updateRetrieve(String testName, String id) {
+ ClientResponse<MultipartInput> res =
+ client.read(id);
+ if (logger.isDebugEnabled()) {
+ logger.debug("read in updateRetrieve for " + testName + " status = " + res.getStatus());
+ }
+ Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("got object to updateRetrieve for " + testName + " with ID: " + id);
+ }
+ return res;
+ }
+
+ private ClientResponse<MultipartInput> updateSend(String testName, String id,
+ CollectionobjectsCommon collectionObject) {
+ MultipartOutput output = new MultipartOutput();
+ OutputPart commonPart = output.addPart(collectionObject, MediaType.APPLICATION_XML_TYPE);
+ commonPart.getHeaders().add("label", client.getCommonPartName());
+
+ ClientResponse<MultipartInput> res = client.update(knownResourceId, output);
+ // Check the status code of the response: does it match the expected response(s)?
+ if (logger.isDebugEnabled()) {
+ logger.debug("updateSend for " + testName + ": status = " + res.getStatus());
+ }
+ return res;
+ }
+
// Failure outcomes
// Placeholders until the three tests below can be uncommented.
// See Issue CSPACE-401.
@Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+ dependsOnMethods = {"read"})
public void updateWithEmptyEntityBody(String testName) throws Exception {
}
@Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+ dependsOnMethods = {"read"})
public void updateWithMalformedXml(String testName) throws Exception {
+ // Perform setup.
+ setupUpdate(testName);
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + " got object to update with ID: " + knownResourceId);
+ }
+
+ ClientResponse<MultipartInput> res = updateRetrieve(testName, knownResourceId);
+
+ MultipartInput input = (MultipartInput) res.getEntity();
+ CollectionobjectsCommon collectionObject =
+ (CollectionobjectsCommon) extractPart(input,
+ client.getCommonPartName(), CollectionobjectsCommon.class);
+ Assert.assertNotNull(collectionObject);
+
+ //update with invalid content
+ collectionObject.setObjectNumber("");
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(testName + " updated object");
+ logger.debug(objectAsXmlString(collectionObject,
+ CollectionobjectsCommon.class));
+ }
+
+ // Submit the request to the service and store the response.
+ res = updateSend(testName, knownResourceId, collectionObject);
+ int statusCode = res.getStatus();
+ Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+ Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
+
}
@Override
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
+ dependsOnMethods = {"read"})
public void updateWithWrongXmlSchema(String testName) throws Exception {
}
collectionObject.setBriefDescription("Papier mache bird cow mask with horns, "
+ "painted red with black and yellow spots. "
+ "Puerto Rico. ca. 8" high, 6" wide, projects 10" (with horns).");
+
+ CollectionobjectsNaturalhistory conh = new CollectionobjectsNaturalhistory();
+ conh.setNhString("test-string");
+ conh.setNhInt(999);
+ conh.setNhLong(9999);
+
+
+ MultipartOutput multipart = createCollectionObjectInstance(commonPartName, collectionObject, conh);
+ return multipart;
+ }
+
+ private MultipartOutput createCollectionObjectInstance(String commonPartName,
+ CollectionobjectsCommon collectionObject, CollectionobjectsNaturalhistory conh) {
+
MultipartOutput multipart = new MultipartOutput();
OutputPart commonPart = multipart.addPart(collectionObject,
MediaType.APPLICATION_XML_TYPE);
CollectionobjectsCommon.class));
}
- CollectionobjectsNaturalhistory conh = new CollectionobjectsNaturalhistory();
- conh.setNhString("test-string");
- conh.setNhInt(999);
- conh.setNhLong(9999);
- OutputPart nhPart = multipart.addPart(conh, MediaType.APPLICATION_XML_TYPE);
- nhPart.getHeaders().add("label", getNHPartName());
+ if (conh != null) {
+ OutputPart nhPart = multipart.addPart(conh, MediaType.APPLICATION_XML_TYPE);
+ nhPart.getHeaders().add("label", getNHPartName());
- if (logger.isDebugEnabled()) {
- logger.debug("to be created, collectionobject nhistory");
- logger.debug(objectAsXmlString(conh,
- CollectionobjectsNaturalhistory.class));
+ if (logger.isDebugEnabled()) {
+ logger.debug("to be created, collectionobject nhistory");
+ logger.debug(objectAsXmlString(conh,
+ CollectionobjectsNaturalhistory.class));
+ }
}
return multipart;
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.BadRequestException;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
import org.collectionspace.services.common.document.DocumentFilter;
-import org.collectionspace.services.common.document.DocumentHandlerFactory;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@Override
protected String getVersionString() {
- /** The last change revision. */
- final String lastChangeRevision = "$LastChangedRevision$";
- return lastChangeRevision;
+ /** The last change revision. */
+ final String lastChangeRevision = "$LastChangedRevision$";
+ return lastChangeRevision;
}
-
+
@Override
public String getServiceName() {
return serviceName;
@Override
public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
if (ctx.getInput() != null) {
- Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), CollectionobjectsCommon.class);
+ Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(),
+ CollectionobjectsCommon.class);
if (obj != null) {
docHandler.setCommonPart((CollectionobjectsCommon) obj);
}
path.path("" + csid);
Response response = Response.created(path.build()).build();
return response;
+ } catch (BadRequestException bre) {
+ Response response = Response.status(
+ Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build();
+ throw new WebApplicationException(response);
} catch (UnauthorizedException ue) {
Response response = Response.status(
Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build();
DocumentHandler handler = createDocumentHandler(ctx);
getRepositoryClient(ctx).update(ctx, csid, handler);
result = (MultipartOutput) ctx.getOutput();
+ } catch (BadRequestException bre) {
+ Response response = Response.status(
+ Response.Status.BAD_REQUEST).entity("Update failed reason " + bre.getErrorReason()).type("text/plain").build();
+ throw new WebApplicationException(response);
} catch (UnauthorizedException ue) {
Response response = Response.status(
Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build();
}
}
-
+
@GET
- @Path("/search")
+ @Path("/search")
@Produces("application/xml")
public CollectionobjectsCommonList keywordsSearchCollectionObjects(@Context UriInfo ui,
- @QueryParam (IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
+ @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
CollectionobjectsCommonList collectionObjectList = new CollectionobjectsCommonList();
try {
ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
// perform a keyword search
if (keywords != null && !keywords.isEmpty()) {
- String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
- DocumentFilter documentFilter = handler.getDocumentFilter();
- documentFilter.setWhereClause(whereClause);
- if (logger.isDebugEnabled()) {
- logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
- }
- getRepositoryClient(ctx).getFiltered(ctx, handler);
+ String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
+ DocumentFilter documentFilter = handler.getDocumentFilter();
+ documentFilter.setWhereClause(whereClause);
+ if (logger.isDebugEnabled()) {
+ logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
+ }
+ getRepositoryClient(ctx).getFiltered(ctx, handler);
} else {
- getRepositoryClient(ctx).getAll(ctx, handler);
- }
+ getRepositoryClient(ctx).getAll(ctx, handler);
+ }
collectionObjectList = (CollectionobjectsCommonList) handler.getCommonPartList();
-
+
} catch (UnauthorizedException ue) {
Response response = Response.status(
Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build();
throw new WebApplicationException(response);
}
return collectionObjectList;
- }
+ }
}
--- /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.
+ *//**
+ * 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.
+ */
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.collectionspace.services.collectionobject.nuxeo;
+
+import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentHandler.Action;
+import org.collectionspace.services.common.document.InvalidDocumentException;
+import org.collectionspace.services.common.document.ValidatorHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author
+ */
+public class CollectionObjectValidatorHandler implements ValidatorHandler {
+
+ final Logger logger = LoggerFactory.getLogger(CollectionObjectValidatorHandler.class);
+
+ @Override
+ public void validate(Action action, ServiceContext ctx)
+ throws InvalidDocumentException {
+ if(logger.isDebugEnabled()) {
+ logger.debug("validate() action=" + action.name());
+ }
+ try {
+ MultipartServiceContext mctx = (MultipartServiceContext) ctx;
+ CollectionobjectsCommon co = (CollectionobjectsCommon) mctx.getInputPart(mctx.getCommonPartLabel(),
+ CollectionobjectsCommon.class);
+ String msg = "";
+ boolean invalid = false;
+ if (co.getObjectNumber() == null || co.getObjectNumber().isEmpty()) {
+ invalid = true;
+ msg += "objectNumber is missing!";
+ }
+ if(action.equals(Action.CREATE)) {
+ //create specific validation here
+ } else if(action.equals(Action.UPDATE)) {
+ //update specific validation here
+ }
+
+ if (invalid) {
+ logger.error(msg);
+ throw new InvalidDocumentException(msg);
+ }
+ } catch (InvalidDocumentException ide) {
+ throw ide;
+ } catch (Exception e) {
+ throw new InvalidDocumentException(e);
+ }
+ }
+}
<service:documentHandler xmlns:service='http://collectionspace.org/services/common/service'>
org.collectionspace.services.collectionobject.nuxeo.CollectionObjectDocumentModelHandler
</service:documentHandler>
+ <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
+ org.collectionspace.services.collectionobject.nuxeo.CollectionObjectValidatorHandler
+ </service:validatorHandler>
<service:object name="CollectionObject" version="0.1"
xmlns:service='http://collectionspace.org/services/common/service'>
<service:part id="0" control_group="Managed"
<service:documentHandler xmlns:service='http://collectionspace.org/services/common/service'>
org.collectionspace.services.account.storage.AccountDocumentHandler
</service:documentHandler>
+ <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
+ org.collectionspace.services.account.storage.AccountValidatorHandler
+ </service:validatorHandler>
<service:object name="Acccount" version="0.1"
xmlns:service='http://collectionspace.org/services/common/service'>
<service:part id="0" control_group="Managed"
public class ServiceException extends Exception {
private int errorCode;
- private String errorReason;
/**
* Creates a new instance of <code>ServiceException</code> without detail message, error code
* @param errorReason reason for error
*/
public ServiceException(int errorCode, String errorReason) {
+ super(errorReason);
this.errorCode = errorCode;
- this.errorReason = errorReason;
}
/**
* @return the errorReason
*/
public String getErrorReason() {
- return errorReason;
- }
-
- /**
- * @param errorReason the ErrorReason to set
- */
- public void setErrorReason(String errorReason) {
- this.errorReason = errorReason;
+ return getMessage();
}
}
package org.collectionspace.services.common.context;
import java.security.acl.Group;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import org.collectionspace.services.common.ClientType;
import org.collectionspace.services.common.ServiceMain;
import org.collectionspace.services.common.config.TenantBindingConfigReader;
+import org.collectionspace.services.common.document.DocumentHandler;
+import org.collectionspace.services.common.document.ValidatorHandler;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.collectionspace.services.common.service.ObjectPartType;
import org.collectionspace.services.common.service.ServiceBindingType;
private ServiceBindingType serviceBinding;
private TenantBindingType tenantBinding;
private String overrideDocumentType = null;
+ private List<ValidatorHandler> valHandlers = null;
+ private DocumentHandler docHandler = null;
public AbstractServiceContext(String serviceName) throws UnauthorizedException {
TenantBindingConfigReader tReader =
@Override
public String getRepositoryClientName() {
- if(serviceBinding.getRepositoryClient() == null) {
+ if (serviceBinding.getRepositoryClient() == null) {
return null;
}
return serviceBinding.getRepositoryClient().trim();
return serviceBinding;
}
- @Override
- public String getDocumentHandlerClass() {
- if (serviceBinding.getDocumentHandler() == null
- || serviceBinding.getDocumentHandler().isEmpty()) {
- String msg = "Missing documentHandler in service binding for "
- + getServiceName() + " for tenant id=" + getTenantId()
- + " name=" + getTenantName();
- logger.error(msg);
- throw new IllegalStateException(msg);
- }
- return serviceBinding.getDocumentHandler().trim();
- }
-
@Override
public String getServiceName() {
return serviceBinding.getName();
return tenantId;
}
+ @Override
+ public DocumentHandler getDocumentHandler() throws Exception {
+ if (docHandler != null) {
+ return docHandler;
+ }
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ Class c = tccl.loadClass(getDocumentHandlerClass());
+ if (DocumentHandler.class.isAssignableFrom(c)) {
+ docHandler = (DocumentHandler) c.newInstance();
+ } else {
+ throw new IllegalArgumentException("Not of type " +
+ DocumentHandler.class.getCanonicalName());
+ }
+ docHandler.setServiceContext(this);
+ return docHandler;
+ }
+
+ private String getDocumentHandlerClass() {
+ if (serviceBinding.getDocumentHandler() == null
+ || serviceBinding.getDocumentHandler().isEmpty()) {
+ String msg = "Missing documentHandler in service binding for "
+ + getServiceName() + " for tenant id=" + getTenantId()
+ + " name=" + getTenantName();
+ logger.error(msg);
+ throw new IllegalStateException(msg);
+ }
+ return serviceBinding.getDocumentHandler().trim();
+ }
+
+ @Override
+ public List<ValidatorHandler> getValidatorHandlers() throws Exception {
+ if (valHandlers != null) {
+ return valHandlers;
+ }
+ List<String> handlerClazzes = getServiceBinding().getValidatorHandler();
+ List<ValidatorHandler> handlers = new ArrayList<ValidatorHandler>(handlerClazzes.size());
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ for (String clazz : handlerClazzes) {
+ clazz = clazz.trim();
+ Class c = tccl.loadClass(clazz);
+ if (ValidatorHandler.class.isAssignableFrom(c)) {
+ handlers.add((ValidatorHandler) c.newInstance());
+ }
+ }
+ valHandlers = handlers;
+ return valHandlers;
+ }
+
@Override
public String toString() {
StringBuilder msg = new StringBuilder();
package org.collectionspace.services.common.context;
import java.io.IOException;
+import java.io.InputStream;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.w3c.dom.Document;
public void setOutput(MultipartOutput output);
/**
- * getInputPart returns part for given label from input
+ * getInputPart returns the input part object for given label and clazz
* @param label
* @param clazz class of the object
* @return part
*/
public Object getInputPart(String label, Class clazz) throws IOException;
+ /**
+ * getInputPartAsString returns the input part with given label in the string form
+ * @param label
+ * @return
+ * @throws IOException
+ */
+ public String getInputPartAsString(String label) throws IOException;
+
+ /**
+ * getInputPartAsStream returns input part as stream for given label
+ * @param label
+ * @return
+ * @throws IOException
+ */
+ public InputStream getInputPartAsStream(String label) throws IOException;
/**
* addOutputPart adds given XML part with given label and content type to output
* @param label
*/
package org.collectionspace.services.common.context;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.Constructor;
import javax.ws.rs.core.MediaType;
import org.collectionspace.services.common.document.DocumentUtils;
}
- @Override
- public Object getInputPart(String label, Class clazz) throws IOException {
- Object obj = null;
- if(getInput() != null){
+ private InputPart getInputPart(String label) throws IOException {
+ if (getInput() != null) {
MultipartInput fdip = getInput();
- for(InputPart part : fdip.getParts()){
+ 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());
+ if (label.equalsIgnoreCase(partLabel)) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("getInputPart found part with label=" + partLabel
+ + "\npayload=" + part.getBodyAsString());
}
- obj = part.getBody(clazz, null);
- break;
+ return part;
}
}
}
+ return null;
+ }
+
+ @Override
+ public Object getInputPart(String label, Class clazz) throws IOException {
+ Object obj = null;
+ InputPart part = getInputPart(label);
+ if (part != null) {
+ obj = part.getBody(clazz, null);
+ }
return obj;
}
+ @Override
+ public String getInputPartAsString(String label) throws IOException {
+ InputPart part = getInputPart(label);
+ if (part != null) {
+ return part.getBodyAsString();
+ }
+ return null;
+ }
+
+ @Override
+ public InputStream getInputPartAsStream(String label) throws IOException {
+ InputPart part = getInputPart(label);
+ if (part != null) {
+ return new ByteArrayInputStream(part.getBodyAsString().getBytes());
+ }
+ return null;
+ }
+
+
+
@Override
public void addOutputPart(String label, Document doc, String contentType) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try{
+ 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{
+ } finally {
+ if (baos != null) {
+ try {
baos.close();
- }catch(Exception e){
+ } catch (Exception e) {
}
}
}
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());
+ 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());
+ ServiceContext ctx = (ServiceContext) ctor.newInstance(getServiceName());
return ctx;
}
}
}
@Override
- public void setInput(IT input){
+ public void setInput(IT input) {
+ //for security reasons, do not allow to set input again (from handlers)
+ if (this.input != null) {
+ String msg = "Non-null input cannot be set!";
+ logger.error(msg);
+ throw new IllegalStateException(msg);
+ }
this.input = input;
}
}
@Override
- public void setOutput(OT output){
+ public void setOutput(OT output) {
this.output = output;
}
-
@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());
+ 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());
+ ServiceContext ctx = (ServiceContext) ctor.newInstance(getServiceName());
return ctx;
}
}
*/
package org.collectionspace.services.common.context;
-import java.util.HashMap;
+import java.util.List;
import java.util.Map;
-import java.util.Properties;
import org.collectionspace.services.common.ClientType;
+import org.collectionspace.services.common.document.DocumentHandler;
+import org.collectionspace.services.common.document.ValidatorHandler;
import org.collectionspace.services.common.service.ObjectPartType;
import org.collectionspace.services.common.service.ServiceBindingType;
*/
public String getRepositoryWorkspaceId();
- /**
- * getDocumentHandlerClass returns the class name for document handler
- * @return class name of document handler
- */
- public String getDocumentHandlerClass();
/**
* Get input parts as received over the wire from service consumer
*/
public void setProperty(String name, Object o);
+
+ /**
+ * getDocumentHanlder returns document handler configured in the the binding
+ * it creates the handler if necessary.
+ * @return document handler
+ */
+ public DocumentHandler getDocumentHandler() throws Exception;
+
+ /**
+ * getValidatorHandlers returns registered (from binding) validtor handlers
+ * for the service. it creates the handlers if necessary.
+ * @return validation handlers
+ */
+ public List<ValidatorHandler> getValidatorHandlers() throws Exception;
+
}
package org.collectionspace.services.common.document;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
final public void prepare(Action action) throws Exception {
switch (action) {
case CREATE:
+ validate(action);
prepareCreate();
break;
case UPDATE:
+ validate(action);
prepareUpdate();
break;
public String getServiceContextPath() {
return "/" + getServiceContext().getServiceName().toLowerCase() + "/";
}
+
+ private void validate(Action action) throws Exception {
+ List<ValidatorHandler> valHandlers = serviceContext.getValidatorHandlers();
+ for (ValidatorHandler handler : valHandlers) {
+ handler.validate(action, serviceContext);
+ }
+ }
}
+++ /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;
-
-/**
- *
- * DocumentHandlerFactory creates document handler
- *
- */
-public class DocumentHandlerFactory {
-
- private static final DocumentHandlerFactory self = new DocumentHandlerFactory();
-
- private DocumentHandlerFactory() {
- }
-
- public static DocumentHandlerFactory getInstance() {
- return self;
- }
-
- /**
- * getHandler returns a document handler. The factory may create a new
- * stateful handler or return an existing stateless handler.
- * @param clazz name of the class to instantiate. The class should implement
- * DocumentHandler
- */
- public DocumentHandler getHandler(String clazz)
- throws ClassNotFoundException, InstantiationException, IllegalAccessException {
- ClassLoader tccl = Thread.currentThread().getContextClassLoader();
- Class c = tccl.loadClass(clazz);
- if (DocumentHandler.class.isAssignableFrom(c)) {
- return (DocumentHandler) c.newInstance();
- } else {
- throw new IllegalArgumentException("Not of type " + DocumentHandler.class.getCanonicalName());
- }
- }
-}
--- /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.
+ */
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.collectionspace.services.common.document;
+
+/**
+ * InvalidDocumentException is used to indicate one or more parts of service
+ * document has failed to validate
+ * @author
+ */
+public class InvalidDocumentException extends BadRequestException {
+
+ /**
+ * Creates a new instance of <code>InvalidDocumentException</code> without detail message.
+ */
+ public InvalidDocumentException() {
+ }
+
+ /**
+ * Constructs an instance of <code>InvalidDocumentException</code> with the specified detail message.
+ * @param msg the detail message.
+ */
+ public InvalidDocumentException(String msg) {
+ super(msg);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and
+ * cause. <p>Note that the detail message associated with
+ * <code>cause</code> is <i>not</i> automatically incorporated in
+ * this exception's detail message.
+ *
+ * @param message the detail message (which is saved for later retrieval
+ * by the {@link #getMessage()} method).
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public InvalidDocumentException(String message, Throwable cause) {
+ super(message, cause);
+ setErrorCode(HTTP_CODE);
+ }
+
+ /**
+ * Constructs a new exception with the specified cause and a detail
+ * message of <tt>(cause==null ? null : cause.toString())</tt> (which
+ * typically contains the class and detail message of <tt>cause</tt>).
+ * This constructor is useful for exceptions that are little more than
+ * wrappers for other throwables (for example, {@link
+ * java.security.PrivilegedActionException}).
+ *
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public InvalidDocumentException(Throwable cause) {
+ super(cause);
+ setErrorCode(HTTP_CODE);
+ }
+}
--- /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 org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.DocumentHandler.Action;
+
+/**
+ * ValidatorHandler provides plugin for application level validation
+ * for content received by services serving objects with extensible schema
+ */
+public interface ValidatorHandler {
+
+ /**
+ * validate is called by the document handler for CREATE and UPDATE actions.
+ * validation is performed as soon as requests are unmarshalled but before any
+ * storage work is performed.
+ * the handler is caleld only if it is registered using the service binding
+ * @param action
+ * @param ctx
+ * @throws InvalidDocumentException
+ */
+ public void validate(Action action, ServiceContext ctx)
+ throws InvalidDocumentException;
+}
String nuxeoWspaceId = ctx.getRepositoryWorkspaceId();
if (nuxeoWspaceId == null) {
throw new DocumentNotFoundException(
- "Unable to find workspace for service " + ctx.getServiceName() +
- " check if the workspace exists in the Nuxeo repository");
+ "Unable to find workspace for service " + ctx.getServiceName()
+ + " check if the workspace exists in the Nuxeo repository");
}
RepositoryInstance repoSession = null;
try {
repoSession.save();
handler.complete(Action.CREATE, wrapDoc);
return id;
+ } catch (BadRequestException bre) {
+ throw bre;
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Caught exception ", e);
String nuxeoWspaceId = ctx.getRepositoryWorkspaceId();
if (nuxeoWspaceId == null) {
throw new DocumentNotFoundException(
- "Unable to find workspace for service " +
- ctx.getServiceName() +
- " check if the workspace exists in the Nuxeo repository");
+ "Unable to find workspace for service "
+ + ctx.getServiceName()
+ + " check if the workspace exists in the Nuxeo repository");
}
RepositoryInstance repoSession = null;
query.append(" WHERE ecm:path STARTSWITH '/" + domain + "'");
if ((null != where) && (where.length() > 0)) {
// query.append(" AND " + where);
- query.append(" AND " + where + "AND ecm:isProxy = 0");
+ query.append(" AND " + where + "AND ecm:isProxy = 0");
}
DocumentModelList docList = null;
if ((docFilter.getOffset() > 0) || (docFilter.getPageSize() > 0)) {
repoSession.saveDocument(doc);
repoSession.save();
handler.complete(Action.UPDATE, wrapDoc);
+ } catch (BadRequestException bre) {
+ throw bre;
} catch (DocumentException de) {
throw de;
} catch (Exception e) {
try {
repoSession = getRepositorySession();
DocumentRef docRef = new PathRef(
- "/" + tenantDomain +
- "/" + "workspaces");
+ "/" + tenantDomain
+ + "/" + "workspaces");
DocumentModel parent = repoSession.getDocument(docRef);
DocumentModel doc = repoSession.createDocumentModel(parent.getPathAsString(),
workspaceName, "Workspace");
doc.setPropertyValue("dc:title", workspaceName);
- doc.setPropertyValue("dc:description", "A CollectionSpace workspace for " +
- workspaceName);
+ doc.setPropertyValue("dc:description", "A CollectionSpace workspace for "
+ + workspaceName);
doc = repoSession.createDocument(doc);
workspaceId = doc.getId();
repoSession.save();
if (logger.isDebugEnabled()) {
- logger.debug("created workspace name=" + workspaceName +
- " id=" + workspaceId);
+ logger.debug("created workspace name=" + workspaceName
+ + " id=" + workspaceId);
}
} catch (Exception e) {
if (logger.isDebugEnabled()) {
try {
repoSession = getRepositorySession();
DocumentRef docRef = new PathRef(
- "/" + tenantDomain +
- "/" + "workspaces" +
- "/" + workspaceName);
+ "/" + tenantDomain
+ + "/" + "workspaces"
+ + "/" + workspaceName);
DocumentModel workspace = repoSession.getDocument(docRef);
workspaceId = workspace.getId();
} catch (DocumentException de) {
client.releaseRepository(repoSession);
} catch (Exception e) {
logger.error("Could not close the repository session", e);
- // no need to throw this service specific exception
+ // no need to throw this service specific exception
}
}
}
<!-- validator handler(s) to be used to validate the content (need to be in classpath) -->
<!-- validator handler is called for create (POST) and update (PUT) requests only -->
<xs:element name="validatorHandler" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
- <!-- event handler is called during prepare and complete document handler events -->
- <!-- event handler is called for create, get, update, delete, index and search requests -->
- <xs:element name="eventHandler" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<!-- name of the repository client (from service-config.xml) -->
<xs:element name="repositoryClient" type="xs:string" minOccurs="0" maxOccurs="1"/>
<!-- repositoryWorkspaceId could be workspace id -->
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
-import org.collectionspace.services.common.document.DocumentHandlerFactory;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@Override
public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
if (ctx.getInput() != null) {
Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), ContactsCommon.class);
if (obj != null) {
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
-import org.collectionspace.services.common.document.DocumentHandlerFactory;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
import org.jboss.resteasy.util.HttpResponseCodes;
@Override
public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
if (ctx.getInput() != null) {
Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), DimensionsCommon.class);
if (obj != null) {
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
-import org.collectionspace.services.common.document.DocumentHandlerFactory;
import org.collectionspace.services.common.query.IQueryManager;
import org.collectionspace.services.common.query.QueryManager;
import org.collectionspace.services.common.security.UnauthorizedException;
@Override
public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
if (ctx.getInput() != null) {
Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), IntakesCommon.class);
if (obj != null) {
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentHandler;
-import org.collectionspace.services.common.document.DocumentHandlerFactory;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.collectionspace.services.common.query.IQueryManager;
*/
@Override
public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler =ctx.getDocumentHandler();
if (ctx.getInput() != null) {
Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), OrgauthoritiesCommon.class);
if (obj != null) {
private DocumentHandler createItemDocumentHandler(
ServiceContext ctx,
String inAuthority) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
((OrganizationDocumentModelHandler) docHandler).setInAuthority(inAuthority);
if (ctx.getInput() != null) {
Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentHandler;
-import org.collectionspace.services.common.document.DocumentHandlerFactory;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.collectionspace.services.common.query.IQueryManager;
*/
@Override
public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
if (ctx.getInput() != null) {
Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), PersonauthoritiesCommon.class);
if (obj != null) {
private DocumentHandler createItemDocumentHandler(
ServiceContext ctx,
String inAuthority) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
((PersonDocumentModelHandler) docHandler).setInAuthority(inAuthority);
if (ctx.getInput() != null) {
Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
import org.collectionspace.services.common.relation.IRelationsManager;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.document.DocumentHandler;
-import org.collectionspace.services.common.document.DocumentHandlerFactory;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
@Override
public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
if (ctx.getInput() != null) {
Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), RelationsCommon.class);
if (obj != null) {
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.document.DocumentFilter;
import org.collectionspace.services.common.document.DocumentHandler;
-import org.collectionspace.services.common.document.DocumentHandlerFactory;
import org.collectionspace.services.common.document.DocumentNotFoundException;
import org.collectionspace.services.common.security.UnauthorizedException;
import org.collectionspace.services.common.query.IQueryManager;
*/
@Override
public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
if (ctx.getInput() != null) {
Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), VocabulariesCommon.class);
if (obj != null) {
private DocumentHandler createItemDocumentHandler(
ServiceContext ctx,
String inVocabulary) throws Exception {
- DocumentHandler docHandler = DocumentHandlerFactory.getInstance().getHandler(
- ctx.getDocumentHandlerClass());
- docHandler.setServiceContext(ctx);
+ DocumentHandler docHandler = ctx.getDocumentHandler();
((VocabularyItemDocumentModelHandler) docHandler).setInVocabulary(inVocabulary);
if (ctx.getInput() != null) {
Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),