Search in sources :

Example 6 with EntityExistsException

use of javax.persistence.EntityExistsException 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 7 with EntityExistsException

use of javax.persistence.EntityExistsException 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 8 with EntityExistsException

use of javax.persistence.EntityExistsException 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 9 with EntityExistsException

use of javax.persistence.EntityExistsException 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 10 with EntityExistsException

use of javax.persistence.EntityExistsException in project API by ca-cwds.

the class ChildClientService method create.

/**
   * {@inheritDoc}
   * 
   * @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
   */
@Override
public gov.ca.cwds.rest.api.domain.cms.ChildClient create(Request request) {
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.ChildClient;
    gov.ca.cwds.rest.api.domain.cms.ChildClient childClient = (gov.ca.cwds.rest.api.domain.cms.ChildClient) request;
    if (childClient.getVictimClientId() == null) {
        LOGGER.info("ChildClient cannot be created with null or empty VictimClientId");
        throw new ServiceException("ChildClient cannot be created with null or empty VictimClientId");
    }
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        ChildClient managed = new ChildClient(childClient.getVictimClientId(), childClient, lastUpdatedId);
        managed = childClientDao.create(managed);
        return new gov.ca.cwds.rest.api.domain.cms.ChildClient(managed);
    } catch (EntityExistsException e) {
        LOGGER.info("ChildClient already exists : {}", childClient);
        throw new ServiceException("ChildClient already exists : {}" + childClient, e);
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) EntityExistsException(javax.persistence.EntityExistsException) ChildClient(gov.ca.cwds.data.persistence.cms.ChildClient)

Aggregations

EntityExistsException (javax.persistence.EntityExistsException)24 ServiceException (gov.ca.cwds.rest.services.ServiceException)13 SQLException (java.sql.SQLException)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 StaffPerson (gov.ca.cwds.data.persistence.cms.StaffPerson)4 PreparedStatement (java.sql.PreparedStatement)4 DB (com.cloud.utils.db.DB)3 PersistenceException (javax.persistence.PersistenceException)3 Ternary (com.cloud.utils.Ternary)2 ResultSet (java.sql.ResultSet)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AttributeOverride (javax.persistence.AttributeOverride)2 EntityNotFoundException (javax.persistence.EntityNotFoundException)2 NoResultException (javax.persistence.NoResultException)2 NonUniqueResultException (javax.persistence.NonUniqueResultException)2 OptimisticLockException (javax.persistence.OptimisticLockException)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 CiscoAsa1000vDevice (com.cloud.network.cisco.CiscoAsa1000vDevice)1