Skip to content

Commit

Permalink
MGR-146
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Müller authored and Matthias Müller committed Jan 11, 2023
1 parent 38c8230 commit 882eb21
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 30 deletions.
14 changes: 12 additions & 2 deletions application-home/conf/datasources/ds-connections.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.appng.org/schema/platform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<datasources xmlns="http://www.appng.org/schema/platform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.appng.org/schema/platform http://www.appng.org/schema/platform/appng-platform.xsd">

<datasource id="databaseConnections">
Expand Down Expand Up @@ -31,6 +32,15 @@
<field name="databaseSize" type="decimal">
<label id="sizeMB" />
</field>
<field name="version" binding="version" type="text">
<label id="version" />
</field>
<field name="productName" binding="productName" type="text">
<label id="productName" />
</field>
<field name="productVersion" binding="productVersion" type="text">
<label id="productVersion" />
</field>
<field name="state" binding="state" type="image" readonly="true">
<label id="status" />
<icon condition="${current.item.active and not current.pendingMigrations}">led_green</icon>
Expand Down Expand Up @@ -178,7 +188,7 @@
<params>
<param name="connectionId" />
</params>
<meta-data bindClass="org.appng.application.manager.business.SqlExecutor$SqlStatement">
<meta-data bindClass="org.appng.application.manager.business.SqlExecutor$SqlStatement">
<field name="content" type="longtext">
<label>sqlStatement</label>
</field>
Expand Down
20 changes: 10 additions & 10 deletions application-home/conf/pages/pg-platform.xml
Expand Up @@ -70,7 +70,7 @@
<!-- Database Connections -->
<section>
<element passive="true">
<action eventId="databaseConnectionEvent" id="updateConnection" onSuccess="/platform#tab_databaseConnections">
<action eventId="databaseConnectionEvent" id="executeSql" onSuccess="/platform/connection/update/${id}&#63;expandSql=true#tab_databaseConnections">
<params>
<param name="id">${id}</param>
<param name="form_action">${form_action}</param>
Expand All @@ -82,15 +82,7 @@
</action>
</element>
<element folded="true" passive="true">
<datasource id="migrations">
<params>
<param name="id">${id}</param>
</params>
<condition expression="${entity eq 'connection' and action eq 'update' and not empty id}" />
</datasource>
</element>
<element folded="${expandSql ne 'true'}" passive="true">
<action eventId="databaseConnectionEvent" id="executeSql" onSuccess="/platform/connection/update/${id}&#63;expandSql=true#tab_databaseConnections">
<action eventId="databaseConnectionEvent" id="updateConnection" onSuccess="/platform#tab_databaseConnections">
<params>
<param name="id">${id}</param>
<param name="form_action">${form_action}</param>
Expand All @@ -101,6 +93,14 @@
</permissions>
</action>
</element>
<element folded="true" passive="true">
<datasource id="migrations">
<params>
<param name="id">${id}</param>
</params>
<condition expression="${entity eq 'connection' and action eq 'update' and not empty id}" />
</datasource>
</element>
<element>
<datasource id="databaseConnections">
<params>
Expand Down
24 changes: 12 additions & 12 deletions application-home/conf/pages/pg-sites.xml
Expand Up @@ -212,8 +212,8 @@
<!-- Database Connections -->
<section>
<element passive="true">
<action eventId="databaseConnectionEvent" id="updateConnection"
onSuccess="/sites/update/${siteid}#tab_databaseConnections">
<action eventId="databaseConnectionEvent" id="executeSql"
onSuccess="/sites/update/${siteid}/database/update/${subentityid1}&#63;expandSql=true#tab_databaseConnections">
<params>
<param name="id">${subentityid1}</param>
<param name="form_action">${form_action}</param>
Expand All @@ -226,27 +226,27 @@
</action>
</element>
<element folded="true" passive="true">
<datasource id="migrations">
<action eventId="databaseConnectionEvent" id="updateConnection"
onSuccess="/sites/update/${siteid}#tab_databaseConnections">
<params>
<param name="id">${subentityid1}</param>
<param name="form_action">${form_action}</param>
</params>
<condition
expression="${action eq 'update' and not empty siteid and subentity1 eq 'database' and subaction1 eq 'update' and not empty subentityid1}" />
</datasource>
<permissions>
<permission ref="site.database.edit" mode="set" />
</permissions>
</action>
</element>
<element passive="true" folded="${expandSql ne 'true'}">
<action eventId="databaseConnectionEvent" id="executeSql"
onSuccess="/sites/update/${siteid}/database/update/${subentityid1}&#63;expandSql=true#tab_databaseConnections">
<element folded="true" passive="true">
<datasource id="migrations">
<params>
<param name="id">${subentityid1}</param>
<param name="form_action">${form_action}</param>
</params>
<condition
expression="${action eq 'update' and not empty siteid and subentity1 eq 'database' and subaction1 eq 'update' and not empty subentityid1}" />
<permissions>
<permission ref="site.database.edit" mode="set" />
</permissions>
</action>
</datasource>
</element>
<element>
<datasource id="databaseConnections">
Expand Down
Expand Up @@ -15,6 +15,9 @@
*/
package org.appng.application.manager.form;

