-
Notifications
You must be signed in to change notification settings - Fork 18
draft: Updated TableWriter to include service descriptors in query results #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
9f63d3a
8410c22
192354e
8e9b8bc
daa789e
24a5a74
4fa02b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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); | ||
|
|
@@ -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? | ||
| } | ||
|
|
||
| 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't matter technically, but probably |
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected void populateAccessURLParam(VOTableResource metaResource) throws MalformedURLException { | ||
| RegistryClient regClient = new RegistryClient(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would probably make |
||
| 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(); | ||
|
|
||
| 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); | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: