Search in sources :

Example 41 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class DatabaseDumper method finalizeDumpFile.

private void finalizeDumpFile(String filename, String dataSourceName, String backupSubFolder, File tempFile) throws ApsSystemException {
    try {
        StringBuilder dirName = new StringBuilder(this.getLocalBackupsFolder());
        if (null != backupSubFolder) {
            dirName.append(backupSubFolder).append(File.separator);
        }
        dirName.append(dataSourceName).append(File.separator);
        InputStream is = new FileInputStream(new File(tempFile.getAbsolutePath()));
        this.save(filename, dirName.toString(), is);
    } catch (ApsSystemException | IOException t) {
        _logger.error("Error saving dump file '{}'", tempFile.getName(), t);
        throw new ApsSystemException("Error saving dump file '" + tempFile.getName() + "'", t);
    } finally {
        if (null != tempFile) {
            tempFile.delete();
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 42 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class DatabaseDumper method dumpTableData.

protected void dumpTableData(String tableName, String dataSourceName, DataSource dataSource, DataSourceDumpReport report, String backupSubFolder) throws ApsSystemException {
    String filename = tableName + ".sql";
    File tempFile = null;
    FileWriter fileWriter = null;
    BufferedWriter bufferWriter = null;
    try {
        tempFile = this.createEmptyTempFile(filename);
        fileWriter = new FileWriter(tempFile.getAbsolutePath());
        bufferWriter = new BufferedWriter(fileWriter);
        TableDumpReport tableDumpReport = TableDataUtils.dumpTable(bufferWriter, dataSource, tableName);
        report.addTableReport(dataSourceName, tableDumpReport);
    } catch (IOException t) {
        _logger.error("Error dumping table '{}' - datasource '{}'", tableName, dataSourceName, t);
        throw new ApsSystemException("Error dumping table '" + tableName + "' - datasource '" + dataSourceName + "'", t);
    } finally {
        try {
            if (null != bufferWriter) {
                bufferWriter.close();
            }
            if (null != fileWriter) {
                fileWriter.close();
            }
        } catch (IOException t2) {
            _logger.error("Error closing FileWriter and BufferedWriter of file '{}'", filename, t2);
            throw new ApsSystemException("Error closing FileWriter and BufferedWriter", t2);
        }
    }
    this.finalizeDumpFile(filename, dataSourceName, backupSubFolder, tempFile);
}
Also used : FileWriter(java.io.FileWriter) TableDumpReport(org.entando.entando.aps.system.init.model.TableDumpReport) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 43 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class DatabaseDumper method save.

protected void save(String filename, String folder, InputStream is) throws ApsSystemException {
    try {
        IStorageManager storageManager = this.getStorageManager();
        String path = folder + filename;
        storageManager.saveFile(path, true, is);
    } catch (Throwable t) {
        _logger.error("Error saving backup '{}'", filename, t);
        throw new ApsSystemException("Error saving backup '" + filename + "'", t);
    }
}
Also used : IStorageManager(org.entando.entando.aps.system.services.storage.IStorageManager) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 44 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class DatabaseManager method readFile.

private String readFile(Resource resource) throws Throwable {
    if (resource == null) {
        return null;
    }
    InputStream is = null;
    String text = null;
    try {
        is = resource.getInputStream();
        if (null == is) {
            return null;
        }
        text = FileTextReader.getText(is, "UTF-8");
    } catch (Throwable t) {
        logger.error("Error reading resource", t);
        throw new ApsSystemException("Error reading resource", t);
    } finally {
        if (null != is) {
            is.close();
        }
    }
    return text;
}
Also used : InputStream(java.io.InputStream) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 45 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class DatabaseManager method restoreDefaultDump.

private void restoreDefaultDump() throws ApsSystemException {
    try {
        String[] dataSourceNames = this.extractBeanNames(DataSource.class);
        Map<String, Resource> defaultDump = this.getDefaultSqlDump();
        if (null == defaultDump || defaultDump.isEmpty()) {
            return;
        }
        for (String dataSourceName : dataSourceNames) {
            DataSource dataSource = (DataSource) this.getBeanFactory().getBean(dataSourceName);
            Resource resource = defaultDump.get(dataSourceName);
            String script = this.readFile(resource);
            if (null != script && script.trim().length() > 0) {
                this.getDatabaseRestorer().initOracleSchema(dataSource);
                TableDataUtils.valueDatabase(script, dataSourceName, dataSource, null);
            }
        }
    } catch (Throwable t) {
        logger.error("Error restoring default Dump", t);
        throw new ApsSystemException("Error restoring default Dump", t);
    }
}
Also used : Resource(org.springframework.core.io.Resource) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) DataSource(javax.sql.DataSource)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)452 ArrayList (java.util.ArrayList)53 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)48 RestServerError (org.entando.entando.aps.system.exception.RestServerError)39 ApsProperties (com.agiletec.aps.util.ApsProperties)26 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)23 HashMap (java.util.HashMap)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)21 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)21 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)20 Date (java.util.Date)20 StringReader (java.io.StringReader)18 IPage (com.agiletec.aps.system.services.page.IPage)17 List (java.util.List)17 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)16 File (java.io.File)16 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 Widget (com.agiletec.aps.system.services.page.Widget)15 IOException (java.io.IOException)15 Cache (org.springframework.cache.Cache)15