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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
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;
}
Aggregations