Search in sources :

Example 1 with NoSuchTypeException

use of org.motechproject.mds.exception.type.NoSuchTypeException in project motech by motech.

the class EntityServiceImpl method createFieldForDraft.

private void createFieldForDraft(EntityDraft draft, DraftData draftData) {
    String typeClass = draftData.getValue(DraftData.TYPE_CLASS).toString();
    String displayName = draftData.getValue(DraftData.DISPLAY_NAME).toString();
    String name = draftData.getValue(DraftData.NAME).toString();
    Type type = ("textArea".equalsIgnoreCase(typeClass)) ? allTypes.retrieveByClassName("java.lang.String") : allTypes.retrieveByClassName(typeClass);
    if (type == null) {
        throw new NoSuchTypeException(typeClass);
    }
    Set<Lookup> fieldLookups = new HashSet<>();
    Field field = new Field(draft, name, displayName, fieldLookups);
    field.setType(type);
    if (type.hasSettings()) {
        for (TypeSetting setting : type.getSettings()) {
            field.addSetting(new FieldSetting(field, setting));
        }
    }
    if (type.hasValidation()) {
        for (TypeValidation validation : type.getValidations()) {
            field.addValidation(new FieldValidation(field, validation));
        }
    }
    if (TypeDto.BLOB.getTypeClass().equals(typeClass)) {
        field.setUIDisplayable(false);
    } else {
        field.setUIDisplayable(true);
        field.setUIDisplayPosition((long) draft.getFields().size());
    }
    if ("textArea".equalsIgnoreCase(typeClass)) {
        setSettingForTextArea(field);
    }
    FieldHelper.addMetadataForRelationship(typeClass, field);
    FieldHelper.addOrUpdateMetadataForCombobox(field);
    draft.addField(field);
    allEntityDrafts.update(draft);
}
Also used : FieldSetting(org.motechproject.mds.domain.FieldSetting) Field(org.motechproject.mds.domain.Field) Type(org.motechproject.mds.domain.Type) TypeValidation(org.motechproject.mds.domain.TypeValidation) NoSuchTypeException(org.motechproject.mds.exception.type.NoSuchTypeException) TypeSetting(org.motechproject.mds.domain.TypeSetting) Lookup(org.motechproject.mds.domain.Lookup) FieldValidation(org.motechproject.mds.domain.FieldValidation) HashSet(java.util.HashSet)

Example 2 with NoSuchTypeException

use of org.motechproject.mds.exception.type.NoSuchTypeException in project motech by motech.

the class TypeServiceImpl method findType.

@Override
@Transactional
public TypeDto findType(Class<?> clazz) {
    String className = getClassNameForType(clazz);
    Type type = allTypes.retrieveByClassName(className);
    if (null != type) {
        return type.toDto();
    } else {
        throw new NoSuchTypeException(clazz.getCanonicalName());
    }
}
Also used : Type(org.motechproject.mds.domain.Type) NoSuchTypeException(org.motechproject.mds.exception.type.NoSuchTypeException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Type (org.motechproject.mds.domain.Type)2 NoSuchTypeException (org.motechproject.mds.exception.type.NoSuchTypeException)2 HashSet (java.util.HashSet)1 Field (org.motechproject.mds.domain.Field)1 FieldSetting (org.motechproject.mds.domain.FieldSetting)1 FieldValidation (org.motechproject.mds.domain.FieldValidation)1 Lookup (org.motechproject.mds.domain.Lookup)1 TypeSetting (org.motechproject.mds.domain.TypeSetting)1 TypeValidation (org.motechproject.mds.domain.TypeValidation)1 Transactional (org.springframework.transaction.annotation.Transactional)1