// Path: src/main/java/com/atomgraph/server/exception/SPINConstraintViolationException.java
// public class SPINConstraintViolationException extends ModelException
// {
//     private final List<ConstraintViolation> cvs;
//     
//     public SPINConstraintViolationException(List<ConstraintViolation> cvs, Model model, String graphURI)
//     {
//         super(model);
//         this.cvs = cvs;
//     }
// 
//     public SPINConstraintViolationException(List<ConstraintViolation> cvs, Model model)
//     {
//         this(cvs, model, null);
//     }
//     
//     public List<ConstraintViolation> getConstraintViolations()
//     {
//         return cvs;
//     }
//     
// }
// 
// Path: src/main/java/com/atomgraph/processor/util/Validator.java
// public class Validator
// {
//     private static final Logger log = LoggerFactory.getLogger(Validator.class);
//     
//     private final OntModel ontModel;
//         
//     public Validator(OntModel ontModel)
//     {
//         if (ontModel == null) throw new IllegalArgumentException("OntModel cannot be null");
//         this.ontModel = ontModel;
//     }
// 
//     public List<ConstraintViolation> validate(Model model)
//     {
//         if (model == null) throw new IllegalArgumentException("Model cannot be null");
// 
//         return SPINConstraints.check(model, getOntModel());
//     }
// 
//     public OntModel getOntModel()
//     {
//         return ontModel;
//     }
// 
// }
// 
// Path: src/main/java/com/atomgraph/server/exception/SHACLConstraintViolationException.java
// public class SHACLConstraintViolationException extends ModelException
// {
// 
//     private final ValidationReport report;
// 
//     public SHACLConstraintViolationException(ValidationReport report, Model model)
//     {
//         super(model);
//         this.report = report;
//     }
// 
//     public ValidationReport getValidationReport()
//     {
//         return report;
//     }
//     
// }


import org.apache.jena.ontology.Ontology;
import org.apache.jena.rdf.model.Model;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.List;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Providers;
import com.atomgraph.server.exception.SPINConstraintViolationException;
import com.atomgraph.processor.util.Validator;
import com.atomgraph.server.exception.SHACLConstraintViolationException;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atomgraph.spinrdf.constraints.ConstraintViolation;
import java.util.Optional;
import org.apache.jena.shacl.ShaclValidator;
import org.apache.jena.shacl.Shapes;
import org.apache.jena.shacl.ValidationReport;
        return validate(model);
    }
    
    public Model validate(Model model)
    {
        if (getOntology().isPresent())
        {
            // SPIN validation
            List<ConstraintViolation> cvs = new Validator(getOntology().get().getOntModel()).validate(model);
            if (!cvs.isEmpty())
            {
                if (log.isDebugEnabled()) log.debug("SPIN constraint violations: {}", cvs);
                throw new SPINConstraintViolationException(cvs, model);
            }

            // SHACL validation
            Shapes shapes = Shapes.parse(getOntology().get().getOntModel().getGraph());
            ValidationReport report = ShaclValidator.get().validate(shapes, model.getGraph());
            if (!report.conforms())
            {
                if (log.isDebugEnabled()) log.debug("SHACL constraint violations: {}", report);
                throw new SHACLConstraintViolationException(report, model);
            }
        }
    
        return model;
    }
        
    public Optional<Ontology> getOntology()
    {
// Path: src/main/java/com/atomgraph/server/exception/SPINConstraintViolationException.java
// public class SPINConstraintViolationException extends ModelException
// {
//     private final List<ConstraintViolation> cvs;
//     
//     public SPINConstraintViolationException(List<ConstraintViolation> cvs, Model model, String graphURI)
//     {
//         super(model);
//         this.cvs = cvs;
//     }
// 
//     public SPINConstraintViolationException(List<ConstraintViolation> cvs, Model model)
//     {
//         this(cvs, model, null);
//     }
//     
//     public List<ConstraintViolation> getConstraintViolations()
//     {
//         return cvs;
//     }
//     
// }
// 
// Path: src/main/java/com/atomgraph/processor/util/Validator.java
// public class Validator
// {
//     private static final Logger log = LoggerFactory.getLogger(Validator.class);
//     
//     private final OntModel ontModel;
//         
//     public Validator(OntModel ontModel)
//     {
//         if (ontModel == null) throw new IllegalArgumentException("OntModel cannot be null");
//         this.ontModel = ontModel;
//     }
// 
//     public List<ConstraintViolation> validate(Model model)
//     {
//         if (model == null) throw new IllegalArgumentException("Model cannot be null");
// 
//         return SPINConstraints.check(model, getOntModel());
//     }
// 
//     public OntModel getOntModel()
//     {
//         return ontModel;
//     }
// 
// }
// 
// Path: src/main/java/com/atomgraph/server/exception/SHACLConstraintViolationException.java
// public class SHACLConstraintViolationException extends ModelException
// {
// 
//     private final ValidationReport report;
// 
//     public SHACLConstraintViolationException(ValidationReport report, Model model)
//     {
//         super(model);
//         this.report = report;
//     }
// 
//     public ValidationReport getValidationReport()
//     {
//         return report;
//     }
//     
// }


// Path: src/main/java/com/atomgraph/server/io/ValidatingModelProvider.java
import org.apache.jena.ontology.Ontology;
import org.apache.jena.rdf.model.Model;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.List;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Providers;
import com.atomgraph.server.exception.SPINConstraintViolationException;
import com.atomgraph.processor.util.Validator;
import com.atomgraph.server.exception.SHACLConstraintViolationException;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atomgraph.spinrdf.constraints.ConstraintViolation;
import java.util.Optional;
import org.apache.jena.shacl.ShaclValidator;
import org.apache.jena.shacl.Shapes;
import org.apache.jena.shacl.ValidationReport;

        return validate(model);
    }
    
    public Model validate(Model model)
    {
        if (getOntology().isPresent())
        {
            // SPIN validation
            List<ConstraintViolation> cvs = new Validator(getOntology().get().getOntModel()).validate(model);
            if (!cvs.isEmpty())
            {
                if (log.isDebugEnabled()) log.debug("SPIN constraint violations: {}", cvs);
                throw new SPINConstraintViolationException(cvs, model);
            }

            // SHACL validation
            Shapes shapes = Shapes.parse(getOntology().get().getOntModel().getGraph());
            ValidationReport report = ShaclValidator.get().validate(shapes, model.getGraph());
            if (!report.conforms())
            {
                if (log.isDebugEnabled()) log.debug("SHACL constraint violations: {}", report);
                throw new SHACLConstraintViolationException(report, model);
            }
        }
    
        return model;
    }
        
    public Optional<Ontology> getOntology()
    {
        return ontology.get();