-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DM-40764] Support rewriting of oga.ObsCore.access_url
This will allow us to have one database and two different tap services on two different hostnames in front of it.
- Loading branch information
Showing
3 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
tap/src/main/java/ca/nrc/cadc/sample/RubinFormatFactory.java
This file contains 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,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); | ||
} | ||
} |
This file contains 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,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); | ||
} | ||
} | ||
} |
This file contains 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