package org.eclipse.rdf4j.validation;

import org.eclipse.rdf4j.common.iteration.Iterations;
import org.eclipse.rdf4j.Main;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.repository.RepositoryResult;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.repository.sail.SailRepositoryConnection;
import org.eclipse.rdf4j.sail.NotifyingSailConnection;
import org.eclipse.rdf4j.sail.Sail;
import org.eclipse.rdf4j.sail.SailException;
import org.eclipse.rdf4j.sail.helpers.NotifyingSailWrapper;
import org.eclipse.rdf4j.shape.Shape;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by heshanjayasinghe on 4/23/17.
 */
public class SHACLSail extends NotifyingSailWrapper {

    List<Shape> shapes;

    @Override
    public void setBaseSail(Sail baseSail) {
        super.setBaseSail(baseSail);
    }

    @Override
    public NotifyingSailConnection getConnection() throws SailException {
        return new SHACLSailConnection(this);
    }

    public void setShaclRules(SailRepository shaclRules){
        try(SailRepositoryConnection connection = shaclRules.getConnection()){
            ValueFactory vf = connection.getValueFactory();
            RepositoryResult<Statement> nodeShape = connection.getStatements(null, RDF.TYPE,vf.createIRI(Main.SH,"NodeShape"));
            List<Resource> collect = Iterations.stream(nodeShape).map(Statement::getSubject).collect(Collectors.toList());

            collect.forEach(System.out::println);
            shapes = collect.stream().map(s -> new Shape(s, connection)).collect(Collectors.toList());

        }

    }

}

@@ -61,66 +61,66 @@
 f4j.
-common.iteration.Iterations;%0Aimport org.eclipse.rdf4j.Main
+Main;%0Aimport org.eclipse.rdf4j.common.iteration.Iterations
 ;%0Aim
@@ -462,32 +462,77 @@
 toryConnection;%0A
+import org.eclipse.rdf4j.sail.NotifyingSail;%0A
 import org.eclip
@@ -941,16 +941,101 @@
 hapes;%0A%0A
+    public SHACLSail(NotifyingSail memoryStore) %7B%0A        super(memoryStore);%0A    %7D%0A%0A
     @Ove
@@ -1224,16 +1224,267 @@
 %0A       
+ try %7B%0A            NotifyingSailConnection con = super.getConnection();%0A            return new SHACLSailConnection(this, con);%0A        %7D%0A        catch (ClassCastException e) %7B%0A            throw new SailException(e.getMessage(), e);%0A        %7D%0A       //
  return 
@@ -1516,24 +1516,30 @@
 his);%0A    %7D%0A
+    %0A%0A
 %0A    public 

return SHACLSailConnection