Search in sources :

Example 6 with EntityNotFoundException

use of org.motechproject.mds.exception.entity.EntityNotFoundException in project motech by motech.

the class ComboboxValueServiceImpl method getAllValuesForCombobox.

@Override
@Transactional
public List<String> getAllValuesForCombobox(String entityClassName, String fieldName) {
    EntityInfo entityInfo = entityInfoReader.getEntityInfo(entityClassName);
    if (entityInfo == null) {
        throw new EntityNotFoundException(entityClassName);
    }
    FieldDto field = entityInfo.getField(fieldName).getField();
    if (field == null) {
        throw new FieldNotFoundException(entityClassName, fieldName);
    } else if (!field.getType().isCombobox()) {
        throw new IllegalArgumentException("Field " + fieldName + "in entity " + entityClassName + " is not a combobx field");
    }
    return getAllValuesForCombobox(entityInfo.getEntity(), field);
}
Also used : EntityInfo(org.motechproject.mds.entityinfo.EntityInfo) FieldNotFoundException(org.motechproject.mds.exception.field.FieldNotFoundException) EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) FieldDto(org.motechproject.mds.dto.FieldDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with EntityNotFoundException

use of org.motechproject.mds.exception.entity.EntityNotFoundException in project motech by motech.

the class EntityControllerTest method shouldNotFindFieldByNameIfEntityNotExists.

@Test
public void shouldNotFindFieldByNameIfEntityNotExists() throws Exception {
    doThrow(new EntityNotFoundException(500L)).when(entityService).findFieldByName(500L, "ID");
    controller.perform(get("/entities/500/fields/ID")).andExpect(status().isConflict()).andExpect(content().string(ENTITY_NOT_FOUND));
}
Also used : EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) Test(org.junit.Test)

Example 8 with EntityNotFoundException

use of org.motechproject.mds.exception.entity.EntityNotFoundException in project motech by motech.

the class EntityControllerTest method shouldNotComitChangesIfEntityNotExists.

@Test
public void shouldNotComitChangesIfEntityNotExists() throws Exception {
    doThrow(new EntityNotFoundException(10000L)).when(entityService).commitChanges(10000L);
    controller.perform(post("/entities/10000/commit").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isConflict()).andExpect(content().string(ENTITY_NOT_FOUND));
}
Also used : EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) Test(org.junit.Test)

Example 9 with EntityNotFoundException

use of org.motechproject.mds.exception.entity.EntityNotFoundException in project motech by motech.

the class EntityControllerTest method shouldThrowExceptionIfEntityToDeleteNotExists.

@Test
public void shouldThrowExceptionIfEntityToDeleteNotExists() throws Exception {
    doThrow(new EntityNotFoundException(1000L)).when(entityService).deleteEntity(1000L);
    controller.perform(delete("/entities/1000")).andExpect(status().isConflict()).andExpect(content().string(ENTITY_NOT_FOUND));
}
Also used : EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) Test(org.junit.Test)

Aggregations

EntityNotFoundException (org.motechproject.mds.exception.entity.EntityNotFoundException)9 Test (org.junit.Test)7 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 DraftData (org.motechproject.mds.dto.DraftData)1 FieldDto (org.motechproject.mds.dto.FieldDto)1 EntityInfo (org.motechproject.mds.entityinfo.EntityInfo)1 FieldNotFoundException (org.motechproject.mds.exception.field.FieldNotFoundException)1 BasicHistoryRecord (org.motechproject.mds.web.domain.BasicHistoryRecord)1 HistoryRecord (org.motechproject.mds.web.domain.HistoryRecord)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1