Connection class

An instance of the Connection class represents an incoming or outgoing connection for the flow element associated with the script (see connection and script element for background information). Connection objects can be obtained through functions of the Switch class.

Accessing the flow definition

getName( ) : String

Returns the name of the connection as displayed in the canvas; this may be an empty string.

getElementID ( ) : String

Returns a string that uniquely identifies the connection (within the limits of the guarantees described below). Callers should not rely on the syntax of the returned string as this may change between Switch versions.

The element ID for a particular flow element offers the following fundamental guarantees:


  • It differs from the element ID for any other flow element in any currently active flow.

  • It remains unchanged as long as the flow in which it resides is not edited, even if the flow is deactivated and reactivated and across Switch sessions.

  • The element ID for a connection is never equal to the element ID for a non-connection flow element.

Note that holding or releasing connections or renaming the flow does not count as editing in this context. However exporting and re-importing (or upgrading) a flow, or renaming a flow element inside the flow, does count as editing.

getConnectionType( ) : String

Returns the type of the connection as one of the following strings: "Move", "Filter", "Traffic-data", Traffic-log", "Traffic-datawithlog".

allowsSuccess ( ) : Boolean

Returns true if this is a traffic-light connection and the Success property is set to yes; otherwise returns false.

allowsWarning ( ) : Boolean

Returns true if this is a traffic-light connection and the Warning property is set to yes; otherwise returns false.

allowsError ( ) : Boolean

Returns true if this is a traffic-light connection and the Error property is set to yes; otherwise returns false.

isOnHold( ) : Boolean

Returns true if the connection is currently on hold, false if it is not.

getFolderName( ) : String

Returns the name of the folder at the other end of this connection (the originating folder for an incoming connection, the target folder for an outgoing connection) as displayed in the canvas; this may be an empty string.

Accessing injected properties

The connection class offers the same functions for accessing injected properties as the Switch class; the function descriptions are not repeated here.

Only outgoing connections have injected properties.

getPropertyLocalizedName( tag : String ) : String

Returns the name of the property as visible in the user interface. The name is localized, i.e. it is translated to the language that is currently used by the Switch. This method is mostly intended for getting property name to be included into a log message.

hasProperty( tag : String ) : Boolean
Returns true if the flow element has the property with the specified tag, else returns false.

Accessing files at the other end of the connection

getFileCount( nested : Boolean ) : Number

Returns the number of files currently residing in the folder at the other end of this connection (the originating folder for an incoming connection, the target folder for an outgoing connection). If nested is false, only items directly inside the folder are counted (i.e. each file and each subfolder is counted as one item). If nested is true, the number of files in subfolders are counted as well, recursively (and subfolders themselves do not contribute to the count).

getByteCount( ) : Number

Returns the size in bytes of the contents currently residing in the folder at the other end of this connection (the originating folder for an incoming connection, the target folder for an outgoing connection). Files in subfolders are included in the count, recursively.

Note:

The getFileCount() and getByteCount() functions tally any and all files that are reported by the file system to reside in the connection's folder at the instant of the function's invocation, including files that have not yet fully arrived, and (for outgoing connections) including files that have been placed in the target folder by other processes. As a consequence, the return value of these functions may vary between subsequent invocations as files are added/removed/updated under or outside of the script's control.