Search in sources :

Example 6 with EntException

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

the class DatabaseManager method initMasterDatabase.

private void initMasterDatabase(String databaseName, DataSource dataSource, DataSourceInstallationReport schemaReport) throws EntException {
    try {
        DatabaseType type = this.getDatabaseRestorer().getType(dataSource);
        if (type.equals(DatabaseType.DERBY)) {
            this.getDatabaseRestorer().initDerbySchema(dataSource);
        }
        List<String> tableClassNames = this.getEntandoTableMapping().get(databaseName);
        if (null == tableClassNames || tableClassNames.isEmpty()) {
            logger.debug("No Master Tables defined for db {}", databaseName);
            schemaReport.getDatabaseStatus().put(databaseName, SystemInstallationReport.Status.NOT_AVAILABLE);
        } else {
            this.createTables(databaseName, tableClassNames, dataSource, schemaReport);
        }
    } catch (Throwable t) {
        schemaReport.getDatabaseStatus().put(databaseName, SystemInstallationReport.Status.INCOMPLETE);
        logger.error("Error creating master tables to db {}", databaseName, t);
        throw new EntException("Error creating master tables to db " + databaseName, t);
    }
}
Also used : EntException(org.entando.entando.ent.exception.EntException)

Example 7 with EntException

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

the class DatabaseManager method uninstallComponentResources.

public void uninstallComponentResources(Component componentConfiguration, SystemInstallationReport report) throws EntException {
    logger.info(INIT_MSG_P, componentConfiguration.getCode(), LOG_PREFIX);
    ComponentInstallationReport componentReport = report.getComponentReport(componentConfiguration.getCode(), false);
    if (componentReport.getStatus().equals(SystemInstallationReport.Status.UNINSTALLED)) {
        logger.debug(LOG_PREFIX + "( ok ) Already uninstalled\n" + LOG_PREFIX);
        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( ok ) Already uninstalled\n" + LOG_PREFIX);
    } else if (componentReport.getStatus().equals(SystemInstallationReport.Status.OK)) {
        DataInstallationReport dataReport = componentReport.getDataReport();
        try {
            ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "Starting uninstall\n" + LOG_PREFIX);
            ComponentUninstallerInfo uninstallInfo = componentConfiguration.getUninstallerInfo();
            // Remove sqlResources
            String[] dataSourceNames = this.extractBeanNames(DataSource.class);
            for (String dataSourceName : dataSourceNames) {
                DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
                SystemInstallationReport.Status dataStatus = dataReport.getDatabaseStatus().get(dataSourceName);
                if (SystemInstallationReport.isSafeStatus(dataStatus)) {
                    // We can proceed with removing the stuff
                    Resource sqlResource = uninstallInfo.getSqlResources(dataSourceName);
                    String script = (null != sqlResource) ? this.readFile(sqlResource) : null;
                    if (null != script && script.trim().length() > 0) {
                        dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.INCOMPLETE);
                        TableDataUtils.valueDatabase(script, dataSourceName, dataSource, dataReport);
                        ApsSystemUtils.directStdoutTrace("|   ( ok )  " + dataSourceName);
                        dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.UNINSTALLED);
                        report.setUpdated();
                    } else {
                        ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "( !! )  skipping " + dataSourceName + ": not available");
                        dataReport.getDatabaseStatus().put(dataSourceName, SystemInstallationReport.Status.NOT_AVAILABLE);
                        report.setUpdated();
                    }
                }
            }
            report.removeComponentReport(componentConfiguration.getCode());
            report.setUpdated();
            ApsSystemUtils.directStdoutTrace(LOG_PREFIX + "\n" + LOG_PREFIX + "Uninstall complete\n" + LOG_PREFIX);
            logger.debug(LOG_PREFIX + "\n" + LOG_PREFIX + "Uninstall complete\n" + LOG_PREFIX);
        } catch (Throwable t) {
            logger.error("Error removing component {}", componentConfiguration.getCode(), t);
            throw new EntException("Error removing component " + componentConfiguration.getCode(), t);
        }
    }
}
Also used : DataInstallationReport(org.entando.entando.aps.system.init.model.DataInstallationReport) ComponentInstallationReport(org.entando.entando.aps.system.init.model.ComponentInstallationReport) Resource(org.springframework.core.io.Resource) ComponentUninstallerInfo(org.entando.entando.aps.system.init.model.ComponentUninstallerInfo) EntException(org.entando.entando.ent.exception.EntException) DataSource(javax.sql.DataSource)

Example 8 with EntException

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

the class DatabaseRestorer method restoreBackup.

protected void restoreBackup(String backupSubFolder) throws EntException {
    try {
        this.restoreLocalDump(this.getEntandoTableMapping(), backupSubFolder);
        List<Component> components = this.getComponents();
        for (int i = 0; i < components.size(); i++) {
            Component componentConfiguration = components.get(i);
            this.restoreLocalDump(componentConfiguration.getTableMapping(), backupSubFolder);
        }
    } catch (Throwable t) {
        _logger.error("Error while restoring local backup", t);
        throw new EntException("Error while restoring local backup", t);
    }
}
Also used : EntException(org.entando.entando.ent.exception.EntException) Component(org.entando.entando.aps.system.init.model.Component)

Example 9 with EntException

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

the class DatabaseRestorer method initDerbySchema.

protected void initDerbySchema(DataSource dataSource) throws Throwable {
    String username = this.invokeGetMethod("getUsername", dataSource);
    try {
        String[] queryCreateSchema = new String[] { "CREATE SCHEMA " + username.toUpperCase() };
        TableDataUtils.executeQueries(dataSource, queryCreateSchema, false);
    } catch (Throwable t) {
        _logger.info("Error creating derby schema" + t);
        throw new EntException("Error creating derby schema", t);
    }
    try {
        String[] initSchemaQuery = new String[] { "SET SCHEMA \"" + username.toUpperCase() + "\"" };
        TableDataUtils.executeQueries(dataSource, initSchemaQuery, true);
    } catch (Throwable t) {
        _logger.error("Error initializating Derby Schema", t);
        throw new EntException("Error initializating Derby Schema", t);
    }
}
Also used : EntException(org.entando.entando.ent.exception.EntException)

Example 10 with EntException

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

the class ApiEntityTypeInterface method getEntityType.

public JAXBEntityType getEntityType(Properties properties) throws Throwable {
    JAXBEntityType jaxbEntityType = null;
    try {
        IEntityManager manager = this.getEntityManager();
        String typeCode = properties.getProperty(this.getTypeCodeParamName());
        IApsEntity masterEntityType = manager.getEntityPrototype(typeCode);
        if (null == masterEntityType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' does not exist");
        }
        jaxbEntityType = this.createJAXBEntityType(masterEntityType);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error extracting entity type", t);
        // ApsSystemUtils.logThrowable(t, this, "getEntityType");
        throw new EntException("Error extracting entity type", t);
    }
    return jaxbEntityType;
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) EntException(org.entando.entando.ent.exception.EntException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

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