From 1cedf53ec65aa9e851c449633b764e4cf9e0356d Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Fri, 23 Apr 2010 21:35:38 +0000 Subject: [PATCH] CSPACE-1596 CSPACE-1595 beefed up error reporting. common messages declared in common/ServiceMessages.java (should eventually go into a message bundle for i18n). invalid password now returns 400 instead of 500 test: account, permission, role, accrole, permrole M services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java M services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleValidatorHandler.java M services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionValidatorHandler.java M services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleValidatorHandler.java M services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java A services/common/src/main/java/org/collectionspace/services/common/ServiceMessages.java M services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountStorageClient.java M services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountValidatorHandler.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 --- .../client/test/AccountServiceTest.java | 76 +++++++++++++-- .../services/account/AccountResource.java | 92 ++++++++++++------- .../account/storage/AccountStorageClient.java | 14 ++- .../storage/AccountValidatorHandler.java | 3 +- .../authorization/PermissionResource.java | 83 +++++++++++------ .../services/authorization/RoleResource.java | 92 +++++++++++-------- .../PermissionRoleValidatorHandler.java | 3 +- .../storage/PermissionValidatorHandler.java | 3 +- .../storage/RoleValidatorHandler.java | 3 +- .../services/common/ServiceMessages.java | 48 ++++++++++ 10 files changed, 299 insertions(+), 118 deletions(-) create mode 100644 services/common/src/main/java/org/collectionspace/services/common/ServiceMessages.java diff --git a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java index a2dc23018..92826b3d3 100644 --- a/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java +++ b/services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountServiceTest.java @@ -241,6 +241,28 @@ public class AccountServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode()); } + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"create"}) + public void createWithInvalidPassword(String testName) throws Exception { + + setupCreate(testName); + + // Submit the request to the service and store the response. + AccountsCommon account = + createAccountInstance("babybop", "babybop", "shpswd", "babybop@dinoland.com", + true, false, true, true); + AccountClient client = new AccountClient(); + ClientResponse res = client.create(account); + int statusCode = res.getStatus(); + // Does it exactly match the expected status code? + 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()); + } + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"}) public void createWithMostInvalid(String testName) throws Exception { @@ -418,7 +440,7 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. AccountClient client = new AccountClient(); ClientResponse res = - client.readSearchList("tom", null, null); + client.readSearchList("tom", null, null); AccountsCommonList list = res.getEntity(); int statusCode = res.getStatus(); @@ -448,7 +470,7 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. AccountClient client = new AccountClient(); ClientResponse res = - client.readSearchList(null, "tom", null); + client.readSearchList(null, "tom", null); AccountsCommonList list = res.getEntity(); int statusCode = res.getStatus(); @@ -478,7 +500,7 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. AccountClient client = new AccountClient(); ClientResponse res = - client.readSearchList(null, null, "dinoland"); + client.readSearchList(null, null, "dinoland"); AccountsCommonList list = res.getEntity(); int statusCode = res.getStatus(); @@ -508,7 +530,7 @@ public class AccountServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. AccountClient client = new AccountClient(); ClientResponse res = - client.readSearchList("tom", null, "jerry"); + client.readSearchList("tom", null, "jerry"); AccountsCommonList list = res.getEntity(); int statusCode = res.getStatus(); @@ -676,6 +698,48 @@ public class AccountServiceTest extends AbstractServiceTestImpl { } + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + dependsOnMethods = {"update"}) + public void updateInvalidPassword(String testName) throws Exception { + + // Perform setup. + setupUpdate(testName); + + AccountClient client = new AccountClient(); + ClientResponse res = client.read(knownResourceId); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if (logger.isDebugEnabled()) { + logger.debug(testName + ": got object to update password with ID: " + knownResourceId); + } + AccountsCommon toUpdateAccount = + (AccountsCommon) res.getEntity(); + Assert.assertNotNull(toUpdateAccount); + + //change password + toUpdateAccount.setPassword("abc123".getBytes()); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": updated object"); + logger.debug(objectAsXmlString(toUpdateAccount, + AccountsCommon.class)); + } + + // Submit the request to the service and store the response. + res = client.update(knownResourceId, toUpdateAccount); + int statusCode = res.getStatus(); + // Check the status code of the response: does it match the expected response(s)? + 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()); + + } + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"updatePasswordWithoutUser"}) public void deactivate(String testName) throws Exception { @@ -758,7 +822,7 @@ public class AccountServiceTest extends AbstractServiceTestImpl { createAccountInstance("simba", "simba", "tiger", "simba@lionking.com", true, false, true, true); ClientResponse res = - client.update(NON_EXISTENT_ID, account); + client.update(NON_EXISTENT_ID, account); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -909,7 +973,7 @@ public class AccountServiceTest extends AbstractServiceTestImpl { * @param usePassword * @return */ - AccountsCommon createAccountInstance(String screenName, + AccountsCommon createAccountInstance(String screenName, String userName, String passwd, String email, boolean useScreenName, boolean invalidTenant, boolean useUser, boolean usePassword) { diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java b/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java index 4794e42a6..1b8ae04b3 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java @@ -42,6 +42,7 @@ import org.collectionspace.services.account.storage.AccountStorageClient; import org.collectionspace.services.authorization.AccountRole; import org.collectionspace.services.authorization.SubjectType; import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; +import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.context.ServiceContextFactory; import org.collectionspace.services.common.context.RemoteServiceContextFactory; @@ -56,7 +57,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The Class AccountResource. + * AccountResource provides RESTful interface to the account service */ @Path("/accounts") @Consumes("application/xml") @@ -144,18 +145,22 @@ public class AccountResource return response; } catch (BadRequestException bre) { Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); + Response.Status.BAD_REQUEST).entity(ServiceMessages.POST_FAILED + + 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(); + Response.Status.UNAUTHORIZED).entity(ServiceMessages.POST_FAILED + + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Caught exception in createAccount", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + Response.Status.INTERNAL_SERVER_ERROR).entity( + ServiceMessages.POST_FAILED + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } } @@ -177,7 +182,7 @@ public class AccountResource if (csid == null || "".equals(csid)) { logger.error("getAccount: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Account csid=" + csid).type( + ServiceMessages.GET_FAILED + ServiceMessages.MISSING_INVALID_CSID + csid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -189,28 +194,31 @@ public class AccountResource result = (AccountsCommon) ctx.getOutput(); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED + + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { if (logger.isDebugEnabled()) { logger.debug("getAccount", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Account csid=" + csid).type( + ServiceMessages.GET_FAILED + "csid=" + csid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("getAccount", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.GET_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Account CSID:" + csid + ": was not found.").type( + ServiceMessages.GET_FAILED + "csid=" + csid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -241,15 +249,18 @@ public class AccountResource accountList = (AccountsCommonList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); + Response.Status.UNAUTHORIZED).entity(ServiceMessages.LIST_FAILED + + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Caught exception in getAccountList", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.LIST_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } return accountList; @@ -274,7 +285,7 @@ public class AccountResource if (csid == null || "".equals(csid)) { logger.error("updateAccount: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Account csid=" + csid).type( + ServiceMessages.PUT_FAILED + ServiceMessages.MISSING_INVALID_CSID + csid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -286,23 +297,27 @@ public class AccountResource result = (AccountsCommon) ctx.getOutput(); } catch (BadRequestException bre) { Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Update failed reason " + bre.getErrorReason()).type("text/plain").build(); + Response.Status.BAD_REQUEST).entity(ServiceMessages.PUT_FAILED + + 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(); + Response.Status.UNAUTHORIZED).entity(ServiceMessages.PUT_FAILED + + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { if (logger.isDebugEnabled()) { logger.debug("caugth exception in updateAccount", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on Account csid=" + csid).type( + ServiceMessages.PUT_FAILED + "csid=" + csid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); + Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.PUT_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } return result; @@ -325,7 +340,7 @@ public class AccountResource if (csid == null || "".equals(csid)) { logger.error("deleteAccount: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on Account csid=" + csid).type( + ServiceMessages.DELETE_FAILED + ServiceMessages.MISSING_INVALID_CSID + csid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -340,7 +355,8 @@ public class AccountResource return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); + Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED + + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { @@ -348,12 +364,14 @@ public class AccountResource logger.debug("caught exception in deleteAccount", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on Account csid=" + csid).type( + ServiceMessages.DELETE_FAILED + "csid=" + csid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); + Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.DELETE_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } @@ -369,7 +387,8 @@ public class AccountResource if (accCsid == null || "".equals(accCsid)) { logger.error("createAccountRole: missing accCsid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "create failed on AccountRole accCsid=" + accCsid).type( + ServiceMessages.POST_FAILED + "accountroles account " + + ServiceMessages.MISSING_INVALID_CSID + accCsid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -382,21 +401,23 @@ public class AccountResource return response; } catch (BadRequestException bre) { Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + Response.Status.BAD_REQUEST).entity(ServiceMessages.POST_FAILED + bre.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Create failed reason " + Response.Status.UNAUTHORIZED).entity(ServiceMessages.POST_FAILED + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Caught exception in createAccountRole", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( - "Create failed").type("text/plain").build(); + ServiceMessages.POST_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } } @@ -412,7 +433,8 @@ public class AccountResource if (accCsid == null || "".equals(accCsid)) { logger.error("getAccountRole: missing accCsid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on AccountRole accCsid=" + accCsid).type( + ServiceMessages.GET_FAILED + "accountroles account " + + ServiceMessages.MISSING_INVALID_CSID + accCsid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -423,7 +445,7 @@ public class AccountResource result = subResource.getAccountRole(accCsid, SubjectType.ROLE); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { @@ -431,22 +453,22 @@ public class AccountResource logger.debug("getAccountRole", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on AccountRole accrolecsid=" + accrolecsid).type( + ServiceMessages.GET_FAILED + "account csid=" + accrolecsid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("getAccountRole", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( - "Get failed").type("text/plain").build(); + ServiceMessages.GET_FAILED + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested AccountRole accrolecsid:" + accrolecsid - + ": was not found.").type( + ServiceMessages.GET_FAILED + "account csid=" + accCsid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -464,7 +486,8 @@ public class AccountResource if (accCsid == null || "".equals(accCsid)) { logger.error("deleteAccountRole: missing accCsid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on AccountRole accCsid=" + accCsid).type( + ServiceMessages.DELETE_FAILED + "accountroles account " + + ServiceMessages.MISSING_INVALID_CSID + accCsid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -475,7 +498,7 @@ public class AccountResource return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { @@ -483,13 +506,14 @@ public class AccountResource logger.debug("caught exception in deleteAccountRole", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on AccountRole accrolecsid=" + accrolecsid).type( + ServiceMessages.DELETE_FAILED + "account csid=" + accCsid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( - "Delete failed").type("text/plain").build(); + ServiceMessages.DELETE_FAILED + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountStorageClient.java b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountStorageClient.java index 491c77330..2b1c5942f 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountStorageClient.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountStorageClient.java @@ -260,8 +260,8 @@ public class AccountStorageClient extends JpaStorageClientImpl { private boolean checkAllowedUpdates(AccountsCommon toAccount, AccountsCommon fromAccount) throws BadRequestException { if (!fromAccount.getUserId().equals(toAccount.getUserId())) { - String msg = "User id " + toAccount.getUserId() + " does not match " + - "for given account with csid=" + fromAccount.getCsid(); + String msg = "User id " + toAccount.getUserId() + " does not match " + + "for given account with csid=" + fromAccount.getCsid(); logger.error(msg); logger.debug(msg + " found userid=" + fromAccount.getUserId()); throw new BadRequestException(msg); @@ -269,7 +269,7 @@ public class AccountStorageClient extends JpaStorageClientImpl { return true; } - private User createUser(AccountsCommon account) { + private User createUser(AccountsCommon account) throws Exception { User user = new User(); user.setUsername(account.getUserId()); if (hasPassword(account.getPassword())) { @@ -304,10 +304,14 @@ public class AccountStorageClient extends JpaStorageClientImpl { } } - private String getEncPassword(AccountsCommon account) { + private String getEncPassword(AccountsCommon account) throws BadRequestException { //jaxb unmarshaller already unmarshal xs:base64Binary, no need to b64 decode //byte[] bpass = Base64.decodeBase64(account.getPassword()); - SecurityUtils.validatePassword(new String(account.getPassword())); + try { + SecurityUtils.validatePassword(new String(account.getPassword())); + } catch (Exception e) { + throw new BadRequestException(e.getMessage()); + } String secEncPasswd = SecurityUtils.createPasswordHash( account.getUserId(), new String(account.getPassword())); return secEncPasswd; diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountValidatorHandler.java b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountValidatorHandler.java index c5bb8ef45..ca58bb4df 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountValidatorHandler.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountValidatorHandler.java @@ -55,6 +55,7 @@ import java.util.regex.Pattern; import org.collectionspace.services.account.AccountTenant; import org.collectionspace.services.account.AccountsCommon; import org.collectionspace.services.account.Tenant; +import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentHandler.Action; import org.collectionspace.services.common.document.InvalidDocumentException; @@ -79,7 +80,7 @@ public class AccountValidatorHandler implements ValidatorHandler { } try { AccountsCommon account = (AccountsCommon) ctx.getInput(); - StringBuilder msgBldr = new StringBuilder("validate() "); + StringBuilder msgBldr = new StringBuilder(ServiceMessages.VALIDATION_FAILURE); boolean invalid = false; List tl = account.getTenants(); diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java index ab9d39127..ec71804f3 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java @@ -40,6 +40,7 @@ import javax.ws.rs.core.UriInfo; import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; //import org.collectionspace.services.common.context.RemoteServiceContextImpl; +import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.context.RemoteServiceContextFactory; import org.collectionspace.services.common.context.ServiceContextFactory; @@ -138,21 +139,23 @@ public class PermissionResource return response; } catch (BadRequestException bre) { Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + Response.Status.BAD_REQUEST).entity(ServiceMessages.POST_FAILED + bre.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Create failed reason " + Response.Status.UNAUTHORIZED).entity(ServiceMessages.POST_FAILED + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Caught exception in createPermission", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( - "Create failed").type("text/plain").build(); + ServiceMessages.POST_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } } @@ -174,7 +177,8 @@ public class PermissionResource if (csid == null || "".equals(csid)) { logger.error("getPermission: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Permission csid=" + csid).type( + ServiceMessages.GET_FAILED + "permission " + + ServiceMessages.MISSING_INVALID_CSID + csid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -186,7 +190,7 @@ public class PermissionResource result = (Permission) ctx.getOutput(); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { @@ -194,22 +198,24 @@ public class PermissionResource logger.debug("getPermission", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Permission csid=" + csid).type( + ServiceMessages.GET_FAILED + "permission csid=" + csid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("getPermission", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( - "Get failed").type("text/plain").build(); + ServiceMessages.GET_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Permission CSID:" + csid + ": was not found.").type( + ServiceMessages.GET_FAILED + " permission csid=" + csid + ": was not found.").type( "text/plain").build(); throw new WebApplicationException(response); } @@ -240,7 +246,7 @@ public class PermissionResource permissionList = (PermissionsList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + Response.Status.UNAUTHORIZED).entity(ServiceMessages.LIST_FAILED + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); @@ -248,9 +254,11 @@ public class PermissionResource if (logger.isDebugEnabled()) { logger.debug("Caught exception in getPermissionsList", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( - "Index failed").type("text/plain").build(); + ServiceMessages.LIST_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } return permissionList; @@ -275,7 +283,8 @@ public class PermissionResource if (csid == null || "".equals(csid)) { logger.error("updatePermission: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Permission csid=" + csid).type( + ServiceMessages.PUT_FAILED + "permission " + + ServiceMessages.MISSING_INVALID_CSID + csid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -287,12 +296,12 @@ public class PermissionResource result = (Permission) ctx.getOutput(); } catch (BadRequestException bre) { Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Update failed reason " + Response.Status.BAD_REQUEST).entity(ServiceMessages.PUT_FAILED + bre.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Update failed reason " + Response.Status.UNAUTHORIZED).entity(ServiceMessages.PUT_FAILED + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { @@ -300,13 +309,15 @@ public class PermissionResource logger.debug("caugth exception in updatePermission", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on Permission csid=" + csid).type( + ServiceMessages.PUT_FAILED + "permission csid=" + csid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( - "Update failed").type("text/plain").build(); + ServiceMessages.PUT_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } return result; @@ -329,7 +340,8 @@ public class PermissionResource if (csid == null || "".equals(csid)) { logger.error("deletePermission: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on Permission csid=" + csid).type( + ServiceMessages.DELETE_FAILED + "permission " + + ServiceMessages.MISSING_INVALID_CSID + csid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -343,7 +355,7 @@ public class PermissionResource return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); @@ -352,13 +364,15 @@ public class PermissionResource logger.debug("caught exception in deletePermission", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on Permission csid=" + csid).type( + ServiceMessages.DELETE_FAILED + "permission csid=" + csid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( - "Delete failed").type("text/plain").build(); + ServiceMessages.DELETE_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } @@ -374,7 +388,8 @@ public class PermissionResource if (permCsid == null || "".equals(permCsid)) { logger.error("createPermissionRole: missing permCsid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "create failed on PermissionRole permCsid=" + permCsid).type( + ServiceMessages.POST_FAILED + "permroles permission " + + ServiceMessages.MISSING_INVALID_CSID + permCsid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -399,9 +414,11 @@ public class PermissionResource if (logger.isDebugEnabled()) { logger.debug("Caught exception in createPermissionRole", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( - "Create failed").type("text/plain").build(); + ServiceMessages.POST_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } } @@ -417,7 +434,8 @@ public class PermissionResource if (permCsid == null || "".equals(permCsid)) { logger.error("getPermissionRole: missing permCsid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on PermissionRole permCsid=" + permCsid).type( + ServiceMessages.GET_FAILED + "permroles permission " + + ServiceMessages.MISSING_INVALID_CSID + permCsid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -428,7 +446,7 @@ public class PermissionResource result = subResource.getPermissionRole(permCsid, SubjectType.ROLE); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { @@ -436,21 +454,23 @@ public class PermissionResource logger.debug("getPermissionRole", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on PermissionRole permrolecsid=" + permrolecsid).type( + ServiceMessages.GET_FAILED + "permroles permission csid=" + permCsid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("getPermissionRole", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( - "Get failed").type("text/plain").build(); + ServiceMessages.GET_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested PermissionRole permrolecsid:" + permrolecsid + ServiceMessages.GET_FAILED + "permroles permisison csid=" + permCsid + ": was not found.").type( "text/plain").build(); throw new WebApplicationException(response); @@ -469,7 +489,8 @@ public class PermissionResource if (permCsid == null || "".equals(permCsid)) { logger.error("deletePermissionRole: missing permCsid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on PermissionRole permCsid=" + permCsid).type( + ServiceMessages.DELETE_FAILED + "permroles permission " + + ServiceMessages.MISSING_INVALID_CSID + permCsid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -480,7 +501,7 @@ public class PermissionResource return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { @@ -488,13 +509,15 @@ public class PermissionResource logger.debug("caught exception in deletePermissionRole", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on PermissionRole permrolecsid=" + permrolecsid).type( + ServiceMessages.DELETE_FAILED + "permisison csid=" + permCsid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( - "Delete failed").type("text/plain").build(); + ServiceMessages.DELETE_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java index 73f02d7d7..cae35ac3b 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java @@ -40,6 +40,7 @@ import javax.ws.rs.core.UriInfo; import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; //import org.collectionspace.services.common.context.RemoteServiceContextImpl; +import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.context.ServiceContextFactory; import org.collectionspace.services.common.context.RemoteServiceContextFactory; @@ -54,7 +55,6 @@ import org.jboss.resteasy.util.HttpResponseCodes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * The Class RoleResource. */ @@ -66,10 +66,8 @@ public class RoleResource /** The service name. */ final private String serviceName = "authorization/roles"; - /** The logger. */ final Logger logger = LoggerFactory.getLogger(RoleResource.class); - /** The storage client. */ final StorageClient storageClient = new JpaStorageClientImpl(); @@ -90,23 +88,22 @@ public class RoleResource public String getServiceName() { return serviceName; } - + /* (non-Javadoc) * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass() */ @Override public Class getCommonPartClass() { - return RoleResource.class; + return RoleResource.class; } - + /* (non-Javadoc) * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory() */ @Override public ServiceContextFactory getServiceContextFactory() { - return RemoteServiceContextFactory.get(); + return RemoteServiceContextFactory.get(); } - // private ServiceContext createServiceContext(T obj) throws Exception { // ServiceContext ctx = new RemoteServiceContextImpl(getServiceName()); @@ -117,9 +114,9 @@ public class RoleResource // } /* (non-Javadoc) - * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getStorageClient(org.collectionspace.services.common.context.ServiceContext) - */ -@Override + * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getStorageClient(org.collectionspace.services.common.context.ServiceContext) + */ + @Override public StorageClient getStorageClient(ServiceContext ctx) { //FIXME use ctx to identify storage client return storageClient; @@ -131,15 +128,14 @@ public class RoleResource // docHandler.setCommonPart(ctx.getInput()); // return docHandler; // } - /** - * Creates the role. - * - * @param input the input - * - * @return the response - */ -@POST + * Creates the role. + * + * @param input the input + * + * @return the response + */ + @POST public Response createRole(Role input) { try { ServiceContext ctx = createServiceContext(input, Role.class); @@ -151,18 +147,22 @@ public class RoleResource return response; } catch (BadRequestException bre) { Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); + Response.Status.BAD_REQUEST).entity(ServiceMessages.POST_FAILED + + 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(); + Response.Status.UNAUTHORIZED).entity(ServiceMessages.POST_FAILED + + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Caught exception in createRole", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.POST_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } } @@ -184,7 +184,7 @@ public class RoleResource if (csid == null || "".equals(csid)) { logger.error("getRole: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on Role csid=" + csid).type( + ServiceMessages.GET_FAILED + "role csid=").type( "text/plain").build(); throw new WebApplicationException(response); } @@ -196,28 +196,31 @@ public class RoleResource result = (Role) ctx.getOutput(); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + Response.Status.UNAUTHORIZED).entity(ServiceMessages.GET_FAILED + + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { if (logger.isDebugEnabled()) { logger.debug("getRole", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on Role csid=" + csid).type( + ServiceMessages.GET_FAILED + "role csid=" + csid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("getRole", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.GET_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested Role CSID:" + csid + ": was not found.").type( + ServiceMessages.GET_FAILED + "role csid=" + csid + ": was not found.").type( "text/plain").build(); throw new WebApplicationException(response); } @@ -248,15 +251,18 @@ public class RoleResource roleList = (RolesList) handler.getCommonPartList(); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); + Response.Status.UNAUTHORIZED).entity(ServiceMessages.LIST_FAILED + + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Caught exception in getRoleList", e); } + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.LIST_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } return roleList; @@ -281,7 +287,8 @@ public class RoleResource if (csid == null || "".equals(csid)) { logger.error("updateRole: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "update failed on Role csid=" + csid).type( + ServiceMessages.PUT_FAILED + "role " + + ServiceMessages.MISSING_INVALID_CSID + csid).type( "text/plain").build(); throw new WebApplicationException(response); } @@ -293,23 +300,28 @@ public class RoleResource result = (Role) ctx.getOutput(); } catch (BadRequestException bre) { Response response = Response.status( - Response.Status.BAD_REQUEST).entity("Update failed reason " + bre.getErrorReason()).type("text/plain").build(); + Response.Status.BAD_REQUEST).entity(ServiceMessages.PUT_FAILED + + 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(); + Response.Status.UNAUTHORIZED).entity(ServiceMessages.PUT_FAILED + + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { if (logger.isDebugEnabled()) { logger.debug("caugth exception in updateRole", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Update failed on Role csid=" + csid).type( + ServiceMessages.PUT_FAILED + "role csid=" + csid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); + Response.Status.INTERNAL_SERVER_ERROR).entity( + ServiceMessages.PUT_FAILED + + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } return result; @@ -332,17 +344,17 @@ public class RoleResource if (csid == null || "".equals(csid)) { logger.error("deleteRole: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "delete failed on Role csid=" + csid).type( + ServiceMessages.DELETE_FAILED + "role csid=" + csid).type( "text/plain").build(); throw new WebApplicationException(response); } try { ServiceContext ctx = createServiceContext((Role) null, Role.class); - ((JpaStorageClientImpl)getStorageClient(ctx)).deleteWhere(ctx, csid); + ((JpaStorageClientImpl) getStorageClient(ctx)).deleteWhere(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) { Response response = Response.status( - Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); + Response.Status.UNAUTHORIZED).entity(ServiceMessages.DELETE_FAILED + ue.getErrorReason()).type("text/plain").build(); throw new WebApplicationException(response); } catch (DocumentNotFoundException dnfe) { @@ -350,12 +362,14 @@ public class RoleResource logger.debug("caught exception in deleteRole", dnfe); } Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Delete failed on Role csid=" + csid).type( + ServiceMessages.DELETE_FAILED + "role csid=" + csid).type( "text/plain").build(); throw new WebApplicationException(response); } catch (Exception e) { + logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e); Response response = Response.status( - Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); + Response.Status.INTERNAL_SERVER_ERROR).entity( + ServiceMessages.DELETE_FAILED + ServiceMessages.UNKNOWN_ERROR_MSG).type("text/plain").build(); throw new WebApplicationException(response); } diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleValidatorHandler.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleValidatorHandler.java index 62044fe07..bfa2e58e5 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleValidatorHandler.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleValidatorHandler.java @@ -29,6 +29,7 @@ import org.collectionspace.services.authorization.PermissionRole; import org.collectionspace.services.authorization.PermissionValue; import org.collectionspace.services.authorization.Role; import org.collectionspace.services.authorization.RoleValue; +import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentHandler.Action; import org.collectionspace.services.common.document.InvalidDocumentException; @@ -53,7 +54,7 @@ public class PermissionRoleValidatorHandler implements ValidatorHandler { } try { PermissionRole permRole = (PermissionRole) ctx.getInput(); - StringBuilder msgBldr = new StringBuilder("validate() "); + StringBuilder msgBldr = new StringBuilder(ServiceMessages.VALIDATION_FAILURE); boolean invalid = false; if (action.equals(Action.CREATE)) { diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionValidatorHandler.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionValidatorHandler.java index 05980eb06..5f5da1cdc 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionValidatorHandler.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionValidatorHandler.java @@ -25,6 +25,7 @@ package org.collectionspace.services.authorization.storage; import org.collectionspace.services.authorization.Permission; +import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentHandler.Action; import org.collectionspace.services.common.document.InvalidDocumentException; @@ -48,7 +49,7 @@ public class PermissionValidatorHandler implements ValidatorHandler { } try { Permission permission = (Permission) ctx.getInput(); - StringBuilder msgBldr = new StringBuilder("validate() "); + StringBuilder msgBldr = new StringBuilder(ServiceMessages.VALIDATION_FAILURE); boolean invalid = false; if (action.equals(Action.CREATE)) { diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleValidatorHandler.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleValidatorHandler.java index 721650248..70dbb1c21 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleValidatorHandler.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleValidatorHandler.java @@ -26,6 +26,7 @@ package org.collectionspace.services.authorization.storage; import org.collectionspace.services.authorization.Role; +import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentHandler.Action; import org.collectionspace.services.common.document.InvalidDocumentException; @@ -49,7 +50,7 @@ public class RoleValidatorHandler implements ValidatorHandler { } try { Role role = (Role) ctx.getInput(); - StringBuilder msgBldr = new StringBuilder("validate() "); + StringBuilder msgBldr = new StringBuilder(ServiceMessages.VALIDATION_FAILURE); boolean invalid = false; if (action.equals(Action.CREATE)) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/ServiceMessages.java b/services/common/src/main/java/org/collectionspace/services/common/ServiceMessages.java new file mode 100644 index 000000000..9a4c5f18a --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/ServiceMessages.java @@ -0,0 +1,48 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2010 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; + +/** + * Common service messages + * @author + */ +public class ServiceMessages { + + private static final String FAILED = "failed : "; + public static final String POST_FAILED = "POST " + FAILED; + public static final String GET_FAILED = "GET " + FAILED; + public static final String PUT_FAILED = "PUT " + FAILED; + public static final String DELETE_FAILED = "DELETE " + FAILED; + public static final String LIST_FAILED = "LIST " + FAILED; + public static final String SEARCH_FAILED = "GET (query) " + FAILED; + + public static final String UNKNOWN_ERROR_MSG = "Unknown error "; + public static final String VALIDATION_FAILURE = "Validation failure "; + public static final String MISSING_INVALID_CSID = "missing/invalid csid="; + +} -- 2.47.3