use of gov.ca.cwds.rest.services.ServiceException in project api-core by ca-cwds.
the class SimpleResourceDelegate method handleException.
/**
* <p>
* Handle API request by delegating to service method,
* {@link ApiSimpleResourceService#handle(Request)} and wrapping resulting API
* {@link gov.ca.cwds.rest.api.Response} with a Java standard web service response.
* </p>
*
* <p>
* Web Service Response, not a CWDS API Response.
* </p>
*
* <p>
* HTTP Response Codes
* </p>
*
* The default method implementation may return the following HTTP response codes:
* <ul>
* <li>{@link javax.ws.rs.core.Response.Status#OK}</li>
* <li>{@link javax.ws.rs.core.Response.Status#NOT_FOUND}</li>
* <li>{@link javax.ws.rs.core.Response.Status#CONFLICT}</li>
* <li>{@link javax.ws.rs.core.Response.Status#INTERNAL_SERVER_ERROR}</li>
* <li>{@link javax.ws.rs.core.Response.Status#EXPECTATION_FAILED}</li>
* <li>{@link javax.ws.rs.core.Response.Status#NOT_IMPLEMENTED}</li>
* <li>{@link javax.ws.rs.core.Response.Status#SERVICE_UNAVAILABLE}</li>
* </ul>
*
* @param e {@link ServiceException} to inspect
* @return web service {@link Response}
* @see ApiSimpleResourceService#handle(Request)
* @see ApiSimpleResourceService#find(Serializable)
* @deprecated Moved to ServiceExceptionMapper
*/
@Deprecated
protected Response handleException(Exception e) throws ServiceException {
Response ret;
// Gold plating. Waiting for further requirements.
if (e != null) {
if (e.getCause() != null) {
if (e.getCause() instanceof EntityNotFoundException) {
throw new ServiceException("EntityNotFoundException", e.getCause());
} else if (e.getCause() instanceof EntityExistsException) {
throw new ServiceException("EntityExistsException", e.getCause());
} else if (e.getCause() instanceof NullPointerException) {
throw new ServiceException("NullPointerException", e.getCause());
} else if (e.getCause() instanceof ClassNotFoundException) {
LOGGER.error("Class not found! {}", e.getMessage(), e);
throw new ServiceException("ClassNotFoundException", e.getCause());
} else if (e.getCause() instanceof NotImplementedException) {
LOGGER.error("Not implemented", e);
throw new ServiceException("NotImplementedException", e.getCause());
} else {
LOGGER.error("Unable to handle request", e);
throw new ServiceException("Unable to handle request", e.getCause());
}
} else if (e instanceof ServiceException) {
final ServiceException svcEx = (ServiceException) e;
LOGGER.error("ServiceException without attached cause: {}", svcEx.getMessage(), e);
throw new ServiceException("ServiceException without attached cause", e);
} else if (e instanceof IllegalArgumentException) {
final IllegalArgumentException lae = (IllegalArgumentException) e;
LOGGER.error("Argument cannot be null: {}", lae.getMessage(), e);
throw new ServiceException("Argument cannot be null", e);
} else if (e instanceof ConstraintViolationException) {
final ConstraintViolationException cve = (ConstraintViolationException) e;
LOGGER.error("ConstraintViolationException: {}", cve.getMessage(), e);
throw new ServiceException("ConstraintViolationException: " + cve.getMessage(), e);
} else {
LOGGER.error("Unhandled error condition: {}", e.getMessage(), e);
throw new ServiceException("Unhandled error condition", e);
}
} else {
throw new ServiceException("No exception to handle");
}
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class IndexQueryService method handleRequest.
@Override
protected IndexQueryResponse handleRequest(IndexQueryRequest req) {
checkArgument(req != null, "query cannot be Null or empty");
@SuppressWarnings("unchecked") String query = new JSONObject((Map<String, String>) req.getQuery()).toString();
if (StringUtils.isBlank(query)) {
LOGGER.error("query cannot be null.");
throw new ServiceException("query cannot be null.");
}
return new IndexQueryResponse(callDao(req.getIndex(), query));
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class ServiceUtils method extractKeyValuePairs.
@SuppressWarnings("javadoc")
public static Map<String, String> extractKeyValuePairs(Serializable nameValuePairsSerializable) {
Map<String, String> keyValuePairs = new HashMap<>();
if (!(nameValuePairsSerializable instanceof String)) {
throw new ServiceException("Unable to read nameValuePairs as string");
}
try {
String primaryKeyString = (String) nameValuePairsSerializable;
for (String keyValueString : primaryKeyString.split(",")) {
String[] keyValuePair = keyValueString.split("=");
keyValuePairs.put(keyValuePair[0].trim(), keyValuePair[1].trim());
}
return keyValuePairs;
} catch (Exception e) {
throw new ServiceException("Problem parsing name value pairs", e);
}
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class AddressService method update.
@Override
public Response update(Serializable primaryKey, Request request) {
assert primaryKey instanceof String;
assert request instanceof gov.ca.cwds.rest.api.domain.cms.Address;
gov.ca.cwds.rest.api.domain.cms.Address address = (gov.ca.cwds.rest.api.domain.cms.Address) request;
try {
String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
Address managed = new Address((String) primaryKey, address, lastUpdatedId);
managed = addressDao.update(managed);
return new gov.ca.cwds.rest.api.domain.cms.Address(managed, true);
} catch (EntityNotFoundException e) {
LOGGER.info("Address not found : {}", address);
throw new ServiceException(e);
}
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class AllegationPerpetratorHistoryService method create.
/**
* {@inheritDoc}
*
* @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
*/
@Override
public PostedAllegationPerpetratorHistory create(Request request) {
assert request instanceof gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory;
gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory allegationPerpetratorHistory = (gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory) request;
try {
String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
AllegationPerpetratorHistory managed = new AllegationPerpetratorHistory(CmsKeyIdGenerator.cmsIdGenertor(lastUpdatedId), allegationPerpetratorHistory, lastUpdatedId);
managed = allegationPerpetratorHistoryDao.create(managed);
return new PostedAllegationPerpetratorHistory(managed);
} catch (EntityExistsException e) {
LOGGER.info("AllegationPerpetratorHistory already exists : {}", allegationPerpetratorHistory);
throw new ServiceException(e);
}
}
Aggregations