package DBFOschemafy_V_3_001;

import java.sql.Connection; 

/**
 *  The <b><code>DBFOschemafyMain</code></b> class serves as the core application 
 *  logic within a Java framework for generating OWL/XML ontologies: It
 *  leverages MySQL tables containing configuration details to
 *  construct the ontology structure. This class acts as the
 *  central controller, directing the overall process of ontology
 *  generation based on user-provided configuration data.
 *  <p>
 *  <b>Key Functionalities:</b>
 *  <p>
 *  Builds connection to the RDB
 *  <p>
 *  Controls ontology generation sequence. Orchestrates the creation
 *  of the ontology by calling dedicated modules responsible for:
 *  <ul>
 *  <li>Generating OWL header
 *  <li>Defining class structures
 *  <li>Setting class disjointness
 *  <li>Defining class annotations
 *  <li>Defining object properties 
 *  <li>Defining triplets (relationships between individuals)
 *  <li>Adding data properties and data property references
 *  <li>Adding OWL trailer
 *  </ul>
 *  <p>
 *  <p>
 *  Logs Console Messages: Provides informative messages during
 *  execution to track progress.
 *  <p>
 *  <b>Additional Notes:</b>
 *  <p>
 *  <b>Environment:</b> 
 *  <ul>
 *  <li>    IDE:              Eclipse IDE for Java Developers
 *  <li>    Version:          2021-12 (4.22.0)
 *  <li>    Build id:         20211202-1639
 *  <li>    HW Model Name:    iMac, MacOS Monterey, 12.5.1
 *  <li>    Processor Name:   Quad-Core Intel Core i5
 *  <li>    Processor Speed:  3.2 GHz
 *  <li>    Memory:           32 GB 1867 MHz DDR3
 *  <li>    Disk:             APPLE SSD SM0256G    
 *  <li>    Serial:           DGKRC080GG7V
 *  <li>    RDB:              MySQL Server (Version 8.0.30), 
 *  <li>    Workbench:        MySQL Workbench (Version 8.0.31 build 2235049 CE (64 bits) Community)
 *  <li>    JDBC connector:   mysql-connector-j-9.1.0.jar
 *  </ul>
 *  @version 1-001
 *  @since   2024/11/27
 *  @author  Edit Hlaszny PhD (https://www.edithlaszny.eu/) 
 */

public class DBFOschemafyMain 
{ 
   /**
    *  The output files should have a common directory where they are stored.
    */
    private final String defaultIOdirName = "/Users/edithlaszny/Documents/OWLschemafy_V_2_002/RunnableEnv/" ;

    /**
     *  Name of the OWL2-XML encoded result file
     */
    private       String OWLresultFile        = defaultIOdirName + "resultOntology/DBFO_P2_ontology.owl" ;

    /*
     *  MySQL DB-relevant definitions (You can find a safer solution instead, as desired)
     */
    private final String     DBurl        = "jdbc:mysql://localhost:3306/DBFOntoMaestro";
    private final String     DBuser       = "root";
    private final String     DBpassword   = "Piros77Macska";
    private       Connection DBconnection = null ;
    
    /**
     *  In silent mode no log messages will be displayed
     */
    private final boolean silentMode      = false ;
    
    /**
     *  The main method starts the app.
     *  @param args Java standard calling arguments 
     */
    public final static void main(String args[])
    {
        new DBFOschemafyMain().generateOWL2ontology(args) ;

    }   //  end of method main() 
 
    /**
     *  The method evaluates the calling arguments...
     *  @param args Java standard calling arguments
     */
    private static void evalCallingArgs(String args[])
    {
        //  you can implement it...
        //  System.exit(-1);
        
    }   //  end of method evalCallingArgs()

    /**
     *  The method controls the sequence of the ontology generation. The app consists of 
     *  the following modules (each of them is controlled by the corresponding DB tables) 
     */
    private void generateOWL2ontology(String args[])
    {
        evalCallingArgs(args) ; 

        log("DBFOschemafy V3-001 started \n") ;

        /**
         *  Establishing MySQL DB-connection
         */
        connectToDB() ;
               
            // -------------------------------------------------------------
            new WriteOWLHeader(this.OWLresultFile,
                               this.DBconnection) ;
            // -------------------------------------------------------------
            new WriteOWLHeaderAnnotations(this.OWLresultFile,
                                          this.DBconnection
                                         ) ;
            //  -------------------------------------------------------------
            new WriteIAOAannotations(this.OWLresultFile,
                                    this.DBconnection
                                   ) ;
            //  -------------------------------------------------------------
            new DeclareClasses(this.OWLresultFile,
                               this.DBconnection
                              ) ;
            //  -------------------------------------------------------------
            new DeclareSubclasses(this.OWLresultFile,
                                  this.DBconnection
                                 ) ;
            //  -------------------------------------------------------------
            new DeclareDisjointClasses(this.OWLresultFile,
                                       this.DBconnection
                                      ) ;
            //  -------------------------------------------------------------
            new DeclareIAOAannotations(this.OWLresultFile,
                                       this.DBconnection
                                      ) ;
            //  -------------------------------------------------------------
            new AnnotateClasses(this.OWLresultFile,
                                this.DBconnection
                               ) ;
            //  -------------------------------------------------------------
            new WriteTriplets(this.OWLresultFile,
                              this.DBconnection
                             ) ;
            // -------------------------------------------------------------
            new WriteOWLTrailer(this.OWLresultFile,
                                this.DBconnection) ;
            
            log("DBFOschemafy V3-001 has succesfully been completed.\n") ;
           
            System.exit(0);
          
    }   //  and of method generateOWL2ontology()

    private void connectToDB()
    {
        DBserverConnection DC = new DBserverConnection() ;
        
        DC.connectDB(this.DBurl, this.DBuser, this.DBpassword) ;
        
        this.DBconnection = DC.getDBconnector() ;

    }   //  end of method connectToDB()
    
    /**
     *  Writes text message to the console
     *  @param logEntry displayed message  
     */
    public void log(String logEntry)
    {
        if (!this.silentMode)
            System.out.print(logEntry) ;  
        
    }   //  end of log()
 
}   //  end of class DBFOschemafyMain
