Search in sources :

Example 6 with FieldNotFoundException

use of org.motechproject.mds.exception.field.FieldNotFoundException in project motech by motech.

the class LookupReader method readFields.

private List<Field> readFields() throws IOException {
    List<Field> fields = new ArrayList<>();
    objectReader.expect("fields");
    jsonReader.beginArray();
    while (jsonReader.hasNext()) {
        String fieldName = jsonReader.nextString();
        Field field = entity.getField(fieldName);
        if (null != field) {
            fields.add(field);
        } else {
            throw new FieldNotFoundException(entity.getClassName(), fieldName);
        }
    }
    jsonReader.endArray();
    return fields;
}
Also used : Field(org.motechproject.mds.domain.Field) ArrayList(java.util.ArrayList) FieldNotFoundException(org.motechproject.mds.exception.field.FieldNotFoundException)

Example 7 with FieldNotFoundException

use of org.motechproject.mds.exception.field.FieldNotFoundException in project motech by motech.

the class EntityServiceImpl method findEntityFieldByName.

@Override
@Transactional
public FieldDto findEntityFieldByName(Long entityId, String name) {
    Entity entity = allEntities.retrieveById(entityId);
    Field field = entity.getField(name);
    if (field == null) {
        throw new FieldNotFoundException(entity.getClassName(), name);
    }
    return field.toDto();
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Field(org.motechproject.mds.domain.Field) FieldNotFoundException(org.motechproject.mds.exception.field.FieldNotFoundException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with FieldNotFoundException

use of org.motechproject.mds.exception.field.FieldNotFoundException in project motech by motech.

the class EntityServiceImpl method getEntityFieldById.

@Override
@Transactional
public FieldDto getEntityFieldById(Long entityId, Long fieldId) {
    Entity entity = allEntities.retrieveById(entityId);
    Field field = entity.getField(fieldId);
    if (field == null) {
        throw new FieldNotFoundException(entity.getClassName(), fieldId);
    }
    return field.toDto();
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) Field(org.motechproject.mds.domain.Field) FieldNotFoundException(org.motechproject.mds.exception.field.FieldNotFoundException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

FieldNotFoundException (org.motechproject.mds.exception.field.FieldNotFoundException)8 ArrayList (java.util.ArrayList)4 Field (org.motechproject.mds.domain.Field)4 FieldDto (org.motechproject.mds.dto.FieldDto)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Entity (org.motechproject.mds.domain.Entity)3 MdsEntity (org.motechproject.mds.domain.MdsEntity)3 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)3 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 CannotCompileException (javassist.CannotCompileException)1 EntityDto (org.motechproject.mds.dto.EntityDto)1 EntityInfo (org.motechproject.mds.entityinfo.EntityInfo)1 EntityNotFoundException (org.motechproject.mds.exception.entity.EntityNotFoundException)1 ObjectNotFoundException (org.motechproject.mds.exception.object.ObjectNotFoundException)1 ObjectReadException (org.motechproject.mds.exception.object.ObjectReadException)1 MotechDataService (org.motechproject.mds.service.MotechDataService)1