Documents > BPS V2 Script API
bps::Robots Class Reference

The robots class is used to synchronize and revoke orders, or synchronize the robot stocks. More...

List of all members.

Public Types

enum  OrderSyncMode {
  SyncAll = 0,
  SyncNew = 1,
  SyncUpdate = 2
}
 Order items synchronize mode. More...
enum  OrderType {
  Trips = 0,
  Rows = 1,
  Columns = 2,
  Items = 3
}
 Type of the keys to process. More...

Public Member Functions

void addRobotsToTrip (Number aOrdertrip)
 Add robot status records for all zones having a robot to a trip.
void lockRobot (Number aZone)
 Lock the zone for exclusive robot access.
void revokeOrders (Number aZone, OrderType aOrderType, Array aKeys)
 Revoke orders from the robot.
 Robots (Datastore aDatastore, String aProgram)
 Constructor for a new Robots object.
void syncOrders (Number aZone, OrderType aOrderType, Array aKeys, OrderSyncMode aSyncMode)
 Synchronize orders to the robot.
void syncStock (Number aZone)
 Import all robot stocks into the BPS stock.
void unlockRobot (Number aZone)
 Unlock the zone, in case it was locked by the current actor.

Properties

Boolean anyRobots
 True if there are any robots.
Array zones
 List of zone keys with active robots.

Detailed Description

The robots class is used to synchronize and revoke orders, or synchronize the robot stocks.

Typically a "New" sync would be done after importing new orders.

Example:

 importExtension('bps');
 
 bps.log('Connect to database');
 var ds = new bps.Datastore;
 ds.connection = 'os_zmc';
 ds.username   = 'os_zmc1234';
 ds.password   = 'os_zmc5678';
 if (!ds.loadConnection())
     throw Error("Invalid connection.\nKnown connections are: "+bps.Datastore.connections);
 ds.connect();
 ds.purgeActors();
 ds.checkin();
 
 bps.log('Import orders');
 var newItems = new Array();
 var utl = new bps.OrderUtils(ds);
 while (!allImported) {
     // create tripKey, tripDate etc. from import source
     var item = utl.makeOrderItem({
         ordertrips_trip:    tripKey,
         ordertrips_date:    tripDate,
         orderrows_partner:  partnerKey,
         ordercols_article:  articleKey,
         orderitems_ordered: ordered
     });
     newItems[newItems.length] = item;
 }

 bps.log('Synchronize new items with robots');
 var robots = new bps.Robots(ds,'Import');
 for (var r = 0; r < robots.zones.length; ++r) {
     robots.syncOrders(
         robots.zones[r], 
         bps.Robots.Items, 
         newItems,
         bps.Robots.SyncNew
     );
 }

 bps.log('Disconnect from database');
 ds.checkout();
 ds.disconnect();

Member Enumeration Documentation

Order items synchronize mode.

Basic condition for all sync operations is that the order trip status must be active.

Enumerator:
SyncAll 

Sync unsent and changed items if robot trip status is unsent, sent or active.

SyncNew 

Sync unsent items if robot trip status is sent or active and t_trips.c_robotupdt is fullfilled.

SyncUpdate 

Sync unsent and changed items if robot trip status is sent or active.

Type of the keys to process.

Enumerator:
Trips 

A list of keys of t_ordertrips.

Rows 

A list of keys of t_orderrows.

Columns 

A list of keys of t_ordercols.

Items 

A list of keys of t_orderitems.


Constructor & Destructor Documentation

bps::Robots::Robots ( Datastore  aDatastore,
String  aProgram 
)

Constructor for a new Robots object.

Parameters:
[in]aDatastoreThe datastore object to use
[in]aProgramName of the program, to be used in license tokens.

Member Function Documentation

void bps::Robots::addRobotsToTrip ( Number  aOrdertrip)

Add robot status records for all zones having a robot to a trip.

Parameters:
[in]aOrdertripThe key of the order trip to send.
Exceptions:
Errorthrown on database errors.
void bps::Robots::lockRobot ( Number  aZone)

Lock the zone for exclusive robot access.

Parameters:
[in]aZoneKey of the zone.
Exceptions:
Errorthrown on SQL errors.
void bps::Robots::revokeOrders ( Number  aZone,
OrderType  aOrderType,
Array  aKeys 
)

Revoke orders from the robot.

The method tries to revoke as many items as possible as long as no fatal error or cancel happens, and only throws an exception about the robot unable to revoke certain items at the end.

  • When revoking of an item succeeds, the robot status of the item is deleted.
  • When revoking of any items is rejected or aborted, the robot status of the affected items remain unchanged.

In case of aborting (fatal error) in a critical communication phase, the status BPS knows about the robot may be inaccurate and have to be cleared manually by the user. The message of the thrown exception will in such a case include information about that fact.

Parameters:
[in]aZoneKey of the zone.
[in]aOrderTypeType of the records addressed by aKeys.
[in]aKeysList of keys to process.
Exceptions:
Errorthrown when revoking the trip failed or was aborted.
void bps::Robots::syncOrders ( Number  aZone,
OrderType  aOrderType,
Array  aKeys,
OrderSyncMode  aSyncMode 
)

Synchronize orders to the robot.

The method tries to synchronize as many items as possible as long as no fatal error or abort happens, and only throws an exception about rejects at the end.

  • When sending of a yet unsent order item is rejected, the order item remains unchanged.
  • When sending updates for a item is rejected, the item is reverted to the known robot status.
  • When sending is aborted, fails fatal or items are locked, the order items remain unchanged.

In case of aborting (fatal error) in a critical communication phase, the status BPS knows about the robot may be inaccurate and have to be cleared manually by the user. The message of the thrown exception will in such a case include information about that fact.

Parameters:
[in]aZoneKey of the zone.
[in]aOrderTypeType of the records addressed by aKeys.
[in]aKeysList of keys to process.
[in]aSyncModeSynchronizing mode.
Exceptions:
Errorthrown when sending the trip failed or was aborted.
void bps::Robots::syncStock ( Number  aZone)

Import all robot stocks into the BPS stock.

Parameters:
[in]aZoneKey of the zone.
Exceptions:
Errorthrown when querying the stock levels failed or was aborted.
void bps::Robots::unlockRobot ( Number  aZone)

Unlock the zone, in case it was locked by the current actor.

Parameters:
[in]aZoneKey of the zone.
Exceptions:
Errorthrown on SQL errors.