Skip to content

Commit

Permalink
Merge pull request #23 from lsst-sqre/tickets/DM-40764
Browse files Browse the repository at this point in the history
[DM-40764] Support rewriting of oga.ObsCore.access_url
  • Loading branch information
cbanek authored Sep 21, 2023
2 parents 808cb63 + a5e5142 commit 6513b80
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
33 changes: 33 additions & 0 deletions tap/src/main/java/ca/nrc/cadc/sample/RubinFormatFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ca.nrc.cadc.sample;

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

import ca.nrc.cadc.sample.RubinURLFormat;


public class RubinFormatFactory extends PostgreSQLFormatFactory {

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) {
// oga.ObsCore
if ("oga.ObsCore".equalsIgnoreCase(columnDesc.tableName)) {
if ("access_url".equalsIgnoreCase(columnDesc.getColumnName())) {
return new RubinURLFormat();
}
}
}

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

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);
}
}
}
4 changes: 2 additions & 2 deletions tap/src/main/resources/PluginFactory.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ ca.nrc.cadc.tap.MaxRecValidator.impl = ca.nrc.cadc.sample.MaxRecValidatorImpl

ca.nrc.cadc.tap.db.DatabaseDataType=ca.nrc.cadc.tap.pg.PostgresDataTypeMapper

ca.nrc.cadc.tap.writer.format.FormatFactory = ca.nrc.cadc.sample.RubinFormatFactory

ca.nrc.cadc.tap.UploadManager = ca.nrc.cadc.sample.RubinUploadManagerImpl

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

ca.nrc.cadc.tap.writer.format.FormatFactory = ca.nrc.cadc.tap.writer.format.PostgreSQLFormatFactory

ca.nrc.cadc.tap.ResultStore = ca.nrc.cadc.sample.ResultStoreImpl

0 comments on commit 6513b80

Please sign in to comment.