Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cadc-tap-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sourceCompatibility = 11

group = 'org.opencadc'

version = '1.1.32'
version = '1.1.33'

description = 'OpenCADC TAP-1.1 tap server library'
def git_url = 'https://github.com/opencadc/tap'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -454,7 +455,7 @@ public static URL getAccessURL(String columnID, URI reqStandardID) throws IOExce
}

// read a votable document matching a {column_id}: currently in the config dir
private static VOTableDocument getDoc(String sid) throws IOException {
protected static VOTableDocument getDoc(String sid) throws IOException {
File configDir = new File(System.getProperty("user.home") + "/config");
String filename = sid + ".xml";
File tmpl = new File(configDir, filename);
Expand Down Expand Up @@ -493,60 +494,64 @@ private static VOTableDocument getDoc(String sid) throws IOException {
*/
protected void addMetaResources(VOTableDocument votableDocument, List<String> fieldIDs)
throws IOException {
RegistryClient regClient = new RegistryClient();

for (String fid : fieldIDs) {
VOTableDocument serviceDocument = getDoc(fid);
String filename = fid + ".xml";
if (serviceDocument == null) {
return;
return; // TODO: verify - continue/return?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please confirm if we have to return if valid document is not found for one of the fieldId.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall the origin of that check but it should not terminate (current usage is likely why we never noticed). Probably something like this is better:

if (serviceDocument != null) {
    for (VOTableResource metaResource : serviceDocument.getResources()) {
...

}

for (VOTableResource metaResource : serviceDocument.getResources()) {
if ("meta".equals(metaResource.getType())) {
votableDocument.getResources().add(metaResource);
try {
URL accessURL = null;
URI resourceIdentifier = null;
URI standardID = null;
Iterator<VOTableParam> i = metaResource.getParams().iterator();
while (i.hasNext()) {
VOTableParam vp = i.next();
if (vp.getName().equals("accessURL")) {
accessURL = new URL(vp.getValue());
} else if (vp.getName().equals("resourceIdentifier")) {
resourceIdentifier = new URI(vp.getValue());
} else if (vp.getName().equals("standardID")) {
standardID = new URI(vp.getValue());
}
}
if (accessURL == null && resourceIdentifier != null && standardID != null) {
// try to augment resource with accessURL
Subject s = AuthenticationUtil.getCurrentSubject();
AuthMethod cur = AuthenticationUtil.getAuthMethod(s);
if (cur == null) {
cur = AuthMethod.ANON;
}
log.debug("resourceIdentifier=" + resourceIdentifier + ", standardID=" + standardID + ", authMethod=" + cur);
accessURL = regClient.getServiceURL(resourceIdentifier, standardID, cur);
if (accessURL != null) {
String surl = accessURL.toExternalForm();
String arraysize = Integer.toString(surl.length()); // fixed length since we know it
VOTableParam accessParam = new VOTableParam("accessURL", "char", arraysize, surl);
metaResource.getParams().add(accessParam);
} else {
// log the error but continue anyway
log.error("failed to find accessURL: resourceIdentifier=" + resourceIdentifier
+ ", standardID=" + standardID + ", authMethod=" + cur);
}
}
} catch (URISyntaxException e) {
throw new RuntimeException("resourceIdentifier in " + filename + " is invalid", e);
}
populateAccessURLParam(metaResource);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't matter technically, but probably populateAccessURLParam before add as you have in the youcat-specific extension

}
}
}
}

protected void populateAccessURLParam(VOTableResource metaResource) throws MalformedURLException {
RegistryClient regClient = new RegistryClient();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably make regClient a member var rather than recreate each time this method is called. To be conservative, private transient ... and instantiate it here if it is null (lazxy init).

URL accessURL = null;
URI resourceIdentifier = null;
URI standardID = null;
Iterator<VOTableParam> i = metaResource.getParams().iterator();
while (i.hasNext()) {
VOTableParam vp = i.next();
try {
if (vp.getName().equals("accessURL")) {
accessURL = new URL(vp.getValue());
} else if (vp.getName().equals("resourceIdentifier")) {
resourceIdentifier = new URI(vp.getValue());
} else if (vp.getName().equals("standardID")) {
standardID = new URI(vp.getValue());
}
} catch (URISyntaxException e) {
throw new RuntimeException("resourceIdentifier - " + resourceIdentifier + " is invalid", e);
}
}
if (accessURL == null && resourceIdentifier != null && standardID != null) {
// try to augment resource with accessURL
Subject s = AuthenticationUtil.getCurrentSubject();
AuthMethod cur = AuthenticationUtil.getAuthMethod(s);
if (cur == null) {
cur = AuthMethod.ANON;
}
log.debug("resourceIdentifier=" + resourceIdentifier + ", standardID=" + standardID + ", authMethod=" + cur);
accessURL = regClient.getServiceURL(resourceIdentifier, standardID, cur);
if (accessURL != null) {
String surl = accessURL.toExternalForm();
String arraysize = Integer.toString(surl.length()); // fixed length since we know it
VOTableParam accessParam = new VOTableParam("accessURL", "char", arraysize, surl);
metaResource.getParams().add(accessParam);
} else {
// log the error but continue anyway
log.error("failed to find accessURL: resourceIdentifier=" + resourceIdentifier
+ ", standardID=" + standardID + ", authMethod=" + cur);
}
}
}

protected VOTableField createVOTableField(TapSelectItem resultCol) {
if (resultCol != null) {
TapDataType tt = resultCol.getDatatype();
Expand Down
2 changes: 1 addition & 1 deletion youcat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies {
implementation 'org.opencadc:cadc-uws-server:[1.2.22,)'
implementation 'org.opencadc:cadc-tap:[1.1.20,)'
implementation 'org.opencadc:cadc-tap-schema:[1.2.7,)'
implementation 'org.opencadc:cadc-tap-server:[1.1.32,)'
implementation 'org.opencadc:cadc-tap-server:[1.1.33,)'
implementation 'org.opencadc:cadc-tap-server-pg:[1.1.1,)'
implementation 'org.opencadc:cadc-adql:[1.1.4,)'
implementation 'org.opencadc:cadc-vosi:[1.4.3,2.0)'
Expand Down
37 changes: 37 additions & 0 deletions youcat/src/main/java/org/opencadc/youcat/YoucatTableWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.opencadc.youcat;

import ca.nrc.cadc.dali.tables.votable.VOTableDocument;
import ca.nrc.cadc.dali.tables.votable.VOTableResource;
import ca.nrc.cadc.tap.DefaultTableWriter;
import ca.nrc.cadc.tap.PluginFactory;

import java.io.IOException;
import java.util.List;

import org.apache.log4j.Logger;
import org.opencadc.datalink.ServiceDescriptorTemplate;

public class YoucatTableWriter extends DefaultTableWriter {

private static final Logger log = Logger.getLogger(YoucatTableWriter.class);

@Override
protected void addMetaResources(VOTableDocument votableDocument, List<String> fieldIDs) throws IOException {
super.addMetaResources(votableDocument, fieldIDs);

// Use TemplateDAO to get descriptors
TemplateDAO templateDAO = new TemplateDAO(new PluginFactory().getTapSchemaDAO());
List<ServiceDescriptorTemplate> templates = templateDAO.list(fieldIDs);

for (ServiceDescriptorTemplate template : templates) {
if (fieldIDs.containsAll(template.getIdentifiers())) {
VOTableResource resource = template.getResource();
if (resource == null) {
log.warn("No resource found for template: " + template.getName());
}
populateAccessURLParam(resource);
votableDocument.getResources().add(resource);
}
}
}
}
2 changes: 1 addition & 1 deletion youcat/src/main/resources/PluginFactory.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ca.nrc.cadc.tap.db.DatabaseDataType=ca.nrc.cadc.tap.pg.PostgresDataTypeMapper

ca.nrc.cadc.tap.UploadManager = org.opencadc.youcat.tap.UploadManagerImpl

#ca.nrc.cadc.tap.TableWriter = ca.nrc.cadc.tap.DefaultTableWriter
ca.nrc.cadc.tap.TableWriter = ca.nrc.cadc.tap.YoucatTableWriter

ca.nrc.cadc.tap.writer.format.FormatFactory = org.opencadc.youcat.tap.FormatFactoryImpl

Expand Down