Discussion
· Oct 31, 2023

Pull files from Azure Blob Storage using EnsLib.CloudStorage.InboundAdapter

Has anyone been able to successfully implement a business service to pull files from Azure Blob storage?

Discussion (2)2
Log in or sign up to continue

Looking for a sample Ensemble BusinessService that uses the adapter to download data. Initially I'd like to just build a passthrough service, but I would also like to create an inbound HL7 service and a Record Mapper service. 

/// https://docs.intersystems.com/irisforhealth20231/csp/docbook/Doc.View.cls?KEY=EGIN_options_connectivity\
/// https://docs.intersystems.com/irisforhealth20231/csp/docbook/DocBook.UI.Page.cls?KEY=ECLOUD_inbound
/// https://docs.intersystems.com/irisforhealth20231/csp/documatic/%25CSP.Documatic.cls?LIBRARY=ENSLIB&CLASSNAME=EnsLib.CloudStorage.InboundAdapter
Class ARTIS.Adapter.CloudStorage.PassthroughService Extends Ens.BusinessService
{

Parameter ADAPTER = "EnsLib.CloudStorage.InboundAdapter";

/// Configuration item(s) to which to send file stream messages
Property TargetConfigNames As %String(MAXLEN = 1000);

Parameter SETTINGS = "TargetConfigNames:Basic:selector?multiSelect=1&context={Ens.ContextSearch/ProductionItems?targets=1&productionName=@productionId}";

Parameter CONTAINERCLASS = "Ens.StreamContainer";

/// Wrap the input stream object in a StreamContainer message object and send it. <p>
/// https://docs.intersystems.com/irisforhealth20231/csp/docbook/DocBook.UI.Page.cls?KEY=ECLOUD_inbound#ECLOUD_inbound_bs
/// based on EnsLib.File.PassthroughService but [at least initially] without archive and work folders.<p>
/// We assume our InboundAdapter has the DeleteAfterDownload to prevent pulling the same over and over.
Method OnProcessInput(pInput As EnsLib.CloudStorage.InboundInput, Output pOutput As %RegisteredObject) As %Status
{
	// https://docs.intersystems.com/irisforhealth20231/csp/docbook/DocBook.UI.Page.cls?KEY=ECLOUD_inbound#ECLOUD_inbound_bs
	#dim tContent As %GlobalBinaryStream = pInput.Content	//a stream that contains the data from cloud storage
	#dim tMeta As %String = pInput.Meta	// metadata associated with the cloud storage blob
	#dim tName As %String = pInput.Name	// the name of cloud storage blob
	
	#dim tSC,tSC1 As %Status = $$$OK
	#dim tSource, iTarget, tOneTarget As %String
	#dim tSyncCommit As %Integer
	
	Set tSource=$G(tName) _ $C(10)_$G(tMeta)
	// Do I need to convert tContent from binary stream to character stream first?? https://docs.intersystems.com/irisforhealth20242/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_fzconvert#RCOS_fzconvert_handle
	Set pInput=$classmethod(..#CONTAINERCLASS,"%New",tContent)
	
	$$$SyncCommitSet(tSyncCommit)
	For iTarget=1:1:$L(..TargetConfigNames, ",") { Set tOneTarget=$ZStrip($P(..TargetConfigNames,",",iTarget),"<>W")  Continue:""=tOneTarget
		$$$sysTRACE("Sending input Stream "_pInput.Stream_"("_pInput.Stream.Size_")"_" from '"_tSource_"' to '"_tOneTarget_"'")
		Set tSC1=..SendRequestAsync(tOneTarget,pInput)  Set:$$$ISERR(tSC1) tSC=$$$ADDSC(tSC,tSC1)
		}

	$$$SyncCommitClear(tSyncCommit)
	Quit tSC
}

/// Return an array of connections for drawing lines on the config diagram
ClassMethod OnGetConnections(Output pArray As %String, pItem As Ens.Config.Item)
{
	Do ##super(.pArray,pItem)
	If pItem.GetModifiedSetting("TargetConfigNames",.tValue) {
		For i=1:1:$L(tValue,",") { Set tOne=$ZStrip($P(tValue,",",i),"<>W")  Continue:""=tOne  Set pArray(tOne)="" }
	}
}

}