From: Ole Streicher <olebole@debian.org>
Date: Tue, 12 Dec 2023 11:32:41 +0100
Subject: Update adql-java API to 2.

Closes: #1058415
---
 cds/aladin/DynamicTapForm.java | 13 +++++++------
 cds/aladin/Server.java         | 20 ++++++++++----------
 cds/aladin/ServerGlu.java      | 10 +++++-----
 cds/aladin/ServerObsTap.java   | 19 ++++++++++---------
 4 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/cds/aladin/DynamicTapForm.java b/cds/aladin/DynamicTapForm.java
index 5bba3a6..2818878 100644
--- a/cds/aladin/DynamicTapForm.java
+++ b/cds/aladin/DynamicTapForm.java
@@ -81,9 +81,10 @@ import adql.db.DBChecker;
 import adql.db.DefaultDBTable;
 import adql.db.exception.UnresolvedIdentifiersException;
 import adql.parser.ADQLParser;
-import adql.parser.ParseException;
+import adql.parser.grammar.ParseException;
 import adql.parser.QueryChecker;
 import adql.query.ADQLQuery;
+import adql.query.ADQLSet;
 import adql.query.from.ADQLTable;
 import cds.aladin.Constants.TapClientMode;
 import cds.tools.ConfigurationReader;
@@ -751,8 +752,8 @@ public abstract class DynamicTapForm extends Server implements FilterActionClass
 	}
 	
 	@Override
