use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class AllegationPerpetratorHistoryServiceTest method testCreateNullIDError.
@Override
@Test
public void testCreateNullIDError() throws Exception {
try {
AllegationPerpetratorHistory allegationPerpetratorHistoryDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/AllegationPerpetratorHistory/valid/valid.json"), AllegationPerpetratorHistory.class);
gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory toCreate = new gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory(null, allegationPerpetratorHistoryDomain, "ABC");
when(allegationPerpetratorHistoryDao.create(any(gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory.class))).thenReturn(toCreate);
PostedAllegationPerpetratorHistory expected = new PostedAllegationPerpetratorHistory(toCreate);
} catch (ServiceException e) {
assertEquals("AllegationPerpetratorHistory ID cannot be blank", e.getMessage());
}
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class AllegationServiceTest method testCreateNullIDError.
@Override
@Test
public void testCreateNullIDError() throws Exception {
try {
Allegation allegationDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Allegation/valid/valid.json"), Allegation.class);
gov.ca.cwds.data.persistence.cms.Allegation toCreate = new gov.ca.cwds.data.persistence.cms.Allegation(null, allegationDomain, "ABC");
when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(toCreate);
PostedAllegation expected = new PostedAllegation(toCreate);
} catch (ServiceException e) {
assertEquals("Allegation ID cannot be blank", e.getMessage());
}
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class AllegationServiceTest method testCreateBlankIDError.
@Override
@Test
public void testCreateBlankIDError() throws Exception {
try {
Allegation allegationDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Allegation/valid/valid.json"), Allegation.class);
gov.ca.cwds.data.persistence.cms.Allegation toCreate = new gov.ca.cwds.data.persistence.cms.Allegation(" ", allegationDomain, "ABC");
when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(toCreate);
PostedAllegation expected = new PostedAllegation(toCreate);
} catch (ServiceException e) {
assertEquals("Allegation ID cannot be blank", e.getMessage());
}
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class CmsDocumentDao method decompressPK.
/**
* Decompress (inflate) an PKWare-compressed document by assembling blob segments and calling Java
* PKWare SDK.
*
* <p>
* The DB2 SQL returns blob segments as hexadecimal.
* </p>
*
* @param doc PK archive to decompress
* @return base64-encoded String of decompressed document
*/
protected String decompressPK(gov.ca.cwds.data.persistence.cms.CmsDocument doc) {
String retval = "";
CmsPKCompressor pk = new CmsPKCompressor();
try {
StringBuilder buf = new StringBuilder(doc.getDocLength().intValue() * 2);
for (CmsDocumentBlobSegment seg : doc.getBlobSegments()) {
buf.append(seg.getDocBlob().trim());
}
final byte[] bytes = pk.decompressHex(buf.toString());
LOGGER.info("DAO: bytes len=" + bytes.length);
retval = DatatypeConverter.printBase64Binary(bytes);
} catch (Exception e) {
LOGGER.error("ERROR DECOMPRESSING PK! " + e.getMessage());
throw new ServiceException("ERROR DECOMPRESSING PK! " + e.getMessage(), e);
}
return retval;
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class CmsDocumentDao method decompressLZW.
/**
* Decompress (inflate) an LZW-compressed document by assembling blob segments and calling native
* library.
*
* @param doc LZW archive to decompress
* @return base64-encoded String of decompressed document
*/
protected String decompressLZW(gov.ca.cwds.data.persistence.cms.CmsDocument doc) {
String retval = "";
try {
File src = File.createTempFile("src", ".lzw");
src.deleteOnExit();
File tgt = File.createTempFile("tgt", ".doc");
tgt.deleteOnExit();
FileOutputStream fos = new FileOutputStream(src);
for (CmsDocumentBlobSegment seg : doc.getBlobSegments()) {
final byte[] bytes = DatatypeConverter.parseHexBinary(seg.getDocBlob().trim());
fos.write(bytes, 0, bytes.length);
}
fos.flush();
fos.close();
// DECOMPRESS!
// TODO: Trap std::exception in shared library and return error code.
// The LZW library currently returns a blank when decompression fails, for safety, since
// unhandled C++ exceptions kill the JVM.
LZWEncoder lzw = new LZWEncoder();
lzw.fileCopyUncompress(src.getAbsolutePath(), tgt.getAbsolutePath());
retval = DatatypeConverter.printBase64Binary(Files.readAllBytes(Paths.get(tgt.getAbsolutePath())));
// For security reasons, remove temporary documents immediately.
// TODO: pass bytes to C++ library instead of file names.
src.delete();
tgt.delete();
} catch (Exception e) {
LOGGER.error("ERROR DECOMPRESSING LZW! " + e.getMessage(), e);
throw new ServiceException("ERROR DECOMPRESSING LZW! " + e.getMessage(), e);
}
return retval;
}
Aggregations