// Path: src/main/java/octopus/api/database/Database.java
// public interface Database {
// 
// 
// 	/**
// 	 * Return a tinkerpop3 graph instance
// 	 * */
// 
// 	public Graph getGraph();
// 
// 	public void closeInstance();
// 
// }
// 
// Path: src/main/java/octopus/api/database/DatabaseManager.java
// public interface DatabaseManager {
// 
// 	public void initializeDatabaseForProject(OctopusProject project) throws IOException;
// 	public Database getDatabaseInstanceForProject(OctopusProject project);
// 	public void deleteDatabaseForProject(OctopusProject project);
// 	public void resetDatabase(OctopusProject project);
// 
// }
// 
// Path: src/main/java/octopus/api/projects/OctopusProject.java
// public class OctopusProject
// {
// 
// 	private final String pathToProjectDir;
// 	private String name;
// 
// 	public OctopusProject(String name, String pathToProjectDir) throws IOException
// 	{
// 		this.pathToProjectDir = pathToProjectDir;
// 		this.name = name;
// 	}
// 
// 	public String getPathToProjectDir()
// 	{
// 		return pathToProjectDir;
// 	}
// 
// 	public String getName()
// 	{
// 		return name;
// 	}
// 
// 	public String getDBConfigFile()
// 	{
// 		return Paths.get(pathToProjectDir, "db").toAbsolutePath().toString();
// 	}
// 
// 	public Database getNewDatabaseInstance()
// 	{
// 		return new TitanLocalDatabaseManager().getDatabaseInstanceForProject(this);
// 	}
// 
// }


import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Paths;
import com.thinkaurelius.titan.core.schema.Mapping;
import org.apache.commons.io.FileUtils;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import com.thinkaurelius.titan.core.PropertyKey;
import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.schema.TitanManagement;
import com.thinkaurelius.titan.core.util.TitanCleanup;
import octopus.api.database.Database;
import octopus.api.database.DatabaseManager;
import octopus.api.projects.OctopusProject;

	private void initializeDatabaseSchema(String configFilename)
	{
		TitanGraph graph = TitanFactory.open(configFilename);
		TitanManagement schema = graph.openManagement();

		PropertyKey extIdKey = schema.makePropertyKey("_key").dataType(String.class).make();
		PropertyKey typeKey = schema.makePropertyKey("type").dataType(String.class).make();

		// At import, we only create separate composite indices for key and type.
		// Additional indices should be built by plugins.

		schema.buildIndex("byKey", Vertex.class).addKey(extIdKey).unique().buildCompositeIndex();
		schema.buildIndex("byType", Vertex.class).addKey(typeKey).buildCompositeIndex();

		// Lucene indices can be built as follows:
		// This would be how to build a STRING index
		PropertyKey codeKey = schema.makePropertyKey("code").dataType(String.class).make();
		schema.buildIndex("byValue", Vertex.class)
				.addKey(codeKey, Mapping.STRING.asParameter()).buildMixedIndex("search");

		// And this is how to build a TEXT index
		// schema.buildIndex("byTypeAndValue", Vertex.class).addKey(typeKey).
		// addKey(valueKey).buildMixedIndex("search");

		schema.commit();
		graph.close();
	}

	@Override
// Path: src/main/java/octopus/api/database/Database.java
// public interface Database {
// 
// 
// 	/**
// 	 * Return a tinkerpop3 graph instance
// 	 * */
// 
// 	public Graph getGraph();
// 
// 	public void closeInstance();
// 
// }
// 
// Path: src/main/java/octopus/api/database/DatabaseManager.java
// public interface DatabaseManager {
// 
// 	public void initializeDatabaseForProject(OctopusProject project) throws IOException;
// 	public Database getDatabaseInstanceForProject(OctopusProject project);
// 	public void deleteDatabaseForProject(OctopusProject project);
// 	public void resetDatabase(OctopusProject project);
// 
// }
// 
// Path: src/main/java/octopus/api/projects/OctopusProject.java
// public class OctopusProject
// {
// 
// 	private final String pathToProjectDir;
// 	private String name;
// 
// 	public OctopusProject(String name, String pathToProjectDir) throws IOException
// 	{
// 		this.pathToProjectDir = pathToProjectDir;
// 		this.name = name;
// 	}
// 
// 	public String getPathToProjectDir()
// 	{
// 		return pathToProjectDir;
// 	}
// 
// 	public String getName()
// 	{
// 		return name;
// 	}
// 
// 	public String getDBConfigFile()
// 	{
// 		return Paths.get(pathToProjectDir, "db").toAbsolutePath().toString();
// 	}
// 
// 	public Database getNewDatabaseInstance()
// 	{
// 		return new TitanLocalDatabaseManager().getDatabaseInstanceForProject(this);
// 	}
// 
// }


// Path: src/main/java/octopus/server/database/titan/TitanLocalDatabaseManager.java
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Paths;
import com.thinkaurelius.titan.core.schema.Mapping;
import org.apache.commons.io.FileUtils;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import com.thinkaurelius.titan.core.PropertyKey;
import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.schema.TitanManagement;
import com.thinkaurelius.titan.core.util.TitanCleanup;
import octopus.api.database.Database;
import octopus.api.database.DatabaseManager;
import octopus.api.projects.OctopusProject;


	private void initializeDatabaseSchema(String configFilename)
	{
		TitanGraph graph = TitanFactory.open(configFilename);
		TitanManagement schema = graph.openManagement();

		PropertyKey extIdKey = schema.makePropertyKey("_key").dataType(String.class).make();
		PropertyKey typeKey = schema.makePropertyKey("type").dataType(String.class).make();

		// At import, we only create separate composite indices for key and type.
		// Additional indices should be built by plugins.

		schema.buildIndex("byKey", Vertex.class).addKey(extIdKey).unique().buildCompositeIndex();
		schema.buildIndex("byType", Vertex.class).addKey(typeKey).buildCompositeIndex();

		// Lucene indices can be built as follows:
		// This would be how to build a STRING index
		PropertyKey codeKey = schema.makePropertyKey("code").dataType(String.class).make();
		schema.buildIndex("byValue", Vertex.class)
				.addKey(codeKey, Mapping.STRING.asParameter()).buildMixedIndex("search");

		// And this is how to build a TEXT index
		// schema.buildIndex("byTypeAndValue", Vertex.class).addKey(typeKey).
		// addKey(valueKey).buildMixedIndex("search");

		schema.commit();
		graph.close();
	}

	@Override
	public Database getDatabaseInstanceForProject(OctopusProject project)