use of org.hl7.fhir.r4.utils.client.FHIRToolingClient in project org.hl7.fhir.core by hapifhir.
the class BatchLoader method sendFile.
private static void sendFile(FHIRToolingClient client, File f, int size, IniFile ini) throws FHIRFormatError, FileNotFoundException, IOException {
long ms = System.currentTimeMillis();
System.out.print("Loading " + f.getName() + ".. ");
IParser parser = f.getName().endsWith(".json") ? new JsonParser() : new XmlParser();
Resource res = parser.parse(new FileInputStream(f));
System.out.println(" done: (" + Long.toString(System.currentTimeMillis() - ms) + " ms)");
if (res instanceof Bundle) {
Bundle bnd = (Bundle) res;
int cursor = ini.hasProperty("progress", f.getName()) ? ini.getIntegerProperty("progress", f.getName()) : 0;
while (cursor < bnd.getEntry().size()) {
Bundle bt = new Bundle();
bt.setType(BundleType.BATCH);
bt.setId(UUID.randomUUID().toString().toLowerCase());
for (int i = cursor; i < Math.min(bnd.getEntry().size(), cursor + size); i++) {
BundleEntryComponent be = bt.addEntry();
be.setResource(bnd.getEntry().get(i).getResource());
be.getRequest().setMethod(HTTPVerb.PUT);
be.getRequest().setUrl(be.getResource().getResourceType().toString() + "/" + be.getResource().getId());
}
System.out.print(f.getName() + " (" + cursor + "/" + bnd.getEntry().size() + "): ");
ms = System.currentTimeMillis();
Bundle resp = client.transaction(bt);
int ncursor = cursor + size;
for (int i = 0; i < resp.getEntry().size(); i++) {
BundleEntryComponent t = resp.getEntry().get(i);
if (!t.getResponse().getStatus().startsWith("2")) {
System.out.println("failed status at " + Integer.toString(i) + ": " + t.getResponse().getStatus());
ncursor = cursor + i - 1;
break;
}
}
cursor = ncursor;
System.out.println(" .. done: (" + Long.toString(System.currentTimeMillis() - ms) + " ms) " + SimpleDateFormat.getInstance().format(new Date()));
ini.setIntegerProperty("progress", f.getName(), cursor, null);
ini.save();
}
ini.setBooleanProperty("finished", f.getName(), true, null);
ini.save();
} else {
client.update(res);
ini.setBooleanProperty("finished", f.getName(), true, null);
ini.save();
}
}
use of org.hl7.fhir.r4.utils.client.FHIRToolingClient in project org.hl7.fhir.core by hapifhir.
the class BatchLoader method loadBundle.
private static int loadBundle(String server, Bundle b, int size, int start, int end) throws URISyntaxException {
System.out.println("Post to " + server + ". size = " + Integer.toString(size) + ", start = " + Integer.toString(start) + ", total = " + Integer.toString(b.getEntry().size()));
FHIRToolingClient client = new FHIRToolingClient(server);
int c = start;
if (end == -1)
end = b.getEntry().size();
while (c < end) {
Bundle bt = new Bundle();
bt.setType(BundleType.BATCH);
bt.setId(UUID.randomUUID().toString().toLowerCase());
for (int i = c; i < Math.min(b.getEntry().size(), c + size); i++) {
BundleEntryComponent be = bt.addEntry();
be.setResource(b.getEntry().get(i).getResource());
be.getRequest().setMethod(HTTPVerb.PUT);
be.getRequest().setUrl(be.getResource().getResourceType().toString() + "/" + be.getResource().getId());
}
System.out.print(" posting..");
long ms = System.currentTimeMillis();
Bundle resp = client.transaction(bt);
for (int i = 0; i < resp.getEntry().size(); i++) {
BundleEntryComponent t = resp.getEntry().get(i);
if (!t.getResponse().getStatus().startsWith("2")) {
System.out.println("failed status at " + Integer.toString(i) + ": " + t.getResponse().getStatus());
return c + i;
}
}
c = c + size;
System.out.println(" ..done: " + Integer.toString(c) + ". (" + Long.toString(System.currentTimeMillis() - ms) + " ms)");
}
System.out.println(" done");
return c;
}
use of org.hl7.fhir.r4.utils.client.FHIRToolingClient in project org.hl7.fhir.core by hapifhir.
the class BatchLoader method loadBundle.
private static int loadBundle(String server, Bundle b, int size, int start, int end) throws URISyntaxException {
System.out.println("Post to " + server + ". size = " + Integer.toString(size) + ", start = " + Integer.toString(start) + ", total = " + Integer.toString(b.getEntry().size()));
FHIRToolingClient client = new FHIRToolingClient(server, "fhir/batch-loader");
int c = start;
if (end == -1)
end = b.getEntry().size();
while (c < end) {
Bundle bt = new Bundle();
bt.setType(BundleType.BATCH);
bt.setId(UUID.randomUUID().toString().toLowerCase());
for (int i = c; i < Math.min(b.getEntry().size(), c + size); i++) {
BundleEntryComponent be = bt.addEntry();
be.setResource(b.getEntry().get(i).getResource());
be.getRequest().setMethod(HTTPVerb.PUT);
be.getRequest().setUrl(be.getResource().getResourceType().toString() + "/" + be.getResource().getId());
}
System.out.print(" posting..");
long ms = System.currentTimeMillis();
Bundle resp = client.transaction(bt);
for (int i = 0; i < resp.getEntry().size(); i++) {
BundleEntryComponent t = resp.getEntry().get(i);
if (!t.getResponse().getStatus().startsWith("2")) {
System.out.println("failed status at " + Integer.toString(i) + ": " + t.getResponse().getStatus());
return c + i;
}
}
c = c + size;
System.out.println(" ..done: " + Integer.toString(c) + ". (" + Long.toString(System.currentTimeMillis() - ms) + " ms)");
}
System.out.println(" done");
return c;
}
use of org.hl7.fhir.r4.utils.client.FHIRToolingClient in project org.hl7.fhir.core by hapifhir.
the class BatchLoader method sendFile.
private static void sendFile(FHIRToolingClient client, File f, int size, IniFile ini) throws FHIRFormatError, FileNotFoundException, IOException {
long ms = System.currentTimeMillis();
System.out.print("Loading " + f.getName() + ".. ");
IParser parser = f.getName().endsWith(".json") ? new JsonParser() : new XmlParser();
Resource res = parser.parse(new FileInputStream(f));
System.out.println(" done: (" + Long.toString(System.currentTimeMillis() - ms) + " ms)");
if (res instanceof Bundle) {
Bundle bnd = (Bundle) res;
int cursor = ini.hasProperty("progress", f.getName()) ? ini.getIntegerProperty("progress", f.getName()) : 0;
while (cursor < bnd.getEntry().size()) {
Bundle bt = new Bundle();
bt.setType(BundleType.BATCH);
bt.setId(UUID.randomUUID().toString().toLowerCase());
for (int i = cursor; i < Math.min(bnd.getEntry().size(), cursor + size); i++) {
if (i >= 0 && i < bnd.getEntry().size()) {
BundleEntryComponent be = bt.addEntry();
be.setResource(bnd.getEntry().get(i).getResource());
be.getRequest().setMethod(HTTPVerb.PUT);
be.getRequest().setUrl(be.getResource().getResourceType().toString() + "/" + be.getResource().getId());
}
}
System.out.print(f.getName() + " (" + cursor + "/" + bnd.getEntry().size() + "): ");
ms = System.currentTimeMillis();
Bundle resp = client.transaction(bt);
int ncursor = cursor + size;
for (int i = 0; i < resp.getEntry().size(); i++) {
BundleEntryComponent t = resp.getEntry().get(i);
if (!t.getResponse().getStatus().startsWith("2")) {
System.out.println("failed status at " + Integer.toString(i) + ": " + t.getResponse().getStatus());
ncursor = cursor + i - 1;
break;
}
}
cursor = ncursor;
System.out.println(" .. done: (" + Long.toString(System.currentTimeMillis() - ms) + " ms) " + SimpleDateFormat.getInstance().format(new Date()));
ini.setIntegerProperty("progress", f.getName(), cursor, null);
ini.save();
}
ini.setBooleanProperty("finished", f.getName(), true, null);
ini.save();
} else {
client.update(res);
ini.setBooleanProperty("finished", f.getName(), true, null);
ini.save();
}
}
use of org.hl7.fhir.r4.utils.client.FHIRToolingClient in project org.hl7.fhir.core by hapifhir.
the class BatchLoader method LoadDirectory.
private static void LoadDirectory(String server, String folder, int size) throws IOException, Exception {
System.out.print("Connecting to " + server + ".. ");
FHIRToolingClient client = new FHIRToolingClient(server, "fhir/batch-loader");
System.out.println("Done");
IniFile ini = new IniFile(Utilities.path(folder, "batch-load-progress.ini"));
for (File f : new File(folder).listFiles()) {
if (f.getName().endsWith(".json") || f.getName().endsWith(".xml")) {
if (!ini.getBooleanProperty("finished", f.getName())) {
sendFile(client, f, size, ini);
}
}
}
}
Aggregations