# (C) 2022 Cadence Design Systems, Inc. (Cadence) 
# All rights reserved.
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of Cadence products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. Cadence claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable Cadence offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
# liable for any damages or liability in connection with the Sample Code
# or its use.
from advanced_cubes import RandomMolRecordGeneratorCube
from floe.api import WorkFloe
from orionplatform.cubes import (CreateCollectionCube,
                                 RecordsToCollectionCube,
                                 CloseCollectionCube)
# Declare WorkFloe
job = WorkFloe("Collection Writing Example (Basic)")
job.title = "Collection Writing Example (Basic)"
job.description = "Example of Writing Records To Shards in a Collection"
job.classification = [["Educational", "Example", "Cube Development", "I/O", "Record", "Shard", "Collection"]]
job.tags = ["Educational", "Example", "Cube Development", "I/O", "Record", "Shard", "Collection"]
# Declare Cubes
generator = RandomMolRecordGeneratorCube("generator")
writer = RecordsToCollectionCube("writer")
make_collection = CreateCollectionCube("make_collection")
close_collection = CloseCollectionCube("close_collection")
# Add Cubes to WorkFloe
job.add_cubes(generator, writer, make_collection, close_collection)
# Promote Parameters
generator.promote_parameter("record_number",
                            promoted_name="record_number",
                            default=100000)
make_collection.promote_parameter("collection_name",
                                  promoted_name="collection",
                                  default="basic_example")
writer.promote_parameter("records_per_shard",
                         promoted_name="records_per_shard",
                         default=500)
# Connect Cubes
generator.success.connect(writer.intake)
make_collection.success.connect(writer.init)
writer.success.connect(close_collection.intake)
if __name__ == "__main__":
    job.run()
