diff --git a/TASMAN-core/pom.xml b/TASMAN-core/pom.xml index 11b6869f0a6c16992b8bc0f284fe07275c0c37ca..bc18744a27195d0e85b7d28d65af2eae9c9ae5a6 100644 --- a/TASMAN-core/pom.xml +++ b/TASMAN-core/pom.xml @@ -3,7 +3,7 @@ <modelVersion>4.0.0</modelVersion> <groupId>it.inaf.ia2.tap</groupId> <artifactId>tasman-core</artifactId> - <version>1.2.0</version> + <version>1.3.0</version> <packaging>jar</packaging> <name>tasman-core</name> <properties> diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/EntityProperty.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/EntityProperty.java index eba9ae5dd6edbb4e126b7af1a535ab48c4d9f6db..c09d49a0affa413364d47b29fc461abcba5237ec 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/EntityProperty.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/EntityProperty.java @@ -59,13 +59,6 @@ public class EntityProperty<T> implements Serializable { return value; } - /** - * Retrieve the current value. - */ - public <X> X getValue(Class<X> type) { - return (X) value; - } - public T getOriginalValue() { return originalValue; } @@ -74,10 +67,6 @@ public class EntityProperty<T> implements Serializable { return defaultValue; } - public <X> X getOriginalValue(Class<X> type) { - return (X) originalValue; - } - public <X> void setValue(X value) { this.setValue(value, true); } diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaEntity.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaEntity.java index b1f684e04739a210c6a698623a1d578d4ba4e29c..e9506a330acc7682fa74e18b7ee748aafd6968c3 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaEntity.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/TapSchemaEntity.java @@ -130,7 +130,7 @@ public abstract class TapSchemaEntity implements Serializable { * Retrieve the current value of the property (the last value set). */ public <T> T getValue(String key, Class<T> type) { - return (T) properties.get(key).getValue(type); + return (T) properties.get(key).getValue(); } public void setValue(String key, Object value) { @@ -145,7 +145,7 @@ public abstract class TapSchemaEntity implements Serializable { * @return */ public <T> T getOriginalValue(String key, Class<T> type) { - return (T) properties.get(key).getOriginalValue(type); + return (T) properties.get(key).getOriginalValue(); } /** diff --git a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/pgsql/PostgresDBBroker.java b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/pgsql/PostgresDBBroker.java index fe87f81ad1e67c977fc8f0807d1d16c0d4e44dba..028a1929936f03b7a082e1588005d4d8d92b7b75 100644 --- a/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/pgsql/PostgresDBBroker.java +++ b/TASMAN-core/src/main/java/it/inaf/ia2/tsm/datalayer/pgsql/PostgresDBBroker.java @@ -275,6 +275,9 @@ public class PostgresDBBroker extends DBBrokerTemplate { if (!isArray && (ADQL.VARCHAR.equals(adqlType) || ADQL.CHAR.equals(adqlType))) { size = resultSet.getInt("character_maximum_length"); + if (size == 0) { + size = null; + } } cm.put(Column.DATATYPE_KEY, datatype); @@ -283,10 +286,16 @@ public class PostgresDBBroker extends DBBrokerTemplate { String arraySize = null; if (isArray) { arraySize = formatArraySize(arraydimension); - } else if (size != null) { - arraySize = String.valueOf(size); + } else { + if (size != null) { + arraySize = String.valueOf(size); + } + // variable length columns must have a "*" symbol on arraysize if (adqlType != null && ADQL.isVariable(adqlType)) { + if (arraySize == null) { + arraySize = ""; + } arraySize += "*"; } } diff --git a/TASMAN-core/src/main/resources/schema_definition/ivoa-1_1.xml b/TASMAN-core/src/main/resources/schema_definition/ivoa-1_1.xml index 8feb50ae337c0f6665aab2c2c4075c43354a5417..ef23dad8d02af9fbcb43510da49a5423cca782c6 100644 --- a/TASMAN-core/src/main/resources/schema_definition/ivoa-1_1.xml +++ b/TASMAN-core/src/main/resources/schema_definition/ivoa-1_1.xml @@ -655,7 +655,7 @@ Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. <type>VARCHAR</type> <updatable>true</updatable> <description>Identifier of proposal to which observation belongs</description> - <standard>false</standard> + <standard>true</standard> <mandatory>true</mandatory> <utype>Provenance.Proposal.identifier</utype> <ucd>meta.id; obs.proposal</ucd> diff --git a/TASMAN-core/src/test/java/it/inaf/ia2/tsm/TestAll.java b/TASMAN-core/src/test/java/it/inaf/ia2/tsm/TestAll.java index 3cafafd130ad344ef7d09e44cb2ffd7d80aeeaa7..6a1c902f0fd3d05336e837b2ea35baf63ae6f345 100644 --- a/TASMAN-core/src/test/java/it/inaf/ia2/tsm/TestAll.java +++ b/TASMAN-core/src/test/java/it/inaf/ia2/tsm/TestAll.java @@ -459,6 +459,14 @@ public class TestAll { operations = new UpdateOperations(tapSchema); assertFalse(operations.getHasOperations()); + // Checking size and arraysize detection + Column descriptionColumn = tapSchema.getChild(tapSchema.getName()).getChild("columns").getChild("utype"); + assertEquals("char", descriptionColumn.getValue("datatype", String.class)); + Integer size = descriptionColumn.getValue("size", Integer.class); + String arraySize = descriptionColumn.getValue("arraysize", String.class); + assertTrue(size == null || size == 255); // null -> Postgres, 255 -> MySQL + assertTrue("*".equals(arraySize) || "255*".equals(arraySize)); // * -> Postgres, 255* -> MySQL + // reloading LOG.debug("----- Reloading saved TAP_SCHEMA -----"); tapSchema = new TapSchema(dbWrapper, settings, true); diff --git a/TASMAN-embedded/src/main/java/it/inaf/ia2/tap/tasman/Main.java b/TASMAN-embedded/src/main/java/it/inaf/ia2/tap/tasman/Main.java index 0e272c7bb4bef8fe83f21319e0b89abfd044e078..a8c06659be10c9d37b62a5dc3d484d445832f092 100644 --- a/TASMAN-embedded/src/main/java/it/inaf/ia2/tap/tasman/Main.java +++ b/TASMAN-embedded/src/main/java/it/inaf/ia2/tap/tasman/Main.java @@ -1,6 +1,10 @@ package it.inaf.ia2.tap.tasman; +import java.io.BufferedReader; import java.io.File; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Properties; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.eclipse.jetty.server.Server; @@ -14,14 +18,26 @@ import org.eclipse.jetty.webapp.WebAppContext; */ public class Main { - private static final int DEFAULT_PORT = 8080; - /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { - int port = DEFAULT_PORT; + Properties props = new Properties(); + try (InputStream in = Main.class.getClassLoader().getResourceAsStream("app.properties")) { + props.load(in); + } + + // Printing the header + try (BufferedReader br = new BufferedReader(new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("header.txt")))) { + for (String line; (line = br.readLine()) != null;) { + System.out.println(line); + } + } catch (Exception e) { + } + + int port = Integer.parseInt(props.getProperty("defaultPort").trim()); + String warFilePath = props.getProperty("warFilePath").trim(); if (args.length == 1) { try { @@ -40,7 +56,7 @@ public class Main { WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); - File warFile = new File("/home/sonia/git/TASMAN/TASMAN-webapp/target/tasman-webapp-1.2.0.war"); + File warFile = new File(warFilePath); webapp.setWar(warFile.getAbsolutePath()); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=477705 @@ -53,7 +69,10 @@ public class Main { webapp.addEventListener(new ServletContextListener() { @Override public void contextInitialized(ServletContextEvent sce) { - System.out.println("TASMAN initialized. Visit http://localhost:" + serverPort); + String message = "# TASMAN initialized. Visit http://localhost:" + serverPort + " #"; + printBorder(message); + System.out.println(message); + printBorder(message); } @Override @@ -68,4 +87,11 @@ public class Main { // wait until the server is done executing. server.join(); } + + private static void printBorder(String text) { + for (int i = 0; i < text.length(); i++) { + System.out.print("#"); + } + System.out.println(); + } } diff --git a/TASMAN-embedded/src/main/resources/app.properties b/TASMAN-embedded/src/main/resources/app.properties new file mode 100644 index 0000000000000000000000000000000000000000..7eebcf0f5d09d9f41e438b2aa86ba79e7e6434f1 --- /dev/null +++ b/TASMAN-embedded/src/main/resources/app.properties @@ -0,0 +1,2 @@ +warFilePath=/home/sonia/git/TASMAN/TASMAN-webapp/target/tasman-webapp-1.3.0.war +defaultPort=8080 \ No newline at end of file diff --git a/TASMAN-embedded/src/main/resources/header.txt b/TASMAN-embedded/src/main/resources/header.txt new file mode 100644 index 0000000000000000000000000000000000000000..bbec691768ae90ff5157840c527f628e80d86a40 --- /dev/null +++ b/TASMAN-embedded/src/main/resources/header.txt @@ -0,0 +1,10 @@ +############################################ +# _____ _ ____ __ __ _ _ _ # +# |_ _|/ \ / ___|| \/ | / \ | \ | | # +# | | / _ \ \___ \| |\/| | / _ \ | \| | # +# | |/ ___ \ ___) | | | |/ ___ \| |\ | # +# |_/_/ \_\____/|_| |_/_/ \_\_| \_| # +# # +# Powered by IA2 # +# # +############################################ \ No newline at end of file diff --git a/TASMAN-webapp/pom.xml b/TASMAN-webapp/pom.xml index cd826caf7bc80fc50c94cd2bfce4360ab1fac410..74f71028f149665f3052c1a594d641e34a23db99 100644 --- a/TASMAN-webapp/pom.xml +++ b/TASMAN-webapp/pom.xml @@ -4,7 +4,7 @@ <groupId>it.inaf.ia2.tap</groupId> <artifactId>tasman-webapp</artifactId> - <version>1.2.0</version> + <version>1.3.0</version> <packaging>war</packaging> <name>tasman-webapp</name> diff --git a/install.sh b/install.sh new file mode 100755 index 0000000000000000000000000000000000000000..8e54c85fb05723eded5a68aa3df690a920a1b12b --- /dev/null +++ b/install.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +echo "############################################" +echo "# _____ _ ____ __ __ _ _ _ #" +echo "# |_ _|/ \ / ___|| \/ | / \ | \ | | #" +echo "# | | / _ \ \___ \| |\/| | / _ \ | \| | #" +echo "# | |/ ___ \ ___) | | | |/ ___ \| |\ | #" +echo "# |_/_/ \_\____/|_| |_/_/ \_\_| \_| #" +echo "# #" +echo "# Powered by IA2 #" +echo "# #" +echo "############################################" +echo "" + +echo "Welcome on the TASMAN installer" + +# Run as root check +if [[ "$(id -u)" != "0" ]]; then + echo "** This script must be run as root **" 1>&2 + exit 1 +fi + +# Default port +echo -e "Specify default port for TASMAN (you can change it runtime) [8080]: \c" +read default_port +if [[ -z "$default_port" ]]; then + default_port=8080 +fi +if [[ ! "$default_port" =~ ^-?[0-9]+$ ]]; then + echo "Port must be a number" + exit 1 +fi +if [[ "$default_port" -lt "1024" ]]; then + echo "Please choose a port number bigger than 1023 (TASMAN will be launched by a non-root user)" + exit 1 +fi + +# Tasman installation dir +echo -e "Specify TASMAN installation directory [/opt/tasman]: \c" +read install_dir +if [[ -z "$install_dir" ]]; then + install_dir="/opt/tasman" +fi + +# UCD service URL +echo -e "Specify UCD service URL [http://ia2-vo.oats.inaf.it/ucd/]: \c" +read ucd_service_url +if [[ -z "$ucd_service_url" ]]; then + ucd_service_url="http://ia2-vo.oats.inaf.it/ucd/" +fi + +# TASMAN configuration directory +echo -e "Specify TASMAN configuration directory [/etc/tasman]: \c" +read tasman_config_dir +if [[ -z "$tasman_config_dir" ]]; then + tasman_config_dir="/etc/tasman" +fi +mkdir -p "$tasman_config_dir" +if [ ! $? -eq 0 ]; then + echo "Unable to create configuration directory $tasman_config_dir" + exit 1 +fi + +# Creating tasman user if it is necessary +#if [[ ! $(getent passwd tasman) ]]; then +# useradd -r tasman +#fi + +# Creating installation directory +mkdir -p "$install_dir" +if [ ! $? -eq 0 ]; then + echo "Unable to create installation directory $install_dir" + exit 1 +fi + +# Add final slash to installation dir if it is necessary +if [[ "$install_dir" != *\/ ]]; then + install_dir="$install_dir/" +fi + +# Copying files +cp data/tasman-embedded.jar "$install_dir" +cp data/tasman-webapp.war "$install_dir" + +cd $install_dir + +# Configuring tasman-embedded +echo "warFilePath=$install_dir""tasman-webapp.war" > app.properties +echo "defaultPort=$default_port" >> app.properties + +jar uf tasman-embedded.jar app.properties +rm app.properties + +# Configuring tasman-webapp +echo "ucd_service_url=$ucd_service_url" > webapp.properties +echo "config_directory=$tasman_config_dir" >> webapp.properties +mkdir -p WEB-INF/classes +mv webapp.properties WEB-INF/classes +jar uf tasman-webapp.war WEB-INF/classes/webapp.properties +rm -Rf WEB-INF + +cd - 1> /dev/null + +# Creating executable +tasman_bin="$install_dir""tasman" +echo "#!/bin/bash" > $tasman_bin +echo "java -jar $install_dir""tasman-embedded.jar" >> $tasman_bin +chmod +x $tasman_bin + +# Creating executable symbolic link +ln -s $tasman_bin /usr/bin/tasman + +# Setting permissions +chmod -R 777 $tasman_config_dir + +echo "######################################" +echo "# TASMAN installation completed! :-) #" +echo "######################################" +echo "Notice that $tasman_config_dir has 777 permissions. If you are planning to use TASMAN only with a specific user you may want to restrict permissions on that folder."