Search in sources :

Example 1 with EntException

use of org.entando.entando.ent.exception.EntException in project entando-engine by entando.

the class DatabaseManager method createTables.

private void createTables(String databaseName, List<String> tableClassNames, DataSource dataSource, DataSourceInstallationReport schemaReport) throws EntException {
    try {
        DatabaseType type = this.getDatabaseRestorer().getType(dataSource);
        TableFactory tableFactory = new TableFactory(databaseName, dataSource, type);
        tableFactory.createTables(tableClassNames, schemaReport);
    } catch (Throwable t) {
        logger.error("Error creating tables to db {}", databaseName, t);
        throw new EntException("Error creating tables to db " + databaseName, t);
    }
}
Also used : TableFactory(org.entando.entando.aps.system.init.util.TableFactory) EntException(org.entando.entando.ent.exception.EntException)

Example 2 with EntException

use of org.entando.entando.ent.exception.EntException in project entando-engine by entando.

the class DatabaseManager method initComponentDatabases.

public void initComponentDatabases(Component componentConfiguration, SystemInstallationReport report, boolean checkOnStatup) throws EntException {
    logger.info(INIT_MSG_P, componentConfiguration.getCode(), LOG_PREFIX);
    ComponentInstallationReport componentReport = report.getComponentReport(componentConfiguration.getCode(), true);
    if (componentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
        logger.debug(LOG_PREFIX + "( ok )  Already installed\n" + LOG_PREFIX);
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok )  Already installed\n" + LOG_PREFIX);
        return;
    } else if (componentReport.getStatus().equals(SystemInstallationReport.Status.UNINSTALLED)) {
        logger.debug(LOG_PREFIX + "( ok )  Uninstalled\n" + LOG_PREFIX);
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok )  Uninstalled\n" + LOG_PREFIX);
        return;
    }
    try {
        String[] dataSourceNames = this.extractBeanNames(DataSource.class);
        Map<String, List<String>> tableMapping = componentConfiguration.getTableMapping();
        DataSourceInstallationReport dataSourceReport = componentReport.getDataSourceReport();
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "Starting installation\n" + LOG_PREFIX);
        for (String dataSourceName : dataSourceNames) {
            List<String> tableClassNames = (null != tableMapping) ? tableMapping.get(dataSourceName) : null;
            if (null == tableClassNames || tableClassNames.isEmpty()) {
                ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( !! )  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(LOG_PREFIX + "( ok )  {} already installed {}", dataSourceName, SystemInstallationReport.Status.PORTING);
                ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok )  " + dataSourceName + " already installed" + SystemInstallationReport.Status.PORTING);
                continue;
            }
            SystemInstallationReport.Status schemaStatus = dataSourceReport.getDatabaseStatus().get(dataSourceName);
            if (SystemInstallationReport.isSafeStatus(schemaStatus)) {
                // Already Done!
                ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( 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);
                ApsSystemUtils.directStdoutTrace(LOG_PREFIX);
                dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.OK);
            } else {
                dataSourceReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.SKIPPED);
            }
            report.setUpdated();
        }
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
        logger.debug(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
    } catch (Throwable t) {
        logger.error("Error initializating component {}", componentConfiguration.getCode(), t);
        throw new EntException("Error initializating component " + componentConfiguration.getCode(), t);
    }
}
Also used : ComponentInstallationReport(org.entando.entando.aps.system.init.model.ComponentInstallationReport) EntException(org.entando.entando.ent.exception.EntException) 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)

Example 3 with EntException

use of org.entando.entando.ent.exception.EntException in project entando-engine by entando.

the class DatabaseManager method initComponentDefaultResources.

public void initComponentDefaultResources(Component componentConfiguration, SystemInstallationReport report, boolean checkOnStatup) throws EntException {
    logger.info(INIT_MSG_P, componentConfiguration.getCode(), LOG_PREFIX);
    ComponentInstallationReport componentReport = report.getComponentReport(componentConfiguration.getCode(), false);
    if (componentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
        logger.debug(LOG_PREFIX + "( ok )  Already installed\n" + LOG_PREFIX);
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok )  Already installed\n" + LOG_PREFIX);
        return;
    } else if (componentReport.getStatus().equals(SystemInstallationReport.Status.UNINSTALLED)) {
        logger.debug(LOG_PREFIX + "( ok )  Uninstalled\n" + LOG_PREFIX);
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok )  Uninstalled\n" + LOG_PREFIX);
        return;
    }
    DataInstallationReport dataReport = componentReport.getDataReport();
    try {
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "Starting installation\n" + LOG_PREFIX);
        String[] dataSourceNames = this.extractBeanNames(DataSource.class);
        for (String dataSourceName : dataSourceNames) {
            if ((report.getStatus().equals(SystemInstallationReport.Status.PORTING) || report.getStatus().equals(SystemInstallationReport.Status.RESTORE)) && checkOnStatup) {
                dataReport.getDatabaseStatus().put(dataSourceName, report.getStatus());
                ApsSystemUtils.directStdoutTrace("|   ( ok )  " + dataSourceName);
                report.setUpdated();
                continue;
            }
            DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
            SystemInstallationReport.Status dataStatus = dataReport.getDatabaseStatus().get(dataSourceName);
            if (SystemInstallationReport.isSafeStatus(dataStatus)) {
                logger.debug(LOG_PREFIX + "( ok )  Already installed\n" + LOG_PREFIX);
                ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok )  Already installed\n" + LOG_PREFIX);
                continue;
            }
            Map<String, ComponentEnvironment> environments = componentConfiguration.getEnvironments();
            String compEnvKey = (Environment.test.equals(this.getEnvironment())) ? Environment.test.toString() : Environment.production.toString();
            ComponentEnvironment componentEnvironment = (null != environments) ? environments.get(compEnvKey) : null;
            Resource resource = (null != componentEnvironment) ? componentEnvironment.getSqlResources(dataSourceName) : null;
            String script = (null != resource) ? this.readFile(resource) : null;
            if (null != script && script.trim().length() > 0) {
                if (checkOnStatup) {
                    dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.INCOMPLETE);
                    this.getDatabaseRestorer().initOracleSchema(dataSource);
                    TableDataUtils.valueDatabase(script, dataSourceName, dataSource, dataReport);
                    ApsSystemUtils.directStdoutTrace("|   ( ok )  " + dataSourceName);
                    dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.OK);
                } else {
                    dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.SKIPPED);
                }
                report.setUpdated();
            } else {
                ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( !! )  skipping " + dataSourceName + ": not available");
                dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.NOT_AVAILABLE);
                report.setUpdated();
            }
        }
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
        logger.debug(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
    } catch (Throwable t) {
        logger.error("Error restoring default resources of component {}", componentConfiguration.getCode(), t);
        throw new EntException("Error restoring default resources of component " + componentConfiguration.getCode(), t);
    }
}
Also used : ComponentEnvironment(org.entando.entando.aps.system.init.model.ComponentEnvironment) DataInstallationReport(org.entando.entando.aps.system.init.model.DataInstallationReport) ComponentInstallationReport(org.entando.entando.aps.system.init.model.ComponentInstallationReport) Resource(org.springframework.core.io.Resource) SystemInstallationReport(org.entando.entando.aps.system.init.model.SystemInstallationReport) EntException(org.entando.entando.ent.exception.EntException) DataSource(javax.sql.DataSource)

