-
Notifications
You must be signed in to change notification settings - Fork 0
/
business_object.go
110 lines (101 loc) · 2.53 KB
/
business_object.go
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package logic
import (
"encoding/gob"
"errors"
"fmt"
errs "github.com/hellgate75/general_utils/errors"
"io"
"reflect"
)
// Componponent that describe data that can be sent / received to / from the Bus
type BusinessObject interface {
ExportableObject
// Get the Map that describes the component fields/value
// Returns:
// logic.ValueMap Map that contains business object field names and values
GetValuesMap() ValuesMap
// Get the Key array
// Returns:
// logic.Keys Business object field name array
GetKeys() Keys
// Get the Business Object Type
// Returns:
// reflect.Type Business object field type
GetType() reflect.Type
// Get the Number of Fields, saved into the Business Objetc
// Returns:
// int Number of Fields
Size() int
}
type __businessData struct {
fieldsMap map[string]interface{}
objectType reflect.Type
}
// Export Data into the flow
// Parameters:
// flows.Flow Input Stream
// Returns:
// error Any error that occurs during the computation or nil
func (business *__businessData) Export(f io.Writer) error {
var err error
defer func() {
itf := recover()
if itf != nil {
if errs.IsError(itf) {
err = itf.(error)
} else {
err = errors.New(fmt.Sprintf("%v", itf))
}
}
}()
encoder := gob.NewEncoder(f)
encoder.Encode(*business)
return err
}
// Import Data from the flow
// Parameters:
// flows.Flow Output Stream
// Returns:
// error Any error that occurs during the computation or nil
func (business *__businessData) Import(f io.Reader) error {
var err error
defer func() {
itf := recover()
if itf != nil {
if errs.IsError(itf) {
err = itf.(error)
} else {
err = errors.New(fmt.Sprintf("%v", itf))
}
}
}()
decoder := gob.NewDecoder(f)
decoder.Decode(business)
return err
}
// Get the Map that describes the component fields/value
// Returns:
// logic.ValueMap Map that contains business object field names and values
func (business *__businessData) GetValuesMap() ValuesMap {
return ValuesMap(business.fieldsMap)
}
// Get the Key array
// Returns:
// logic.Keys business object field name array
func (business *__businessData) GetKeys() Keys {
var lst Keys = make(Keys, 0)
for k, _ := range business.fieldsMap {
// fmt.Println("GetKeys() - k:", k)
lst = append(lst, k)
}
return lst
}
func (business *__businessData) Size() int {
return len(business.GetKeys())
}
// Get the Business Object Type
// Returns:
// reflect.Type business object field type
func (business *__businessData) GetType() reflect.Type {
return business.objectType
}