use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class ReferralServiceTest method testCreateNullIDError.
@Override
@Test
public void testCreateNullIDError() throws Exception {
try {
Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Referral/valid/valid.json"), Referral.class);
gov.ca.cwds.data.persistence.cms.Referral toCreate = new gov.ca.cwds.data.persistence.cms.Referral(null, referralDomain, "0XA");
when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(toCreate);
@SuppressWarnings("unused") PostedReferral expected = new PostedReferral(toCreate);
} catch (ServiceException e) {
assertEquals("Referral ID cannot be empty", e.getMessage());
}
}
use of gov.ca.cwds.rest.services.ServiceException in project api-core by ca-cwds.
the class ElasticSearchPerson method makeESPerson.
/**
* Produce an ElasticSearchPerson domain instance from native ElasticSearch {@link SearchHit}.
* Parse JSON results and populate associated fields. ElasticSearch Java API returns an overly
* broad type of {@code Map<String,Object>}. The enum "knows" how to extract columns of a given
* type.
*
* <p>
* <strong>Classloader Note:</strong> When running in an application server, the root classloader
* may not know of our domain/persistence class, and so we look it up using the current thread's
* classloader, like so:
* </p>
*
* <blockquote>
* {@code Class.forName("some.nested.class", false, Thread.currentThread().getContextClassLoader())}
* </blockquote>
*
* @param hit search result
* @return populated domain-level ES object
* @deprecated retrieves ES document objects for the obsolete Person Search.
* @see #pullCol(Map, ESColumn)
*/
@Deprecated
public static ElasticSearchPerson makeESPerson(final SearchHit hit) {
final Map<String, Object> m = hit.getSource();
ElasticSearchPerson ret = new ElasticSearchPerson(ElasticSearchPerson.<String>pullCol(m, ESColumn.ID), ElasticSearchPerson.<String>pullCol(m, ESColumn.FIRST_NAME), ElasticSearchPerson.<String>pullCol(m, ESColumn.LAST_NAME), null, null, ElasticSearchPerson.<String>pullCol(m, ESColumn.GENDER), ElasticSearchPerson.<String>pullCol(m, ESColumn.BIRTH_DATE), ElasticSearchPerson.<String>pullCol(m, ESColumn.SSN), ElasticSearchPerson.<String>pullCol(m, ESColumn.TYPE), ElasticSearchPerson.<String>pullCol(m, ESColumn.SOURCE), "", null, null, null, null);
if (!StringUtils.isBlank(ret.getSourceType()) && !StringUtils.isBlank(ret.getSourceJson())) {
try {
// Tech debt: reverse compatibility with existing ElasticSearch documents.
if (ret.getSourceType().startsWith("gov.ca.cwds.rest.api.")) {
LOGGER.warn("LEGACY CLASS IN ES! class={}, id={}", ret.getSourceType(), ret.getId());
}
// Remove excess whitespace.
// No job should store excess whitespace in ElasticSearch!
final String json = ret.getSourceJson().replaceAll("\\s+\",", "\",");
// Dynamically instantiate the domain class specified by "type" and load from JSON.
// Note: When running in an application server, the app server's root classloader may not
// know of our domain/persistence class, but the current thread's classloader should.
final Object obj = MAPPER.readValue(json, Class.forName(ret.getSourceType(), false, Thread.currentThread().getContextClassLoader()));
ret.sourceObj = obj;
handleHighlights(hit, ret);
} catch (Exception e) {
throw new ServiceException("ElasticSearch Person error: " + e.getMessage() + ", ES person id=" + ret.getId(), e);
}
}
return ret;
}
use of gov.ca.cwds.rest.services.ServiceException in project api-core by ca-cwds.
the class SimpleResourceDelegateTest method find_A$Object_T$ServiceException.
@Test(expected = ServiceException.class)
public void find_A$Object_T$ServiceException() throws Exception {
final String key = "asdfasdf";
when(svc.find(any())).thenThrow(new ServiceException(new IllegalArgumentException()));
final Response response = target.find(key);
assertTrue(response.getStatus() != Response.Status.OK.ordinal());
}
use of gov.ca.cwds.rest.services.ServiceException in project api-core by ca-cwds.
the class SimpleResourceDelegateTest method handle_A$Object_T$ServiceException.
@Test(expected = ApiException.class)
public void handle_A$Object_T$ServiceException() throws Exception {
TestApiRequest req = new TestApiRequest("&*^(%*#");
when(svc.handle(req)).thenThrow(new ApiException(new ServiceException(new IllegalArgumentException())));
target.handle(req);
final Response response = target.handle(req);
assertTrue(response.getStatus() != Response.Status.OK.ordinal());
}
Aggregations