Skip to content

Commit

Permalink
Fix Capabilities / Refactor UWSInitAction
Browse files Browse the repository at this point in the history
  • Loading branch information
stvoutsin committed Jun 11, 2024
1 parent 6e33b92 commit 763c140
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 158 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ Find changes for the upcoming release in the project's [changelog.d](https://git

<!-- scriv-insert-here -->

<a id='changelog-1.17.2'></a>
## 1.17.2 (2024-06-10)

### Fixed

- Fixed Capabilities based on standard, mainly Table Access and authentication related

### Changed

- Refactor UWSInitAction class a bit, make sure each call in the schema init process is separate

<a id='changelog-1.17.1'></a>
## 1.17.1 (2024-06-10)
Expand Down
53 changes: 34 additions & 19 deletions tap/src/main/java/ca/nrc/cadc/uws/impl/UWSInitAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,12 @@ public UWSInitAction() {
@Override
public void doInit() {
DataSource uws = null;
Connection conn = null;
try {
try {
uws = DBUtil.findJNDIDataSource("jdbc/uws");
conn = uws.getConnection();
if (!schemaExists(conn, "uws")) {
if (!schemaExists(uws, "uws")) {
log.info("uws schema does not exist, creating...");
createSchema(conn, "uws");
createSchema(uws, "uws");
log.info("uws schema created");

// Continue with initialization only if the schema was just created
InitDatabaseUWS uwsi = new InitDatabaseUWS(uws, null, "uws");
uwsi.doInit();
Expand All @@ -110,6 +107,22 @@ public void doInit() {
}
} catch (Exception ex) {
throw new RuntimeException("INIT FAIL", ex);
}
}

private boolean schemaExists(DataSource uws, String schemaName) throws SQLException {
Connection conn = null;
try {
conn = uws.getConnection();
DatabaseMetaData dbMetaData = conn.getMetaData();
ResultSet rs = dbMetaData.getSchemas();
while (rs.next()) {
if (schemaName.equalsIgnoreCase(rs.getString("TABLE_SCHEM").trim())) {
return true;
}
}
} catch (Exception ex) {
throw new RuntimeException("Failed to check if schema exists", ex);
} finally {
if (conn != null) {
try {
Expand All @@ -119,23 +132,25 @@ public void doInit() {
}
}
}
}

private boolean schemaExists(Connection conn, String schemaName) throws SQLException {
DatabaseMetaData dbMetaData = conn.getMetaData();
try (ResultSet rs = dbMetaData.getSchemas()) {
while (rs.next()) {
if (schemaName.equalsIgnoreCase(rs.getString("TABLE_SCHEM").trim())) {
return true;
}
}
}
return false;
}

private void createSchema(Connection conn, String schemaName) throws SQLException {
try (java.sql.Statement stmt = conn.createStatement()) {
private void createSchema(DataSource uws, String schemaName) throws SQLException {
Connection conn = null;
try {
conn = uws.getConnection();
java.sql.Statement stmt = conn.createStatement();
stmt.execute("CREATE SCHEMA " + schemaName);
} catch (Exception ex) {
throw new RuntimeException("Create Schema failed", ex);
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
log.error("Failed to close connection", e);
}
}
}
}
}
228 changes: 89 additions & 139 deletions tap/src/main/webapp/capabilities.xml
Original file line number Diff line number Diff line change
@@ -1,193 +1,143 @@
<?xml version="1.0" encoding="UTF-8"?>
<vosi:capabilities
xmlns:vosi="http://www.ivoa.net/xml/VOSICapabilities/v1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:vs="http://www.ivoa.net/xml/VODataService/v1.1">
xmlns:vosi="http://www.ivoa.net/xml/VOSICapabilities/v1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:vs="http://www.ivoa.net/xml/VODataService/v1.1">

<capability standardID="ivo://ivoa.net/std/VOSI#capabilities">
<interface xsi:type="vs:ParamHTTP" role="std">
<accessURL use="full">http://replace.me.com/tap/capabilities</accessURL>
<accessURL use="full">https://replace.me.com/api/tap/capabilities</accessURL>
</interface>
</capability>

<capability standardID="ivo://ivoa.net/std/VOSI#availability">
<interface xsi:type="vs:ParamHTTP" role="std">
<accessURL use="full">http://replace.me.com/tap/availability</accessURL>
<accessURL use="full">https://replace.me.com/api/tap/availability</accessURL>
</interface>
</capability>

<capability standardID="vos://cadc.nrc.ca~vospace/CADC/std/Logging#control-1.0">
<interface xsi:type="vs:ParamHTTP" role="std" version="1.0">
<accessURL use="full">http://replace.me.com/tap/logControl</accessURL>
</interface>
</capability>

<capability standardID="ivo://ivoa.net/std/VOSI#tables-1.1">
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">http://replace.me.com/tap/tables</accessURL>
</interface>
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">http://replace.me.com/tap/auth-tables</accessURL>
<securityMethod standardID="http://www.w3.org/Protocols/HTTP/1.0/spec.html#BasicAA"/>
</interface>
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">http://replace.me.com/tap/tables</accessURL>
<accessURL use="full">https://replace.me.com/api/tap/logControl</accessURL>
<securityMethod standardID="ivo://ivoa.net/sso#BasicAA"/>
<securityMethod standardID="ivo://ivoa.net/sso#cookie"/>
</interface>
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">https://replace.me.com/tap/tables</accessURL>
<securityMethod standardID="ivo://ivoa.net/sso#tls-with-certificate"/>
<securityMethod standardID="ivo://ivoa.net/sso#OAuth"/>
<securityMethod standardID="ivo://ivoa.net/sso#saml2.0"/>
<securityMethod standardID="ivo://ivoa.net/sso#OpenID"/>
</interface>
</capability>

<!-- TAP-1.1 sync -->
<capability standardID="ivo://ivoa.net/std/TAP#sync-1.1">
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">http://replace.me.com/tap/sync</accessURL>
</interface>
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">http://replace.me.com/tap/auth-sync</accessURL>
<securityMethod standardID="http://www.w3.org/Protocols/HTTP/1.0/spec.html#BasicAA"/>
</interface>
<capability standardID="ivo://ivoa.net/std/VOSI#tables-1.1">
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">http://replace.me.com/tap/sync</accessURL>
<accessURL use="full">https://replace.me.com/api/tap/tables</accessURL>
<securityMethod standardID="ivo://ivoa.net/sso#BasicAA"/>
<securityMethod standardID="ivo://ivoa.net/sso#cookie"/>
<securityMethod standardID="ivo://ivoa.net/sso#OAuth"/>
<securityMethod standardID="ivo://ivoa.net/sso#saml2.0"/>
<securityMethod standardID="ivo://ivoa.net/sso#OpenID"/>
</interface>
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">https://replace.me.com/tap/sync</accessURL>
<securityMethod standardID="ivo://ivoa.net/sso#tls-with-certificate"/>
</interface>
<!-- cannot use TAPRegExt-1.0 and xsi:type=tr:TableAccess because it restricts the
standardID to the plain TAP value -->
</capability>

<!-- TAP-1.1 async -->
<capability standardID="ivo://ivoa.net/std/TAP#async-1.1">
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">http://replace.me.com/tap/async</accessURL>
</interface>
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">http://replace.me.com/tap/auth-async</accessURL>
<securityMethod standardID="http://www.w3.org/Protocols/HTTP/1.0/spec.html#BasicAA"/>
</interface>

<!-- TAP-1.1 -->
<capability standardID="ivo://ivoa.net/std/TAP"
xmlns:tr="http://www.ivoa.net/xml/TAPRegExt/v1.0" xsi:type="tr:TableAccess">
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">http://replace.me.com/tap/async</accessURL>
<accessURL use="base">https://replace.me.com/api/tap</accessURL>
<securityMethod standardID="ivo://ivoa.net/sso#BasicAA"/>
<securityMethod standardID="ivo://ivoa.net/sso#cookie"/>
<securityMethod standardID="ivo://ivoa.net/sso#OAuth"/>
<securityMethod standardID="ivo://ivoa.net/sso#saml2.0"/>
<securityMethod standardID="ivo://ivoa.net/sso#OpenID"/>
</interface>
<interface xsi:type="vs:ParamHTTP" role="std" version="1.1">
<accessURL use="base">https://replace.me.com/tap/async</accessURL>
<securityMethod standardID="ivo://ivoa.net/sso#tls-with-certificate"/>
</interface>
<!-- cannot use TAPRegExt-1.0 and xsi:type=tr:TableAccess because it restricts the
standardID to the plain TAP value -->
</capability>

<!-- TAP-1.0 base -->
<capability standardID="ivo://ivoa.net/std/TAP"
xmlns:tr="http://www.ivoa.net/xml/TAPRegExt/v1.0" xsi:type="tr:TableAccess">
<interface xsi:type="vs:ParamHTTP" role="std">
<accessURL use="base">http://replace.me.com/tap</accessURL>
</interface>
<interface xsi:type="vs:ParamHTTP" role="std">
<accessURL use="base">https://replace.me.com/tap</accessURL>
<securityMethod standardID="ivo://ivoa.net/sso#tls-with-certificate"/>
</interface>
<!-- cannot describe the #BasicAA access because TAP-1.0 only has a base URL standardID -->

<!--
<dataModel ivo-id="ivo://ivoa.net/std/ObsCore/v1.0">ObsCore-1.0</dataModel>
dataModel ivo-id="ivo://ivoa.net/std/ObsCore/v1.0">ObsCore-1.0</dataModel>
-->

<language>
<name>ADQL</name>
<version ivo-id="ivo://ivoa.net/std/ADQL#v2.0">2.0</version>
<description>ADQL-2.0</description>
<languageFeatures type="ivo://ivoa.net/std/TAPRegExt#features-adqlgeo">
<feature>
<form>POINT</form>
</feature>
<feature>
<form>CIRCLE</form>
</feature>
<feature>
<form>BOX</form>
</feature>
<feature>
<form>POLYGON</form>
</feature>
<feature>
<form>REGION</form>
</feature>
<feature>
<form>CONTAINS</form>
</feature>
<feature>
<form>INTERSECTS</form>
</feature>
<feature>
<form>AREA</form>
</feature>
<feature>
<form>CENTROID</form>
</feature>
<feature>
<form>COORDSYS</form>
</feature>
<feature>
<form>COORD1</form>
</feature>
<feature>
<form>COORD2</form>
</feature>
</languageFeatures>
<name>ADQL</name>
<version ivo-id="ivo://ivoa.net/std/ADQL#v2.0">2.0</version>
<description>ADQL-2.0</description>
<languageFeatures type="ivo://ivoa.net/std/TAPRegExt#features-adqlgeo">
<feature>
<form>POINT</form>
</feature>
<feature>
<form>CIRCLE</form>
</feature>
<feature>
<form>DISTANCE</form>
</feature>
<feature>
<form>POLYGON</form>
</feature>
<feature>
<form>CONTAINS</form>
</feature>
<feature>
<form>BOX</form>
</feature>
<feature>
<form>REGION</form>
</feature>
<feature>
<form>INTERSECTS</form>
</feature>
<feature>
<form>AREA</form>
</feature>
<feature>
<form>CENTROID</form>
</feature>
<feature>
<form>COORDSYS</form>
</feature>
<feature>
<form>COORD1</form>
</feature>
<feature>
<form>COORD2</form>
</feature>
</languageFeatures>
</language>

<outputFormat ivo-id="ivo://ivoa.net/std/TAPRegExt#output-votable-td">
<mime>application/x-votable+xml</mime>
<alias>votable</alias>
<mime>application/x-votable+xml</mime>
<alias>votable</alias>
</outputFormat>

<outputFormat ivo-id="ivo://ivoa.net/std/TAPRegExt#output-votable-td">
<mime>text/xml</mime>
<mime>text/xml</mime>
</outputFormat>

<outputFormat>
<mime>text/csv</mime>
<alias>csv</alias>
<mime>text/csv</mime>
<alias>csv</alias>
</outputFormat>

<outputFormat>
<mime>text/tab-separated-values</mime>
<alias>tsv</alias>
<mime>text/tab-separated-values</mime>
<alias>tsv</alias>
</outputFormat>

<uploadMethod ivo-id="ivo://ivoa.net/std/TAPRegExt#upload-inline"/>
<uploadMethod ivo-id="ivo://ivoa.net/std/TAPRegExt#upload-http"/>
<uploadMethod ivo-id="ivo://ivoa.net/std/TAPRegExt#upload-https"/>

<retentionPeriod>
<default>7200</default>
<hard>7200</hard>
<default>604800</default>
<hard>604800</hard>
</retentionPeriod>

<executionDuration>
<default>600</default>
<hard>600</hard>
<default>600</default>
<hard>600</hard>
</executionDuration>

<!-- outputLimit for async queries: 10000 -->
<!-- outputLimit for async queries: 128MB -->
<outputLimit>
<default unit="row">1000</default>
<hard unit="row">10000</hard>
<default unit="byte">134217728</default>
<hard unit="byte">134217728</hard>
</outputLimit>
<!-- outputLimit for sync queries: no limit -->

<uploadLimit>
<default unit="row">10000</default>
<hard unit="row">10000</hard>
<default unit="row">10000</default>
<hard unit="row">10000</hard>
</uploadLimit>

</capability>

</vosi:capabilities>

</vosi:capabilities>

0 comments on commit 763c140

Please sign in to comment.