Search in sources :

Example 11 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.

the class ReporterService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@Override
public PostedReporter create(Request request) {
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.Reporter;
    gov.ca.cwds.rest.api.domain.cms.Reporter reporter = (gov.ca.cwds.rest.api.domain.cms.Reporter) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        Reporter managed = new Reporter(reporter, lastUpdatedId);
        managed = reporterDao.create(managed);
        return new PostedReporter(managed);
    } catch (EntityExistsException e) {
        LOGGER.info("Reporter already exists : {}", reporter);
        throw new ServiceException(e);
    }
}
Also used : PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) Reporter(gov.ca.cwds.data.persistence.cms.Reporter) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) EntityExistsException(javax.persistence.EntityExistsException) ServiceException(gov.ca.cwds.rest.services.ServiceException)

Example 12 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.

the class StaffPersonService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@Override
public PostedStaffPerson create(Request request) {
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.StaffPerson;
    StaffPerson staffPerson = (StaffPerson) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        gov.ca.cwds.data.persistence.cms.StaffPerson managed = new gov.ca.cwds.data.persistence.cms.StaffPerson(IdGenerator.randomString(3), staffPerson, lastUpdatedId);
        managed = staffPersonDao.create(managed);
        return new PostedStaffPerson(managed);
    } catch (EntityExistsException e) {
        LOGGER.info("StaffPerson already exists : {}", staffPerson);
        throw new ServiceException(e);
    }
}
Also used : PostedStaffPerson(gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson) StaffPerson(gov.ca.cwds.rest.api.domain.cms.StaffPerson) PostedStaffPerson(gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson) EntityExistsException(javax.persistence.EntityExistsException) ServiceException(gov.ca.cwds.rest.services.ServiceException)

Example 13 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException 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 14 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException 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 15 with ServiceException

use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.

the class ClientUcService 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.ClientUc update(Serializable primaryKey, Request request) {
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.ClientUc;
    gov.ca.cwds.rest.api.domain.cms.ClientUc clientUc = (gov.ca.cwds.rest.api.domain.cms.ClientUc) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        ClientUc managed = new ClientUc(clientUc, lastUpdatedId);
        managed = clientucDao.update(managed);
        return new gov.ca.cwds.rest.api.domain.cms.ClientUc(managed);
    } catch (EntityNotFoundException e) {
        LOGGER.info("Client not found : {}", clientUc);
        throw new ServiceException(e);
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) ClientUc(gov.ca.cwds.data.persistence.cms.ClientUc) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Aggregations

ServiceException (gov.ca.cwds.rest.services.ServiceException)59 Test (org.junit.Test)22 EntityNotFoundException (javax.persistence.EntityNotFoundException)16 EntityExistsException (javax.persistence.EntityExistsException)15 StaffPerson (gov.ca.cwds.data.persistence.cms.StaffPerson)7 PostedReferral (gov.ca.cwds.rest.api.domain.cms.PostedReferral)5 PostedReporter (gov.ca.cwds.rest.api.domain.cms.PostedReporter)5 PostedStaffPerson (gov.ca.cwds.rest.api.domain.cms.PostedStaffPerson)5 StaffPerson (gov.ca.cwds.rest.api.domain.cms.StaffPerson)5 PostedAllegation (gov.ca.cwds.rest.api.domain.cms.PostedAllegation)4 PostedAllegationPerpetratorHistory (gov.ca.cwds.rest.api.domain.cms.PostedAllegationPerpetratorHistory)4 PostedClient (gov.ca.cwds.rest.api.domain.cms.PostedClient)4 PostedLongText (gov.ca.cwds.rest.api.domain.cms.PostedLongText)4 Referral (gov.ca.cwds.rest.api.domain.cms.Referral)3 Reporter (gov.ca.cwds.rest.api.domain.cms.Reporter)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Address (gov.ca.cwds.data.persistence.cms.Address)2 Allegation (gov.ca.cwds.data.persistence.cms.Allegation)2 AllegationPerpetratorHistory (gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory)2 ChildClient (gov.ca.cwds.data.persistence.cms.ChildClient)2