Search in sources :

Example 1 with PostedAddress

use of gov.ca.cwds.rest.api.domain.cms.PostedAddress in project API by ca-cwds.

the class ScreeningToReferralService method processReferralAddress.

private gov.ca.cwds.rest.api.domain.Address processReferralAddress(ScreeningToReferral scr, Set<ErrorMessage> messages) throws ServiceException {
    gov.ca.cwds.rest.api.domain.Address address = scr.getAddress();
    if (address == null || address.getZip() == null || address.getStreetAddress() == null || address.getType() == null) {
        String message = " Screening address is null or empty";
        ServiceException se = new ServiceException(message);
        logError(message, se, messages);
        return address;
    }
    try {
        Address domainAddress = Address.createWithDefaults(address, DEFAULT_STATE_CODE);
        buildErrors(messages, validator.validate(domainAddress));
        PostedAddress postedAddress = (PostedAddress) this.addressService.create(domainAddress);
        address.setLegacyId(postedAddress.getExistingAddressId());
        address.setLegacySourceTable("ADDRS_T");
    } catch (Exception e) {
        logError(e.getMessage(), e, messages);
    }
    return address;
}
Also used : Address(gov.ca.cwds.rest.api.domain.cms.Address) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) PostedAddress(gov.ca.cwds.rest.api.domain.cms.PostedAddress) PostedAddress(gov.ca.cwds.rest.api.domain.cms.PostedAddress) ParseException(java.text.ParseException) NotImplementedException(org.apache.commons.lang3.NotImplementedException)

Example 2 with PostedAddress

use of gov.ca.cwds.rest.api.domain.cms.PostedAddress in project API by ca-cwds.

the class AddressService method create.

@Override
public Response create(Request request) {
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.Address;
    gov.ca.cwds.rest.api.domain.cms.Address address = (gov.ca.cwds.rest.api.domain.cms.Address) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        Address managed = new Address(CmsKeyIdGenerator.cmsIdGenertor(lastUpdatedId), address, lastUpdatedId);
        managed = addressDao.create(managed);
        if (managed.getId() == null) {
            throw new ServiceException("Address ID cannot be null");
        }
        return new PostedAddress(managed, true);
    } catch (EntityExistsException e) {
        LOGGER.info("Address already exists : ()", address);
        throw new ServiceException(e);
    }
}
Also used : Address(gov.ca.cwds.data.persistence.cms.Address) PostedAddress(gov.ca.cwds.rest.api.domain.cms.PostedAddress) EntityExistsException(javax.persistence.EntityExistsException) ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedAddress(gov.ca.cwds.rest.api.domain.cms.PostedAddress)

Example 3 with PostedAddress

use of gov.ca.cwds.rest.api.domain.cms.PostedAddress in project API by ca-cwds.

the class ScreeningToReferralService method processClientAddress.

/*
   * CMS Address - create ADDRESS and CLIENT_ADDRESS for each address of the participant
   */
private Participant processClientAddress(Participant clientParticipant, String referralId, String clientId, Set<ErrorMessage> messages) throws ServiceException {
    String addressId = new String("");
    Set<gov.ca.cwds.rest.api.domain.Address> addresses;
    Set<gov.ca.cwds.rest.api.domain.Address> newAddresses = new HashSet();
    addresses = clientParticipant.getAddresses();
    if (addresses == null) {
        return null;
    }
    for (gov.ca.cwds.rest.api.domain.Address address : addresses) {
        if (address.getLegacyId() == null || address.getLegacyId().isEmpty()) {
            // add the Address row
            Address domainAddress = Address.createWithDefaults(address, DEFAULT_STATE_CODE);
            zipSuffix = domainAddress.getZip4();
            buildErrors(messages, validator.validate(domainAddress));
            PostedAddress postedAddress = (PostedAddress) this.addressService.create(domainAddress);
            addressId = postedAddress.getExistingAddressId();
        } else {
            // verify that Address row exist - no update for now
            Address foundAddress = (Address) this.addressService.find(address.getLegacyId());
            if (foundAddress == null) {
                String message = " Legacy Id on Address does not correspond to an existing CMS/CWS Address ";
                ServiceException se = new ServiceException(message);
                logError(message, se, messages);
                // next address
                continue;
            }
            addressId = foundAddress.getExistingAddressId();
        }
        /*
       * CMS Client Address
       */
        if (addressId.isEmpty()) {
            String message = " ADDRESS/IDENTIFIER is required for CLIENT_ADDRESS table ";
            ServiceException se = new ServiceException(message);
            logError(message, se, messages);
            // next address
            continue;
        }
        if (clientId.isEmpty()) {
            String message = " CLIENT/IDENTIFIER is required for CLIENT_ADDRESS ";
            ServiceException se = new ServiceException(message);
            logError(message, se, messages);
            // next address
            continue;
        }
        if (address.getLegacyId() == null || address.getLegacyId().isEmpty()) {
            ClientAddress clientAddress = new ClientAddress(DEFAULT_ADDRESS_TYPE, "", "", "", addressId, clientId, "", referralId);
            buildErrors(messages, validator.validate(clientAddress));
            this.clientAddressService.create(clientAddress);
            buildErrors(messages, validator.validate(clientAddress));
            // update the addresses of the participant
            address.setLegacySourceTable(CLIENT_ADDRESS_TABLE_NAME);
            address.setLegacyId(addressId);
            newAddresses.add(address);
        } else {
            // verify that ClientAddress exists - no update for now
            ClientAddress foundClientAddress = (ClientAddress) this.clientAddressService.find(address.getLegacyId());
            if (foundClientAddress == null) {
                String message = " Legacy Id on Address does not correspond to an existing CMS/CWS Client Address ";
                ServiceException se = new ServiceException(message);
                logError(message, se, messages);
                // next address
                continue;
            }
        }
    }
    clientParticipant.setAddresses(newAddresses);
    return clientParticipant;
}
Also used : Address(gov.ca.cwds.rest.api.domain.cms.Address) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) PostedAddress(gov.ca.cwds.rest.api.domain.cms.PostedAddress) ClientAddress(gov.ca.cwds.rest.api.domain.cms.ClientAddress) PostedAddress(gov.ca.cwds.rest.api.domain.cms.PostedAddress) HashSet(java.util.HashSet)

Aggregations

PostedAddress (gov.ca.cwds.rest.api.domain.cms.PostedAddress)3 Address (gov.ca.cwds.rest.api.domain.cms.Address)2 ClientAddress (gov.ca.cwds.rest.api.domain.cms.ClientAddress)2 Address (gov.ca.cwds.data.persistence.cms.Address)1 ServiceException (gov.ca.cwds.rest.services.ServiceException)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 EntityExistsException (javax.persistence.EntityExistsException)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1