Search in sources :

Example 11 with StaffPerson

use of gov.ca.cwds.data.persistence.cms.StaffPerson 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 12 with StaffPerson

use of gov.ca.cwds.data.persistence.cms.StaffPerson 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 13 with StaffPerson

use of gov.ca.cwds.data.persistence.cms.StaffPerson in project API by ca-cwds.

the class StaffPersonDaoIT method testFindEntityNotFoundException.

@Override
@Test
public void testFindEntityNotFoundException() throws Exception {
    String id = "ZZZ";
    StaffPerson found = staffPersonDao.find(id);
    assertThat(found, is(nullValue()));
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) Test(org.junit.Test)

Example 14 with StaffPerson

use of gov.ca.cwds.data.persistence.cms.StaffPerson in project API by ca-cwds.

the class StaffPersonDaoIT method testCreateExistingEntityException.

@Override
@Test
public void testCreateExistingEntityException() throws Exception {
    thrown.expect(EntityExistsException.class);
    StaffPerson staffPerson = new StaffPerson("q1p", null, "External Interface", "external interface", "SCXCIN7", " ", "", BigDecimal.valueOf(9165672100L), 0, null, "    ", "N", "MIZN02k00E", "  ", "    ", "99", "N", "3XPCP92q38", null);
    staffPersonDao.create(staffPerson);
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) Test(org.junit.Test)

Example 15 with StaffPerson

use of gov.ca.cwds.data.persistence.cms.StaffPerson in project API by ca-cwds.

the class StaffPersonDaoIT method testUpdate.

@Override
@Test
public void testUpdate() throws Exception {
    StaffPerson staffPerson = new StaffPerson("q1p", null, "External Interface", "external interface", "SCXCIN7", " ", "", BigDecimal.valueOf(9165672100L), 0, null, "    ", "N", "MIZN02k00E", "  ", "    ", "99", "N", "3XPCP92q38", null);
    StaffPerson updated = staffPersonDao.update(staffPerson);
    assertThat(updated, is(staffPerson));
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) Test(org.junit.Test)

Aggregations

StaffPerson (gov.ca.cwds.data.persistence.cms.StaffPerson)17 Test (org.junit.Test)10 ServiceException (gov.ca.cwds.rest.services.ServiceException)7 EntityExistsException (javax.persistence.EntityExistsException)4 PostedReferral (gov.ca.cwds.rest.api.domain.cms.PostedReferral)3 EntityNotFoundException (javax.persistence.EntityNotFoundException)3 ClientAddress (gov.ca.cwds.data.persistence.cms.ClientAddress)2 Referral (gov.ca.cwds.data.persistence.cms.Referral)2 ReferralClient (gov.ca.cwds.data.persistence.cms.ReferralClient)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Client (gov.ca.cwds.data.persistence.cms.Client)1 PostedClient (gov.ca.cwds.rest.api.domain.cms.PostedClient)1 Referral (gov.ca.cwds.rest.api.domain.cms.Referral)1 ReferralClient (gov.ca.cwds.rest.api.domain.cms.ReferralClient)1