use of gov.ca.cwds.rest.services.ServiceException 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);
}
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class ReferralService 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.Referral update(Serializable primaryKey, Request request) {
assert primaryKey instanceof String;
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((String) primaryKey, referral, lastUpdatedId);
managed = referralDao.update(managed);
// checking the staffPerson county code
StaffPerson staffperson = staffpersonDao.find(managed.getLastUpdatedId());
if (staffperson != null && (triggerTablesDao.getLaCountySpecificCode().equals(staffperson.getCountyCode()))) {
laCountyTrigger.createCountyTrigger(managed);
}
return new gov.ca.cwds.rest.api.domain.cms.Referral(managed);
} catch (EntityNotFoundException e) {
final String msg = "Referral not found : " + referral;
LOGGER.error("Referral not found : {}", referral);
throw new ServiceException(msg, e);
}
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class StaffPersonService method update.
/**
* {@inheritDoc}
*
* @see gov.ca.cwds.rest.services.CrudsService#update(java.io.Serializable,
* gov.ca.cwds.rest.api.Request)
*/
@Override
public StaffPerson update(Serializable primaryKey, Request request) {
assert primaryKey instanceof String;
assert request instanceof gov.ca.cwds.rest.api.domain.cms.StaffPerson;
gov.ca.cwds.rest.api.domain.cms.StaffPerson staffPerson = (gov.ca.cwds.rest.api.domain.cms.StaffPerson) request;
try {
String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
gov.ca.cwds.data.persistence.cms.StaffPerson managed = new gov.ca.cwds.data.persistence.cms.StaffPerson((String) primaryKey, staffPerson, lastUpdatedId);
managed = staffPersonDao.update(managed);
return new gov.ca.cwds.rest.api.domain.cms.StaffPerson(managed);
} catch (EntityNotFoundException e) {
LOGGER.info("StaffPerson not found : {}", staffPerson);
throw new ServiceException(e);
}
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class AllegationPerpetratorHistoryServiceTest method testCreateNullIDError.
@Override
@Test
public void testCreateNullIDError() throws Exception {
try {
AllegationPerpetratorHistory allegationPerpetratorHistoryDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/AllegationPerpetratorHistory/valid/valid.json"), AllegationPerpetratorHistory.class);
gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory toCreate = new gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory(null, allegationPerpetratorHistoryDomain, "ABC");
when(allegationPerpetratorHistoryDao.create(any(gov.ca.cwds.data.persistence.cms.AllegationPerpetratorHistory.class))).thenReturn(toCreate);
PostedAllegationPerpetratorHistory expected = new PostedAllegationPerpetratorHistory(toCreate);
} catch (ServiceException e) {
assertEquals("AllegationPerpetratorHistory ID cannot be blank", e.getMessage());
}
}
use of gov.ca.cwds.rest.services.ServiceException in project API by ca-cwds.
the class AllegationServiceTest method testCreateNullIDError.
@Override
@Test
public void testCreateNullIDError() throws Exception {
try {
Allegation allegationDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Allegation/valid/valid.json"), Allegation.class);
gov.ca.cwds.data.persistence.cms.Allegation toCreate = new gov.ca.cwds.data.persistence.cms.Allegation(null, allegationDomain, "ABC");
when(allegationDao.create(any(gov.ca.cwds.data.persistence.cms.Allegation.class))).thenReturn(toCreate);
PostedAllegation expected = new PostedAllegation(toCreate);
} catch (ServiceException e) {
assertEquals("Allegation ID cannot be blank", e.getMessage());
}
}
Aggregations