AssetManager

public class AssetManager

AssetManager manages the communication with backend Predix-Asset service. This class has the knowledge of how to create new Assets and fetch existing assets from the backend Predix-Asset service based on the given query parameters. Example: // First, create an asset configuration with your Asset service instanceId let config = AssetManagerConfiguration(instanceId: my-asset-instanceId)

// Next, create an AssetManager object with the configuration
let manager = AssetManager(configuration: config)

// now you can call:
// `createAssets(jsonAssets: [[String:Any]], completionHandler: @escaping (Asset?, AssetStatus)->Void)`
// `fetchAssets(assetType: String, query: AssetQuery, completionHandler: @escaping (Asset?, AssetStatus)->Void)`
  • Create Assets in configured Predix Asset Service instance .

    As an example the models below are for a locomotives type Asset. It has a nested subobject called coords. uri field is always required:

    [{
    "uri": "/locomotives/1",
    "type": "Diesel-electric",
    "model": "ES44AC",
    "manufacturer": "/manufacturers/GE",
    "engine": "/engines/v12-1",
    "installedOn": "01/12/2005",
    "coords": {
    "lat": 33.914605,
    "lng": -117.253374
    }
    }]
    

    Declaration

    Swift

    public func createAssets(jsonAssets: [[String: Any]], completionHandler: @escaping (_ asset: Asset?, _ assetStatus: AssetStatus) -> Void)

    Parameters

    jsonAssets

    An array of dictionaries, where each dictionary represents an asset to be ingested.

    completionHandler

    closure called when register has completed. Asset?: holds of the created asset. AssetStatus: hold the information about whether the call was success/failure.

    asset

    Returns an Asset class that represents the asset for the given JSON.

    assetStatus

    The status for the Asset that was attempted to be created Note: The jsonAsset parameter supports nested (sub)dictionaries representing subobjects.

  • Fetches the Assets from the configured Predix-Asset service based on the search criteria provided in AssetQuery. See more: https://docs.predix.io/en-US/content/service/data_management/asset/using-asset-service

    Declaration

    Swift

    public func fetchAssets(assetType: String, query: AssetQuery, completionHandler: @escaping (_ asset: Asset?, _ assetStatus: AssetStatus) -> Void)

    Parameters

    assetType

    Asset collection that is being queried

    query

    AssetQuery: Request parameters.

    completionHandler

    closure called when request has completed.

    asset

    an Asset object for the requested assert type and query.

    assetStatus

    A status that represents the succuess or failure of a fetch asset request.