Search in sources :

Example 1 with StaffPerson

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

the class ReferralClientService method update.

@Override
public gov.ca.cwds.rest.api.domain.cms.ReferralClient update(Serializable primaryKeyObject, Request request) {
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.ReferralClient;
    gov.ca.cwds.rest.api.domain.cms.ReferralClient referralClient = (gov.ca.cwds.rest.api.domain.cms.ReferralClient) request;
    try {
        ReferralClient managed = new ReferralClient(referralClient, "BTr");
        // checking the staffPerson county code
        StaffPerson staffperson = staffpersonDao.find(managed.getLastUpdatedId());
        if (staffperson != null && (triggerTablesDao.getLaCountySpecificCode().equals(staffperson.getCountyCode()))) {
            laCountyTrigger.createCountyTrigger(managed);
        } else {
            nonLaTriggers.createAndUpdateReferralClientCoutyOwnership(managed);
        }
        return new gov.ca.cwds.rest.api.domain.cms.ReferralClient(managed);
    } catch (EntityNotFoundException e) {
        LOGGER.info("Referral not found : {}", referralClient);
        LOGGER.error(e.getMessage(), e);
        throw new ServiceException(e);
    }
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) ServiceException(gov.ca.cwds.rest.services.ServiceException) EntityNotFoundException(javax.persistence.EntityNotFoundException) ReferralClient(gov.ca.cwds.data.persistence.cms.ReferralClient)

Example 2 with StaffPerson

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

the class ClientService method create.

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

Example 3 with StaffPerson

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

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

the class ReferralClientServiceTest method createCountyTriggerForLACounty.

/*
   * Test for checking the staffperson county Code
   */
@SuppressWarnings("javadoc")
@Test
public void createCountyTriggerForLACounty() throws Exception {
    ReferralClient referralClientDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/ReferralClient/valid/valid.json"), ReferralClient.class);
    gov.ca.cwds.data.persistence.cms.ReferralClient toCreate = new gov.ca.cwds.data.persistence.cms.ReferralClient(referralClientDomain, "BTr");
    ReferralClient request = new ReferralClient(toCreate);
    when(triggerTablesDao.getLaCountySpecificCode()).thenReturn("19");
    StaffPerson staffPerson = new StaffPerson("BTr", null, "External Interface", "external interface", "SCXCIN7", " ", "", BigDecimal.valueOf(9165672100L), 0, null, "    ", "N", "MIZN02k00E", "  ", "    ", "19", "N", "3XPCP92q38", null);
    when(staffpersonDao.find(any(String.class))).thenReturn(staffPerson);
    when(referralClientDao.create(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenReturn(toCreate);
    when(laCountyTrigger.createCountyTrigger(any(gov.ca.cwds.data.persistence.cms.ReferralClient.class))).thenAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            isLaCountyTrigger = true;
            return true;
        }
    });
    referralClientService.create(request);
    assertThat(isLaCountyTrigger, is(true));
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ReferralClient(gov.ca.cwds.rest.api.domain.cms.ReferralClient) Test(org.junit.Test)

Example 5 with StaffPerson

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

the class ReferralServiceTest method createCountyTriggerForLACounty.

/*
   * Test for checking the staffperson county Code
   */
@SuppressWarnings("javadoc")
@Test
public void createCountyTriggerForLACounty() throws Exception {
    Referral referralDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Referral/valid/valid.json"), Referral.class);
    gov.ca.cwds.data.persistence.cms.Referral toCreate = new gov.ca.cwds.data.persistence.cms.Referral("1234567ABC", referralDomain, "BTr");
    Referral request = new Referral(toCreate);
    when(triggerTablesDao.getLaCountySpecificCode()).thenReturn("19");
    StaffPerson staffPerson = new StaffPerson("BTr", null, "External Interface", "external interface", "SCXCIN7", " ", "", BigDecimal.valueOf(9165672100L), 0, null, "    ", "N", "MIZN02k00E", "  ", "    ", "19", "N", "3XPCP92q38", null);
    when(staffpersonDao.find(any(String.class))).thenReturn(staffPerson);
    when(referralDao.create(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenReturn(toCreate);
    when(laCountyTrigger.createCountyTrigger(any(gov.ca.cwds.data.persistence.cms.Referral.class))).thenAnswer(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            isLaCountyTrigger = true;
            return true;
        }
    });
    referralService.create(request);
    assertThat(isLaCountyTrigger, is(true));
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) Referral(gov.ca.cwds.rest.api.domain.cms.Referral) PostedReferral(gov.ca.cwds.rest.api.domain.cms.PostedReferral) InvocationOnMock(org.mockito.invocation.InvocationOnMock) 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