package won.utils.acknowledgement;

import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.jena.query.Dataset;
import org.apache.jena.update.UpdateExecutionFactory;
import org.apache.jena.update.UpdateFactory;
import org.apache.jena.update.UpdateProcessor;
import org.apache.jena.update.UpdateRequest;
import won.protocol.util.RdfUtils;


import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;

public class AcknowledgedSelection {
    private String queryString;
    private static final String queryFile = "/acknowledgement/query.sq";

    public AcknowledgedSelection() {
        InputStream is  = AcknowledgedSelection.class.getResourceAsStream(queryFile);
        StringWriter writer = new StringWriter();
        try {
            IOUtils.copy(is, writer, Charsets.UTF_8);
        } catch (IOException e) {
            throw new IllegalStateException("Could not read queryString file", e);
        }
        this.queryString = writer.toString();
    }

    public Dataset applyAcknowledgedSelection(Dataset conversationDataset){
        UpdateRequest update = UpdateFactory.create(queryString);
        Dataset copy = RdfUtils.cloneDataset(conversationDataset);
        UpdateProcessor updateProcessor = UpdateExecutionFactory.create(update,copy);
        updateProcessor.execute();
        return copy;
    }
}

@@ -601,16 +601,111 @@
 y.sq%22;%0A%0A
+    // Function that reads in the query file to a string using Apache's IOUtils and java.utils%0A
     publ
@@ -1201,136 +1201,435 @@
     
-    UpdateRequest update = UpdateFactory.create(queryString);%0A        Dataset copy = RdfUtils.cloneDataset(conversationDataset);
+%09// creates an update request by grabbing the queryString variable, populated by the Acknowledged Section method%0A        UpdateRequest update = UpdateFactory.create(queryString);%0A       %0A        // create a clone of the input datast ... See the RdfUtils class comments%0A        Dataset copy = RdfUtils.cloneDataset(conversationDataset);%0A        %0A        // perform a sparql update with the clone and the acknowledgement/query.sq
 %0A   

add comment messages to the Acknowledge Method