hmx_client 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,45 +1,45 @@
1
- require "hmx/command/base"
2
- require 'date'
3
-
4
- module HmxClient::Command
5
-
6
- # Display and manage type information in hmx
7
- #
8
- class Type < Base
9
-
10
- # type
11
- #
12
- # Display information about a HMX type
13
- def index
14
- puts JSON.pretty_generate(hmx.getType(args.shift))
15
- end
16
-
17
- # type:create
18
- #
19
- # Create a type with default settings - no triggers, no entitlements
20
- def create
21
- typeInfo = { "name" => args.shift, "triggers" => [], "typeNature" => "CONTENT", "typeIndexScript" => "", "typeAspect" => "JSONDOCUMENT" }
22
- hmx.updateType(typeInfo)
23
- puts "Done..."
24
- end
25
-
26
- # type:clone-ent
27
- #
28
- # Clone the entitlements from one type to another
29
- #
30
- # <srcType> <targType>
31
- def clone
32
- # We basically load the documents for sys.ent/type/[source]/query and sys.ent/type/[source]/query and copy them to the target
33
- sourceType = args.shift
34
- targetType = args.shift
35
- arr = JSON.parse(hmx.getContent(["sys.ent/type/#{ sourceType }/get"]))
36
- arr["MXEntitlement"]["entitlementPath"] = "type/#{ targetType }/get"
37
- hmx.putSimpleData([ "sys.ent/type/#{ targetType}/get", JSON.generate(arr)])
38
-
39
- arr = JSON.parse(hmx.getContent(["sys.ent/type/#{ sourceType }/query"]))
40
- arr["MXEntitlement"]["entitlementPath"] = "type/#{ targetType }/query"
41
- hmx.putSimpleData([ "sys.ent/type/#{ targetType}/query", JSON.generate(arr)])
42
- puts "Done..."
43
- end
44
- end
45
- end
1
+ require "hmx/command/base"
2
+ require 'date'
3
+
4
+ module HmxClient::Command
5
+
6
+ # Display and manage type information in hmx
7
+ #
8
+ class Type < Base
9
+
10
+ # type
11
+ #
12
+ # Display information about a HMX type
13
+ def index
14
+ puts JSON.pretty_generate(hmx.doGetType(args))
15
+ end
16
+
17
+ # type:create
18
+ #
19
+ # Create a type with default settings - no triggers, no entitlements
20
+ def create
21
+ typeInfo = { "name" => args.shift, "triggers" => [], "typeNature" => "CONTENT", "typeIndexScript" => "" }
22
+ hmx.doUpdateType([typeInfo])
23
+ puts "Done..."
24
+ end
25
+
26
+ # type:clone-ent
27
+ #
28
+ # Clone the entitlements from one type to another
29
+ #
30
+ # <srcType> <targType>
31
+ def clone
32
+ # We basically load the documents for sys.ent/type/[source]/query and sys.ent/type/[source]/query and copy them to the target
33
+ sourceType = args.shift
34
+ targetType = args.shift
35
+ arr = JSON.parse(hmx.doGetContent(["sys.ent/type/#{ sourceType }/get"]))
36
+ arr["MXEntitlement"]["entitlementPath"] = "type/#{ targetType }/get"
37
+ hmx.doPutSimpleData([ "sys.ent/type/#{ targetType}/get", JSON.generate(arr)])
38
+
39
+ arr = JSON.parse(hmx.doGetContent(["sys.ent/type/#{ sourceType }/query"]))
40
+ arr["MXEntitlement"]["entitlementPath"] = "type/#{ targetType }/query"
41
+ hmx.doPutSimpleData([ "sys.ent/type/#{ targetType}/query", JSON.generate(arr)])
42
+ puts "Done..."
43
+ end
44
+ end
45
+ end
@@ -1,68 +1,68 @@
1
- require "hmx/command/base"
2
-
3
- module HmxClient::Command
4
-
5
- # Manipulate user entities in hmx
6
- #
7
- class User < Base
8
-
9
- # user
10
- #
11
- # manipulate user enties in hMX
12
- #
13
- #
14
- def index
15
- unless args.size > 0
16
- raise CommandFailed, "Usage: hmx user <userId>"
17
- end
18
- userName = args.shift
19
- dout JSON.pretty_generate(hmx.getData(["sys.user/#{userName}"]))
20
- end
21
-
22
- # user:list
23
- #
24
- # Lists all of the users in the system
25
-
26
- def list
27
- views = hmx.query("sys.user", nil)
28
- views.each { | v |
29
- display v.rpartition('/')[2]
30
- }
31
- end
32
-
33
- # user:get
34
- #
35
- # Retrieves the definition of a user
36
- #
37
- def get
38
- index
39
- end
40
-
41
- # user:password
42
- #
43
- # Sets the password for a user
44
- #
45
- def password
46
- unless args.size > 1
47
- raise CommandFailed, "Usage: hmx user:password <userId> <newPassword>"
48
- end
49
- user = args.shift
50
- userName = "sys.user/#{user}"
51
- password = Digest::MD5.hexdigest(args.shift)
52
- dataDocument = hmx.getData([userName])
53
- dataDocument['document']['MXUser']['hashPassword'] = password
54
- display hmx.putData([JSON.generate(dataDocument)])
55
- end
56
-
57
- # user:delete
58
- #
59
- # Removes a user
60
- #
61
- def delete
62
- # We also need to remove the user reference from any groups they belong to (sys.entgroup)
63
- # We should be clever and use a custom view for that purpose
64
- # something like
65
- # (fn[param] (fn[x] (contains (param "user" (.get x '(:document :MXEntitlementGroup :users ))))))
66
- end
67
- end
68
- end
1
+ require "hmx/command/base"
2
+
3
+ module HmxClient::Command
4
+
5
+ # Manipulate user entities in hmx
6
+ #
7
+ class User < Base
8
+
9
+ # user
10
+ #
11
+ # manipulate user enties in hMX
12
+ #
13
+ #
14
+ def index
15
+ unless args.size > 0
16
+ raise CommandFailed, "Usage: hmx user <userId>"
17
+ end
18
+ userName = args.shift
19
+ dout JSON.pretty_generate(hmx.doGetData(["sys.user/#{userName}"]))
20
+ end
21
+
22
+ # user:list
23
+ #
24
+ # Lists all of the users in the system
25
+
26
+ def list
27
+ views = hmx.doQuery(["sys.user", nil])
28
+ views.each { | v |
29
+ display v.rpartition('/')[2]
30
+ }
31
+ end
32
+
33
+ # user:get
34
+ #
35
+ # Retrieves the definition of a user
36
+ #
37
+ def get
38
+ index
39
+ end
40
+
41
+ # user:password
42
+ #
43
+ # Sets the password for a user
44
+ #
45
+ def password
46
+ unless args.size > 1
47
+ raise CommandFailed, "Usage: hmx user:password <userId> <newPassword>"
48
+ end
49
+ user = args.shift
50
+ userName = "sys.user/#{user}"
51
+ password = Digest::MD5.hexdigest(args.shift)
52
+ dataDocument = hmx.doGetData([userName])
53
+ dataDocument['document']['MXUser']['hashPassword'] = password
54
+ display hmx.doPutData([JSON.generate(dataDocument)])
55
+ end
56
+
57
+ # user:delete
58
+ #
59
+ # Removes a user
60
+ #
61
+ def delete
62
+ # We also need to remove the user reference from any groups they belong to (sys.entgroup)
63
+ # We should be clever and use a custom view for that purpose
64
+ # something like
65
+ # (fn[param] (fn[x] (contains (param "user" (.get x '(:document :MXEntitlementGroup :users ))))))
66
+ end
67
+ end
68
+ end
@@ -1,155 +1,161 @@
1
- require "hmx/command/base"
2
-
3
- module HmxClient::Command
4
-
5
- # Display the results of a view and list all views
6
- #
7
- class View < Base
8
-
9
- # view
10
- #
11
- # run a view in hmx, passing in a view name and an input to the filter function
12
- #
13
- #
14
- def index
15
- unless args.size > 0
16
- raise CommandFailed, "Usage: hmx view <viewName> <filterContext>"
17
- end
18
- viewData = hmx.runView(args.shift, JSON.parse(args.shift))
19
- resp = ''
20
- viewData.each { | line |
21
- line.each { | cell | resp = resp + "%20.20s\t" % cell }
22
- resp = resp + "\n"
23
- }
24
- dout resp
25
- end
26
-
27
- # view:list
28
- #
29
- # Lists all of the views in the system
30
-
31
- def list
32
- views = hmx.query("sys.view", nil)
33
- views.each { | v |
34
- display v.rpartition('/')[2]
35
- }
36
- end
37
-
38
- # view:get
39
- #
40
- # Retrieves the definition of a view
41
- #
42
- def get
43
- unless args.size > 0
44
- raise CommandFailed, "Usage: hmx view:get <viewName>"
45
- end
46
- typeName = "sys.view/#{args.shift}"
47
- display "Retrieving #{ typeName }"
48
- dout JSON.pretty_generate(hmx.getData([typeName]))
49
- end
50
-
51
- # view:create
52
- #
53
- # Create a new (initially blank) view.
54
- # You will then need to call update to set the filter function, map function, query params and
55
- # result columns.
56
- #
57
- # Views are based on types, for create define a name and the type
58
- def create
59
- unless args.size > 1
60
- raise CommanFailed, "Usage: hmx view:create <viewName> <typeName>"
61
- end
62
- view = args.shift
63
- viewName = "sys.view/#{view}"
64
- typeName = args.shift
65
-
66
- dataDocument = {
67
- "MXView" => {
68
- :typeName => typeName,
69
- :parameterNames => [],
70
- :filterFn => "",
71
- :mappingFn => "",
72
- :resultColumns => [],
73
- :viewName => view
74
- }
75
- }
76
-
77
- dout JSON.pretty_generate(hmx.putSimpleData([viewName, JSON.generate(dataDocument)]))
78
- end
79
-
80
- # view:updateFilter
81
- #
82
- # Set the filter function for a view
83
- #
84
- def updateFilter
85
- unless args.size > 1
86
- raise CommandFailed, "Usage: hmx view:updateFilter <viewName> <filterFn>"
87
- end
88
- view = args.shift
89
- viewName = "sys.view/#{view}"
90
- filterFn = args.shift
91
-
92
- dataDocument = hmx.getData([viewName])
93
- puts dataDocument
94
- dataDocument['document']['MXView']['filterFn'] = filterFn
95
- display hmx.putData([JSON.generate(dataDocument)])
96
- end
97
- # view:updateMap
98
- #
99
- # Set the map function for a view
100
- #
101
- def updateMap
102
- unless args.size > 1
103
- raise CommandFailed, "Usage: hmx view:updateMap <viewName> <filterFn>"
104
- end
105
- view = args.shift
106
- viewName = "sys.view/#{view}"
107
- mapFn = args.shift
108
- dataDocument = hmx.getData([viewName])
109
- dataDocument['document']['MXView']['mappingFn'] = mapFn
110
- display hmx.putData([JSON.generate(dataDocument)])
111
- end
112
- # view:updateParam
113
- #
114
- # Set the parameter names for a view
115
- #
116
- def updateParam
117
- unless args.size > 1
118
- raise CommandFailed, "Usage: hmx view:updateParam <viewName> <param> [<param2> ...]"
119
- end
120
- view = args.shift
121
- viewName = "sys.view/#{view}"
122
- dataDocument = hmx.getData([viewName])
123
- dataDocument['document']['MXView']['parameterNames'] = args
124
- display hmx.putData([JSON.generate(dataDocument)])
125
- end
126
- # view:updateResult
127
- #
128
- # Set the result names for a view
129
- #
130
- def updateResult
131
- unless args.size > 1
132
- raise CommandFailed, "Usage: hmx view:updateResult <viewName> <param> [<param2> ...]"
133
- end
134
- view = args.shift
135
- viewName = "sys.view/#{view}"
136
-
137
- dataDocument = hmx.getData([viewName])
138
- dataDocument['document']['MXView']['resultColumns'] = args
139
- display hmx.putData([JSON.generate(dataDocument)])
140
- end
141
- # view:delete
142
- #
143
- # Delete a view definition
144
- #
145
- def delete
146
- unless args.size >0
147
- raise CommandFailed, "Usage: hmx view:delete <viewName>"
148
- end
149
- view = args.shift
150
- viewName = "sys.view/#{view}"
151
- display hmx.deleteData(viewName)
152
- end
153
-
154
- end
155
- end
1
+ require "hmx/command/base"
2
+
3
+ module HmxClient::Command
4
+
5
+ # Display the results of a view and list all views
6
+ #
7
+ class View < Base
8
+
9
+ # view
10
+ #
11
+ # run a view in hmx, passing in a view name and an input to the filter function
12
+ #
13
+ #
14
+ def index
15
+ unless args.size > 0
16
+ raise CommandFailed, "Usage: hmx view <viewName> <filterContext>"
17
+ end
18
+ viewData = hmx.doRunView([args.shift, JSON.parse(args.shift)])
19
+ resp = ''
20
+ viewData.each { | line |
21
+ line.each { | cell |
22
+ if (cell.is_a? Array)
23
+ cell.each { | inner | resp = resp + "%20.20s\t" % inner }
24
+ else
25
+ resp = resp + "%20.20s\t" % cell
26
+ end
27
+ }
28
+ resp = resp + "\n"
29
+ }
30
+ dout resp
31
+ end
32
+
33
+ # view:list
34
+ #
35
+ # Lists all of the views in the system
36
+
37
+ def list
38
+ views = hmx.doQuery(["sys.view", nil])
39
+ views.each { | v |
40
+ display v.rpartition('/')[2]
41
+ }
42
+ end
43
+
44
+ # view:get
45
+ #
46
+ # Retrieves the definition of a view
47
+ #
48
+ def get
49
+ unless args.size > 0
50
+ raise CommandFailed, "Usage: hmx view:get <viewName>"
51
+ end
52
+ typeName = "sys.view/#{args.shift}"
53
+ display "Retrieving #{ typeName }"
54
+ dout JSON.pretty_generate(hmx.doGetData([typeName]))
55
+ end
56
+
57
+ # view:create
58
+ #
59
+ # Create a new (initially blank) view.
60
+ # You will then need to call update to set the filter function, map function, query params and
61
+ # result columns.
62
+ #
63
+ # Views are based on types, for create define a name and the type
64
+ def create
65
+ unless args.size > 1
66
+ raise CommanFailed, "Usage: hmx view:create <viewName> <typeName>"
67
+ end
68
+ view = args.shift
69
+ viewName = "sys.view/#{view}"
70
+ typeName = args.shift
71
+
72
+ dataDocument = {
73
+ "MXView" => {
74
+ :typeName => typeName,
75
+ :parameterNames => [],
76
+ :filterFn => "",
77
+ :mappingFn => "",
78
+ :resultColumns => [],
79
+ :viewName => view
80
+ }
81
+ }
82
+
83
+ dout JSON.pretty_generate(hmx.doPutSimpleData([viewName, JSON.generate(dataDocument)]))
84
+ end
85
+
86
+ # view:updateFilter
87
+ #
88
+ # Set the filter function for a view
89
+ #
90
+ def updateFilter
91
+ unless args.size > 1
92
+ raise CommandFailed, "Usage: hmx view:updateFilter <viewName> <filterFn>"
93
+ end
94
+ view = args.shift
95
+ viewName = "sys.view/#{view}"
96
+ filterFn = args.shift
97
+
98
+ dataDocument = hmx.doGetData([viewName])
99
+ puts dataDocument
100
+ dataDocument['document']['MXView']['filterFn'] = filterFn
101
+ display hmx.doPutData([JSON.generate(dataDocument)])
102
+ end
103
+ # view:updateMap
104
+ #
105
+ # Set the map function for a view
106
+ #
107
+ def updateMap
108
+ unless args.size > 1
109
+ raise CommandFailed, "Usage: hmx view:updateMap <viewName> <filterFn>"
110
+ end
111
+ view = args.shift
112
+ viewName = "sys.view/#{view}"
113
+ mapFn = args.shift
114
+ dataDocument = hmx.doGetData([viewName])
115
+ dataDocument['document']['MXView']['mappingFn'] = mapFn
116
+ display hmx.doPutData([JSON.generate(dataDocument)])
117
+ end
118
+ # view:updateParam
119
+ #
120
+ # Set the parameter names for a view
121
+ #
122
+ def updateParam
123
+ unless args.size > 1
124
+ raise CommandFailed, "Usage: hmx view:updateParam <viewName> <param> [<param2> ...]"
125
+ end
126
+ view = args.shift
127
+ viewName = "sys.view/#{view}"
128
+ dataDocument = hmx.doGetData([viewName])
129
+ dataDocument['document']['MXView']['parameterNames'] = args
130
+ display hmx.doPutData([JSON.generate(dataDocument)])
131
+ end
132
+ # view:updateResult
133
+ #
134
+ # Set the result names for a view
135
+ #
136
+ def updateResult
137
+ unless args.size > 1
138
+ raise CommandFailed, "Usage: hmx view:updateResult <viewName> <param> [<param2> ...]"
139
+ end
140
+ view = args.shift
141
+ viewName = "sys.view/#{view}"
142
+
143
+ dataDocument = hmx.doGetData([viewName])
144
+ dataDocument['document']['MXView']['resultColumns'] = args
145
+ display hmx.doPutData([JSON.generate(dataDocument)])
146
+ end
147
+ # view:delete
148
+ #
149
+ # Delete a view definition
150
+ #
151
+ def delete
152
+ unless args.size >0
153
+ raise CommandFailed, "Usage: hmx view:delete <viewName>"
154
+ end
155
+ view = args.shift
156
+ viewName = "sys.view/#{view}"
157
+ display hmx.doDeleteData([viewName])
158
+ end
159
+
160
+ end
161
+ end