Search in sources :

Example 41 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.

the class ReferralService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@Override
public PostedReferral create(Request request) {
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.Referral;
    gov.ca.cwds.rest.api.domain.cms.Referral referral = (gov.ca.cwds.rest.api.domain.cms.Referral) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        Referral managed = new Referral(CmsKeyIdGenerator.cmsIdGenertor(lastUpdatedId), referral, lastUpdatedId);
        managed = referralDao.create(managed);
        if (managed.getId() == null) {
            throw new ServiceException("Referral ID cannot be null");
        }
        // checking the staffPerson county code
        StaffPerson staffperson = staffpersonDao.find(managed.getLastUpdatedId());
        if (staffperson != null && (triggerTablesDao.getLaCountySpecificCode().equals(staffperson.getCountyCode()))) {
            laCountyTrigger.createCountyTrigger(managed);
        }
        return new PostedReferral(managed);
    } catch (EntityExistsException e) {
        LOGGER.info("Referral already exists : {}", referral);
        throw new ServiceException(e);
    }
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) EntityExistsException(javax.persistence.EntityExistsException) ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) Referral(gov.ca.cwds.data.persistence.cms.Referral) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral)

Example 42 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.

the class ReferralService method update.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#update(java.io.Serializable,
   *      gov.ca.cwds.rest.api.Request)
   */
@Override
public gov.ca.cwds.rest.api.domain.cms.Referral update(Serializable primaryKey, Request request) {
    assert primaryKey instanceof String;
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.Referral;
    gov.ca.cwds.rest.api.domain.cms.Referral referral = (gov.ca.cwds.rest.api.domain.cms.Referral) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        Referral managed = new Referral((String) primaryKey, referral, lastUpdatedId);
        managed = referralDao.update(managed);
        // checking the staffPerson county code
        StaffPerson staffperson = staffpersonDao.find(managed.getLastUpdatedId());
        if (staffperson != null && (triggerTablesDao.getLaCountySpecificCode().equals(staffperson.getCountyCode()))) {
            laCountyTrigger.createCountyTrigger(managed);
        }
        return new gov.ca.cwds.rest.api.domain.cms.Referral(managed);
    } catch (EntityNotFoundException e) {
        final String msg = "Referral not found : " + referral;
        LOGGER.error("Referral not found : {}", referral);
        throw new ServiceException(msg, e);
    }
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) EntityNotFoundException(javax.persistence.EntityNotFoundException) ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) Referral(gov.ca.cwds.data.persistence.cms.Referral)

Example 43 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.

the class StaffPersonService method update.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#update(java.io.Serializable,
   *      gov.ca.cwds.rest.api.Request)
   */
@Override
public StaffPerson update(Serializable primaryKey, Request request) {
    assert primaryKey instanceof String;
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.StaffPerson;
    gov.ca.cwds.rest.api.domain.cms.StaffPerson staffPerson = (gov.ca.cwds.rest.api.domain.cms.StaffPerson) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        gov.ca.cwds.data.persistence.cms.StaffPerson managed = new gov.ca.cwds.data.persistence.cms.StaffPerson((String) primaryKey, staffPerson, lastUpdatedId);
        managed = staffPersonDao.update(managed);
        return new gov.ca.cwds.rest.api.domain.cms.StaffPerson(managed);
    } catch (EntityNotFoundException e) {
        LOGGER.info("StaffPerson not found : {}", staffPerson);
        throw new ServiceException(e);
    }
}
Also used : PostedStaffPerson(gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson) StaffPerson(gov.ca.cwds.rest.api.domain.cms.StaffPerson) EntityNotFoundException(javax.persistence.EntityNotFoundException) ServiceException(gov.ca.cwds.rest.services.ServiceException) StaffPerson(gov.ca.cwds.rest.api.domain.cms.StaffPerson)

Example 44 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 45 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)

Aggregations

ServiceException (gov.ca.cwds.rest.services.ServiceException)59 Test (org.junit.Test)22 EntityNotFoundException (javax.persistence.EntityNotFoundException)16 EntityExistsException (javax.persistence.EntityExistsException)15 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 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 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