import uk.ac.ic.doc.automed.*;
import uk.ac.ic.doc.automed.reps.*;
import uk.ac.ic.doc.automed.templates.*;
import uk.ac.ic.doc.automed.wrappers.*;
import uk.ac.ic.doc.automed.templates.wrapper.*;

public class UniversityTemplateIntegration {
  private static TemplateCompilerSimulator coltohier;
  private static TemplateCompilerSimulator coldownhier;

  public static Schema transforms1tosg(Schema s1)
    throws NotFoundException,TemplateDefinitionException,Exception {
    SchemaObject person=s1.getSchemaObject("<<staff>>");
    SchemaObject personsex=s1.getSchemaObject("<<staff,sex>>");
    SchemaObject personid=s1.getSchemaObject("<<staff,id>>");
		
    CompositeTransformation template= 
      CompositeTransformation.getCompositeTransformation(
	coltohier.templateName());
    TTemplateInputArgumentList argumentList= 
      new TTemplateInputArgumentList(template);
    argumentList.addArgument(s1);
    argumentList.addArgument(person);
    argumentList.addArgument(personsex);
    argumentList.addArgument(personid);
    argumentList.addArgument(new String[]{"male","female"});
    argumentList.addArgument(new String[]{"'M'","'F'"});
    CompositeTransformationRecord record=argumentList.executeTransformation();
    return record.getFinalSchema();
  }

  public static Schema transformrels2tosg(Schema s2)
    throws NotFoundException,TemplateDefinitionException,Exception {
    SchemaObject person=s2.getSchemaObject("<<person>>");
    SchemaObject personid=s2.getSchemaObject("<<person,name>>");
    SchemaObject male=s2.getSchemaObject("<<male>>");
    SchemaObject female=s2.getSchemaObject("<<female>>");
    
    CompositeTransformation template=
      CompositeTransformation.getCompositeTransformation(
        coldownhier.templateName());
    TTemplateInputArgumentList argumentList=
      new TTemplateInputArgumentList(template);
    argumentList.addArgument(s2);
    argumentList.addArgument(person);
    argumentList.addArgument(personid);
    argumentList.addArgument(new SchemaObject[]{male, female});	
    CompositeTransformationRecord record=argumentList.executeTransformation();
    return record.getFinalSchema();			
  }	
	  
  public static void main(String[] args) throws Exception {
    System.out.println("Template Based University Integration");

    // level 5 prints all the old debug information, 0 makes it silent
    STR.setDebugLevel(0);
      
    SQLWrapperFactory awf=new SQLWrapperFactory();
    awf.setFeatures(SQLWrapperFactory.PRIMARY_KEY);
    awf.setFeatures(SQLWrapperFactory.FOREIGN_KEY);
    awf.setFeatures(SQLWrapperFactory.DATA_TYPE);

    coltohier=new templates.MandatoryColumnToHierarchyEquivalence(awf);
    //coldownhier=new templates.ColumnMovedDownHierarchy(awf);

    Schema s1=Schema.getSchema("uni_s1");
    Schema rel_sg=transforms1tosg(s1);
    rel_sg.listSchema();   
  }
}
