Search in sources :

Example 36 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class EntityServiceImpl method editFieldForDraft.

private void editFieldForDraft(EntityDraft draft, DraftData draftData) {
    String fieldIdStr = draftData.getValue(DraftData.FIELD_ID).toString();
    if (StringUtils.isNotBlank(fieldIdStr)) {
        Long fieldId = Long.valueOf(fieldIdStr);
        Field field = draft.getField(fieldId);
        if (field != null) {
            String path = draftData.getPath();
            List value = (List) draftData.getValue(DraftData.VALUE);
            // Convert to dto for UI updates
            FieldDto dto = field.toDto();
            dto.setUiChanged(true);
            FieldHelper.setField(dto, path, value);
            // If field name was changed add this change to map
            if (NAME_PATH.equals(path)) {
                draft.addFieldNameChange(field.getName(), value.get(0).toString());
                List<LookupDto> lookups = draft.advancedSettingsDto().getIndexes();
                // Perform update
                field.update(dto);
                // we need update fields name in lookup fieldsOrder
                draft.updateIndexes(lookups);
                FieldHelper.addOrUpdateMetadataForCombobox(field);
            } else if (UNIQUE_PATH.equals(path)) {
                // check if unique was removed on this field
                boolean originalUnique = false;
                Field originalField = draft.getParentEntity().getField(field.getName());
                if (originalField != null) {
                    originalUnique = originalField.isUnique();
                }
                boolean newVal = (boolean) value.get(0);
                if (originalUnique && !newVal) {
                    // we will be dropping the unique constraint for this field
                    draft.addUniqueToRemove(field.getName());
                }
                // Perform update
                field.update(dto);
            } else if (REQUIRED_PATH.equals(path)) {
                Field originalField = draft.getParentEntity().getField(field.getName());
                handleRequiredChanges(originalField, draft, value, field);
                // Perform update
                field.update(dto);
            } else {
                // Perform update
                field.update(dto);
            }
            allEntityDrafts.update(draft);
        }
    }
}
Also used : Field(org.motechproject.mds.domain.Field) LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) List(java.util.List) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 37 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class EntityServiceImpl method getSchema.

@Override
@Transactional
public SchemaHolder getSchema() {
    StopWatch stopWatch = new StopWatch();
    SchemaHolder entitiesHolder = new SchemaHolder();
    LOGGER.debug("Retrieving entities for processing");
    stopWatch.start();
    List<Entity> entities = allEntities.getActualEntities();
    stopWatch.stop();
    LOGGER.debug("{} entities retrieved in {} ms", entities.size(), stopWatch.getTime());
    StopWatchHelper.restart(stopWatch);
    for (Entity entity : entities) {
        LOGGER.debug("Preparing entity: {}", entity.getClassName());
        StopWatchHelper.restart(stopWatch);
        EntityDto entityDto = entity.toDto();
        stopWatch.stop();
        LOGGER.debug("Entity dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        AdvancedSettingsDto advSettingsDto = entity.advancedSettingsDto();
        stopWatch.stop();
        LOGGER.debug("Advanced settings dto created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        List<FieldDto> fieldDtos = entity.getFieldDtos();
        stopWatch.stop();
        LOGGER.debug("Field dtos created in {} ms", stopWatch.getTime());
        StopWatchHelper.restart(stopWatch);
        entitiesHolder.addEntity(entityDto, advSettingsDto, fieldDtos);
        stopWatch.stop();
        LOGGER.debug("Result stored in {} ms", stopWatch.getTime());
    }
    LOGGER.debug("Retrieving types for processing");
    List<Type> types = allTypes.retrieveAll();
    for (Type type : types) {
        TypeDto typeDto = type.toDto();
        entitiesHolder.addType(typeDto);
        entitiesHolder.addTypeValidation(typeDto, type.getTypeValidationDtos());
    }
    LOGGER.debug("Entities holder ready");
    return entitiesHolder;
}
Also used : MdsEntity(org.motechproject.mds.domain.MdsEntity) Entity(org.motechproject.mds.domain.Entity) MdsVersionedEntity(org.motechproject.mds.domain.MdsVersionedEntity) EntityDto(org.motechproject.mds.dto.EntityDto) Type(org.motechproject.mds.domain.Type) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) TypeDto(org.motechproject.mds.dto.TypeDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) StopWatch(org.apache.commons.lang.time.StopWatch) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class EntityServiceImpl method toFieldDtos.

private List<FieldDto> toFieldDtos(Entity entity, List<Field> fields, boolean fetchComboboxOptions) {
    List<FieldDto> fieldDtos = new ArrayList<>();
    for (Field field : fields) {
        FieldDto fieldDto = field.toDto();
        if (fetchComboboxOptions && field.getType().isCombobox()) {
            List<String> values = getAllComboboxValues(entity, field);
            fieldDto.setSetting(Constants.Settings.COMBOBOX_VALUES, values);
        }
        fieldDtos.add(fieldDto);
    }
    return fieldDtos;
}
Also used : Field(org.motechproject.mds.domain.Field) ArrayList(java.util.ArrayList) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 39 with FieldDto

use of org.motechproject.mds.dto.FieldDto 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 40 with FieldDto

use of org.motechproject.mds.dto.FieldDto in project motech by motech.

the class MdsBundleIT method createEntityForPreferencesTest.

private EntityDto createEntityForPreferencesTest() {
    EntityDto entityDto = new EntityDto(null, FOO);
    entityDto = entityService.createEntity(entityDto);
    SchemaHolder schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder);
    List<FieldDto> fields = new ArrayList<>();
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.BOOLEAN, new FieldBasicDto("Some Boolean", "someBoolean"), false, false, false, false, false, null, null, null, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("Some String", "someString"), false, false, false, false, false, null, null, asList(new SettingDto("mds.form.label.textarea", false, BOOLEAN)), null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("Some Integer", "someInteger"), false, false, false, false, false, null, null, null, null));
    fields.add(new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("Other Integer", "otherInteger"), false, false, false, false, false, null, null, null, null));
    entityService.addFields(entityDto, fields);
    Map<String, Long> displayedFields = new HashMap<>();
    displayedFields.put("someInteger", 1L);
    displayedFields.put("someBoolean", 2L);
    displayedFields.put("someString", 3L);
    entityService.addDisplayedFields(entityDto, displayedFields);
    schemaHolder = entityService.getSchema();
    generator.regenerateMdsDataBundle(schemaHolder);
    return entityDto;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) SettingDto(org.motechproject.mds.dto.SettingDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Aggregations

FieldDto (org.motechproject.mds.dto.FieldDto)158 Test (org.junit.Test)61 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)60 EntityDto (org.motechproject.mds.dto.EntityDto)53 ArrayList (java.util.ArrayList)47 LookupDto (org.motechproject.mds.dto.LookupDto)29 List (java.util.List)23 MetadataDto (org.motechproject.mds.dto.MetadataDto)22 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)19 TypeDto (org.motechproject.mds.dto.TypeDto)17 Method (java.lang.reflect.Method)14 MotechDataService (org.motechproject.mds.service.MotechDataService)14 HashMap (java.util.HashMap)12 Field (org.motechproject.mds.domain.Field)12 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)12 Arrays.asList (java.util.Arrays.asList)11 SettingDto (org.motechproject.mds.dto.SettingDto)11 Before (org.junit.Before)7 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)7