Search in sources :

Example 1 with PostedLongText

use of gov.ca.cwds.rest.api.domain.cms.PostedLongText 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 2 with PostedLongText

use of gov.ca.cwds.rest.api.domain.cms.PostedLongText in project API by ca-cwds.

the class LongTextServiceTest method testCreateBlankIDError.

@Override
@Test
public void testCreateBlankIDError() throws Exception {
    try {
        LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/LongText/valid/valid.json"), LongText.class);
        gov.ca.cwds.data.persistence.cms.LongText toCreate = new gov.ca.cwds.data.persistence.cms.LongText(" ", longTextDomain, "q27");
        when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(toCreate);
        PostedLongText expected = new PostedLongText(toCreate);
    } catch (ServiceException e) {
        assertEquals("LongText ID cannot be blank", e.getMessage());
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedLongText(gov.ca.cwds.rest.api.domain.cms.PostedLongText) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) PostedLongText(gov.ca.cwds.rest.api.domain.cms.PostedLongText) Test(org.junit.Test)

Example 3 with PostedLongText

use of gov.ca.cwds.rest.api.domain.cms.PostedLongText in project API by ca-cwds.

the class ScreeningToReferralService method createLongText.

private String createLongText(String countySpecificCode, String textDescription, Set<ErrorMessage> messages) throws ServiceException {
    LongText longText = new LongText(countySpecificCode, textDescription);
    PostedLongText postedLongText = longTextService.create(longText);
    buildErrors(messages, validator.validate(longText));
    return postedLongText.getId();
}
Also used : LongText(gov.ca.cwds.rest.api.domain.cms.LongText) PostedLongText(gov.ca.cwds.rest.api.domain.cms.PostedLongText) PostedLongText(gov.ca.cwds.rest.api.domain.cms.PostedLongText)

Example 4 with PostedLongText

use of gov.ca.cwds.rest.api.domain.cms.PostedLongText in project API by ca-cwds.

the class LongTextServiceTest method testCreateNullIDError.

@Override
@Test
public void testCreateNullIDError() throws Exception {
    try {
        LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/LongText/valid/valid.json"), LongText.class);
        gov.ca.cwds.data.persistence.cms.LongText toCreate = new gov.ca.cwds.data.persistence.cms.LongText(null, longTextDomain, "q27");
        when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(toCreate);
        PostedLongText expected = new PostedLongText(toCreate);
    } catch (ServiceException e) {
        assertEquals("LongText ID cannot be blank", e.getMessage());
    }
}
Also used : ServiceException(gov.ca.cwds.rest.services.ServiceException) PostedLongText(gov.ca.cwds.rest.api.domain.cms.PostedLongText) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) PostedLongText(gov.ca.cwds.rest.api.domain.cms.PostedLongText) Test(org.junit.Test)

Example 5 with PostedLongText

use of gov.ca.cwds.rest.api.domain.cms.PostedLongText in project API by ca-cwds.

the class LongTextServiceTest method testCreateReturnsNonNull.

@SuppressWarnings("javadoc")
@Test
public void testCreateReturnsNonNull() throws Exception {
    String id = "AaoDyiJq27";
    LongText longTextDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/LongText/valid/valid.json"), LongText.class);
    gov.ca.cwds.data.persistence.cms.LongText toCreate = new gov.ca.cwds.data.persistence.cms.LongText(id, longTextDomain, "q27");
    LongText request = new LongText(toCreate);
    when(longTextDao.create(any(gov.ca.cwds.data.persistence.cms.LongText.class))).thenReturn(toCreate);
    PostedLongText postedLongText = longTextService.create(request);
    assertThat(postedLongText, is(notNullValue()));
}
Also used : PostedLongText(gov.ca.cwds.rest.api.domain.cms.PostedLongText) LongText(gov.ca.cwds.rest.api.domain.cms.LongText) PostedLongText(gov.ca.cwds.rest.api.domain.cms.PostedLongText) Test(org.junit.Test)

Aggregations

PostedLongText (gov.ca.cwds.rest.api.domain.cms.PostedLongText)7 LongText (gov.ca.cwds.rest.api.domain.cms.LongText)6 Test (org.junit.Test)5 ServiceException (gov.ca.cwds.rest.services.ServiceException)3 LongText (gov.ca.cwds.data.persistence.cms.LongText)1 EntityExistsException (javax.persistence.EntityExistsException)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1