use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method getFields.
private List<FieldDto> getFields(Long entityId, boolean forDraft, boolean forUi) {
Entity entity = (forDraft) ? getEntityDraft(entityId) : allEntities.retrieveById(entityId);
assertEntityExists(entity, entityId);
// the returned collection is unmodifiable
List<Field> fields = new ArrayList<>(entity.getFields());
// for data browser purposes, we sort the fields by their ui display order
if (!forDraft) {
Collections.sort(fields, new UIDisplayFieldComparator());
}
// if it's for the UI, then we add combobox options
List<FieldDto> fieldDtos = toFieldDtos(entity, fields, forUi);
return addNonPersistentFieldsData(fieldDtos, entity);
}
use of org.motechproject.mds.domain.Field 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.domain.Field in project motech by motech.
the class EntityServiceImpl method findFieldByName.
@Override
@Transactional
public FieldDto findFieldByName(Long entityId, String name) {
Entity entity = getEntityDraft(entityId);
Field field = entity.getField(name);
if (field == null) {
throw new FieldNotFoundException(entity.getClassName(), name);
}
return field.toDto();
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method addNonEditableFields.
@Override
@Transactional
public void addNonEditableFields(EntityDto entityDto, Map<String, Boolean> nonEditableFields) {
Entity entity = allEntities.retrieveById(entityDto.getId());
assertEntityExists(entity, entityDto.getId());
List<Field> fields = entity.getFields();
for (Field field : fields) {
boolean isNonEditable = nonEditableFields.containsKey(field.getName());
Boolean display = nonEditableFields.get(field.getName());
field.setNonEditable(isNonEditable);
if (display != null) {
field.setNonDisplayable(!display);
} else {
field.setNonDisplayable(false);
}
}
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class EntityServiceImpl method getDisplayFields.
@Override
@Transactional
public List<FieldDto> getDisplayFields(Long entityId) {
Entity entity = allEntities.retrieveById(entityId);
assertEntityExists(entity, entityId);
List<Field> displayFields = new ArrayList<>(entity.getFields());
CollectionUtils.filter(displayFields, new Predicate() {
@Override
public boolean evaluate(Object object) {
Field field = (Field) object;
return field.isUIDisplayable() && !field.isNonDisplayable();
}
});
return toFieldDtos(entity, displayFields, true);
}
Aggregations