Search in sources :

Example 1 with RecordReaderFactory

use of com.revolsys.record.io.RecordReaderFactory in project com.revolsys.open by revolsys.

the class FileRecordLayer method newPropertiesTabGeneralPanelSource.

@Override
protected ValueField newPropertiesTabGeneralPanelSource(final BasePanel parent) {
    final ValueField panel = super.newPropertiesTabGeneralPanelSource(parent);
    final String url = getUrl();
    if (url.startsWith("file:")) {
        final String fileName = url.replaceFirst("file:(//)?", "");
        SwingUtil.addLabelledReadOnlyTextField(panel, "File", fileName);
    } else {
        SwingUtil.addLabelledReadOnlyTextField(panel, "URL", url);
    }
    final String fileNameExtension = FileUtil.getFileNameExtension(url);
    if (Property.hasValue(fileNameExtension)) {
        SwingUtil.addLabelledReadOnlyTextField(panel, "File Extension", fileNameExtension);
        final RecordReaderFactory factory = IoFactory.factory(RecordReaderFactory.class, fileNameExtension);
        if (factory != null) {
            SwingUtil.addLabelledReadOnlyTextField(panel, "File Type", factory.getName());
        }
    }
    GroupLayouts.makeColumns(panel, 2, true);
    return panel;
}
Also used : ValueField(com.revolsys.swing.component.ValueField) RecordReaderFactory(com.revolsys.record.io.RecordReaderFactory)

Example 2 with RecordReaderFactory

use of com.revolsys.record.io.RecordReaderFactory in project com.revolsys.open by revolsys.

the class RecordReaderHttpMessageConverter method read.

@Override
public RecordReader read(final Class<? extends RecordReader> clazz, final HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
    try {
        final HttpHeaders headers = inputMessage.getHeaders();
        final MediaType mediaType = headers.getContentType();
        Charset charset = mediaType.getCharSet();
        if (charset == null) {
            charset = StandardCharsets.UTF_8;
        }
        final InputStream body = inputMessage.getBody();
        final String mediaTypeString = mediaType.getType() + "/" + mediaType.getSubtype();
        final RecordReaderFactory readerFactory = IoFactory.factoryByMediaType(RecordReaderFactory.class, mediaTypeString);
        if (readerFactory == null) {
            throw new HttpMessageNotReadableException("Cannot read data in format" + mediaType);
        } else {
            final Reader<Record> reader = readerFactory.newRecordReader(new InputStreamResource("recordInput", body));
            GeometryFactory factory = this.geometryFactory;
            final ServletWebRequest requestAttributes = (ServletWebRequest) RequestContextHolder.getRequestAttributes();
            final String srid = requestAttributes.getParameter("srid");
            if (srid != null && srid.trim().length() > 0) {
                factory = GeometryFactory.floating3d(Integer.parseInt(srid));
            }
            reader.setProperty(IoConstants.GEOMETRY_FACTORY, factory);
            return (RecordReader) reader;
        }
    } catch (final IOException e) {
        throw new HttpMessageNotReadableException("Error reading data", e);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) InputStream(java.io.InputStream) RecordReader(com.revolsys.record.io.RecordReader) Charset(java.nio.charset.Charset) IOException(java.io.IOException) RecordReaderFactory(com.revolsys.record.io.RecordReaderFactory) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) MediaType(org.springframework.http.MediaType) Record(com.revolsys.record.Record) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) InputStreamResource(com.revolsys.spring.resource.InputStreamResource)

Example 3 with RecordReaderFactory

use of com.revolsys.record.io.RecordReaderFactory in project com.revolsys.open by revolsys.

the class RecordIoTestSuite method doRecordReadTest.

private static void doRecordReadTest(final PathResource resource, final ArrayRecord record) {
    if (RecordReader.isReadable(resource)) {
        final RecordReaderFactory recordReaderFactory = IoFactory.factory(RecordReaderFactory.class, resource);
        try (RecordReader recordReader = RecordReader.newRecordReader(resource)) {
            final ClockDirection polygonRingDirection = recordReader.getPolygonRingDirection();
            final List<Record> records = recordReader.toList();
            Assert.assertEquals("Record Count", 1, records.size());
            final Record actualRecord = records.get(0);
            if (recordReaderFactory.isCustomFieldsSupported() && !(recordReader instanceof GeometryRecordReader)) {
                for (final String fieldName : record.getRecordDefinition().getFieldNames()) {
                    if (!fieldName.equals("GEOMETRY")) {
                        final Object expectedValue = record.getValue(fieldName);
                        final Object actualValue = actualRecord.getValue(fieldName);
                        final boolean equals = DataType.equal(expectedValue, actualValue);
                        com.revolsys.geometry.util.Assert.equals(fieldName, equals, expectedValue, actualValue);
                    }
                }
            }
            if (recordReaderFactory.isGeometrySupported()) {
                final Geometry expectedGeometry = record.getGeometry();
                final Geometry actualGeometry = actualRecord.getGeometry();
                assertGeometry(polygonRingDirection, expectedGeometry, actualGeometry);
            }
        }
    } else {
        Logs.debug(RecordIoTestSuite.class, "Reading geometry not supported for: " + resource.getFileNameExtension());
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) RecordReader(com.revolsys.record.io.RecordReader) GeometryRecordReader(com.revolsys.record.io.GeometryRecordReader) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) GeometryRecordReader(com.revolsys.record.io.GeometryRecordReader) RecordReaderFactory(com.revolsys.record.io.RecordReaderFactory) ClockDirection(com.revolsys.geometry.model.ClockDirection)

Aggregations

RecordReaderFactory (com.revolsys.record.io.RecordReaderFactory)3 Record (com.revolsys.record.Record)2 RecordReader (com.revolsys.record.io.RecordReader)2 ClockDirection (com.revolsys.geometry.model.ClockDirection)1 Geometry (com.revolsys.geometry.model.Geometry)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 ArrayRecord (com.revolsys.record.ArrayRecord)1 GeometryRecordReader (com.revolsys.record.io.GeometryRecordReader)1 InputStreamResource (com.revolsys.spring.resource.InputStreamResource)1 ValueField (com.revolsys.swing.component.ValueField)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Charset (java.nio.charset.Charset)1 HttpHeaders (org.springframework.http.HttpHeaders)1 MediaType (org.springframework.http.MediaType)1 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1