Skip to content

Commit

Permalink
Merge pull request #97 from lsst-sqre/tickets/DM-40764
Browse files Browse the repository at this point in the history
[DM-40764] Rewrite URL to use local environment, not what's in the da…
  • Loading branch information
cbanek authored Sep 21, 2023
2 parents 2fc0b9f + 34f2aea commit ac7a405
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/main/java/org/opencadc/tap/impl/RubinFormatFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.opencadc.tap.impl;

import ca.nrc.cadc.dali.util.Format;
import ca.nrc.cadc.tap.TapSelectItem;
import ca.nrc.cadc.tap.writer.format.OracleFormatFactory;
import org.apache.log4j.Logger;

import org.opencadc.tap.impl.RubinURLFormat;


public class RubinFormatFactory extends OracleFormatFactory {

private static Logger log = Logger.getLogger(RubinFormatFactory.class);

public RubinFormatFactory() {
super();
}

@Override
public Format<Object> getClobFormat(TapSelectItem columnDesc) {
// function with CLOB argument
if (columnDesc != null) {
// ivoa.ObsCore
if ("ivoa.ObsCore".equalsIgnoreCase(columnDesc.tableName)) {
if ("access_url".equalsIgnoreCase(columnDesc.getColumnName())) {
log.info("getClobFormat called for access_url");
return new RubinURLFormat();
}
}
}

return super.getClobFormat(columnDesc);
}
}
43 changes: 43 additions & 0 deletions src/main/java/org/opencadc/tap/impl/RubinURLFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.opencadc.tap.impl;

import java.net.MalformedURLException;
import java.net.URL;

import ca.nrc.cadc.dali.util.Format;
import org.apache.log4j.Logger;


public class RubinURLFormat implements Format<Object> {

private static Logger log = Logger.getLogger(RubinURLFormat.class);

private static final String BASE_URL = System.getProperty("base_url");

public RubinURLFormat() {
super();
}

@Override
public Object parse(String s) {
throw new UnsupportedOperationException("TAP Formats cannot parse strings.");
}

@Override
public String format(Object o) {
if (o == null) {
return "";
}

String s = (String) o;

try {
URL orig = new URL((String) o);
URL base_url = new URL(BASE_URL);
URL rewritten = new URL(orig.getProtocol(), base_url.getHost(), orig.getFile());

return rewritten.toExternalForm();
} catch (MalformedURLException ex) {
throw new RuntimeException("BUG: Failed to rewrite URL: " + s, ex);
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/PluginFactory.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ca.nrc.cadc.tap.MaxRecValidator.impl = org.opencadc.tap.impl.MaxRecValidatorImpl

ca.nrc.cadc.tap.TableWriter = org.opencadc.tap.impl.RubinTableWriter

ca.nrc.cadc.tap.writer.format.FormatFactory = ca.nrc.cadc.tap.writer.format.OracleFormatFactory
ca.nrc.cadc.tap.writer.format.FormatFactory = org.opencadc.tap.impl.RubinFormatFactory
ca.nrc.cadc.tap.upload.datatype.DatabaseDataType = ca.nrc.cadc.tap.upload.datatype.OracleDataType

# the package name here could be changed now that we have a config file
Expand Down

0 comments on commit ac7a405

Please sign in to comment.