Search in sources :

Example 16 with ServiceException

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

Example 17 with ServiceException

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

the class ChildClientService 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.ChildClient update(Serializable primaryKey, 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;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        ChildClient managed = new ChildClient(childClient.getVictimClientId(), childClient, lastUpdatedId);
        managed = childClientDao.update(managed);
        return new gov.ca.cwds.rest.api.domain.cms.ChildClient(managed);
    } catch (EntityNotFoundException e) {
        LOGGER.info("childClient not found : {}", childClient);
        throw new ServiceException(e);
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) EntityNotFoundException(javax.persistence.EntityNotFoundException) ChildClient(gov.ca.cwds.data.persistence.cms.ChildClient)

Example 18 with ServiceException

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

the class ClientAddressService method update.

@Override
public Response update(Serializable primaryKey, Request request) {
    assert primaryKey instanceof String;
    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 {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        ClientAddress managed = new ClientAddress((String) primaryKey, clientAddress, lastUpdatedId);
        // checking the staffPerson county code
        StaffPerson staffperson = staffpersonDao.find(managed.getLastUpdatedId());
        if (staffperson != null && (triggerTablesDao.getLaCountySpecificCode().equals(staffperson.getCountyCode()))) {
            laCountyTrigger.createClientAddressCountyTrigger(managed);
        }
        managed = clientAddressDao.update(managed);
        return new gov.ca.cwds.rest.api.domain.cms.ClientAddress(managed, true);
    } catch (EntityNotFoundException e) {
        LOGGER.info("ClientAddress not found : {}", clientAddress);
        throw new ServiceException(e);
    }
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) ClientAddress(gov.ca.cwds.data.persistence.cms.ClientAddress) EntityNotFoundException(javax.persistence.EntityNotFoundException) ServiceException(gov.ca.cwds.rest.services.ServiceException)

Example 19 with ServiceException

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

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

Example 20 with ServiceException

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

the class AllegationService method create.

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

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