Search in sources :

Example 66 with FieldDto

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);
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) ValidationCriterionDto(org.motechproject.mds.dto.ValidationCriterionDto) FieldValidationDto(org.motechproject.mds.dto.FieldValidationDto) TypeDto(org.motechproject.mds.dto.TypeDto) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 67 with FieldDto

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;
}
Also used : FieldDto(org.motechproject.mds.dto.FieldDto) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 68 with FieldDto

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);
}
Also used : EntityInfo(org.motechproject.mds.entityinfo.EntityInfo) FieldNotFoundException(org.motechproject.mds.exception.field.FieldNotFoundException) EntityNotFoundException(org.motechproject.mds.exception.entity.EntityNotFoundException) FieldDto(org.motechproject.mds.dto.FieldDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 69 with FieldDto

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);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) DataExportException(org.motechproject.mds.exception.csv.DataExportException) MotechDataService(org.motechproject.mds.service.MotechDataService) FieldDto(org.motechproject.mds.dto.FieldDto)

Example 70 with FieldDto

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()]);
}
Also used : TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) 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