import java.sql.Connection;
import java.sql.SQLException;

import org.appng.core.domain.DatabaseConnection;
import org.flywaydb.core.api.MigrationInfoService;

Expand All @@ -23,6 +26,7 @@

public class DatabaseConnectionForm {

private static final String UNKNOWN = "UNKNOWN";
@Getter
@Setter
private DatabaseConnection item;
Expand All @@ -38,8 +42,30 @@ public boolean isPendingMigrations() {

public String getState() {
MigrationInfoService migrationInfoService = item.getMigrationInfoService();
return null == migrationInfoService || null == migrationInfoService.current() ? "UNKNOWN"
return null == migrationInfoService || null == migrationInfoService.current() ? UNKNOWN
: migrationInfoService.current().getState().name();
}

public String getVersion() {
MigrationInfoService migrationInfoService = item.getMigrationInfoService();
return null == migrationInfoService || null == migrationInfoService.current() ? UNKNOWN
: migrationInfoService.current().getVersion().getVersion();
}

public String getProductName() {
try (Connection connection = item.getConnection()) {
return connection.getMetaData().getDatabaseProductName();
} catch (SQLException e) {
}
return UNKNOWN;
}

public String getProductVersion() {
try (Connection connection = item.getConnection()) {
return connection.getMetaData().getDatabaseProductVersion();
} catch (SQLException e) {
}
return UNKNOWN;
}

}
29 changes: 24 additions & 5 deletions src/test/resources/xml/DataBaseConnectionsTest-testOverview.xml
Expand Up @@ -28,6 +28,15 @@
<field name="databaseSize" type="decimal" format="#.##" binding="item.databaseSize">
<label id="sizeMB">Size (MB)</label>
</field>
<field name="version" type="text" binding="version">
<label id="version">Version</label>
</field>
<field name="productName" type="text" binding="productName">
<label id="productName">Product Name</label>
</field>
<field name="productVersion" type="text" binding="productVersion">
<label id="productVersion">Product Version</label>
</field>
<field name="state" type="image" readonly="true" binding="state">
<label id="status">Status</label>
<icon condition="${current.item.active and not current.pendingMigrations}">led_green</icon>
Expand All @@ -45,18 +54,19 @@
</meta-data>
<linkpanel id="create" location="both" />
<linkpanel id="actions" location="inline">
<link id="actions[1]" mode="intern" target="${current.item.id}" default="true">
<link id="actions[1]" target="${current.item.id}" mode="intern" default="true">
<label id="edit">Edit</label>
<icon>edit</icon>
</link>
<link id="actions[3]" mode="intern" target="${current.item.id}">
<link id="actions[3]" target="${current.item.id}" mode="intern">
<label id="test">Test</label>
<icon>start</icon>
</link>
</linkpanel>
</config>
<data>
<resultset chunk="0" chunkname="databaseConnections" chunksize="10" nextchunk="0" previouschunk="0" firstchunk="0" lastchunk="0" hits="1">
<resultset chunk="0" chunkname="databaseConnections" chunksize="10" nextchunk="0" previouschunk="0"
firstchunk="0" lastchunk="0" hits="1">
<result>
<field name="type" type="text">
<value>HSQL</value>
Expand All @@ -73,6 +83,15 @@
<field name="databaseSize" type="decimal">
<value></value>
</field>
<field name="version" type="text">
<value>UNKNOWN</value>
</field>
<field name="productName" type="text">
<value>HSQL Database Engine</value>
</field>
<field name="productVersion" type="text">
<value>2.5.0</value>
</field>
<field name="state" type="image">
<value>UNKNOWN</value>
<icon type="class">led_red</icon>
Expand All @@ -82,11 +101,11 @@
<icon type="class">led_green</icon>
</field>
<linkpanel id="actions" location="inline">
<link id="actions[1]" mode="intern" target="1" default="true">
<link id="actions[1]" target="1" mode="intern" default="true">
<label id="edit">Edit</label>
<icon>edit</icon>
</link>
<link id="actions[3]" mode="intern" target="1">
<link id="actions[3]" target="1" mode="intern">
<label id="test">Test</label>
<icon>start</icon>
</link>
Expand Down

0 comments on commit 882eb21

Please sign in to comment.