package eu.semagrow.scraper.cassandra;

import eu.semagrow.scraper.cassandra.utils.CassandraClient;
import org.openrdf.rio.RDFHandlerException;

import java.io.*;

/**
 * Created by antonis on 6/4/2016.
 */
public class CassandraScraper {

    public static void main(String [] args) throws RDFHandlerException, IOException {

        if (args.length != 7) {
            throw new IllegalArgumentException("Usage: cassandraScraper [address] [port] [keyspace] [base] [endpoint] [cassandra desc output file] [void desc output file]");
        }

        String address = args[0];
        int port = Integer.valueOf(args[1]);
        String keyspace = args[2];
        String base = args[3];
        String endpoint = args[4];
        String descPath = args[5];
        String voidPath = args[6];

        File descFile = new File(descPath);
        File voidFile = new File(voidPath);

        if (!descFile.exists()) {
            descFile.createNewFile();
        }
        if (!voidFile.exists()) {
            voidFile.createNewFile();
        }

        if (!endpoint.contains("cassandra")) {
            throw new IllegalArgumentException("Endpoint string should contain the substring \"cassandra\"");
        }

        CassandraClient client = new CassandraClient();
        client.setCredentials(address, port, keyspace);
        client.connect();

        CassandraSchemaMetatataWriter schemaWriter = new CassandraSchemaMetatataWriter();
        CassandraTriplesMetadataWriter sevodWriter = new CassandraTriplesMetadataWriter();

        schemaWriter.setClient(client);
        sevodWriter.setClient(client);

        schemaWriter.setBase(base);
        schemaWriter.setEndpoint(endpoint);
        sevodWriter.setBase(base);
        sevodWriter.setEndpoint(endpoint);

        schemaWriter.writeMetadata(new PrintStream(descFile));
        sevodWriter.writeMetadata(new PrintStream(voidFile));

        client.close();




    }



}

@@ -351,9 +351,9 @@
  != 
-7
+5
 ) %7B%0A
@@ -464,58 +464,14 @@
 e%5D %5B
+s
 e
-ndpoint%5D %5Bcassandra desc output file%5D %5B
 vo
-i
 d 
-desc 
 outp
@@ -657,81 +657,12 @@
 ing 
+s
 e
-ndpoint = args%5B4%5D;%0A        String descPath = args%5B5%5D;%0A        String 
 vo
-i
 dPat
@@ -670,17 +670,17 @@
  = args%5B
-6
+4
 %5D;%0A%0A    
@@ -688,20 +688,21 @@
    File 
-desc
+sevod
 File = n
@@ -709,20 +709,21 @@
 ew File(
-desc
+sevod
 Path);%0A 
@@ -733,41 +733,54 @@
     
-File voidFile = new File(voidPath
+PrintStream stream = new PrintStream(sevodFile
 );%0A%0A
@@ -792,20 +792,21 @@
    if (!
-desc
+sevod
 File.exi
@@ -826,20 +826,21 @@
         
-desc
+sevod
 File.cre
@@ -863,16 +863,17 @@
       %7D%0A
+%0A
         
@@ -880,77 +880,147 @@
 if (
-!voidFile.exists()) %7B%0A            voidFile.createNewFile();%0A        %7D
+base.endsWith(%22/%22)) %7B%0A            base = base.substring(0,base.length()-1);%0A        %7D%0A        String base_keyspace = base + %22/%22 + keyspace;
 %0A%0A  
@@ -1030,24 +1030,29 @@
    if (!
-endpoint
+base_keyspace
 .contain
@@ -1121,23 +1121,12 @@
 on(%22
-Endpoint string
+Base
  sho
@@ -1605,32 +1605,41 @@
 ter.setBase(base
+_keyspace
 );%0A        schem
@@ -1658,24 +1658,29 @@
 ndpoint(
-endpoint
+base_keyspace
 );%0A     
@@ -1706,16 +1706,25 @@
 ase(base
+_keyspace
 );%0A     
@@ -1754,16 +1754,21 @@
 int(
-endpoint
+base_keyspace
 );%0A%0A
@@ -1806,33 +1806,14 @@
 ata(
-new PrintStream(descFile)
+stream
 );%0A 
@@ -1849,33 +1849,14 @@
 ata(
-new PrintStream(voidFile)
+stream
 );%0A%0A

change command line arguments for cassandra scraper main class