Search in sources :

Example 1 with DataSourceInstallationReport

use of org.entando.entando.aps.system.init.model.DataSourceInstallationReport in project entando-core by entando.

the class DatabaseManager method initMasterDatabases.

private void initMasterDatabases(SystemInstallationReport report, boolean checkOnStatup) throws ApsSystemException {
    String logPrefix = "|   ";
    System.out.println("+ [ Component: Core ] :: SCHEMA\n" + logPrefix);
    ComponentInstallationReport componentReport = report.getComponentReport("entandoCore", true);
    DataSourceInstallationReport dataSourceReport = componentReport.getDataSourceReport();
    if (componentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
        logger.debug("{}( ok )  Already installed\n{}", logPrefix, logPrefix);
        System.out.println(logPrefix + "( ok )  Already installed\n" + logPrefix);
        return;
    }
    try {
        String[] dataSourceNames = this.extractBeanNames(DataSource.class);
        Map<String, SystemInstallationReport.Status> databasesStatus = dataSourceReport.getDatabaseStatus();
        System.out.println(logPrefix + "Starting installation");
        for (String dataSourceName : dataSourceNames) {
            if (report.getStatus().equals(SystemInstallationReport.Status.PORTING)) {
                System.out.println(logPrefix + " - Already present! db " + dataSourceName);
                SystemInstallationReport.Status status = (checkOnStatup) ? report.getStatus() : SystemInstallationReport.Status.SKIPPED;
                databasesStatus.put(dataSourceName, status);
                report.setUpdated();
                continue;
            }
            SystemInstallationReport.Status dbStatus = databasesStatus.get(dataSourceName);
            if (dbStatus != null && (SystemInstallationReport.isSafeStatus(dbStatus))) {
                System.out.println(logPrefix + "\n" + logPrefix + "( ok )  " + dataSourceName + " already installed");
            } else if (dbStatus == null || !dbStatus.equals(SystemInstallationReport.Status.OK)) {
                DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
                // System.out.println(logPrefix + " - '" + dataSourceName + "' Installation Started... ");
                if (checkOnStatup) {
                    databasesStatus.put(dataSourceName, SystemInstallationReport.Status.INCOMPLETE);
                    System.out.println(logPrefix);
                    this.initMasterDatabase(dataSourceName, dataSource, dataSourceReport);
                    databasesStatus.put(dataSourceName, SystemInstallationReport.Status.OK);
                } else {
                    databasesStatus.put(dataSourceName, SystemInstallationReport.Status.SKIPPED);
                }
                report.setUpdated();
            }
        }
        System.out.println(logPrefix + "\n" + logPrefix + "Installation complete\n" + logPrefix);
        logger.debug(logPrefix + "\n" + logPrefix + "Installation complete\n" + logPrefix);
    } catch (Throwable t) {
        logger.error("Error initializating master databases", t);
        throw new ApsSystemException("Error initializating master databases", t);
    }
}
Also used : ComponentInstallationReport(org.entando.entando.aps.system.init.model.ComponentInstallationReport) SystemInstallationReport(org.entando.entando.aps.system.init.model.SystemInstallationReport) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataSourceInstallationReport(org.entando.entando.aps.system.init.model.DataSourceInstallationReport) DataSource(javax.sql.DataSource)

Example 2 with DataSourceInstallationReport

use of org.entando.entando.aps.system.init.model.DataSourceInstallationReport in project entando-core by entando.

the class DatabaseManager method initComponentDatabases.

