Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -454,7 +454,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 @@ -498,7 +498,7 @@ protected void addMetaResources(VOTableDocument votableDocument, List<String> fi
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()) {
Expand Down
2 changes: 1 addition & 1 deletion youcat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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
103 changes: 103 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,103 @@
package org.opencadc.youcat;

import ca.nrc.cadc.auth.AuthMethod;
import ca.nrc.cadc.auth.AuthenticationUtil;
import ca.nrc.cadc.dali.tables.votable.VOTableDocument;
import ca.nrc.cadc.dali.tables.votable.VOTableParam;
import ca.nrc.cadc.dali.tables.votable.VOTableResource;
import ca.nrc.cadc.reg.client.RegistryClient;
import ca.nrc.cadc.tap.DefaultTableWriter;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.security.auth.Subject;

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 {
RegistryClient regClient = new RegistryClient();

// Use TemplateDAO to get descriptors
TemplateDAO templateDAO = new TemplateDAO();
Comment thread
pdowler marked this conversation as resolved.
Outdated
List<ServiceDescriptorTemplate> templates = templateDAO.list(fieldIDs);
Map<String, VOTableDocument> serviceDocs = new HashMap<>();

for (ServiceDescriptorTemplate template : templates) {
VOTableResource resource = template.getResource();

if (resource != null && !template.getIdentifiers().isEmpty()) {
for (String id : template.getIdentifiers()) {
if (fieldIDs.contains(id) && !serviceDocs.containsKey(id)) {
Comment thread
pdowler marked this conversation as resolved.
Outdated
VOTableDocument voTableDocument = new VOTableDocument();
voTableDocument.getResources().add(resource);
serviceDocs.put(id, voTableDocument);
break;
}
}
}
}

for (String fid : fieldIDs) {
VOTableDocument serviceDocument = serviceDocs.getOrDefault(fid, getDoc(fid));
Comment thread
pdowler marked this conversation as resolved.
Outdated
if (serviceDocument == null) {
return; // TODO: verify - continue/return?
}

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 for fieldID: " + fid + " is invalid", e);
}
}
}
}
}
}
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