use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class ClientServiceTest method testCreateEmptyIDError.
@Override
@Test
public void testCreateEmptyIDError() throws Exception {
try {
Client clientDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Client/valid/serviceValid.json"), Client.class);
gov.ca.cwds.data.persistence.cms.Client toCreate = new gov.ca.cwds.data.persistence.cms.Client(" ", clientDomain, "ABC");
when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(toCreate);
} catch (ServiceException e) {
assertEquals("Client ID cannot be empty", e.getMessage());
}
}
use of gov.ca.cwds.rest.services.ServiceException in project api-core by ca-cwds.
the class CmsSystemCodeCacheLoader method main.
public static void main(String[] args) {
try {
ApiSystemCodeDao dao = new SystemCodeDaoFileImpl();
if (args.length > 1) {
// dao = new FileSystemCodeDao(new File(args[0]));
}
ApiSystemCodeCache cache = new CmsSystemCodeCacheService(dao);
} catch (ServiceException e) {
LOGGER.error("FATAL ERROR", e);
}
}
use of gov.ca.cwds.rest.services.ServiceException in project api-core by ca-cwds.
the class CmsKeyIdGenerator method doubleToStrN.
/**
* @param dstLen the string width
* @param src source value
* @param powers the power vector for the destination base
* @return the double to string
*/
public static String doubleToStrN(int dstLen, double src, final BigDecimal[] powers) {
int i;
int p = 0;
double integral;
double raw;
final char[] dest = new char[20];
final BigDecimal bdSrc = BigDecimal.valueOf(src);
// NOSONAR
for (i = 0; bdSrc.doubleValue() >= powers[i].doubleValue(); i++, p++) ;
// Left-pad the string with the destination string width.
final int pad = dstLen - p;
if (pad < 0) {
throw new ServiceException("invalid pad value");
} else {
for (i = 0; i < pad; i++) {
dest[i] = ALPHABET[0];
}
for (i = 0; i < p; i++) {
raw = src / powers[p - i - 1].doubleValue();
// Break down the number and convert the integer portion to a character.
integral = (int) raw;
dest[i + pad] = ALPHABET[(int) Math.abs(integral)];
// NOSONAR
src -= (integral * powers[p - i - 1].doubleValue());
}
}
final StringBuilder buf = new StringBuilder();
for (final char c : dest) {
if (c > 0) {
buf.append(c);
}
}
return buf.toString();
}
use of gov.ca.cwds.rest.services.ServiceException in project api-core by ca-cwds.
the class ElasticSearchPerson method handleHighlights.
protected static void handleHighlights(final SearchHit hit, final ElasticSearchPerson ret) {
// ElasticSearch Java API returns map of highlighted fields
final Map<String, HighlightField> h = hit.getHighlightFields();
final Map<String, String> highlightValues = new LinkedHashMap<>();
// Go through the HighlightFields returned from ES deal with fragments and create map.
for (final Map.Entry<String, HighlightField> entry : h.entrySet()) {
String highlightValue;
final HighlightField highlightField = entry.getValue();
final Text[] fragments = highlightField.fragments();
if (fragments != null && fragments.length != 0) {
final String[] texts = new String[fragments.length];
for (int i = 0; i < fragments.length; i++) {
texts[i] = fragments[i].string().trim();
}
highlightValue = StringUtils.join(texts, "...");
highlightValues.put(DomainChef.camelCaseToLowerUnderscore(highlightField.getName()), highlightValue);
}
}
// Update this ElasticSearchPerson property with the highlighted text.
String highLights = "";
try {
highLights = MAPPER.writeValueAsString(highlightValues);
} catch (JsonProcessingException e) {
throw new ServiceException("ElasticSearch Person error: Failed serialize map to JSON " + ret.getSourceType() + ", doc id=" + ret.getId(), e);
}
ret.setHighlightFields(highLights);
ret.setHighlights(highlightValues);
}
use of gov.ca.cwds.rest.services.ServiceException in project api-core by ca-cwds.
the class ServiceBackedResourceDelegateTest method setup.
@Before
public void setup() throws Exception {
nonUniqueDomainObject = new ResourceDelegateTestDomainObject(ID_FOUND);
uniqueDomainObject = new ResourceDelegateTestDomainObject(ID_NOT_FOUND);
unexpectedExceptionDomainObject = new ResourceDelegateTestDomainObject(new Long(13));
validationErrorMessageDomainObject = new ResourceDelegateTestDomainObject(new Long(15));
ArrayList messages = new ArrayList<>();
validationErrorMessageDomainObject.setMessages(messages);
when(crudsService.find(ID_NOT_FOUND)).thenReturn(null);
when(crudsService.find(ID_FOUND)).thenReturn(nonUniqueDomainObject);
when(crudsService.delete(ID_NOT_FOUND)).thenReturn(null);
when(crudsService.delete(ID_FOUND)).thenReturn(nonUniqueDomainObject);
when(crudsService.create(eq(uniqueDomainObject))).thenReturn(new PrimaryKeyResponse(nonUniqueDomainObject.getId()));
when(crudsService.create(eq(nonUniqueDomainObject))).thenThrow(new ServiceException(new EntityExistsException()));
when(crudsService.create(eq(unexpectedExceptionDomainObject))).thenThrow(new ServiceException(new RuntimeException()));
when(crudsService.create(eq(validationErrorMessageDomainObject))).thenReturn(validationErrorMessageDomainObject);
when(crudsService.update(eq(1L), eq(unexpectedExceptionDomainObject))).thenThrow(new ServiceException(new RuntimeException()));
when(crudsService.update(eq(-1L), eq(uniqueDomainObject))).thenThrow(new ServiceException(new EntityNotFoundException()));
when(crudsService.update(eq(1L), eq(nonUniqueDomainObject))).thenReturn(new PrimaryKeyResponse(nonUniqueDomainObject.getId()));
}
Aggregations