Importing Visualizations
For public-facing projects using Hoglin, including bundled visualizations to aggregate and display custom analytics is a great way to show off the possibilities of your Hoglin integration. Hoglin’s SDK provides simple ways to achieve this. For more info on visualizations and how to set them up, check out the Visualizations Guide.
Understanding visualization snapshots
Section titled “Understanding visualization snapshots”When a visualization is shared via a link, a snapshot of its current state is created. Snapshots are independent of the original visualization, so subsequent changes (including updates or deletion) will not affect the snapshot.
Primary usage
Section titled “Primary usage”// Only snapshotId is required for importing, overloads allow for importing with any combinations of parametersHoglin#importSnapshot(UUID snapshotId, String name, Boolean preventDuplicate)
// Checking if a snapshot has been imported standaloneHoglin#isVisualizationImported(UUID snapshotId)Hoglin#getImportedSnapshotInfo(UUID snapshotId)Hoglin#getImportedSnapshotInfoRaw(UUID snapshotId)We provide some configuration over the importing of snapshots. Notably:
nameYou can specify a custom name for the imported visualization. If you leave this blank, the original visualization’s name will be used.preventDuplicateThis prevents importing the snapshot if a visualization that was imported from the same snapshot already exists on the dashboard. Specifying this parameter withHoglin#importSnapshotis recommended as it does this logic in one round trip to the Hoglin backend, as opposed to manually checking withHoglin#isVisualizationImported(), which would require two separate requests.
Retrieving your snapshot ID for importing
Section titled “Retrieving your snapshot ID for importing”To retrieve your snapshot ID, export your visualization via the Hoglin dashboard. You can do this by navigating to the visualization you wish to export on the sidebar, right-clicking and selecting “Export Snapshot”. This will copy a link which is used for manually importing through a web interface. For SDK usage, you only need the ID. To get this, open the link and click on “Copy Snapshot ID”.
Video Demonstration
Importing visualizations
Section titled “Importing visualizations”Hoglin hoglin = /** Your Hoglin instance */;UUID snapshotId = UUID.fromString("your-snapshot-id-here");
hoglin.importSnapshot(snapshotId, "Imported Visualization", true); // Imports a visualization with a custom name and prevents duplicates
// Outline of additional method overloadshoglin.importSnapshot(snapshotId); // Retains original visualization name, won't prevent duplicateshoglin.importSnapshot(snapshotId, true); // Retains original visualization name, prevents duplicateshoglin.importSnapshot(snapshotId, "Imported Visualization"); // Custom name, won't prevent duplicatesval hoglin = /** Your Hoglin instance */val snapshotId = UUID.fromString("your-snapshot-id-here")
hoglin.importSnapshot(snapshotId, "Imported Visualization", true); // Imports a visualization with a custom name and prevents duplicates
// Outline of additional method overloadshoglin.importSnapshot(snapshotId); // Retains original visualization name, won't prevent duplicateshoglin.importSnapshot(snapshotId, true); // Retains original visualization name, prevents duplicateshoglin.importSnapshot(snapshotId, "Imported Visualization"); // Custom name, won't prevent duplicatesStandalone check for if a snapshot is imported
Section titled “Standalone check for if a snapshot is imported”Hoglin hoglin = /** Your Hoglin instance */;UUID snapshotId = UUID.fromString("your-snapshot-id-here");
if (hoglin.isVisualizationImported(snapshotId)) { System.out.println("This snapshot been imported before and is on the dashboard!");}
// Or, for more detailsfinal ImportedSnapshotEvaluation importedSnapshotInfo = hoglin.getImportedSnapshotInfo(snapshotId);if (importedSnapshotInfo.isImported()) { final int amount = importedSnapshotInfo.getVisualizationIds().length; System.out.println("This snapshot been imported before and is on the dashboard " + amount + " times! Ids: " + Arrays.toString(importedSnapshotInfo.getVisualizationIds())); // Example output: "[...] on the dashboard 2 times! Ids: [db8868a7-e3d8-417b-92bc-bf75a47fd08a, 20e79621-50e2-4171-bc43-6633bedc3fc1]"}val hoglin: Hoglin = /** Your Hoglin instance */val snapshotId = UUID.fromString("your-snapshot-id-here")
if (hoglin.isVisualizationImported(snapshotId)) { println("This snapshot been imported before and is on the dashboard!")}
// Or, for more detailsval importedSnapshotInfo = hoglin.getImportedSnapshotInfo(snapshotId)if (importedSnapshotInfo.isImported) { val amount = importedSnapshotInfo.visualizationIds.size println("This snapshot been imported before and is on the dashboard $amount times! Ids: ${importedSnapshotInfo.visualizationIds.contentToString()}") // Example output: "[...] on the dashboard 2 times! Ids: [db8868a7-e3d8-417b-92bc-bf75a47fd08a, 20e79621-50e2-4171-bc43-6633bedc3fc1]"}In the event of requests failing, getImportedSnapshotInfo() and isVisualizationImported() will fail gracefully,
returning null or false where applicable and logging an error in the console without throwing an exception.
If you wish to handle request failure differently, you may use getImportedSnapshotInfoRaw(), which returns the raw
HttpResponse<String> from the request. Similarly, Hoglin#importSnapshot() will also return the raw
HttpResponse<String> for further handling.