Search in sources :

Example 1 with Address

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

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

the class AddressService method update.

@Override
public Response update(Serializable primaryKey, Request request) {
    assert primaryKey instanceof String;
    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((String) primaryKey, address, lastUpdatedId);
        managed = addressDao.update(managed);
        return new gov.ca.cwds.rest.api.domain.cms.Address(managed, true);
    } catch (EntityNotFoundException e) {
        LOGGER.info("Address not found : {}", address);
        throw new ServiceException(e);
    }
}
Also used : Address(gov.ca.cwds.data.persistence.cms.Address) PostedAddress(gov.ca.cwds.rest.api.domain.cms.PostedAddress) ServiceException(gov.ca.cwds.rest.services.ServiceException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Aggregations

Address (gov.ca.cwds.data.persistence.cms.Address)2 PostedAddress (gov.ca.cwds.rest.api.domain.cms.PostedAddress)2 ServiceException (gov.ca.cwds.rest.services.ServiceException)2 EntityExistsException (javax.persistence.EntityExistsException)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1