package semistructured.xml.biomap;

import org.w3c.dom.Document;

import uk.ac.bbk.dcs.automed.xml.XMLConstants;
import uk.ac.bbk.dcs.automed.xml.XMLRestructurer;
import uk.ac.bbk.dcs.automed.xml.utilities.PrintUtility;
import uk.ac.bbk.dcs.automed.xml.utilities.UIDUtility;
import uk.ac.bbk.dcs.automed.xml.wrappers.XMLDSSFromAMSchema;
import uk.ac.ic.doc.automed.reps.Construct;
import uk.ac.ic.doc.automed.reps.Model;
import uk.ac.ic.doc.automed.reps.Schema;

/**
 * Class Task Description
 * 
 * @author <a href="mailto:lucas@dcs.bbk.ac.uk">Lucas Zamboulis </a>
 */
public class CATHIntegration {

	public static void main(String[] args) {
		try {
			System.out.println("Starting CATH integration: " + System.currentTimeMillis());
			String finalCATHSchemaName = "CATH_final2";
			String finalGlobalSchemaName = "GLOBAL_final";
			String cathSchemaName = "cath_int";
			String globalSchemaName = "global_int";

			Model xmlModel = Model.getModel(XMLConstants.model);
			Construct element = xmlModel.getConstruct(XMLConstants.element);
			Construct nestList = xmlModel.getConstruct(XMLConstants.nestList);

			// Get XMLDSS in AutoMed schema and DOM formats
			System.out.println("p1");
			Schema finalCATHSchema = Schema.getSchema(finalCATHSchemaName);
			System.out.println("p2");
			Schema finalGlobalSchema = Schema.getSchema(finalGlobalSchemaName);
			System.out.println("p3");

			Schema cathSchema = UIDUtility.changeSchemaUIDs(finalCATHSchema, cathSchemaName);
			Schema globalSchema = UIDUtility.changeSchemaUIDs(finalGlobalSchema, globalSchemaName);
			Document cathDoc = XMLDSSFromAMSchema.getXMLDSSFromAMSchema(cathSchema);
			Document globalDoc = XMLDSSFromAMSchema.getXMLDSSFromAMSchema(globalSchema);

			// Transform and integrate source schemas
			PrintUtility.banner();
			cathSchema.listSchema();
			PrintUtility.banner();
			globalSchema.listSchema();
			PrintUtility.banner();
			XMLRestructurer t1 = new XMLRestructurer(cathSchema, cathDoc, globalSchema, globalDoc, null);
			t1.restructure();
			System.out.println("Finished CATH integration: " + System.currentTimeMillis());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}