Skip to content

Commit

Permalink
Merge pull request #648 from ngageoint/GEOWAVE-647
Browse files Browse the repository at this point in the history
Issue #647 WholeFeatureDataAdapter persists time configuration
  • Loading branch information
rwgdrummer committed Feb 27, 2016
2 parents 3ff8dfc + 17f115e commit 293ee1a
Showing 1 changed file with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package mil.nga.giat.geowave.adapter.vector;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

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;
Expand Down Expand Up @@ -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();
Expand All @@ -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(
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 293ee1a

Please sign in to comment.