in core/src/main/java/org/apache/sdap/mudrod/metadata/pre/ApiHarvester.java [131:181]
private void harvestMetadatafromWeb() {
LOG.info("Metadata download started.");
int startIndex = 0;
int docLength = 0;
JsonParser parser = new JsonParser();
do {
String searchAPI = props.getProperty(MudrodConstants.METADATA_DOWNLOAD_URL);
searchAPI = searchAPI.replace("$startIndex", Integer.toString(startIndex));
HttpRequest http = new HttpRequest();
String response = http.getRequest(searchAPI);
JsonElement json = parser.parse(response);
JsonObject responseObject = json.getAsJsonObject();
JsonArray docs = responseObject.getAsJsonObject("response").getAsJsonArray("docs");
docLength = docs.size();
File file = new File(props.getProperty(MudrodConstants.RAW_METADATA_PATH));
if (!file.exists()) {
if (file.mkdir()) {
LOG.info("Directory is created!");
} else {
LOG.error("Failed to create directory!");
}
}
for (int i = 0; i < docLength; i++) {
JsonElement item = docs.get(i);
int docId = startIndex + i;
File itemfile = new File(props.getProperty(MudrodConstants.RAW_METADATA_PATH) + "/" + docId + ".json");
try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(itemfile.getAbsoluteFile()), StandardCharsets.UTF_8)) {
itemfile.createNewFile();
osw.write(item.toString());
} catch (IOException e) {
LOG.error("Error writing metadata to local file!", e);
}
}
startIndex += 10;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
LOG.error("Error entering Elasticsearch Mappings!", e);
Thread.currentThread().interrupt();
}
} while (docLength != 0);
LOG.info("Metadata downloading finished");
}