-
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.
- Loading branch information
Showing
13 changed files
with
445 additions
and
112 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -5,3 +5,5 @@ etc/export.properties | |
etc/config.properties | ||
tmp/ | ||
etc/config_xl.properties | ||
.idea | ||
/.nb-gradle/ |
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
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
OaiPmhBaseUrl="http://data.libris.kb.se" | ||
AuthBaseUrl="http://data.libris.kb.se/auth/oaipmh" | ||
BibBaseUrl="http://data.libris.kb.se/bib/oaipmh" | ||
HoldBsaeUrl="http://data.libris.kb.se/hold/oaipmh" | ||
User="" | ||
Password="" |
Binary file not shown.
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 |
---|---|---|
|
@@ -95,3 +95,4 @@ System.in.eachLine() { line -> | |
} | ||
|
||
writer.close() | ||
|
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
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
109 changes: 109 additions & 0 deletions
109
src/main/java/se/kb/libris/export/listener/AuthThread.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,109 @@ | ||
package se.kb.libris.export.listener; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
import java.util.concurrent.*; | ||
import java.util.logging.*; | ||
import oaij.client.*; | ||
|
||
class AuthThread extends Thread { | ||
OaiPmhClient client = null; | ||
Properties configProperties, exportProperties; | ||
String timestampFile, latestDatestamp = null; | ||
BlockingDeque<String> bdq; | ||
boolean run; | ||
|
||
AuthThread(Properties configProperties, Properties exportProperties, String timestampFile, BlockingDeque<String> bdq) { | ||
this.configProperties = configProperties; | ||
this.exportProperties = exportProperties; | ||
this.timestampFile = timestampFile; | ||
this.bdq = bdq; | ||
run = true; | ||
|
||
client = new OaiPmhClient(configProperties.getProperty("BibBaseUrl")); | ||
if (!configProperties.getProperty("User", "").equals("")) { | ||
client.withCredentials( | ||
configProperties.getProperty("User"), | ||
configProperties.getProperty("Password")); | ||
} | ||
} | ||
|
||
public String getLatestDatestamp() throws IOException { | ||
if (latestDatestamp != null) return latestDatestamp; | ||
|
||
if (timestampFile != null) { | ||
File f = new File(timestampFile); | ||
|
||
if (f.exists()) { | ||
try (Scanner s = new Scanner(f)) { | ||
s.useDelimiter("\\Z"); | ||
latestDatestamp = s.next(); | ||
Logger.getGlobal().log(Level.INFO, "Read latest datestamp from file (" + latestDatestamp + ")"); | ||
} catch (FileNotFoundException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} else { | ||
setLatestDatestamp(client.identify().getResponseDate().asString()); | ||
} | ||
|
||
return latestDatestamp; | ||
} | ||
|
||
public void setLatestDatestamp(String latestDatestamp) throws IOException { | ||
if (timestampFile != null) { | ||
FileWriter fw = new FileWriter(timestampFile); | ||
fw.write(latestDatestamp); | ||
fw.close(); | ||
} | ||
|
||
this.latestDatestamp = latestDatestamp; | ||
|
||
//Logger.getGlobal().log(Level.CONFIG, "latestDatestamp is now " + latestDatestamp); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
Logger.getGlobal().log(Level.INFO, "AuthThread enter"); | ||
|
||
ListIdentifiers li = null; | ||
int sleep = 1000; | ||
while (run) { | ||
try { | ||
if (li != null && li.hasNext()) { | ||
Identifier id = li.next(); | ||
|
||
// mask out identifiers with datestamp >= responseDate | ||
if (li.getResponseDate().compareTo(id.getDatestamp()) > 0) { | ||
Logger.getGlobal().log(Level.INFO, "Adding URI " + id.getIdentifier()); | ||
bdq.offer(id.getIdentifier()); | ||
} | ||
} else { | ||
try { | ||
Thread.sleep(5000); | ||
li = client.listIdentifiers("marcxml").withFrom(getLatestDatestamp()); | ||
setLatestDatestamp(li.getResponseDate().asString()); | ||
} catch (InterruptedException e) { | ||
run = false; | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
sleep = 1000; | ||
} catch (Exception e) { | ||
if (run) { | ||
Logger.getGlobal().log(Level.WARNING, "Exception in main loop, retry in " + sleep + " msecs.", e); | ||
try { | ||
if (sleep < 5*60*1000) sleep *= 2; | ||
Thread.sleep(sleep); | ||
} catch (InterruptedException ex) { | ||
} | ||
} | ||
} | ||
} | ||
|
||
Logger.getGlobal().log(Level.INFO, "AuthThread exit"); | ||
|
||
client.close(); | ||
} | ||
} |
Oops, something went wrong.