Concepts and architecture
How it works
Riversoft® STCP Gemini Rename is a command-line utility: it runs, processes the files and exits. Each run receives a routing, which is a set of rules. For each file, Riversoft STCP Gemini Rename looks for the first rule that matches it and applies that rule’s actions.
Registering routings
The operator registers the routings in the Riversoft Console Portal, which writes them to the configuration database through the Riversoft STCP Gemini API. In the local file mode, the operator creates the routing JSON file.
flowchart LR
OP[Operator] -->|database mode:<br/>registers the routing| PORTAL[Riversoft<br/>Console Portal] --> API[Riversoft STCP<br/>Gemini API] -->|writes| DB[(Configuration<br/>database)]
OP -->|local file mode:<br/>creates the routing JSON file| JSON[Routing<br/>JSON file]
Event trigger
When a partner sends a file, Riversoft STCP Gemini Server or Riversoft STCP DirectLink triggers Riversoft STCP Gemini Rename with the received file. Riversoft STCP Gemini Rename reads the routing and applies the rule to the file.
flowchart LR
PARC[Partner] -->|sends the file| GEM[Riversoft STCP Gemini Server<br/>or Riversoft STCP DirectLink]
GEM -->|triggers with the<br/>received file| REN[Riversoft STCP<br/>Gemini Rename]
DB[(Configuration<br/>database)] -->|routing| REN
REN -->|applies the rule| DEST[Destination]
Schedule trigger
At the set time, an instance or operating system schedule runs Riversoft STCP Gemini Rename with a scan (-scan). It reads the routing, goes through the source directory and applies the rule to each file found.
flowchart LR
AG[Schedule] -->|runs the scan| REN[Riversoft STCP<br/>Gemini Rename]
DB[(Configuration<br/>database)] -->|routing| REN
DIR[Source<br/>directory] -->|files| REN
REN -->|applies the rule<br/>to each file| DEST[Destination]
Configuration modes
The mode is set in cfgProviderType, in the configuration file. See Configuration.
| Mode | cfgProviderType | Instance and routings | Log |
|---|---|---|---|
| Database | stcpgeminidb | Read from the configuration database. Routings are maintained in the Riversoft Console Portal. | Instance log database. |
| Local file | stcpgeminifile | The instance is in the cfgInstance section of config.json, and each routing is a JSON file. | Text file in the applLogDir directory. |
The database mode is the most common: routings are registered in the Portal and runs appear in the instance log, together with the transfers.
Ways of running
| Way | When to use | Example |
|---|---|---|
| One file | Riversoft STCP Gemini Server or Riversoft STCP DirectLink triggers Riversoft STCP Gemini Rename for each received file, passing the file name. | stcpren -db -rules INBOUND /mailbox/IN/NOTES.TXT |
| Scan | Process all files in a directory, on a schedule or manually. | stcpren -db -rules INBOUND -scan /mailbox/IN |
| Rule conversion | Convert old INI rules to JSON. | stcpren -ini rules.ini -rules rules.json |
| Export | Write a routing registered in the database to a JSON file. | stcpren -db -rules INBOUND -export /tmp |
All options are in Command reference.
Routings and rules
A routing has a general part, with the scan and log options, and a list of rules numbered (Index) from 0.
- Rules are evaluated in order, and the first one that matches the file applies.
- A rule matches when the file name (
FileRegEx), the directory (DirRegEx) and the source (SrcRegEx) satisfy the regular expressions. Optionally, the content of the first lines is also checked (ContentRegEx). - A locked rule (
Locked) is ignored. - Numbering must be continuous: a gap in
Indexends the evaluation. - A rule can name the next rule to run (
NextSection), which chains actions on the same file.
The full structure is in Rule reference.
Processing a file
Riversoft STCP Gemini Rename looks for the first rule that matches the file and checks that rule’s limits. If no rule matches, or if the file is outside the limits, it stays at the source.
flowchart LR
A[File] --> B{Does any rule<br/>match?}
B -- no --> X[Records error MSG7003<br/>and the file stays at the source]
B -- yes --> C{Time, day, age<br/>and size allowed?}
C -- no --> W[Records a warning<br/>and the file stays at the source]
C -- yes --> P[Applies the rule<br/>actions]
The actions run in this order. Each step is optional and runs only when it is configured in the rule.
Builds the new name
New name and copy and backup directories (Filename, CopyToDir, BkpToDir).
Checks and creates the control files
CheckLockUnlockOption.
Runs the command before the copy
ExecProgBefore.
Makes the backup before the copy
BkpFileOption with option 32.
Copies or moves the file
CopyFileOption.
Makes the backup after the copy
BkpFileOption.
Removes the original file
RemoveAfterCopy.
Removes the control files
CheckLockUnlockOption.
Runs the command after the copy
ExecProg.
If the command before the copy, the backup before the copy or the copy step fails, the error command (ExecProgError) runs, when configured, and processing of the file ends. If the backup after the copy or the command after the copy step fails, the error command also runs, but processing continues. If the rule names a next rule (NextSection), it runs on the same file.
flowchart LR
S[Rule step] -- completed --> N{Next rule<br/>defined?}
N -- yes --> R[Runs the next rule<br/>on the same file]
N -- no --> F[End of the file]
S -- failure --> E[Error command<br/>ExecProgError]
E --> T[End of the file<br/>with an error]
In a scan, each file is processed the same way. A file with an error does not stop the scan of the others.
Variables
External commands and control file names accept variables, such as $FILENEWNAME (full name of the new file) and $SRCUSER (source user). The values of -var0 to -var9, given on the command line, can also be used. See Variable reference.
Concurrent runs
To prevent two runs from processing the same files at the same time:
- the scan can use a semaphore (
ScanLockSem): another scan with the same semaphore waits or exits; - each rule can use control files (lock and unlock), created and checked before and after the copy;
- the application lock control is set in
lockProvider, inconfig.json.
Key concepts
| Concept | Description |
|---|---|
| Routing | Named set of rules. It is given in -rules. |
| Rule | Selection criteria and actions applied to a file. |
| Instance | Associated Riversoft STCP Gemini instance, given in cfgInstanceName. It is the same as the Riversoft STCP Gemini Server or Riversoft STCP DirectLink instance. |
| Source | User or source name given in -src, compared with SrcRegEx. |
| Scan | Search for files in a directory (-scan or ScanDir). |
| Control file | File created or checked by the rule to signal that a file is in use (lock) or released (unlock). |