-	public ADQLQuery checkQuery(Map<String, Object> requestParams)  throws UnresolvedIdentifiersException {
-		ADQLQuery query = null;
+	public ADQLSet checkQuery(Map<String, Object> requestParams)  throws UnresolvedIdentifiersException {
+		ADQLSet query = null;
 		try {
 //			if (Aladin.PROTO) {
 				try {
@@ -767,7 +768,7 @@ public abstract class DynamicTapForm extends Server implements FilterActionClass
 //			System.err.println("getADQLCatalogName "+table.getADQLCatalogName()+"\ngetADQLSchemaName "+table.getADQLSchemaName()+"\ngetADQLName "+table.getADQLName()+"\ntoString "+table.toString());
 		} catch (UnresolvedIdentifiersException uie) {	
 			Aladin.trace(3, "Number of errors in the query: "+uie.getNbErrors());
-			adql.parser.ParseException ex = null;
+			adql.parser.grammar.ParseException ex = null;
 			try {
 				List<String> tableNames = getTableNamesofNoMetadataInQuery(tap.getText());
 				if (tableNames != null && !tableNames.isEmpty()) {
@@ -784,7 +785,7 @@ public abstract class DynamicTapForm extends Server implements FilterActionClass
 			} catch (UnresolvedIdentifiersException uie2) {
 				//yeah those are columns then get those table meta data
 				//if still there is an issue then you go ahead and highlight
-				Iterator<adql.parser.ParseException> it = uie2.getErrors();
+				Iterator<adql.parser.grammar.ParseException> it = uie2.getErrors();
 				while (it.hasNext()) {
 					ex = it.next();
 					highlightQueryError(tap.getHighlighter(), ex);
@@ -802,7 +803,7 @@ public abstract class DynamicTapForm extends Server implements FilterActionClass
 		ADQLParser syntaxParser = new ADQLParser();
 		List<String> tableNames = null;
 		try {
-			ADQLQuery adqlQuery = syntaxParser.parseQuery(query);
+			ADQLQuery adqlQuery = (ADQLQuery)syntaxParser.parseQuery(query);
 			tableNames = new ArrayList<>();
 //			DBColumn[] columns = query.getResultingColumns();//match columns with the unresolvedIdentifiers?
 			for (ADQLTable adqlTable : adqlQuery.getFrom().getTables()) {
diff --git a/cds/aladin/Server.java b/cds/aladin/Server.java
index 98045cc..8918fa2 100644
--- a/cds/aladin/Server.java
+++ b/cds/aladin/Server.java
@@ -79,8 +79,8 @@ import javax.swing.text.Highlighter.HighlightPainter;
 
 import adql.db.exception.UnresolvedIdentifiersException;
 import adql.parser.ADQLParser;
-import adql.parser.TokenMgrError;
-import adql.query.ADQLQuery;
+import adql.parser.grammar.TokenMgrError;
+import adql.query.ADQLSet;
 import adql.query.TextPosition;
 import cds.moc.SMoc;
 import cds.tools.Astrodate;
@@ -2133,8 +2133,8 @@ public void layout() {
 			}
 		} catch (UnresolvedIdentifiersException uie) {
 			// TODO Auto-generated catch block
-			Iterator<adql.parser.ParseException> it = uie.getErrors();
-			adql.parser.ParseException ex = null;
+			Iterator<adql.parser.grammar.ParseException> it = uie.getErrors();
+			adql.parser.grammar.ParseException ex = null;
 			while(it.hasNext()){
 				ex = it.next();
 				highlightQueryError(tap.getHighlighter(), ex);
@@ -2148,12 +2148,12 @@ public void layout() {
 	 * @return the adql query
 	 * @throws UnresolvedIdentifiersException 
 	 */
-	public ADQLQuery checkQuery(Map<String, Object> requestParams) throws UnresolvedIdentifiersException {
+	public ADQLSet checkQuery(Map<String, Object> requestParams) throws UnresolvedIdentifiersException {
 		if (tap.getText().isEmpty()) {
 			Aladin.error(this, CHECKQUERY_ISBLANK);
 			return null;
 		}
-		ADQLQuery query = null;
+		ADQLSet query = null;
 		Highlighter highlighter = tap.getHighlighter();
 		try {
 			highlighter.removeAllHighlights();
@@ -2161,7 +2161,7 @@ public void layout() {
 		} catch (UnresolvedIdentifiersException ie) {	
 			Aladin.trace(3, "Number of errors in the query:"+ie.getNbErrors());
 			throw ie;
-		} catch (adql.parser.ParseException pe) {
+		} catch (adql.parser.grammar.ParseException pe) {
 			highlightQueryError(highlighter, pe);
 			Aladin.error(this, "Check the syntax around the highlighted words : " + pe.getMessage());
 		} catch (TokenMgrError e) {
@@ -2179,7 +2179,7 @@ public void layout() {
 	 * @param url
 	 */
 	public void submitTapServerRequest(boolean sync, String name, String url, String queryString) {
-		ADQLQuery query = null;
+		ADQLSet query = null;
 		Map<String, Object> requestParams = new HashMap<>();
 		try {
 			query = checkQuery(requestParams);
@@ -2188,7 +2188,7 @@ public void layout() {
 			ADQLParser syntaxParser = new ADQLParser();
 			try {
 				query = syntaxParser.parseQuery(queryString);
-			} catch (adql.parser.ParseException e1) {
+			} catch (adql.parser.grammar.ParseException e1) {
 				// TODO Auto-generated catch block
 				Aladin.trace(3, "Parse exception with query..");
 			}
@@ -2219,7 +2219,7 @@ public void layout() {
 		server.setStatusForCurrentRequest(requestNumber, Ball.NOK);
 	}
 	
-	public void highlightQueryError(Highlighter highlighter, adql.parser.ParseException pe) {
+	public void highlightQueryError(Highlighter highlighter, adql.parser.grammar.ParseException pe) {
 		TextPosition errPosition = pe.getPosition();
 		if (errPosition != null) {
 			int errorStart = pe.getPosition().beginColumn-1;
diff --git a/cds/aladin/ServerGlu.java b/cds/aladin/ServerGlu.java
index d97f63a..7cc268e 100644
--- a/cds/aladin/ServerGlu.java
+++ b/cds/aladin/ServerGlu.java
@@ -84,7 +84,7 @@ import javax.swing.event.ListSelectionListener;
 
 import adql.db.exception.UnresolvedIdentifiersException;
 import adql.parser.ADQLParser;
-import adql.query.ADQLQuery;
+import adql.query.ADQLSet;
 import cds.aladin.stc.STCObj;
 import cds.aladin.stc.STCStringParser;
 import cds.moc.SMoc;
@@ -2135,15 +2135,15 @@ public class ServerGlu extends Server implements Runnable {
    }
    
 	@Override
-	public ADQLQuery checkQuery(Map<String, Object> requestParams) throws UnresolvedIdentifiersException {
+	public ADQLSet checkQuery(Map<String, Object> requestParams) throws UnresolvedIdentifiersException {
 		// TODO Auto-generated method stub
-		ADQLQuery result = null;
+		ADQLSet result = null;
 		try {
 			result = super.checkQuery(requestParams);
 		} catch (UnresolvedIdentifiersException uie) {
 			Aladin.trace(3, "Number of errors in the query:"+uie.getNbErrors());
-			Iterator<adql.parser.ParseException> it = uie.getErrors();
-			adql.parser.ParseException ex = null;
+			Iterator<adql.parser.grammar.ParseException> it = uie.getErrors();
+			adql.parser.grammar.ParseException ex = null;
 			while(it.hasNext()){
 				ex = it.next();
 				highlightQueryError(tap.getHighlighter(), ex);
diff --git a/cds/aladin/ServerObsTap.java b/cds/aladin/ServerObsTap.java
index ad1f979..3af28ba 100644
--- a/cds/aladin/ServerObsTap.java
+++ b/cds/aladin/ServerObsTap.java
@@ -85,8 +85,9 @@ import adql.db.DBChecker;
 import adql.db.exception.UnresolvedIdentifiersException;
 import adql.parser.ADQLParser;
 import adql.parser.QueryChecker;
-import adql.parser.TokenMgrError;
+import adql.parser.grammar.TokenMgrError;
 import adql.query.ADQLQuery;
+import adql.query.ADQLSet;
 import adql.query.ClauseConstraints;
 import cds.tools.Util;
 
@@ -925,7 +926,7 @@ public class ServerObsTap extends DynamicTapForm implements ItemListener {
 	 */
 	public void appendConstraint(JComboBox andOrOp, String constraint, boolean inRange, boolean processAsNumber,
 			String value, String defaultValue) {
-		ADQLQuery query = null;
+		ADQLSet query = null;
 		try {
 			if (tap.getText().isEmpty()) {
 				writeQuery();
@@ -933,8 +934,8 @@ public class ServerObsTap extends DynamicTapForm implements ItemListener {
 			query = this.checkQuery(null);
 		} catch (UnresolvedIdentifiersException uie) {
 			// TODO Auto-generated catch block
-			Iterator<adql.parser.ParseException> it = uie.getErrors();
-			adql.parser.ParseException ex = null;
+			Iterator<adql.parser.grammar.ParseException> it = uie.getErrors();
+			adql.parser.grammar.ParseException ex = null;
 			while (it.hasNext()) {
 				ex = it.next();
 				highlightQueryError(tap.getHighlighter(), ex);
@@ -946,8 +947,8 @@ public class ServerObsTap extends DynamicTapForm implements ItemListener {
 				e.printStackTrace();
 			}
 		}
-		if (query != null) {
-			ClauseConstraints whereConstraints = query.getWhere();
+		if (query != null && (query instanceof ADQLQuery)) {
+			ClauseConstraints whereConstraints = ((ADQLQuery)query).getWhere();
 			boolean firstConstraint = false;
 			StringBuffer queryInput = new StringBuffer(tap.getText().trim());
 			if (whereConstraints == null || whereConstraints.size() == 0) {
@@ -1041,18 +1042,18 @@ public class ServerObsTap extends DynamicTapForm implements ItemListener {
 	 * @return the adql query
 	 * @throws Exception 
 	 */
-	public ADQLQuery checkSyntax() throws Exception {
+	public ADQLSet checkSyntax() throws Exception {
 		if (tap.getText().isEmpty()) {
 			throw new Exception(CHECKQUERY_ISBLANK);
 		}
-		ADQLQuery query = null;
+		ADQLSet query = null;
 		ADQLParser syntaxParser = new ADQLParser();
 		try {
 			query = syntaxParser.parseQuery(tap.getText());
 		} catch (UnresolvedIdentifiersException ie) {	
 			Aladin.trace(3, "Number of errors in the query:"+ie.getNbErrors());
 			throw ie;
-		} catch (adql.parser.ParseException pe) {
+		} catch (adql.parser.grammar.ParseException pe) {
 			throw pe;
 		} catch (TokenMgrError e) {
 			// TODO: handle exception