Example 4 with EntException

use of org.entando.entando.ent.exception.EntException in project entando-engine by entando.

the class DatabaseManager method deleteBackup.

@Override
public void deleteBackup(String subFolderName) throws EntException {
    try {
        String baseDir = this.getLocalBackupsFolder();
        String directoryName = baseDir + subFolderName;
        this.getStorageManager().deleteDirectory(directoryName, true);
    } catch (Throwable t) {
        logger.error("Error while deleting backup", t);
        throw new EntException("Error while deleting backup", t);
    }
}
Also used : EntException(org.entando.entando.ent.exception.EntException)

Example 5 with EntException

use of org.entando.entando.ent.exception.EntException in project entando-engine by entando.

the class DatabaseManager method initMasterDatabases.

private void initMasterDatabases(SystemInstallationReport report, boolean checkOnStatup) throws EntException {
    logger.info(INIT_MSG_P, "Core", LOG_PREFIX);
    ComponentInstallationReport componentReport = report.getComponentReport("entandoCore", true);
    DataSourceInstallationReport dataSourceReport = componentReport.getDataSourceReport();
    if (componentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
        logger.debug("{}( ok )  Already installed\n{}", LOG_PREFIX, LOG_PREFIX);
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok )  Already installed\n" + LOG_PREFIX);
        return;
    }
    try {
        String[] dataSourceNames = this.extractBeanNames(DataSource.class);
        Map<String, SystemInstallationReport.Status> databasesStatus = dataSourceReport.getDatabaseStatus();
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "Starting installation");
        for (String dataSourceName : dataSourceNames) {
            if (report.getStatus().equals(SystemInstallationReport.Status.PORTING)) {
                ApsSystemUtils.directStdoutTrace(LOG_PREFIX + " - 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))) {
                ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "\n" + LOG_PREFIX + "( ok )  " + dataSourceName + " already installed");
            } else if (dbStatus == null || !dbStatus.equals(SystemInstallationReport.Status.OK)) {
                DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
                if (checkOnStatup) {
                    databasesStatus.put(dataSourceName, SystemInstallationReport.Status.INCOMPLETE);
                    ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "");
                    this.initMasterDatabase(dataSourceName, dataSource, dataSourceReport);
                    databasesStatus.put(dataSourceName, SystemInstallationReport.Status.OK);
                } else {
                    databasesStatus.put(dataSourceName, SystemInstallationReport.Status.SKIPPED);
                }
                report.setUpdated();
            }
        }
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
        logger.debug(LOG_PREFIX + "\n" + LOG_PREFIX + "Installation complete\n" + LOG_PREFIX);
    } catch (Throwable t) {
        logger.error("Error initializating master databases", t);
        throw new EntException("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) EntException(org.entando.entando.ent.exception.EntException) DataSourceInstallationReport(org.entando.entando.aps.system.init.model.DataSourceInstallationReport) DataSource(javax.sql.DataSource)

Aggregations

EntException (org.entando.entando.ent.exception.EntException)296 RestServerError (org.entando.entando.aps.system.exception.RestServerError)44 ArrayList (java.util.ArrayList)31 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)22 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)18 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)18 ApsProperties (com.agiletec.aps.util.ApsProperties)16 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)15 HashMap (java.util.HashMap)14 Cache (org.springframework.cache.Cache)14 IPage (com.agiletec.aps.system.services.page.IPage)13 StringReader (java.io.StringReader)12 Connection (java.sql.Connection)12 SQLException (java.sql.SQLException)12 List (java.util.List)11 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)11 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)11 Date (java.util.Date)10 DataSource (javax.sql.DataSource)10 SAXBuilder (org.jdom.input.SAXBuilder)10