private void initComponentDatabases(Component componentConfiguration, SystemInstallationReport report, boolean checkOnStatup) throws ApsSystemException {
    String logPrefix = "|   ";
    System.out.println("+ [ Component: " + componentConfiguration.getCode() + " ] :: SCHEMA\n" + logPrefix);
    ComponentInstallationReport componentReport = report.getComponentReport(componentConfiguration.getCode(), true);
    if (componentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
        logger.debug(logPrefix + "( ok )  Already installed\n" + logPrefix);
        System.out.println(logPrefix + "( ok )  Already installed\n" + logPrefix);
        return;
    } else if (componentReport.getStatus().equals(SystemInstallationReport.Status.UNINSTALLED)) {
        logger.debug(logPrefix + "( ok )  Uninstalled\n" + logPrefix);
        System.out.println(logPrefix + "( ok )  Uninstalled\n" + logPrefix);
        return;
    }
    try {
        String[] dataSourceNames = this.extractBeanNames(DataSource.class);
        Map<String, List<String>> tableMapping = componentConfiguration.getTableMapping();
        DataSourceInstallationReport dataSourceReport = componentReport.getDataSourceReport();
        System.out.println(logPrefix + "Starting installation\n" + logPrefix);
        for (String dataSourceName : dataSourceNames) {
            List<String> tableClassNames = (null != tableMapping) ? tableMapping.get(dataSourceName) : null;
            if (null == tableClassNames || tableClassNames.isEmpty()) {
                System.out.println(logPrefix + "( !! )  skipping " + dataSourceName + ": not available");
                dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.NOT_AVAILABLE);
                report.setUpdated();
                continue;
            }
            if (report.getStatus().equals(SystemInstallationReport.Status.PORTING)) {
                SystemInstallationReport.Status status = (checkOnStatup) ? report.getStatus() : SystemInstallationReport.Status.SKIPPED;
                dataSourceReport.getDatabaseStatus().put(dataSourceName, status);
                logger.debug(logPrefix + "( ok )  " + dataSourceName + " already installed" + SystemInstallationReport.Status.PORTING);
                System.out.println(logPrefix + "( ok )  " + dataSourceName + " already installed" + SystemInstallationReport.Status.PORTING);
                continue;
            }
            SystemInstallationReport.Status schemaStatus = dataSourceReport.getDatabaseStatus().get(dataSourceName);
            if (SystemInstallationReport.isSafeStatus(schemaStatus)) {
                // Already Done!
                System.out.println(logPrefix + "( ok )  " + dataSourceName + " already installed" + SystemInstallationReport.Status.PORTING);
                continue;
            }
            if (null == dataSourceReport.getDataSourceTables().get(dataSourceName)) {
                dataSourceReport.getDataSourceTables().put(dataSourceName, new ArrayList<String>());
            }
            if (checkOnStatup) {
                dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.INCOMPLETE);
                DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
                this.createTables(dataSourceName, tableClassNames, dataSource, dataSourceReport);
                System.out.println(logPrefix);
                dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.OK);
            } else {
                dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.SKIPPED);
            }
            report.setUpdated();
        }
        System.out.println(logPrefix + "\n" + logPrefix + "Installation complete\n" + logPrefix);
        logger.debug(logPrefix + "\n" + logPrefix + "Installation complete\n" + logPrefix);
    } catch (Throwable t) {
        logger.error("Error initializating component {}", componentConfiguration.getCode(), t);
        throw new ApsSystemException("Error initializating component " + componentConfiguration.getCode(), t);
    }
}
Also used : ComponentInstallationReport(org.entando.entando.aps.system.init.model.ComponentInstallationReport) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataSourceInstallationReport(org.entando.entando.aps.system.init.model.DataSourceInstallationReport) DataSource(javax.sql.DataSource) ArrayList(java.util.ArrayList) List(java.util.List) SystemInstallationReport(org.entando.entando.aps.system.init.model.SystemInstallationReport)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 DataSource (javax.sql.DataSource)2 ComponentInstallationReport (org.entando.entando.aps.system.init.model.ComponentInstallationReport)2 DataSourceInstallationReport (org.entando.entando.aps.system.init.model.DataSourceInstallationReport)2 SystemInstallationReport (org.entando.entando.aps.system.init.model.SystemInstallationReport)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1