Search in sources :

Example 21 with EntityExistsException

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

the class ClientAddressService method create.

@Override
public Response create(Request request) {
    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 {
        ClientAddress managedClientAddress = new ClientAddress(IdGenerator.randomString(10), clientAddress, "BTr");
        // checking the staffPerson county code
        StaffPerson staffperson = staffpersonDao.find(managedClientAddress.getLastUpdatedId());
        if (staffperson != null && (triggerTablesDao.getLaCountySpecificCode().equals(staffperson.getCountyCode()))) {
            laCountyTrigger.createClientAddressCountyTrigger(managedClientAddress);
        }
        managedClientAddress = clientAddressDao.create(managedClientAddress);
        return new gov.ca.cwds.rest.api.domain.cms.ClientAddress(managedClientAddress, false);
    } catch (EntityExistsException e) {
        LOGGER.info("ClientAddress already exists : {}", clientAddress);
        throw new ServiceException(e);
    }
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) ServiceException(gov.ca.cwds.rest.services.ServiceException) ClientAddress(gov.ca.cwds.data.persistence.cms.ClientAddress) EntityExistsException(javax.persistence.EntityExistsException)

Example 22 with EntityExistsException

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

the class ClientUcService 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.ClientUc create(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);
        // NOSONAR
        managed = clientucDao.create(managed);
        return mockDomain;
    } catch (EntityExistsException e) {
        LOGGER.info("Client already exists : {}", clientUc);
        throw new ServiceException(e);
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) ClientUc(gov.ca.cwds.data.persistence.cms.ClientUc) EntityExistsException(javax.persistence.EntityExistsException)

Example 23 with EntityExistsException

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

the class ReferralClientService method create.

@Override
public gov.ca.cwds.rest.api.domain.cms.ReferralClient create(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 {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        ReferralClient managed = new ReferralClient(referralClient, lastUpdatedId);
        managed = referralClientDao.create(managed);
        // 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 (EntityExistsException e) {
        LOGGER.info("Referral Client already exists : {}", referralClient);
        throw new ServiceException(e);
    }
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) EntityExistsException(javax.persistence.EntityExistsException) ServiceException(gov.ca.cwds.rest.services.ServiceException) ReferralClient(gov.ca.cwds.data.persistence.cms.ReferralClient)

Example 24 with EntityExistsException

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

the class ReferralService method create.

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

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