diff --git a/extensions/adapters/vector/src/main/java/mil/nga/giat/geowave/adapter/vector/KryoFeatureDataAdapter.java b/extensions/adapters/vector/src/main/java/mil/nga/giat/geowave/adapter/vector/KryoFeatureDataAdapter.java index 51ee13ba225..83204a99d7f 100644 --- a/extensions/adapters/vector/src/main/java/mil/nga/giat/geowave/adapter/vector/KryoFeatureDataAdapter.java +++ b/extensions/adapters/vector/src/main/java/mil/nga/giat/geowave/adapter/vector/KryoFeatureDataAdapter.java @@ -1,5 +1,6 @@ package mil.nga.giat.geowave.adapter.vector; +import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; @@ -7,6 +8,8 @@ import mil.nga.giat.geowave.adapter.vector.field.SimpleFeatureSerializationProvider; import mil.nga.giat.geowave.adapter.vector.plugin.visibility.AdaptorProxyFieldLevelVisibilityHandler; import mil.nga.giat.geowave.adapter.vector.plugin.visibility.JsonDefinitionColumnVisibilityManagement; +import mil.nga.giat.geowave.adapter.vector.stats.StatsConfigurationCollection.SimpleFeatureStatsConfigurationCollection; +import mil.nga.giat.geowave.adapter.vector.utils.SimpleFeatureUserDataConfigurationSet; import mil.nga.giat.geowave.adapter.vector.utils.TimeDescriptors; import mil.nga.giat.geowave.adapter.vector.utils.TimeDescriptors.TimeDescriptorConfiguration; import mil.nga.giat.geowave.core.geotime.store.dimension.Time; @@ -128,13 +131,33 @@ protected byte[] defaultTypeDataToBinary() { final byte[] typeNameBytes = StringUtils.stringToBinary(typeName); final byte[] visibilityManagementClassNameBytes = StringUtils.stringToBinary(fieldVisibilityManagement.getClass().getCanonicalName()); final byte[] encodedTypeBytes = StringUtils.stringToBinary(encodedType); - final ByteBuffer buf = ByteBuffer.allocate(encodedTypeBytes.length + typeNameBytes.length + visibilityManagementClassNameBytes.length + adapterId.getBytes().length + 16); + byte[] attrBytes = new byte[0]; + + final SimpleFeatureUserDataConfigurationSet userDataConfiguration = new SimpleFeatureUserDataConfigurationSet(); + userDataConfiguration.addConfigurations(new TimeDescriptorConfiguration( + featureType)); + userDataConfiguration.addConfigurations(new SimpleFeatureStatsConfigurationCollection( + featureType)); + try { + attrBytes = StringUtils.stringToBinary(userDataConfiguration.asJsonString()); + } + catch (final IOException e) { + LOGGER.error( + "Failure to encode simple feature user data configuration", + e); + } + + final ByteBuffer buf = ByteBuffer.allocate(encodedTypeBytes.length + typeNameBytes.length + visibilityManagementClassNameBytes.length + adapterId.getBytes().length + attrBytes.length + 24); + + buf.putInt(0); // a signal for the new version buf.putInt(typeNameBytes.length); buf.putInt(visibilityManagementClassNameBytes.length); + buf.putInt(attrBytes.length); buf.putInt(encodedTypeBytes.length); buf.putInt(adapterId.getBytes().length); buf.put(typeNameBytes); buf.put(visibilityManagementClassNameBytes); + buf.put(attrBytes); buf.put(encodedTypeBytes); buf.put(adapterId.getBytes()); return buf.array(); @@ -145,12 +168,17 @@ protected byte[] defaultTypeDataToBinary() { protected Object defaultTypeDataFromBinary( final byte[] bytes ) { final ByteBuffer buf = ByteBuffer.wrap(bytes); - final byte[] typeNameBytes = new byte[buf.getInt()]; + final int initialBytes = buf.getInt(); + // temporary hack for backward compatibility + boolean skipConfig = (initialBytes > 0); + final byte[] typeNameBytes = skipConfig ? new byte[initialBytes] : new byte[buf.getInt()]; final byte[] visibilityManagementClassNameBytes = new byte[buf.getInt()]; + final byte[] attrBytes = skipConfig ? new byte[0] : new byte[buf.getInt()]; final byte[] encodedTypeBytes = new byte[buf.getInt()]; final byte[] adapterIdBytes = new byte[buf.getInt()]; buf.get(typeNameBytes); buf.get(visibilityManagementClassNameBytes); + buf.get(attrBytes); buf.get(encodedTypeBytes); buf.get(adapterIdBytes); adapterId = new ByteArrayId( @@ -183,6 +211,23 @@ protected Object defaultTypeDataFromBinary( e); } + final SimpleFeatureUserDataConfigurationSet userDataConfiguration = new SimpleFeatureUserDataConfigurationSet(); + userDataConfiguration.addConfigurations(new TimeDescriptorConfiguration( + featureType)); + userDataConfiguration.addConfigurations(new SimpleFeatureStatsConfigurationCollection( + featureType)); + try { + userDataConfiguration.fromJsonString( + StringUtils.stringFromBinary(attrBytes), + featureType); + + } + catch (final IOException e) { + LOGGER.error( + "Failure to decode simple feature user data configuration", + e); + } + return null; }