Commit 1991f0df authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Bugfix Reload button on new TAP_SCHEMA schemas, UCD dialog improvements,...

Bugfix Reload button on new TAP_SCHEMA schemas, UCD dialog improvements, protected TAP_SCHEMA entities from removal, minor changes
parent 471f2ac7
......@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>it.inaf.ia2.tap</groupId>
<artifactId>TapSchemaManagerAPI</artifactId>
<version>1.0.1</version>
<version>1.0.3</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......
......@@ -153,4 +153,11 @@ public class Credentials implements Serializable {
}
return null;
}
@Override
public String toString() {
return String.format("[%s] type=%s, hostname=%s, port=%s, username=%s, password=%s, database=%s",
Credentials.class.getCanonicalName(),
databaseType, hostname, port, username, password, database);
}
}
......@@ -22,13 +22,11 @@
*/
package it.inaf.ia2.tsm.api;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import it.inaf.ia2.tsm.api.contract.DatabaseType;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.postgresql.ds.PGPoolingDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -161,12 +159,12 @@ public class DBWrapper implements Serializable {
public DataSource getTapSchemaDataSource() {
if (credentials != null) {
if (dataSource == null) {
dataSource = createDataSource(credentials);
dataSource = TSMUtil.createDataSource(credentials);
}
return dataSource;
}
if (tapSchemaDataSource == null) {
tapSchemaDataSource = createDataSource(tapSchemaCredentials);
tapSchemaDataSource = TSMUtil.createDataSource(tapSchemaCredentials);
}
return tapSchemaDataSource;
}
......@@ -174,44 +172,14 @@ public class DBWrapper implements Serializable {
public DataSource getSourceDataSource() {
if (credentials != null) {
if (dataSource == null) {
dataSource = createDataSource(credentials);
dataSource = TSMUtil.createDataSource(credentials);
}
return dataSource;
}
if (sourceDataSource == null) {
sourceDataSource = createDataSource(sourceCredentials);
sourceDataSource = TSMUtil.createDataSource(sourceCredentials);
}
return sourceDataSource;
}
private DataSource createDataSource(Credentials credentials) {
switch (credentials.getDatabaseType()) {
case MYSQL:
MysqlDataSource myds = new MysqlDataSource();
myds.setServerName(credentials.getHostname());
myds.setPortNumber(credentials.getPort());
myds.setUser(credentials.getUsername());
myds.setPassword(credentials.getPassword());
return myds;
case POSTGRES:
PGPoolingDataSource pgds = new PGPoolingDataSource();
pgds.setServerName(credentials.getHostname());
pgds.setPortNumber(credentials.getPort());
pgds.setUser(credentials.getUsername());
pgds.setPassword(credentials.getPassword());
pgds.setDatabaseName(credentials.getDatabase());
return pgds;
default:
throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet.");
}
}
}
}
......@@ -582,11 +582,22 @@ public class Dao {
}
}
public static List<String> getAllTAPSchemasNames(Credentials credentials) throws SQLException {
DatabaseType dbType = credentials.getDatabaseType();
DataSource ds = TSMUtil.createDataSource(credentials);
List<String> allSchemas = DaoSchema.getAllSchemasNames(ds, dbType);
return getAllTAPSchemasNames(ds, dbType, allSchemas);
}
public static List<String> getAllTAPSchemasNames(DBWrapper dbs) throws SQLException {
List<String> allSchemas = DaoSchema.getAllSchemasNames(dbs.getTapSchemaDataSource(), dbs.getTapSchemaDatabaseType());
return getAllTAPSchemasNames(dbs, allSchemas);
}
public static List<String> getAllTAPSchemasNames(DBWrapper dbs, List<String> allSchemas) throws SQLException {
return getAllTAPSchemasNames(dbs.getTapSchemaDataSource(), dbs.getTapSchemaDatabaseType(), allSchemas);
}
/**
* Retrieve the list of all TAP_SCHEMA schemas names contained in the
* TAP_SCHEMA <code>DataSource</code>.<br>
......@@ -600,7 +611,7 @@ public class Dao {
* @return list of all TAP_SCHEMA schemas names alphabetically and case
* insensitively ordered.
*/
public static List<String> getAllTAPSchemasNames(DBWrapper dbs, List<String> allSchemas) throws SQLException {
public static List<String> getAllTAPSchemasNames(DataSource dataSource, DatabaseType dbType, List<String> allSchemas) throws SQLException {
List<String> allTAPSchemas = new ArrayList<>();
......@@ -612,8 +623,6 @@ public class Dao {
keys = false,
keyColumns = false;
DatabaseType dbType = dbs.getTapSchemaDatabaseType();
String query;
if (dbType == DatabaseType.MYSQL) {
query = "SHOW TABLES FROM `" + schemaName + "`";
......@@ -625,7 +634,7 @@ public class Dao {
log.debug("Executing query {}", query);
try (Connection connection = dbs.getTapSchemaConnection();
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query)) {
while (resultSet.next()) {
......
......@@ -48,6 +48,11 @@ public class DaoSchema {
private static final Logger log = LoggerFactory.getLogger(DaoSchema.class);
public static List<String> getAllSchemasNames(Credentials credentials) throws SQLException {
DataSource ds = TSMUtil.createDataSource(credentials);
return getAllSchemasNames(ds, credentials.getDatabaseType());
}
/**
* Retrieve the list of the names of the all the schemas contained into the
* database specified by the <code>DataSource</code> parameter.
......@@ -99,7 +104,7 @@ public class DaoSchema {
protected TapSchemaEntity getEntity(ResultSet rs) throws SQLException {
String schemaName = rs.getString("schema_name");
Schema schema = tapSchema.addChild(schemaName);
if(schema == null) {
if (schema == null) {
return null;
}
schema.setStatus(Status.ADDED_PERSISTED);
......
......@@ -22,6 +22,7 @@
*/
package it.inaf.ia2.tsm.api;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import it.inaf.ia2.tsm.api.contract.DatabaseType;
import it.inaf.ia2.tsm.api.contract.ChildEntity;
import it.inaf.ia2.tsm.api.contract.Column;
......@@ -40,6 +41,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.postgresql.ds.PGPoolingDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -53,6 +55,36 @@ public class TSMUtil {
private static final Logger log = LoggerFactory.getLogger(TSMUtil.class);
public static DataSource createDataSource(Credentials credentials) {
switch (credentials.getDatabaseType()) {
case MYSQL:
MysqlDataSource myds = new MysqlDataSource();
myds.setServerName(credentials.getHostname());
myds.setPortNumber(credentials.getPort());
myds.setUser(credentials.getUsername());
myds.setPassword(credentials.getPassword());
return myds;
case POSTGRES:
PGPoolingDataSource pgds = new PGPoolingDataSource();
pgds.setServerName(credentials.getHostname());
pgds.setPortNumber(credentials.getPort());
pgds.setUser(credentials.getUsername());
pgds.setPassword(credentials.getPassword());
pgds.setDatabaseName(credentials.getDatabase());
return pgds;
default:
throw new UnsupportedOperationException(credentials.getDatabaseType() + " not supported yet.");
}
}
protected static List<String> sortStringsList(List<String> list) {
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
return list;
......
......@@ -4,7 +4,7 @@
<groupId>it.inaf.ia2.tap</groupId>
<artifactId>TapSchemaManagerWebApp</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<packaging>war</packaging>
<name>TapSchemaManagerWebApp</name>
......@@ -87,7 +87,7 @@
<dependency>
<groupId>it.inaf.ia2.tap</groupId>
<artifactId>TapSchemaManagerAPI</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>ari.ucd</groupId>
......
......@@ -197,7 +197,7 @@ public class SchemaSelectionBean implements Serializable {
throw new RuntimeException(e);
}
}
public String getTapSchemaName() {
return tapSchemaName;
}
......
......@@ -90,11 +90,8 @@ public class SearchUCDDialog implements Serializable {
UCDServiceErrorMessage = null;
}
public void search(String description) {
public void search() {
try {
setDefault();
this.description = description;
String assignResponse = SearchUCD.assign(description);
if (assignResponse == null) {
UCDnotFound = true;
......
......@@ -337,7 +337,7 @@ public class TapSchemaEditingBean implements Serializable {
String description = selectedColumn.getDescription();
if (description != null && !description.isEmpty()) {
searchUCDDialog.setDescription(description);
searchUCDDialog.search(description);
searchUCDDialog.search();
}
}
......@@ -408,6 +408,17 @@ public class TapSchemaEditingBean implements Serializable {
}
public String reload() {
return schemaSelection.edit();
if (schemaSelection.getSelectedRadioOption().equals("edit")) {
return schemaSelection.edit();
} else {
if (tapSchema.exists()) {
schemaSelection.setSelectedRadioOption("edit");
schemaSelection.setSelectedTAPSchema(tapSchema.getName());
return schemaSelection.edit();
} else {
return schemaSelection.create();
}
}
}
}
......@@ -135,6 +135,9 @@ input[type="checkbox"].changed {
.removable-tab.to-remove a {
padding-right: 15px !important;
}
.removable-tab.unremovable-tab a {
padding-right: 15px !important;
}
.strikeout, .strikeout:hover {
text-decoration: line-through !important;
}
......
......@@ -58,11 +58,11 @@
<ul class="nav nav-tabs" id="schemas" role="tablist">
<ui:repeat value="#{tapSchemaEditing.tapSchema.addedOrRemovedChildren}" var="schema">
<li role="presentation" class="removable-tab #{tapSchemaEditing.selectedSchema.name eq schema.name ? 'active': ''} #{tapSchemaEditing.toRemove(schema) ? 'to-remove' : ''}">
<li role="presentation" class="removable-tab #{schema.name eq tapSchemaEditing.tapSchema.name ? 'unremovable-tab': ''} #{tapSchemaEditing.selectedSchema.name eq schema.name ? 'active': ''} #{tapSchemaEditing.toRemove(schema) ? 'to-remove' : ''}">
<h:commandLink role="tab" action="#{tapSchemaEditing.setSelectedSchema(schema)}">
<span class="#{tapSchemaEditing.toRemove(schema) ? 'strikeout':''}">#{schema.name}</span>
<f:ajax execute="@form" render="@form" />
<h:commandButton class="remove-btn" rendered="#{!tapSchemaEditing.toRemove(schema)}" action="#{tapSchemaEditing.tapSchema.removeChild(schema.name)}" value="&#215;" onclick="TSM.stopPropagation(event)">
<h:commandButton class="remove-btn" rendered="#{!tapSchemaEditing.toRemove(schema) and schema.name ne tapSchemaEditing.tapSchema.name}" action="#{tapSchemaEditing.tapSchema.removeChild(schema.name)}" value="&#215;" onclick="TSM.stopPropagation(event)">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
</h:commandLink>
......@@ -125,11 +125,11 @@
<h:panelGroup id="tables_wrapper">
<ul class="nav nav-tabs" id="tables" role="tablist">
<ui:repeat value="#{tapSchemaEditing.selectedSchema.addedOrRemovedChildren}" var="table">
<li role="presentation" class="removable-tab #{tapSchemaEditing.selectedTable.name eq table.name ? 'active':''} #{tapSchemaEditing.toRemove(table) ? 'to-remove':''}">
<li role="presentation" class="removable-tab #{table.parent.name eq tapSchemaEditing.tapSchema.name ? 'unremovable-tab': ''} #{tapSchemaEditing.selectedTable.name eq table.name ? 'active':''} #{tapSchemaEditing.toRemove(table) ? 'to-remove':''}">
<h:commandLink role="tab" action="#{tapSchemaEditing.setSelectedTable(table)}">
<span class="#{tapSchemaEditing.toRemove(table) ? 'strikeout':''}">#{table.name}</span>
<f:ajax execute="@form" render=":main:tables_wrapper" />
<h:commandButton class="remove-btn" rendered="#{!tapSchemaEditing.toRemove(table)}" action="#{tapSchemaEditing.selectedSchema.removeChild(table.name)}" value="&#215;" onclick="TSM.stopPropagation(event)">
<h:commandButton class="remove-btn" rendered="#{!tapSchemaEditing.toRemove(table) and table.parent.name ne tapSchemaEditing.tapSchema.name}" action="#{tapSchemaEditing.selectedSchema.removeChild(table.name)}" value="&#215;" onclick="TSM.stopPropagation(event)">
<f:ajax execute="@form" render=":main:tables_wrapper" />
</h:commandButton>
</h:commandLink>
......@@ -217,7 +217,7 @@
<ui:repeat value="#{tapSchemaEditing.selectedTable.addedOrRemovedChildren}" var="column" id="columns-list">
<li role="presentation" class="#{tapSchemaEditing.selectedColumn.name eq column.name ? 'active': ''}">
<h:commandLink role="tab" action="#{tapSchemaEditing.setSelectedColumn(column)}" id="column-selector">
<h:commandButton class="btn btn-link remove-btn" disabled="#{tapSchemaEditing.toRemove(column)}" value="&#215;" onclick="TSM.stopPropagation(event)" id="column-remover">
<h:commandButton class="btn btn-link remove-btn" disabled="#{tapSchemaEditing.toRemove(column) or column.parent.parent.name eq tapSchemaEditing.tapSchema.name}" value="&#215;" onclick="TSM.stopPropagation(event)" id="column-remover">
<f:ajax execute="@form" render=":main:column_wrapper :main:columns_header" listener="#{tapSchemaEditing.removeColumn(column.name)}" onevent="TSM.columnRemoved" />
</h:commandButton>
......@@ -438,7 +438,7 @@
</div>
<div class="modal-body">
<div class="form-group">
<h:selectOneRadio value="#{UCDDialog.manualInsertion}" valueChangeListener="#{UCDDialog.setDefault()}">
<h:selectOneRadio value="#{UCDDialog.manualInsertion}">
<f:selectItem itemValue="#{false}" itemLabel="Search by description" />
<f:selectItem itemValue="#{true}" itemLabel="Manual insertion" />
<f:ajax execute="@this" render=":ucd_search_form:UCDDialogBodyMainContent :ucd_search_form:ucdDialogFooter" />
......@@ -458,65 +458,67 @@
<f:ajax execute="@form" render=":ucd_search_form:ucd_validation_result :ucd_search_form:save_ucd" event="keyup" listener="#{UCDDialog.validateManualUCD}" />
</h:inputText>
<h:panelGroup id="ucd_validation_result">
<table class="table">
<thead>
<tr>
<th>Valid:</th>
<th>Recognized:</th>
<th>Recommended:</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<h:panelGroup rendered="${UCDDialog.parsedUCD.valid}">
<span class="text-success"><span class="glyphicon glyphicon-ok"></span></span>
</h:panelGroup>
<h:panelGroup rendered="${!UCDDialog.parsedUCD.valid}">
<span class="text-danger"><span class="glyphicon glyphicon-remove"></span></span>
</h:panelGroup>
</td>
<td>
<h:panelGroup rendered="${UCDDialog.parsedUCD.recognised}">
<span class="text-success"><span class="glyphicon glyphicon-ok"></span></span>
</h:panelGroup>
<h:panelGroup rendered="${!UCDDialog.parsedUCD.recognised}">
<span class="text-danger"><span class="glyphicon glyphicon-remove"></span></span>
</h:panelGroup>
</td>
<td>
<h:panelGroup rendered="${UCDDialog.parsedUCD.recommended}">
<span class="text-success"><span class="glyphicon glyphicon-ok"></span></span>
</h:panelGroup>
<h:panelGroup rendered="${!UCDDialog.parsedUCD.recommended}">
<span class="text-danger"><span class="glyphicon glyphicon-remove"></span></span>
</h:panelGroup>
</td>
</tr>
</tbody>
</table>
<h:panelGroup rendered="#{UCDDialog.UCDManualText ne null}">
<table class="table">
<thead>
<tr>
<th>Valid:</th>
<th>Recognized:</th>
<th>Recommended:</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<h:panelGroup rendered="${UCDDialog.parsedUCD.valid}">
<span class="text-success"><span class="glyphicon glyphicon-ok"></span></span>
</h:panelGroup>
<h:panelGroup rendered="${!UCDDialog.parsedUCD.valid}">
<span class="text-danger"><span class="glyphicon glyphicon-remove"></span></span>
</h:panelGroup>
</td>
<td>
<h:panelGroup rendered="${UCDDialog.parsedUCD.recognised}">
<span class="text-success"><span class="glyphicon glyphicon-ok"></span></span>
</h:panelGroup>
<h:panelGroup rendered="${!UCDDialog.parsedUCD.recognised}">
<span class="text-danger"><span class="glyphicon glyphicon-remove"></span></span>
</h:panelGroup>
</td>
<td>
<h:panelGroup rendered="${UCDDialog.parsedUCD.recommended}">
<span class="text-success"><span class="glyphicon glyphicon-ok"></span></span>
</h:panelGroup>
<h:panelGroup rendered="${!UCDDialog.parsedUCD.recommended}">
<span class="text-danger"><span class="glyphicon glyphicon-remove"></span></span>
</h:panelGroup>
</td>
</tr>
</tbody>
</table>
<h:panelGroup rendered="${UCDDialog.parsedUCD ne null}">
<h:panelGroup rendered="${UCDDialog.parsedUCD.suggestedUCD ne null}">
Suggested UCD: ${UCDDialog.parsedUCD.suggestedUCD}
</h:panelGroup>
<h:panelGroup rendered="${UCDDialog.parsedUCD ne null}">
<h:panelGroup rendered="${UCDDialog.parsedUCD.suggestedUCD ne null}">
Suggested UCD: ${UCDDialog.parsedUCD.suggestedUCD}
</h:panelGroup>
<h:panelGroup rendered="${UCDDialog.parsedUCD.advices.size() gt 0}">
<h5 class="text-info"><strong>Advices:</strong></h5>
<ul>
<ui:repeat value="${UCDDialog.parsedUCD.advices}" var="advice">
<li class="text-info">${advice}</li>
</ui:repeat>
</ul>
</h:panelGroup>
<h:panelGroup rendered="${UCDDialog.parsedUCD.advices.size() gt 0}">
<h5 class="text-info"><strong>Advices:</strong></h5>
<ul>
<ui:repeat value="${UCDDialog.parsedUCD.advices}" var="advice">
<li class="text-info">${advice}</li>
</ui:repeat>
</ul>
</h:panelGroup>
<h:panelGroup rendered="${UCDDialog.parsedUCD.errors.size() gt 0}">
<h5 class="text-danger"><strong>Errors:</strong></h5>
<ul>
<ui:repeat value="${UCDDialog.parsedUCD.errors}" var="error">
<li class="text-danger">${error}</li>
</ui:repeat>
</ul>
<h:panelGroup rendered="${UCDDialog.parsedUCD.errors.size() gt 0}">
<h5 class="text-danger"><strong>Errors:</strong></h5>
<ul>
<ui:repeat value="${UCDDialog.parsedUCD.errors}" var="error">
<li class="text-danger">${error}</li>
</ui:repeat>
</ul>
</h:panelGroup>
</h:panelGroup>
</h:panelGroup>
</h:panelGroup>
......@@ -528,7 +530,7 @@
<div class="input-group">
<h:inputText id="ucd_dialog_description" class="form-control" value="#{UCDDialog.description}" onkeydown="TSM.ucdTextKeyDown(event)" />
<span class="input-group-btn">
<h:commandLink class="btn btn-default" action="#{UCDDialog.search(UCDDialog.description)}" id="search_UCD_btn">
<h:commandLink class="btn btn-default" action="#{UCDDialog.search()}" id="search_UCD_btn">
<span class="glyphicon glyphicon-search"></span>
<f:ajax execute="@form" render="@form" />
</h:commandLink>
......@@ -587,7 +589,7 @@
</div>
<h:panelGroup class="modal-footer" id="ucdDialogFooter" layout="block">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<h:commandButton id="save_ucd" class="btn btn-primary" disabled="#{(!UCDDialog.manualInsertion and UCDDialog.selectedUCD eq null) or (UCDDialog.manualInsertion and (UCDDialog.parsedUCD eq null or !UCDDialog.parsedUCD.valid))}" action="#{tapSchemaEditing.saveUCD()}" value="Save changes">
<h:commandButton id="save_ucd" class="btn btn-primary" disabled="#{(!UCDDialog.manualInsertion and UCDDialog.selectedUCD eq null) or (UCDDialog.manualInsertion and (UCDDialog.parsedUCD ne null and !UCDDialog.parsedUCD.valid))}" action="#{tapSchemaEditing.saveUCD()}" value="Save changes">
<f:ajax execute="@form" render="@form :main:column_ucd" onevent="TSM.saveUCDCalled" />
</h:commandButton>
</h:panelGroup>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment