use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class FieldHelperTest method fieldDto.
private FieldDto fieldDto() {
TypeDto type = new TypeDto("typeDispName", "typeDesc", "typeDefaultName", "typeClass");
FieldBasicDto basic = new FieldBasicDto("fieldDispName", "fieldName", true, false, "defVal", "tooltip", "placeholder");
MetadataDto metadata = new MetadataDto("key", "val");
ValidationCriterionDto criterion = new ValidationCriterionDto("criterionDispName", type);
FieldValidationDto validation = new FieldValidationDto(criterion);
return new FieldDto(1L, 100L, type, basic, false, new ArrayList<>(asList(metadata)), validation, null, null);
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class EntityController method getFieldByName.
@RequestMapping(value = "entities/{entityId}/fields/{name}", method = RequestMethod.GET)
@PreAuthorize(Roles.HAS_DATA_OR_SCHEMA_ACCESS)
@ResponseBody
public FieldDto getFieldByName(@PathVariable Long entityId, @PathVariable String name) {
FieldDto field = entityService.findFieldByName(entityId, name);
processFieldForUI(field);
return field;
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class ComboboxValueServiceImpl method getAllValuesForCombobox.
@Override
@Transactional
public List<String> getAllValuesForCombobox(String entityClassName, String fieldName) {
EntityInfo entityInfo = entityInfoReader.getEntityInfo(entityClassName);
if (entityInfo == null) {
throw new EntityNotFoundException(entityClassName);
}
FieldDto field = entityInfo.getField(fieldName).getField();
if (field == null) {
throw new FieldNotFoundException(entityClassName, fieldName);
} else if (!field.getType().isCombobox()) {
throw new IllegalArgumentException("Field " + fieldName + "in entity " + entityClassName + " is not a combobx field");
}
return getAllValuesForCombobox(entityInfo.getEntity(), field);
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class AbstractMdsExporter method exportData.
protected long exportData(EntityInfo entityInfo, TableWriter writer, String lookupName, QueryParams params, List<String> headers, Map<String, Object> lookupFields, CsvExportCustomizer exportCustomizer) {
final MotechDataService dataService = DataServiceHelper.getDataService(bundleContext, entityInfo.getClassName());
final Map<String, FieldDto> fieldMap = new HashMap<>();
for (FieldDto field : entityInfo.getFieldDtos()) {
fieldMap.put(exportCustomizer.exportDisplayName(field), field);
}
// we must respect field ordering
String[] orderedHeaders = orderHeaders(entityInfo.getAdvancedSettings().getBrowsing(), headers == null ? fieldsToHeaders(entityInfo.getFieldDtos(), exportCustomizer) : headers.toArray(new String[headers.size()]), entityInfo.getFieldDtos(), exportCustomizer);
try {
writer.writeHeader(orderedHeaders);
long rowsExported = 0;
Map<String, String> row = new HashMap<>();
List<Object> instances = StringUtils.isBlank(lookupName) ? dataService.retrieveAll(params) : mdsLookupService.findMany(entityInfo.getClassName(), lookupName, lookupFields, params);
for (Object instance : instances) {
buildCsvRow(row, fieldMap, instance, orderedHeaders, exportCustomizer);
writer.writeRow(row, orderedHeaders);
rowsExported++;
}
return rowsExported;
} catch (IOException e) {
throw new DataExportException("IO Error when writing data", e);
}
}
use of org.motechproject.mds.dto.FieldDto in project motech by motech.
the class AbstractMdsExporter method orderHeaders.
protected String[] orderHeaders(BrowsingSettingsDto browsingSettingsDtos, String[] selectedHeaders, List<FieldDto> entityFields, CsvExportCustomizer customizer) {
Set<String> selectedHeadersSet = new HashSet<>(Arrays.asList(selectedHeaders));
TreeSet<FieldDto> orderedFields = new TreeSet<>(customizer.columnOrderComparator(browsingSettingsDtos));
for (FieldDto field : entityFields) {
if (selectedHeadersSet.contains(customizer.exportDisplayName(field))) {
orderedFields.add(field);
}
}
// after ordering, we are only interested in field names
List<String> headers = new ArrayList<>();
for (FieldDto field : orderedFields) {
headers.add(customizer.exportDisplayName(field));
}
return headers.toArray(new String[headers.size()]);
}
Aggregations