Skip to content
Snippets Groups Projects
Commit e447a487 authored by Grégory Mantelet's avatar Grégory Mantelet
Browse files

[TAP] Return a clear error message in case of duplicated items in UPLOADs.

Before correction, if two uploaded tables have been submitted by the user with
the same name, or if one uploaded table contained duplicated column names, an
obscure error message coming from the database was returned to the user.

Now, duplicated items (tables and columns) are searched before ingestion in the
database. When one is detected, an error is immediately returned to the user and
the query is aborted.
parent 25f373f6
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ package tap.upload; ...@@ -22,6 +22,7 @@ package tap.upload;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashSet;
import com.oreilly.servlet.multipart.ExceededSizeException; import com.oreilly.servlet.multipart.ExceededSizeException;
...@@ -167,12 +168,18 @@ public class Uploader { ...@@ -167,12 +168,18 @@ public class Uploader {
public TAPSchema upload(final DALIUpload[] uploads) throws TAPException{ public TAPSchema upload(final DALIUpload[] uploads) throws TAPException{
TableIterator dataIt = null; TableIterator dataIt = null;
InputStream votable = null; InputStream votable = null;
HashSet<String> tableNames = new HashSet<String>(uploads.length);
String tableName = null; String tableName = null;
try{ try{
// Iterate over the full list of uploaded tables: // Iterate over the full list of uploaded tables:
for(DALIUpload upl : uploads){ for(DALIUpload upl : uploads){
tableName = upl.label; tableName = upl.label;
// Check uniqueness of the table name inside TAP_UPLOAD:
boolean uniqueTableName = tableNames.add(tableName.toLowerCase());
if (!uniqueTableName)
throw new TAPException("Non unique table name (case insensitive) among all tables to upload: \"" + tableName + "\"!", UWSException.BAD_REQUEST);
// Open a stream toward the VOTable: // Open a stream toward the VOTable:
votable = upl.open(); votable = upl.open();
...@@ -181,6 +188,15 @@ public class Uploader { ...@@ -181,6 +188,15 @@ public class Uploader {
// Define the table to upload: // Define the table to upload:
TAPColumn[] columns = dataIt.getMetadata(); TAPColumn[] columns = dataIt.getMetadata();
// Check uniqueness of all column names:
HashSet<String> columnNames = new HashSet<String>(columns.length);
for(TAPColumn col : columns){
boolean uniqueColumnName = columnNames.add(col.getADQLName().toLowerCase());
if (!uniqueColumnName)
throw new TAPException("Non unique column name (case insensitive) among all columns of the table \"" + tableName + "\": \"" + col.getADQLName() + "\"!", UWSException.BAD_REQUEST);
}
TAPTable table = new TAPTable(tableName); TAPTable table = new TAPTable(tableName);
table.setDBName(tableName + "_" + System.currentTimeMillis()); table.setDBName(tableName + "_" + System.currentTimeMillis());
for(TAPColumn col : columns) for(TAPColumn col : columns)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment