Business Units
Introduction
To Code provides the ability to define APIs that can be designed around business units to expose relevant functionalities and data. This allows different parts of a business to use and interact with the system in a modular way.
In Code Model, especially in the context of software architecture and design, a "business unit" typically refers to a logical grouping of related functionalities or processes that align with specific business objectives.
Syntax
Implementing business units effectively requires a deep understanding of the organization’s structure and goals. Proper modeling helps in maintaining flexibility, scalability, and alignment between the technical and business aspects of a Code Model.
LogicalId
{
"LogicalId": "Tags"
}
- Description: the LogicalId is unique, represent the name of business unit.
Description
{
"Description": "Manage System Tags"
}
- Description: the field serve as descriptors for the business unit, useful for referencing and understanding the purpose of the business unit.
Operations
In a Code Model, particularly when dealing with business units, an "operation" typically refers to a specific function or method that represents a business process or action within that unit.
To Code provides the ability to define your operations.
Refer to Operations section for definition and implementation of an operation in the Code Model.
Expressions
In a Code Model, the term "expression" refers to a combination of variables, operators, and values that the programming language interprets and computes to produce another value.
Expressions are fundamental components of code that can perform calculations, manipulate data, and produce outputs.
To Code provides the ability to define your expressions.
Refer to Expressions section for definition and implementation of an Expression in the Code Model.
Example
This document describes the setup and functionality of the business unit Tag
configuration used for update from an business unit identified as TagManager
.
{
"BusinessUnits": [
{
"LogicalId": "Tags",
"Description": "Manage System Tags",
"Operations": [
{
"LogicalId": "createTag",
"Description": "Define a new tag",
"ExposedAsRest": false,
"Type": "Post",
"Inputs": [
{
"DataType": "String",
"MaxLength": null,
"DefaultValue": null,
"RegularExpression": null,
"LogicalId": "Name",
"Description": null,
"Required": true,
"IsUnique": false,
"AutoGenerate": false
}
],
"ResultType": {
"Type": "None"
},
"Functionality": [
{
"ExpressionType": "InitiateVariable",
"TypeOf": {
"Type": "Primitive",
"IsArray": false,
"DataType": "Boolean"
},
"DefaultValue": {
"ExpressionType": "Constant",
"DataType": "Boolean",
"Value": false
},
"LogicalId": "tagexist",
"Description": null
},
{
"ExpressionType": "InitiateVariable",
"TypeOf": {
"Type": "Pagination",
"ObjectLogicalId": "RetrieveTags"
},
"DefaultValue": {
"ExpressionType": "ExecuteQuery",
"PageNumber": {
"ExpressionType": "Constant",
"DataType": "Int32",
"Value": 1
},
"PageSize": {
"ExpressionType": "Constant",
"DataType": "Int32",
"Value": 2147483647
},
"Arguments": [
{
"LogicalId": "Name",
"Value": {
"ExpressionType": "GetInput",
"Extension": null,
"LogicalId": "Name",
"Description": null
}
}
],
"Extension": null,
"LogicalId": "RetrieveTags",
"Description": null
},
"LogicalId": "existingTags",
"Description": null
},
{
"ExpressionType": "ForEach",
"ItemVariableLogicalId": "item",
"ArrayLogicalId": {
"ExpressionType": "GetProperty",
"SourceLogicalId": "existingTags",
"Extension": null,
"LogicalId": "List",
"Description": null
},
"Expressions": [
{
"ExpressionType": "IfCondition",
"LeftCondition": {
"ExpressionType": "GetProperty",
"SourceLogicalId": "item",
"Extension": null,
"LogicalId": "Name",
"Description": null
},
"Operator": "Equal",
"RightCondition": {
"ExpressionType": "GetInput",
"Extension": null,
"LogicalId": "Name",
"Description": null
},
"LogicalOperator": "And",
"Operands": null,
"OnSuccess": [
{
"ExpressionType": "SetVariable",
"Value": {
"ExpressionType": "Constant",
"DataType": "Boolean",
"Value": true
},
"LogicalId": "tagexist",
"Description": null
}
],
"OnFailure": null
}
]
},
{
"ExpressionType": "IfCondition",
"LeftCondition": {
"ExpressionType": "GetVariable",
"Extension": null,
"LogicalId": "tagexist",
"Description": null
},
"Operator": "NotEqual",
"RightCondition": {
"ExpressionType": "Constant",
"DataType": "Boolean",
"Value": true
},
"LogicalOperator": "And",
"Operands": null,
"OnSuccess": [
{
"ExpressionType": "CreateEntity",
"Arguments": [
{
"LogicalId": "Name",
"Value": {
"ExpressionType": "GetInput",
"Extension": null,
"LogicalId": "Name",
"Description": null
}
}
],
"LogicalId": "Tag",
"Description": null
}
],
"OnFailure": [
{
"ExpressionType": "ThrowError",
"Errors": [
{
"Name": "TagAlreadyExist",
"Message": "Tag already exist"
}
]
}
]
}
],
"ReturnResult": null
}
]
},
]
}
The JSON structure describes a Business unit Tag
.
Output
To Code you provided is a C# class named TagManager
.
{
/// <summary>
/// Manage System Tags
/// </summary>
public class TagsManager
{
private readonly IRetrieveTagsService _retrieveTagsService;
private readonly ITagService _tagService;
public TagsManager(
IRetrieveTagsService retrieveTagsService,
ITagService tagService)
{
this._retrieveTagsService = retrieveTagsService;
this._tagService = tagService;
}
public virtual async Task<ActionResult> CreateTag(
string name)
{
ArgumentNullException.ThrowIfNullOrEmpty(name);
ArgumentOutOfRangeException.ThrowIfLessThan<int>(name.Length, 50);
var errors = await Task.FromResult(new List<Error>());
bool tagexist = false;
PagedList<RetrieveTags> existingTags = await this._retrieveTagsService.Execute(
new PagingParams() {PageNumber = 1,PageSize = 2147483647},
name);
foreach(var item in existingTags.List)
{
if(item.Name.Equals(item.Name))
{
tagexist = true;
}
}
if(!tagexist.Equals(tagexist))
{
await this._tagService.Create(
name);
return new ActionResult(errors);
}
return new ActionResult(errors);
}
}
}