223 lines
6.7 KiB
Plaintext
223 lines
6.7 KiB
Plaintext
// Governance Example - Demonstrates using the governance models with embedded types
|
|
// This example shows how to create, retrieve, and manipulate governance entities with embedded types
|
|
|
|
// Get the database instance
|
|
let db = get_db();
|
|
println("Hero Models - Governance Example");
|
|
println("================================");
|
|
|
|
// Create a company with a business type using the fluent builder pattern
|
|
println("Creating a company...");
|
|
// Create a business type directly
|
|
let business_type = #{
|
|
type_name: "Corporation",
|
|
description: "A corporation is a legal entity that is separate and distinct from its owners"
|
|
};
|
|
|
|
let company = company__builder(1)
|
|
.name("Acme Corporation")
|
|
.registration_number("REG123456")
|
|
.incorporation_date(now())
|
|
.fiscal_year_end("December 31")
|
|
.email("info@acme.com")
|
|
.phone("+1 555-123-4567")
|
|
.website("https://acme.com")
|
|
.address("123 Main St, Anytown, USA")
|
|
.business_type(business_type)
|
|
.industry("Technology")
|
|
.description("A leading technology company")
|
|
.status("Active")
|
|
.build();
|
|
|
|
// Save the company to the database
|
|
set_company(db, company);
|
|
println("Company created successfully!");
|
|
println("");
|
|
|
|
// Create a committee with members using the fluent builder pattern
|
|
println("Creating a committee...");
|
|
let committee = committee__builder(1)
|
|
.company_id(1)
|
|
.name("Board of Directors")
|
|
.description("The main governing body of the company")
|
|
.add_member(
|
|
committee_member()
|
|
.id(1)
|
|
.user_id(101)
|
|
.name("John Smith")
|
|
.role(CommitteeRole::Chair)
|
|
)
|
|
.add_member(
|
|
committee_member()
|
|
.id(2)
|
|
.user_id(102)
|
|
.name("Jane Doe")
|
|
.role(CommitteeRole::Secretary)
|
|
)
|
|
.add_member(
|
|
committee_member()
|
|
.id(3)
|
|
.user_id(103)
|
|
.name("Bob Johnson")
|
|
.role(CommitteeRole::Member)
|
|
)
|
|
.build();
|
|
|
|
// Save the committee to the database
|
|
set_committee(db, committee);
|
|
println("Committee created successfully!");
|
|
println("");
|
|
|
|
// Create a meeting with attendees using the fluent builder pattern
|
|
println("Creating a meeting...");
|
|
let meeting = meeting__builder(1)
|
|
.company_id(1)
|
|
.title("Q2 Board Meeting")
|
|
.date(now() + days(7))
|
|
.location("Conference Room A")
|
|
.description("Quarterly board meeting to review financial performance")
|
|
.add_attendee(
|
|
attendee()
|
|
.id(1)
|
|
.user_id(101)
|
|
.name("John Smith")
|
|
.role(AttendeeRole::Coordinator)
|
|
.status(AttendeeStatus::Confirmed)
|
|
)
|
|
.add_attendee(
|
|
attendee()
|
|
.id(2)
|
|
.user_id(102)
|
|
.name("Jane Doe")
|
|
.role(AttendeeRole::Secretary)
|
|
.status(AttendeeStatus::Confirmed)
|
|
)
|
|
.add_attendee(
|
|
attendee()
|
|
.id(3)
|
|
.user_id(103)
|
|
.name("Bob Johnson")
|
|
.role(AttendeeRole::Member)
|
|
.status(AttendeeStatus::Pending)
|
|
)
|
|
.build();
|
|
|
|
// Save the meeting to the database
|
|
set_meeting(db, meeting);
|
|
println("Meeting created successfully!");
|
|
println("");
|
|
|
|
// Create a resolution with approvals using the fluent builder pattern
|
|
println("Creating a resolution...");
|
|
let resolution = resolution__builder(1)
|
|
.company_id(1)
|
|
.title("New Product Line Resolution")
|
|
.description("Resolution to approve the development of a new product line")
|
|
.resolution_type(ResolutionType::Ordinary)
|
|
.status(ResolutionStatus::Proposed)
|
|
.proposed_date(now())
|
|
.effective_date(now() + days(30))
|
|
.expiry_date(now() + days(365))
|
|
.add_approval("John Smith")
|
|
.add_approval("Jane Doe")
|
|
.build();
|
|
|
|
// Save the resolution to the database
|
|
set_resolution(db, resolution);
|
|
println("Resolution created successfully!");
|
|
println("");
|
|
|
|
// Create a vote with ballots using the fluent builder pattern
|
|
println("Creating a vote...");
|
|
let vote = vote__builder(1)
|
|
.company_id(1)
|
|
.resolution_id(1)
|
|
.title("Vote on New Product Line")
|
|
.description("Vote to approve the development of a new product line")
|
|
.status(VoteStatus::Open)
|
|
.add_ballot(
|
|
ballot()
|
|
.id(1)
|
|
.user_id(101)
|
|
.user_name("John Smith")
|
|
.option(VoteOption::Yes)
|
|
.comments("Strongly support this initiative")
|
|
)
|
|
.add_ballot(
|
|
ballot()
|
|
.id(2)
|
|
.user_id(102)
|
|
.user_name("Jane Doe")
|
|
.option(VoteOption::Yes)
|
|
.comments("Agree with the proposal")
|
|
)
|
|
.add_ballot(
|
|
ballot()
|
|
.id(3)
|
|
.user_id(103)
|
|
.user_name("Bob Johnson")
|
|
.option(VoteOption::Abstain)
|
|
.comments("Need more information")
|
|
)
|
|
.start_date(now())
|
|
.end_date(now() + days(7))
|
|
.build();
|
|
|
|
// Save the vote to the database
|
|
set_vote(db, vote);
|
|
println("Vote created successfully!");
|
|
println("");
|
|
|
|
// Retrieve and display the company
|
|
println("Retrieving company...");
|
|
let retrieved_company = get_company_by_id(db, 1);
|
|
println("Company: " + retrieved_company.name);
|
|
println("Business Type: " + retrieved_company.business_type.type_name);
|
|
println("");
|
|
|
|
// Retrieve and display the committee
|
|
println("Retrieving committee...");
|
|
let retrieved_committee = get_committee_by_id(db, 1);
|
|
println("Committee: " + retrieved_committee.name);
|
|
println("Members: " + retrieved_committee.members.len());
|
|
for member in retrieved_committee.members {
|
|
println("- " + member.name + " (" + member.role + ")");
|
|
}
|
|
println("");
|
|
|
|
// Retrieve and display the meeting
|
|
println("Retrieving meeting...");
|
|
let retrieved_meeting = get_meeting_by_id(db, 1);
|
|
println("Meeting: " + retrieved_meeting.title);
|
|
println("Date: " + retrieved_meeting.date);
|
|
println("Attendees: " + retrieved_meeting.attendees.len());
|
|
for attendee in retrieved_meeting.attendees {
|
|
println("- " + attendee.name + " (" + attendee.role + ", " + attendee.status + ")");
|
|
}
|
|
println("");
|
|
|
|
// Retrieve and display the resolution
|
|
println("Retrieving resolution...");
|
|
let retrieved_resolution = get_resolution_by_id(db, 1);
|
|
println("Resolution: " + retrieved_resolution.title);
|
|
println("Status: " + retrieved_resolution.status);
|
|
println("Approvals: " + retrieved_resolution.approvals.len());
|
|
for approval in retrieved_resolution.approvals {
|
|
println("- " + approval);
|
|
}
|
|
println("");
|
|
|
|
// Retrieve and display the vote
|
|
println("Retrieving vote...");
|
|
let retrieved_vote = get_vote_by_id(db, 1);
|
|
println("Vote: " + retrieved_vote.title);
|
|
println("Status: " + retrieved_vote.status);
|
|
println("Ballots: " + retrieved_vote.ballots.len());
|
|
for ballot in retrieved_vote.ballots {
|
|
println("- " + ballot.user_name + ": " + ballot.option);
|
|
}
|
|
println("");
|
|
|
|
println("Governance example completed successfully!");
|
|
()
|