Fetch data from Azure storage
This article shows you how to populate an adaptive form with the data stored in Azure storage.
It is assumed that you have stored the adaptive form data in Azure storage and now want to prefill your adaptive form with that data.
Create GET request
The next step is to write the code to fetch the data from the Azure Storage using the blobID. The following code was written to fetch the data. The url was constructed using the sasToken and storageURI values from the OSGi configuration and the blobID passed to the getBlobData function
@Override
public String getBlobData(String blobID) {
String sasToken = azurePortalConfigurationService.getSASToken();
String storageURI = azurePortalConfigurationService.getStorageURI();
log.debug("The SAS Token is " + sasToken);
log.debug("The Storage URL is " + storageURI);
String httpGetURL = storageURI + blobID;
httpGetURL = httpGetURL + sasToken;
HttpGet httpGet = new HttpGet(httpGetURL);
org.apache.http.impl.client.CloseableHttpClient httpClient = HttpClientBuilder.create().build();
CloseableHttpResponse httpResponse = null;
try {
httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
String blobData = EntityUtils.toString(httpEntity);
log.debug("The blob data I got was " + blobData);
return blobData;
} catch (ClientProtocolException e) {
log.debug("Got Client Protocol Exception " + e.getMessage());
} catch (IOException e) {
log.debug("Got IOEXception " + e.getMessage());
}
return null;
}
When an adaptive form is rendered with a guid parameter in the url, the custom page component associated with the template fetches and populates the adaptive form with the data from Azure storage.
The following is the code in the jsp of the page component asscoiated with the template
com.aemforms.saveandfetchfromazure.StoreAndFetchDataFromAzureStorage azureStorage = sling.getService(com.aemforms.saveandfetchfromazure.StoreAndFetchDataFromAzureStorage.class);
String guid = request.getParameter("guid");
if(guid!=null&&!guid.isEmpty())
{
String dataXml = azureStorage.getBlobData(guid);
slingRequest.setAttribute("data",dataXml);
}
Test the solution
-
Import the custom adaptive form template and the page component associated with the template
-
Verify the data is stored in the Azure storage container of your choice. Copy the Blob ID.
-
Preview the BankAccount form and specify the Blob ID as a guid parameter in the URL for the form to be prepopulated with the data from Azure storage