Search in sources :

Example 1 with FieldInfo

use of org.motechproject.mds.entityinfo.FieldInfo in project motech by motech.

the class JarGeneratorServiceImpl method getFieldsInfo.

private List<FieldInfo> getFieldsInfo(EntityDto entity, List<FieldDto> fields, AdvancedSettingsDto advancedSettings) {
    List<FieldInfo> fieldsInfo = new ArrayList<>();
    Collections.sort(fields, new UIDisplayFieldComparator(advancedSettings.getBrowsing().getDisplayedFields()));
    for (FieldDto field : fields) {
        FieldInfo fieldInfo = new FieldInfo();
        fieldInfo.setField(field);
        boolean exposedByRest = advancedSettings.isFieldExposedByRest(field.getBasic().getName());
        fieldInfo.setRestExposed(exposedByRest);
        FieldInfo.TypeInfo typeInfo = fieldInfo.getTypeInfo();
        typeInfo.setType(field.getType().getTypeClass());
        typeInfo.setTaskType(ActionParameterTypeResolver.resolveType(entity, field));
        // combobox values
        typeInfo.setCombobox(field.getType().isCombobox());
        if (field.getType().isCombobox()) {
            ComboboxHolder cbHolder = new ComboboxHolder(entity, field);
            String[] items = cbHolder.getValues();
            if (ArrayUtils.isNotEmpty(items)) {
                typeInfo.setItems(Arrays.asList(items));
            }
            typeInfo.setAllowsMultipleSelection(cbHolder.isCollection());
            typeInfo.setAllowUserSupplied(cbHolder.isAllowUserSupplied());
        }
        fieldsInfo.add(fieldInfo);
    }
    return fieldsInfo;
}
Also used : ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder) ArrayList(java.util.ArrayList) FieldInfo(org.motechproject.mds.entityinfo.FieldInfo) UIDisplayFieldComparator(org.motechproject.mds.dto.UIDisplayFieldComparator) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 2 with FieldInfo

use of org.motechproject.mds.entityinfo.FieldInfo in project motech by motech.

the class DefaultMotechDataService method init.

@PostConstruct
public void init() {
    debug("Initializing {}", getClass().getName());
    EntityInfo entityInfo = entityInfoReader.getEntityInfo(repository.getClassType().getName());
    securityMode = entityInfo.getSecurityMode();
    schemaVersion = entityInfo.getSchemaVersion();
    recordHistory = entityInfo.isRecordHistory();
    allowCreateEvent = entityInfo.isCreateEventFired();
    allowUpdateEvent = entityInfo.isUpdateEventFired();
    allowDeleteEvent = entityInfo.isDeleteEventFired();
    module = entityInfo.getModule();
    entityName = entityInfo.getEntityName();
    namespace = entityInfo.getNamespace();
    // we need the field types for handling lookups with null values
    Map<String, String> fieldTypeMap = new HashMap<>();
    for (FieldInfo field : entityInfo.getFieldsInfo()) {
        fieldTypeMap.put(field.getName(), field.getType());
        if (field.isVersionField()) {
            versionFieldName = field.getName();
        }
    }
    repository.setFieldTypeMap(fieldTypeMap);
    debug("{} ready", getClass().getName());
}
Also used : HashMap(java.util.HashMap) EntityInfo(org.motechproject.mds.entityinfo.EntityInfo) FieldInfo(org.motechproject.mds.entityinfo.FieldInfo) PostConstruct(javax.annotation.PostConstruct)

Example 3 with FieldInfo

use of org.motechproject.mds.entityinfo.FieldInfo in project motech by motech.

the class FieldTestHelper method fieldInfo.

public static FieldInfo fieldInfo(String name, Class typeClass, boolean required, boolean restExposed, boolean autoGenerated) {
    FieldInfo field = new FieldInfo();
    FieldDto fieldDto = new FieldDto();
    fieldDto.setBasic(new FieldBasicDto());
    fieldDto.getBasic().setName(name);
    fieldDto.getBasic().setDisplayName(name + " disp");
    fieldDto.getBasic().setRequired(required);
    TypeDto type = new TypeDto();
    type.setTypeClass(typeClass.getName());
    fieldDto.setType(type);
    field.setRestExposed(restExposed);
    if (autoGenerated) {
        fieldDto.addMetadata(new MetadataDto(Constants.Util.AUTO_GENERATED, Constants.Util.TRUE));
    }
    field.setField(fieldDto);
    field.getTypeInfo().setType(typeClass.getName());
    return field;
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) TypeDto(org.motechproject.mds.dto.TypeDto) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldInfo(org.motechproject.mds.entityinfo.FieldInfo) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 4 with FieldInfo

use of org.motechproject.mds.entityinfo.FieldInfo in project motech by motech.

