Search in sources :

Example 6 with ServiceException

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

the class CrossReportService 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.CrossReport create(Request request) {
    assert request instanceof gov.ca.cwds.rest.api.domain.cms.CrossReport;
    gov.ca.cwds.rest.api.domain.cms.CrossReport crossReport = (gov.ca.cwds.rest.api.domain.cms.CrossReport) request;
    try {
        String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
        CrossReport managed = new CrossReport(CmsKeyIdGenerator.cmsIdGenertor(lastUpdatedId), crossReport, lastUpdatedId);
        managed = crossReportDao.create(managed);
        return new gov.ca.cwds.rest.api.domain.cms.CrossReport(managed);
    } catch (EntityExistsException e) {
        LOGGER.info("CrossReport already exists : {}", crossReport);
        throw new ServiceException("CrossReport already exists : {}" + crossReport, e);
    }
}
Also used : CrossReport(gov.ca.cwds.data.persistence.cms.CrossReport) ServiceException(gov.ca.cwds.rest.services.ServiceException) EntityExistsException(javax.persistence.EntityExistsException)

Example 7 with ServiceException

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

the class LongTextService method create.

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

Example 8 with ServiceException

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

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

Example 9 with ServiceException

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

the class ReferralClientService method update.

@Override
public gov.ca.cwds.rest.api.domain.cms.ReferralClient update(Serializable primaryKeyObject, 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 {
        ReferralClient managed = new ReferralClient(referralClient, "BTr");
        // 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 (EntityNotFoundException e) {
        LOGGER.info("Referral not found : {}", referralClient);
        LOGGER.error(e.getMessage(), e);
        throw new ServiceException(e);
    }
}
Also used : StaffPerson(gov.ca.cwds.data.persistence.cms.StaffPerson) ServiceException(gov.ca.cwds.rest.services.ServiceException) EntityNotFoundException(javax.persistence.EntityNotFoundException) ReferralClient(gov.ca.cwds.data.persistence.cms.ReferralClient)

Example 10 with ServiceException

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

the class ReporterService 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.Reporter update(Serializable primaryKey, Request request) {
    assert primaryKey instanceof String;
    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.update(managed);
        return new gov.ca.cwds.rest.api.domain.cms.Reporter(managed);
    } catch (EntityNotFoundException e) {
        LOGGER.info("Reporter not found : {}", reporter);
        throw new ServiceException(e);
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedReporter(gov.ca.cwds.rest.api.domain.cms.PostedReporter) Reporter(gov.ca.cwds.data.persistence.cms.Reporter) 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