package rdfsuite.registry;

import gr.forth.ics.rdfsuite.services.util.Args;
import gr.forth.ics.rdfsuite.swkm.model.IRDF_Model;
import gr.forth.ics.rdfsuite.swkm.model.impl.RDF_Model;
import gr.forth.ics.swkmclient.utils.Comparisons;
import gr.forth.ics.swkmclient.utils.Comparisons.TripleComparison;
import junit.framework.*;
import gr.forth.ics.rdfsuite.services.DbSettings;
import gr.forth.ics.rdfsuite.services.Deps;
import gr.forth.ics.rdfsuite.services.RdfDocument;
import gr.forth.ics.rdfsuite.services.Format;
import gr.forth.ics.rdfsuite.services.Registry.ClassName;
import gr.forth.ics.rdfsuite.services.Registry.SchemaSubClasses;
import gr.forth.ics.rdfsuite.services.Registry.PropertyRangeType;
import gr.forth.ics.rdfsuite.services.util.*;
import gr.forth.ics.rdfsuite.services.exceptions.*;
import gr.forth.ics.swkmclient.*;
import java.io.File;
import java.util.*;
/**
 *
 * @author papavas
 */
public class RegistryExample1 extends TestCase {
    private String path= "/home/papavas/ite/registry/testSuite1/";   
    
    
    private void testRegistryMethods(Client client) {

        /* Inserts into the registry the instances and properties described in the file */
	client.registry().insertSchema("http://www.test.com/schema1.rdf",new String[] {"http://www.test.com/schema1.rdf~_~version0"},
                IOUtils.readFileAsString(new File(path+"schema1.rdf")),Format.RDF_XML);
        
         /* Inserts into the registry the instances and properties described in the file */
        client.registry().insertPerson("http://www.test.com/schema1.rdf",new String[] {"http://Neil_Armstrong"},"creator"
                IOUtils.readFileAsString(new File(path+"testInsertPerson.rdf")),Format.RDF_XML);

	 /*Inserts into the registry the instances and properties described in the file */ 
	client.registry().insertOrganization("http://www.test.com/schema1.rdf",new String[] {"http://www.ics.forth.gr"},"publisher"
                IOUtils.readFileAsString(new File(path+"testInsertOrg.rdf")),Format.RDF_XML);
   
        /* Inserts into the registry a new instance of class Taxonomy, subClass of class Schema */	
        client.registry().insertSchemaURI(SchemaSubClasses.TAXONOMY, "http://www.google.com/TaxonomySchema",
                new String[] {"http://TaxonomySchema_version0","http://TaxonomySchema_version1"}); 

	/* Inserts into the registry a new property instance with name keywords that has as domain the Schema instance
  	   http://www.google.com/TaxonomySchema and range the value "Mountain bikes, Motorcycles" */	 
        client.registry().insertProperty(ClassName.SCHEMA,"http://www.google.com/TaxonomySchema","keywords",
                new String[] {"Mountain bikes, Motorcycles"},PropertyRangeType.STRING);

	/* Inserts into the registry the property instance hasLanguage that has as domain the instance http://www.google.com/TaxonomySchema
 	   and range the instance "http://OWL-LITE".
	   The same function applies for the classes Person,Organization, Version, Change, Language, Encoding and Physical_Language. */
        client.registry().insertProperty(ClassName.SCHEMA,"http://www.google.com/TaxonomySchema","hasLanguage",
                new String[] {"http://OWL-LITE"},PropertyRangeType.RESOURCE);       
        
	/* The query returns as result all the instances of class Schema whom properties with name keywords have range values like "Mountain" */
        client.registry().evaluatePredefinedQuery("SimpleQueries","query1",new String[] {"Mountain"},Format.RDF_XML).replaceFirst("#Bag_\\d+","#Bag"),
                Format.RDF_XML));
        
        /* The query returns as result all the instances of class Version that are imported or exported by the Version instances of this Schema instance*/
	client.registry().evaluatePredefinedQuery("Versioning","getRelations",
                new String[] {"http://www.test.com/schema2.rdf"},Format.RDF_XML).replaceFirst("#Bag_\\d+","#Bag"),Format.RDF_XML));
	
	/* The query returns as result the most recent Version instance of all the version of this Schema instance. */ 
	client.registry().evaluatePredefinedQuery("Versioning","mostRecentVersion",
                new String[] {"http://www.test.com/schema2.rdf"},Format.RDF_XML).replaceFirst("#Bag_\\d+","#Bag"),Format.RDF_XML));   
        
	/* Removes from the registry the Schema instance with uri http://www.test.com/schema2.rdf.
 	   The same function applies for the classes Person,Organization, Version, Change, Language, Encoding and Physical_Language. */
        client.registry().removeInstance(ClassName.SCHEMA,"http://www.test.com/schema2.rdf");  
      
	/* Edits the value of the property instance hasDomain that has as range the Schema instance  http://www.test.com/schema3.rdf.
 	   The same function applies for the classes Person,Organization, Version, Change, Language, Encoding and Physical_Language. */
        client.registry().editProperty(ClassName.SCHEMA, "http://www.test.com/schema3.rdf",
            "hasDomain", "Sports","Sports,Tennis",PropertyRangeType.STRING);
 
        /* Inserts into the registry an instance of class Domain_Ontology subClass of class Schema with uri http://Domain.rdf */
        client.registry().insertSchemaURI(SchemaSubClasses.DOMAIN_ONTOLOGY,"http://Domain.rdf",new String[] {"http://domain_v0"});
        
	/* Inserts into the registry the Person instances with uris http://Arnold_Schwarzeneger and http://Osama_Bi_Laden respectively.  */
	client.registry().insertPersonURI("http://www.test.com/schema1.rdf~_~version0",
	new String[] {"http://Arnold_Schwarzeneger", "http://Osama_Bi_Laden"},"contributor");
      
        /* Edits the uri of the Version instance http://www.test.com/schema1.rdf~_~version0.
 	   The same function applies for the classes Person,Organization, Schema, Change, Language, Encoding and Physical_Language.  */
        client.registry().editInstanceURI(ClassName.Version,"http://www.test.com/schema1.rdf~_~version0","http://schema1_version0");  

	/* Removes the property instance with name description that has as domain the instance http://www.test.com/schema1.rdf
 	   and range the value "This is a test ontology,the first one i have created".
	   The same function applies for the classes Person,Organization, Version, Change, Language, Encoding and Physical_Language. */
        client.registry().removeProperty(ClassName.SCHEMA,"http://www.test.com/schema1.rdf","description",
                new String[]{"This is a test ontology,the first one i have created"},PropertyRangeType.STRING);

	/* Checkes whether the given uri has been stored into the registry and is classified under the class Schema. 
 	   The same function applies for the classes Person,Organization, Version, Change, Language, Encoding and Physical_Language.*/
        client.registry().existInstanceURI(ClassName.SCHEMA,new String("http://www.test.com/schema1.rdf"));               
    }       
}