the class BaseInstanceIT method createService.

private MotechDataService createService() throws Exception {
    Object repository = MDSClassLoader.getInstance().loadClass(getRepositoryClass()).newInstance();
    Object service = MDSClassLoader.getInstance().loadClass(getServiceClass()).newInstance();
    EntityInfoReader entityInfoReader = new EntityInfoReader() {

        @Override
        public EntityInfo getEntityInfo(String entityClassName) {
            return buildEntityInfo();
        }

        @Override
        public EntityInfo getEntityInfo(Long entityId) {
            return buildEntityInfo();
        }

        @Override
        public Collection<String> getEntitiesClassNames() {
            List<String> classNames = new ArrayList<>();
            classNames.add(entity.getClassName());
            return classNames;
        }

        private EntityInfo buildEntityInfo() {
            EntityInfo info = new EntityInfo();
            info.setEntity(entity);
            info.setAdvancedSettings(new AdvancedSettingsDto());
            List<FieldInfo> fieldInfos = new ArrayList<>();
            for (FieldDto fieldDto : getEntityFields()) {
                FieldInfo fieldInfo = new FieldInfo();
                fieldInfo.setField(fieldDto);
                fieldInfos.add(fieldInfo);
            }
            info.setFieldsInfo(fieldInfos);
            return info;
        }
    };
    PropertyUtil.safeSetProperty(repository, "persistenceManagerFactory", getDataPersistenceManagerFactory());
    PropertyUtil.safeSetProperty(service, "transactionManager", getDataTransactionManager());
    PropertyUtil.safeSetProperty(service, "repository", repository);
    PropertyUtil.safeSetProperty(service, "entityInfoReader", entityInfoReader);
    PropertyUtil.safeSetProperty(service, "historyService", getHistoryService());
    PropertyUtil.safeSetProperty(service, "trashService", getTrashService());
    PropertyUtil.safeSetProperty(service, "osgiEventProxy", getOsgiEventProxy());
    MotechDataService mds = (MotechDataService) service;
    ((DefaultMotechDataService) mds).init();
    return mds;
}
Also used : ArrayList(java.util.ArrayList) DefaultMotechDataService(org.motechproject.mds.service.DefaultMotechDataService) MotechDataService(org.motechproject.mds.service.MotechDataService) EntityInfoReader(org.motechproject.mds.entityinfo.EntityInfoReader) EntityInfo(org.motechproject.mds.entityinfo.EntityInfo) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) DefaultMotechDataService(org.motechproject.mds.service.DefaultMotechDataService) FieldInfo(org.motechproject.mds.entityinfo.FieldInfo) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 5 with FieldInfo

use of org.motechproject.mds.entityinfo.FieldInfo in project motech by motech.

the class RevertConverter method convert.

@Override
public Object convert(Object value, PropertyDescriptor descriptor) {
    FieldInfo field = entityInfo.getField(descriptor.getName());
    FieldDto fieldDto = field.getField();
    if (value == null || field == null || !fieldDto.getType().isRelationship()) {
        return value;
    } else {
        RelationshipHolder relHolder = new RelationshipHolder(fieldDto);
        String relatedClass = relHolder.getRelatedClass();
        MotechDataService relatedDataService = ServiceUtil.getServiceFromAppContext(applicationContext, relatedClass);
        if (value instanceof Collection) {
            Collection<Long> idColl = (Collection<Long>) value;
            return idCollToRelColl(idColl, relatedDataService);
        } else {
            Long id = (Long) value;
            return relatedDataService.findById(id);
        }
    }
}
Also used : RelationshipHolder(org.motechproject.mds.domain.RelationshipHolder) Collection(java.util.Collection) FieldInfo(org.motechproject.mds.entityinfo.FieldInfo) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

FieldInfo (org.motechproject.mds.entityinfo.FieldInfo)5 FieldDto (org.motechproject.mds.dto.FieldDto)4 ArrayList (java.util.ArrayList)2 EntityInfo (org.motechproject.mds.entityinfo.EntityInfo)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 ComboboxHolder (org.motechproject.mds.domain.ComboboxHolder)1 RelationshipHolder (org.motechproject.mds.domain.RelationshipHolder)1 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)1 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)1 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)1 MetadataDto (org.motechproject.mds.dto.MetadataDto)1 TypeDto (org.motechproject.mds.dto.TypeDto)1 UIDisplayFieldComparator (org.motechproject.mds.dto.UIDisplayFieldComparator)1 EntityInfoReader (org.motechproject.mds.entityinfo.EntityInfoReader)1 DefaultMotechDataService (org.motechproject.mds.service.DefaultMotechDataService)1 MotechDataService (org.motechproject.mds.service.MotechDataService)1