Search in sources :

Example 1 with ClientAddress

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

the class ClientAddressService method update.

@Override
public Response update(Serializable primaryKey, Request request) {
    assert primaryKey instanceof String;
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.ClientAddress;
    gov.ca.cwds.rest.api.domain.cms.ClientAddress clientAddress = (gov.ca.cwds.rest.api.domain.cms.ClientAddress) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        ClientAddress managed = new ClientAddress((String) primaryKey, clientAddress, lastUpdatedId);
        // checking the staffPerson county code
        StaffPerson staffperson = staffpersonDao.find(managed.getLastUpdatedId());
        if (staffperson != null && (triggerTablesDao.getLaCountySpecificCode().equals(staffperson.getCountyCode()))) {
            laCountyTrigger.createClientAddressCountyTrigger(managed);
        }
        managed = clientAddressDao.update(managed);
        return new gov.ca.cwds.rest.api.domain.cms.ClientAddress(managed, true);
    } catch (EntityNotFoundException e) {
        LOGGER.info("ClientAddress not found : {}", clientAddress);
        throw new ServiceException(e);
    }
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) ClientAddress(gov.ca.cwds.data.persistence.cms.ClientAddress) EntityNotFoundException(javax.persistence.EntityNotFoundException) ServiceException(gov.ca.cwds.rest.services.ServiceException)

Example 2 with ClientAddress

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

the class LACountyTriggerTest method clientAddressfkAddressIdNullTest.

/*
   * Test for checking clientAddress county trigger not created as FkAddress_T is null
   */
@SuppressWarnings("javadoc")
@Test
public void clientAddressfkAddressIdNullTest() throws JsonParseException, JsonMappingException, IOException {
    when(countyTriggerDao.find(any(String.class))).thenReturn(null);
    gov.ca.cwds.rest.api.domain.cms.ClientAddress validDomainClientAddress = MAPPER.readValue(fixture("fixtures/legacy/business/rules/laCountyTrigger/fkAddressTNull.json"), gov.ca.cwds.rest.api.domain.cms.ClientAddress.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;
        }
    });
    ClientAddress clientAddress = new ClientAddress("ABC1234567", validDomainClientAddress, "BTr");
    laCountyTrigger.createClientAddressCountyTrigger(clientAddress);
    assertThat(countyTrigger, is(equalTo(null)));
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) ClientAddress(gov.ca.cwds.data.persistence.cms.ClientAddress) CountyTrigger(gov.ca.cwds.data.persistence.cms.CountyTrigger) Test(org.junit.Test)

Example 3 with ClientAddress

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

the class LACountyTriggerTest method clientAddressfkclientIdNullTest.

/*
   * Test for checking clientAddress county trigger not created as FkClient_T is null
   */
@SuppressWarnings("javadoc")
@Test
public void clientAddressfkclientIdNullTest() throws JsonParseException, JsonMappingException, IOException {
    when(countyTriggerDao.find(any(String.class))).thenReturn(null);
    gov.ca.cwds.rest.api.domain.cms.ClientAddress validDomainClientAddress = MAPPER.readValue(fixture("fixtures/legacy/business/rules/laCountyTrigger/fkClientTNull.json"), gov.ca.cwds.rest.api.domain.cms.ClientAddress.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;
        }
    });
    ClientAddress clientAddress = new ClientAddress("ABC1234567", validDomainClientAddress, "BTr");
    laCountyTrigger.createClientAddressCountyTrigger(clientAddress);
    assertThat(countyTrigger, is(equalTo(null)));
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) ClientAddress(gov.ca.cwds.data.persistence.cms.ClientAddress) CountyTrigger(gov.ca.cwds.data.persistence.cms.CountyTrigger) Test(org.junit.Test)

Example 4 with ClientAddress

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

the class LACountyTrigger method createClientAddressCountyTrigger.

/**
   * @param object The object creates the county Trigger for the clientAddress
   * @return the CountyTrigger created
   */
public boolean createClientAddressCountyTrigger(Object object) {
    ClientAddress clientAddress;
    if (object instanceof ClientAddress) {
        clientAddress = (ClientAddress) object;
        if (clientAddress.getFkClient() != "" && clientAddress.getFkClient() != null && clientAddress.getFkAddress() != "" && clientAddress.getFkAddress() != null) {
            CountyTrigger countyTrigger1 = new CountyTrigger(clientAddress.getFkClient(), LA_COUNTY_SPECIFIC_CODE, CLIENT_COUNTYOWNERSHIP, new Date(), ClientAddress.class.getDeclaredAnnotation(Table.class).name());
            CountyTrigger countyTrigger2 = new CountyTrigger(clientAddress.getFkAddress(), LA_COUNTY_SPECIFIC_CODE, ADDRESS_COUNTYOWNERSHIP, new Date(), ClientAddress.class.getDeclaredAnnotation(Table.class).name());
            countyTriggerDao.create(countyTrigger1);
            countyTriggerDao.create(countyTrigger2);
        }
        LOGGER.info("LA county clientAddress triggered");
    }
    return true;
}
Also used : ClientAddress(gov.ca.cwds.data.persistence.cms.ClientAddress) CountyTrigger(gov.ca.cwds.data.persistence.cms.CountyTrigger) Date(java.util.Date)

Example 5 with ClientAddress

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

the class LACountyTriggerTest method createClientAddressCountyTriggerTest.

/*
   * Test for checking the clientAddress county trigger created with the CL_ADDRT
   */
@SuppressWarnings("javadoc")
@Test
public void createClientAddressCountyTriggerTest() throws JsonParseException, JsonMappingException, IOException {
    when(countyTriggerDao.find(any(String.class))).thenReturn(null);
    gov.ca.cwds.rest.api.domain.cms.ClientAddress validDomainClientAddress = MAPPER.readValue(fixture("fixtures/legacy/business/rules/laCountyTrigger/validClientAddress.json"), gov.ca.cwds.rest.api.domain.cms.ClientAddress.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;
        }
    });
    ClientAddress clientAddress = new ClientAddress("1234567ABC", validDomainClientAddress, "BTr");
    laCountyTrigger.createClientAddressCountyTrigger(clientAddress);
    assertThat(countyTrigger.getCountyTriggerEmbeddable().getCountyOwnershipT(), is(equalTo("1234567ABC")));
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) ClientAddress(gov.ca.cwds.data.persistence.cms.ClientAddress) CountyTrigger(gov.ca.cwds.data.persistence.cms.CountyTrigger) Test(org.junit.Test)

Aggregations

ClientAddress (gov.ca.cwds.data.persistence.cms.ClientAddress)6 CountyTrigger (gov.ca.cwds.data.persistence.cms.CountyTrigger)4 Test (org.junit.Test)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 StaffPerson (gov.ca.cwds.data.persistence.cms.StaffPerson)2 ServiceException (gov.ca.cwds.rest.services.ServiceException)2 Date (java.util.Date)1 EntityExistsException (javax.persistence.EntityExistsException)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1