Search in sources :

Example 6 with Referral

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

the class LACountyTriggerTest method referralFkAddresssIdNullTest.

/*
   * Test for checking referral county trigger not created as FkAddress_T is null
   */
@SuppressWarnings("javadoc")
@Test
public void referralFkAddresssIdNullTest() throws JsonParseException, JsonMappingException, IOException {
    when(countyTriggerDao.find(any(String.class))).thenReturn(null);
    gov.ca.cwds.rest.api.domain.cms.Referral validDomainReferral = MAPPER.readValue(fixture("fixtures/legacy/business/rules/laCountyTrigger/allegesAbuseOccurredAtAddressIdNull.json"), gov.ca.cwds.rest.api.domain.cms.Referral.class);
    when(countyTriggerDao.create(any(CountyTrigger.class))).thenAnswer(new Answer<CountyTrigger>() {

        @Override
        public CountyTrigger answer(InvocationOnMock invocation) throws Throwable {
            CountyTrigger report = (CountyTrigger) invocation.getArguments()[0];
            countyTrigger = report;
            return report;
        }
    });
    Referral referral = new Referral("ABC1234567", validDomainReferral, "BTr");
    laCountyTrigger.createCountyTrigger(referral);
    assertThat(countyTrigger, is(equalTo(null)));
}
Also used : Referral(gov.ca.cwds.data.persistence.cms.Referral) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CountyTrigger(gov.ca.cwds.data.persistence.cms.CountyTrigger) Test(org.junit.Test)

Example 7 with Referral

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

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

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

the class ReferralDaoIT method testCreateExistingEntityException.

@Override
@Test
public void testCreateExistingEntityException() throws Exception {
    thrown.expect(EntityExistsException.class);
    Referral referral = new Referral("AbiQCgu0Hj", " ", "N", "N", "D5YRVOm0Ht", (short) 122, " ", (Date) null, (short) 409, "", "", "L3H7sSC0Ht", "", "N", "N", (short) 1118, " ", "N", "N", (Date) null, "Verification (R3)", " ", (Date) null, (Date) null, (short) 1520, (short) 0, (Date) null, (Date) null, "", "", " ", " ", " ", "", "", "0Ht", "0Ht", "51", "N", "N", "N", "N", (Date) null, "C", (short) 0, (Date) null, "", (Date) null, null, null, null, null);
    referralDao.create(referral);
}
Also used : Referral(gov.ca.cwds.data.persistence.cms.Referral) Test(org.junit.Test)

Example 10 with Referral

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

the class ReferralDaoIT method testUpdateEntityNotFoundException.

@Override
@Test
public void testUpdateEntityNotFoundException() throws Exception {
    thrown.expect(EntityNotFoundException.class);
    Referral referral = new Referral("ZZZZZZZZZ", " ", "N", "N", "D5YRVOm0Ht", (short) 122, " ", (Date) null, (short) 409, "", "", "L3H7sSC0Ht", "", "N", "N", (short) 1118, " ", "N", "N", (Date) null, "Verification (R3)", " ", (Date) null, (Date) null, (short) 1520, (short) 0, (Date) null, (Date) null, "", "", " ", " ", " ", "", "", "0Ht", "0Ht", "51", "N", "N", "N", "N", (Date) null, "C", (short) 0, (Date) null, "", (Date) null, null, null, null, null);
    referralDao.update(referral);
}
Also used : Referral(gov.ca.cwds.data.persistence.cms.Referral) Test(org.junit.Test)

Aggregations

Referral (gov.ca.cwds.data.persistence.cms.Referral)13 Test (org.junit.Test)10 CountyTrigger (gov.ca.cwds.data.persistence.cms.CountyTrigger)3 StaffPerson (gov.ca.cwds.data.persistence.cms.StaffPerson)2 PostedReferral (gov.ca.cwds.rest.api.domain.cms.PostedReferral)2 ServiceException (gov.ca.cwds.rest.services.ServiceException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ReferralClient (gov.ca.cwds.data.persistence.cms.ReferralClient)1 EntityExistsException (javax.persistence.EntityExistsException)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1