-
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
Open
aratikakadiya
wants to merge
7
commits into
opencadc:main
Choose a base branch
from
aratikakadiya:service-descriptors-from-db
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9f63d3a
Upgraded TableWriter to support service descriptors from DB along wit…
aratikakadiya 8410c22
Merge branch 'opencadc:main' into service-descriptors-from-db
aratikakadiya 192354e
Rework in youcat table writer.
aratikakadiya 8e9b8bc
Rework in youcat table writer.
aratikakadiya daa789e
Integration Tests for service descriptor adaption change.
aratikakadiya 24a5a74
Small changes.
aratikakadiya 4fa02b2
Fixed build failure.
aratikakadiya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
youcat/src/main/java/org/opencadc/youcat/YoucatTableWriter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
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)) { | ||
|
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)); | ||
|
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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: