-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from lsst-sqre/tickets/DM-40764
[DM-40764] Rewrite URL to use local environment, not what's in the da…
- Loading branch information
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/java/org/opencadc/tap/impl/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,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); | ||
} | ||
} |
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 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); | ||
} | ||
} | ||
} |
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