Class: AssetRegistry

composer-runtime. AssetRegistry

An asset registry manages a set of assets.


new AssetRegistry()

Do not attempt to create an instance of this class.

You must use the getAssetRegistry
method instead.

Source:

Methods


add(asset)

Add the specified asset to this asset registry.

Parameters:
Name Type Description
asset Resource

The assets to add to this asset registry.

Source:
Returns:

A promise. The promise is resolved when the asset has
been added to this asset registry. If the asset cannot be added to this
asset registry, or if the asset already exists in the asset registry,
then the promise will be rejected with an error that describes the problem.

Type
Promise
Example
// Get the vehicle asset registry.
return getAssetRegistry('org.acme.Vehicle')
  .then(function (vehicleAssetRegistry) {
    // Get the factory for creating new asset instances.
    var factory = getFactory();
    // Create the vehicle.
    var vehicle = factory.newInstance('org.acme', 'Vehicle', 'VEHICLE_1');
    vehicle.colour = 'BLUE';
    // Add the vehicle to the vehicle asset registry.
    return vehicleAssetRegistry.add(vehicle);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

addAll(assets)

Add all of the specified assets to this asset registry.

Parameters:
Name Type Description
assets Array.<Resource>

The assets to add to this asset registry.

Source:
Returns:

A promise. The promise is resolved when all of the
assets have been added to this asset registry. If the assets cannot be
added to this asset registry, or if the assets already exist in the
asset registry, then the promise will be rejected with an error
that describes the problem.

Type
Promise
Example
// Get the vehicle asset registry.
return getAssetRegistry('org.acme.Vehicle')
  .then(function (vehicleAssetRegistry) {
    // Get the factory for creating new asset instances.
    var factory = getFactory();
    // Create the first vehicle.
    var vehicle1 = factory.newInstance('org.acme', 'Vehicle', 'VEHICLE_1');
    vehicle1.colour = 'BLUE';
    // Create the second vehicle.
    var vehicle2 = factory.newInstance('org.acme', 'Vehicle', 'VEHICLE_2');
    vehicle2.colour = 'GREEN';
    // Add the vehicles to the vehicle asset registry.
    return vehicleAssetRegistry.addAll([vehicle1, vehicle2]);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

get(id)

Get the specified asset in this asset registry using the unique identifier
of the asset.

Parameters:
Name Type Description
id string

The ID of the asset.

Source:
Returns:

A promise. The promise is resolved with a Resource
instance representing the specified asset in this asset registry. If the
specified asset does not exist, or the current user does not have access
to the specified asset, then the promise will be rejected with an error
that describes the problem.

Type
Promise
Example
// Get the vehicle asset registry.
return getAssetRegistry('org.acme.Vehicle')
  .then(function (vehicleAssetRegistry) {
    // Get the specific vehicle from the vehicle asset registry.
    return assetRegistry.get('VEHICLE_1');
  })
  .then(function (vehicle) {
    // Process the the vehicle object.
    console.log(vehicle.vehicleId);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

getAll()

Get a list of all of the existing assets in this asset registry.

Source:
Returns:

A promise. The promise is resolved with an array of
Resource instances representing all of the assets stored in this
asset registry. If the asset registry does not exist, or the current
user does not have access to the asset registry, then the promise will
be rejected with an error that describes the problem.

Type
Promise
Example
// Get the vehicle asset registry.
return getAssetRegistry('org.acme.Vehicle')
  .then(function (vehicleAssetRegistry) {
    // Get all of the vehicles in the vehicle asset registry.
    return assetRegistry.getAll();
  })
  .then(function (vehicles) {
    // Process the array of vehicle objects.
    vehicles.forEach(function (vehicle) {
      console.log(vehicle.vehicleId);
    });
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

remove(asset)

Remove the specified asset from this asset registry.

Parameters:
Name Type Description
asset string | Resource

The asset, or ID of the asset, to remove
from this asset registry.

Source:
Returns:

A promise. The promise is resolved when the asset
has been removed from this asset registry. If the asset cannot be
removed from this asset registry, or if the asset does not exist in the
asset registry, then the promise will be rejected with an error that
describes the problem.

Type
Promise
Example
// The existing vehicle that has come from elsewhere.
var vehicle;
// Get the vehicle asset registry.
return getAssetRegistry('org.acme.Vehicle')
  .then(function (vehicleAssetRegistry) {
    // Get the factory for creating new asset instances.
    var factory = getFactory();
    // Remove the vehicle from the vehicle asset registry.
    return vehicleAssetRegistry.remove(vehicle);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

removeAll(assets)

Remove all of the specified assets from this asset registry.

Parameters:
Name Type Description
assets Array.<string> | Array.<Resource>

The assets, or the IDs of the assets,
to remove from this asset registry.

Source:
Returns:

A promise. The promise is resolved when all of the
assets have been removed from this asset registry. If the assets cannot be
removed from this asset registry, or if the assets do not exist in the
asset registry, then the promise will be rejected with an error that
describes the problem.

Type
Promise
Example
// The existing vehicles that have come from elsewhere.
var vehicle1;
// Get the vehicle asset registry.
return getAssetRegistry('org.acme.Vehicle')
  .then(function (vehicleAssetRegistry) {
    // Get the factory for creating new asset instances.
    var factory = getFactory();
    // Remove the vehicles from the vehicle asset registry. Note that
    // one vehicle is specified as a vehicle instance, and the other
    // vehicle is specified by the ID of the vehicle.
    return vehicleAssetRegistry.removeAll([vehicle1, 'VEHICLE_2']);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

update(asset)

Update the specified asset in this asset registry.

Parameters:
Name Type Description
asset Resource

The asset to update in this asset registry.

Source:
Returns:

A promise. The promise is resolved when the asset
have been updated in this asset registry. If the asset cannot be
updated in this asset registry, or if the asset does not exist in the
asset registry, then the promise will be rejected with an error that
describes the problem.

Type
Promise
Example
// The existing vehicle that has come from elsewhere.
var vehicle;
// Get the vehicle asset registry.
return getAssetRegistry('org.acme.Vehicle')
  .then(function (vehicleAssetRegistry) {
    // Get the factory for creating new asset instances.
    var factory = getFactory();
    // Modify the properties of the vehicle.
    vehicle.colour = 'PURPLE';
    // Update the vehicle in the vehicle asset registry.
    return vehicleAssetRegistry.update(vehicle);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

updateAll(assets)

Update all of the specified assets in this asset registry.

Parameters:
Name Type Description
assets Array.<Resource>

The assets to update in this asset registry.

Source:
Returns:

A promise. The promise is resolved when all of the
assets have been updated in this asset registry. If the assets cannot be
updated in this asset registry, or if the assets do not exist in the
asset registry, then the promise will be rejected with an error that
describes the problem.

Type
Promise
Example
// The existing vehicles that have come from elsewhere.
var vehicle1;
var vehicle2;
// Get the vehicle asset registry.
return getAssetRegistry('org.acme.Vehicle')
  .then(function (vehicleAssetRegistry) {
    // Get the factory for creating new asset instances.
    var factory = getFactory();
    // Modify the properties of the first vehicle.
    vehicle1.colour = 'PURPLE';
    // Modify the properties of the second vehicle.
    vehicle2.colour = 'ORANGE';
    // Update the vehicles in the vehicle asset registry.
    return vehicleAssetRegistry.updateAll([vehicle1, vehicle2]);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });