Search in sources :

Example 46 with ServiceException

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());
    }
}
Also used : PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedAllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory) AllegationPerpetratorHistory(gov.ca.cwds.rest.api.domain.cms.AllegationPerpetratorHistory) Test(org.junit.Test)

Example 47 with ServiceException

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());
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) Test(org.junit.Test)

Example 48 with ServiceException

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());
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) Allegation(gov.ca.cwds.rest.api.domain.cms.Allegation) PostedAllegation(gov.ca.cwds.rest.api.domain.cms.PostedAllegation) Test(org.junit.Test)

Example 49 with ServiceException

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;
}
Also used : CmsPKCompressor(gov.ca.cwds.rest.util.jni.CmsPKCompressor) ServiceException(gov.ca.cwds.rest.services.ServiceException) CmsDocumentBlobSegment(gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment) ServiceException(gov.ca.cwds.rest.services.ServiceException)

Example 50 with ServiceException

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;
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) FileOutputStream(java.io.FileOutputStream) CmsDocumentBlobSegment(gov.ca.cwds.data.persistence.cms.CmsDocumentBlobSegment) File(java.io.File) ServiceException(gov.ca.cwds.rest.services.ServiceException) LZWEncoder(gov.ca.cwds.rest.util.jni.LZWEncoder)

Aggregations

ServiceException (gov.ca.cwds.rest.services.ServiceException)51 Test (org.junit.Test)20 EntityNotFoundException (javax.persistence.EntityNotFoundException)14 EntityExistsException (javax.persistence.EntityExistsException)13 StaffPerson (gov.ca.cwds.data.persistence.cms.StaffPerson)7 PostedReferral (gov.ca.cwds.rest.api.domain.cms.PostedReferral)5 PostedReporter (gov.ca.cwds.rest.api.domain.cms.PostedReporter)5 PostedStaffPerson (gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson)5 StaffPerson (gov.ca.cwds.rest.api.domain.cms.StaffPerson)5 PostedAllegation (gov.ca.cwds.rest.api.domain.cms.PostedAllegation)4 PostedAllegationPerpetratorHistory (gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory)4 PostedClient (gov.ca.cwds.rest.api.domain.cms.PostedClient)4 PostedLongText (gov.ca.cwds.rest.api.domain.cms.PostedLongText)4 Referral (gov.ca.cwds.rest.api.domain.cms.Referral)3 Reporter (gov.ca.cwds.rest.api.domain.cms.Reporter)3 Address (gov.ca.cwds.data.persistence.cms.Address)2 Allegation (gov.ca.cwds.data.persistence.cms.Allegation)2 AllegationPerpetratorHistory (gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory)2 ChildClient (gov.ca.cwds.data.persistence.cms.ChildClient)2 Client (gov.ca.cwds.data.persistence.cms.Client)2