-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetActionAsText.js
More file actions
76 lines (65 loc) · 2.1 KB
/
getActionAsText.js
File metadata and controls
76 lines (65 loc) · 2.1 KB
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
// Begin ---------------------------------------------------------------
/**
* @function getActionAsText
*
* @param {string} in_moduleName - Module name which contains the action
* @param {string} in_actionName - Action name which contains the text
* @returns {string} actionAsText
*
* @author Stefan Schnell <mail@stefan-schnell.de>
* @license MIT
* @version 0.4.0
*
* @example
* var in_moduleName = "com.vmware.basic";
* var in_actionName = "createDirectory";
*
* @example
* var in_moduleName = "com.vmware.library.powershell.converter";
* var in_actionName = "getConverter";
*
* Checked with Aria Automation 8.12.0, 8.13.1, 8.14.0, 8.16.0 and 8.18.0
*/
var _getActionAsText = {
main : function(moduleName, actionName) {
var allActions =
System.getModule("com.vmware.library.action").getAllActions();
var allActionsInModule = allActions.filter( function(actionItems) {
return actionItems.module.name === moduleName;
});
if (allActionsInModule.length === 0) {
throw new Error("No actions were found in the module " +
moduleName + ".");
}
var action = allActionsInModule.filter( function(actionItem) {
return actionItem.name === actionName;
});
if (action.length === 0) {
throw new Error("The action " + actionName +
" was not found in the module " + moduleName + ".");
} else if (action.length > 1) {
System.warn("Too many actions, with the name " + actionName +
", were found in the module " + moduleName + ".");
action.forEach( function(actionItem) {
System.warn("ID: " + actionItem.id);
});
throw new Error("Too many actions, with the name " + actionName +
", were found in the module " + moduleName + ".");
}
return action[0].script;
}
};
if (
String(in_moduleName).trim() !== "" &&
String(in_actionName).trim() !== ""
) {
return _getActionAsText.main(
in_moduleName,
in_actionName
);
} else {
throw new Error(
"in_moduleName or in_actionName argument can not be null"
);
}
// End -----------------------------------------------------------------