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);
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations