File size: 2,194 Bytes
70cbb67
65e2363
8a15af8
 
65e2363
 
 
 
 
 
 
 
 
 
 
 
 
 
8a15af8
f43a395
8a15af8
8abafca
 
8a15af8
 
 
 
 
 
 
65e2363
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1be54f0
65e2363
1be54f0
 
 
 
 
 
65e2363
 
8a15af8
65e2363
8a15af8
 
65e2363
 
8a15af8
 
65e2363
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from ..tool_utils import *

class EditOrCreateBooleanAttributeSchema(CommonAttributeFields):
    pass


@tool("edit_or_create_boolean_attribute", return_direct=False, args_schema=EditOrCreateBooleanAttributeSchema)
def edit_or_create_boolean_attribute(
    operation: str,
    name: str,
    system_name: str,
    application_system_name: str,
    template_system_name: str,
    description: Optional[str] = None,
    write_changes_to_the_log: Optional[bool] = False,
    calculate_value: Optional[bool] = False,
    expression_for_calculation: Optional[str] = None
) -> Dict[str, Any]:
    """
    Edit or Create a boolean attribute (Логический атрибут).
    
    Boolean attribute stores `true` or `false`.
    
    Returns:
        dict: {
            "success": bool - True if the attribute was created or edited successfully
            "status_code": int - HTTP response status code  
            "raw_response": dict|str|None - Raw response for auditing or payload body (sanitized)
            "error": str|None - Error message if operation failed
        }
    """

    request_body: Dict[str, Any] = {
        "globalAlias": {
            "owner": template_system_name,
            "type": "Undefined",
            "alias": system_name
        },
        "type": "Boolean",
        "name": name,
        "description": description,
        "isTracked": write_changes_to_the_log,
        "isCalculated": calculate_value if expression_for_calculation != None else False,
        "expression": expression_for_calculation,
    }

    endpoint = f"{ATTRIBUTE_ENDPOINT}/{application_system_name}"

    return execute_edit_or_create_operation(
        request_body=request_body,
        operation=operation,
        endpoint=endpoint,
        result_model=AttributeResult
    )

if __name__ == "__main__":
    results = edit_or_create_boolean_attribute.invoke({
        "operation": "create",
        "name": "Is Active",
        "system_name": "IsActive",
        "application_system_name": "AItestAndApi",
        "template_system_name": "Test",
        "description": "Indicates if the record is active",
        "write_changes_to_the_log": False
    })
    print(results)