Skip to content

Commit

Permalink
added date type converter for DSVImport
Browse files Browse the repository at this point in the history
  • Loading branch information
breinero committed Jan 24, 2016
1 parent e2eba3c commit dbfe810
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .gitignore
@@ -1,5 +1,5 @@
.idea/
.gradle/
build/
Firehose.iml
test.csv
gradle/
**build
**.iml
Expand Up @@ -9,7 +9,9 @@

import com.bryanreinero.firehose.cli.CallBack;
import com.bryanreinero.firehose.dao.DataAccessHub;
import com.bryanreinero.firehose.dao.DataStore;
import com.bryanreinero.firehose.dao.mongo.MongoDAO;
import com.bryanreinero.firehose.dao.mongo.Read;
import com.bryanreinero.firehose.dao.mongo.Write;
import com.bryanreinero.firehose.metrics.Interval;
import com.bryanreinero.firehose.metrics.SampleSet;
Expand All @@ -18,6 +20,8 @@
import com.mongodb.MongoClient;
import org.bson.Document;

import javax.naming.NamingException;

public class Firehose {

private static final String appName = "Firehose";
Expand All @@ -29,13 +33,16 @@ public class Firehose {
private Converter converter = new Converter();
private BufferedReader br = null;

private final DataAccessHub dataHub;
private final String SFCabDB = "127.0.0.1:27017";

private Boolean verbose = false;
private String filename = null;

private AtomicBoolean running = new AtomicBoolean( true );

private MongoDAO<MongoDAO, Read> logDAO
= new MongoDAO( "insert", "SFCabDB", "SFCab.GPSLog", MongoDAO.class );

private void unitOfWork() {

String currentLine = null;
Expand Down Expand Up @@ -65,10 +72,13 @@ private void unitOfWork() {
object = converter.convert(currentLine);
}

Write<Document> op = new Write<Document>(
object,
(MongoDAO) DataAccessHub.INSTANCE.getDescriptor( "insert" ) );
op.setSamples( app.getSampleSet() );

// Insert the new Document
app.getThreadPool().submitTask(
new Write<Document>(object, (MongoDAO) dataHub.getDescriptor("insert"))
);
app.getThreadPool().submitTask( op );
}
}
}
Expand All @@ -77,7 +87,7 @@ public void parseCommandLineArgs( String[] args ) {
app.parseCommandLineArgs( args );
}

public Firehose () {
public Firehose () throws Exception {

app = new Application( appName );

Expand Down Expand Up @@ -121,11 +131,12 @@ public void handle(String[] values) {
stats = new Statistics( samples );

// Initialize the connection to the DB
dataHub = new DataAccessHub();
dataHub.addCluster( "test", new MongoClient() );
MongoDAO d = new MongoDAO<Document, Write>( "insert", "test", "firehose.csv" );
d.setSamples( app.getSampleSet() );
dataHub.addDAO( d );
DataAccessHub.INSTANCE.setDataStore(
new DataStore( "SFCabDB", appName, SFCabDB, DataStore.Type.mongodb )
);

logDAO.setSamples( app.getSampleSet() );
DataAccessHub.INSTANCE.setDao( logDAO );

app.addPrinable(this);
}
Expand Down
@@ -1,5 +1,6 @@
package com.bryanreinero.dsvload;

import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.regex.Matcher;
Expand All @@ -24,6 +25,7 @@ public abstract class Transformer <V extends Object> {
public static final String TYPE_DOUBLE = "double";
public static final String TYPE_BINARY = "binary";
public static final String TYPE_Object = "object";
public static final String TYPE_Date = "date";

public static enum Type {
ArrayType( Type_Array ),
Expand All @@ -33,7 +35,8 @@ public static enum Type {
FloatType(TYPE_FLOAT),
DoubleType(TYPE_DOUBLE),
BinaryType(TYPE_BINARY),
ObjectType(TYPE_Object);
ObjectType(TYPE_Object),
DateType(TYPE_Date);

private final String name;
private Type ( String name ) { this.name = name; }
Expand All @@ -54,6 +57,8 @@ public static Type getType( String type ) {
return BinaryType;
if( type.compareTo(TYPE_Object) == 0 )
return BinaryType;
if( type.compareTo(TYPE_Date) == 0 )
return DateType;
return null;
}
}
Expand Down Expand Up @@ -140,6 +145,20 @@ public String toString() {
}
}
);

transformers.put( TYPE_Date ,
new Transformer <Date> () {
@Override
public Date transform( String value ) {
return new Date( Long.parseLong( value ) * 1000 );
}

@Override
public String toString() {
return TYPE_Date;
}
}
);
}

public static Transformer getTransformer( String type ) {
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Expand Up @@ -3,7 +3,6 @@ group 'bryanreinero'
ext.javaDriverVersion = '3.0.0'
ext.buildDir = './build'


allprojects {
apply plugin: 'java'
apply plugin: 'application'
Expand Down Expand Up @@ -34,8 +33,11 @@ configure(subprojects.findAll { it.name.contains('applications/') }) {

project( 'core' ) {

println System.properties['java.home'];

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile files("${System.properties['java.home']}/../lib/tools.jar")
compile "org.mongodb:mongo-java-driver:${javaDriverVersion}"
compile "org.apache.commons:commons-math3:3.0"
compile "commons-cli:commons-cli:1.2"
Expand Down
2 changes: 1 addition & 1 deletion build.xml
@@ -1,6 +1,6 @@
<project name="Inserter" default="compile" basedir="." >

<property name="src.dir" value="src/"/>
<property name="src.dir" value="core/src/"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
Expand Down

0 comments on commit dbfe810

Please sign in to comment.