Skip to content

Commit cc83389

Browse files
committed
Enhance _Common class by excluding additional properties from member listing and add new method for configuration initialization in Common.cls
1 parent 9dedc5c commit cc83389

File tree

5 files changed

+71
-4
lines changed

5 files changed

+71
-4
lines changed

src/iop/_common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ def _get_properties(cls) -> List[List[Any]]:
148148
if not member[0].startswith('_'):
149149
# remove other methods and functions
150150
if not inspect.ismethod(member[1]) and not inspect.isfunction(member[1]) and not inspect.isclass(member[1]):
151-
if member[0] not in ('INFO_URL','ICON_URL','PERSISTENT_PROPERTY_LIST') :
151+
if member[0] not in ('INFO_URL','ICON_URL','PERSISTENT_PROPERTY_LIST'
152+
,'log_to_console','logger','iris_handle'
153+
,'DISPATCH','adapter','Adapter','buffer'):
152154
name = member[0]
153155
req = 0
154156
cat = "Additional"

src/iop/cls/IOP/Common.cls

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ Property %settings As %String(MAXLEN = "");
1919
/// Instance of class
2020
Property %class As %SYS.Python;
2121

22+
Method %OnNew(pConfigName As %String) As %Status
23+
{
24+
set tSC = $$$OK
25+
try {
26+
$$$ThrowOnError(..Connect())
27+
$$$ThrowOnError($method($this,"initConfig",.pConfigName)) ; call subclass
28+
} catch ex {
29+
set tSC = ex.AsStatus()
30+
}
31+
quit tSC
32+
}
33+
2234
/// Get Class
2335
Method GetClass() As %SYS.Python
2436
{
@@ -41,7 +53,6 @@ Method OnInit() As %Status
4153
{
4254
set tSC = $$$OK
4355
try {
44-
$$$ThrowOnError(..Connect())
4556
do ..%class."_dispatch_on_init"($this)
4657
} catch ex {
4758
set tSC = ex.AsStatus()
@@ -199,7 +210,6 @@ ClassMethod OnGetConnections(
199210
Catch ex {
200211
}
201212

202-
203213
// Get settings
204214
do pItem.GetModifiedSetting("%classpaths", .tClasspaths)
205215
do pItem.GetModifiedSetting("%classname", .tClassname)

src/iop/cls/IOP/Utils.cls

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,54 @@ ClassMethod GenerateProxyClass(
275275
set:($Case(tSuperClass,"IOP.InboundAdapter":1,"IOP.OutboundAdapter":1,:0)) type = "Adapter"
276276
set tSETTINGSParamValue = $REPLACE(tSETTINGSParamValue,"$type",type)
277277

278+
#dim tCustomProp As %Dictionary.PropertyDefinition
279+
#dim tPropInfo,tPropName,tDataType,tDefault,tDesc,tPropCat,tContext As %String
280+
281+
set builtins = ##class(%SYS.Python).Import("builtins")
282+
#; each remote setting is of form $lb(propName,dataType,defaultVal,required,category,description,editorContext)
283+
For i=0:1:builtins.len(pRemoteSettings)-1 {
284+
Set tPropInfo = pRemoteSettings."__getitem__"(i)
285+
Continue:""=tPropInfo ; this shouldn't happen, but just in case
286+
Set tPropName = tPropInfo."__getitem__"(0)
287+
Set tDataType = tPropInfo."__getitem__"(1)
288+
If (""=tPropName) || (""=tDataType) {
289+
Set tSC = $$$ERROR($$$EnsErrGeneral,"All properties must have a name and datatype defined")
290+
Quit
291+
}
292+
Set tCustomProp = ##class(%Dictionary.PropertyDefinition).%New()
293+
Set tCustomProp.Name = tPropName
294+
If $Case(tDataType,"String":1,"Integer":1,"Boolean":1,"Numeric":1,:0) {
295+
Set tDataType = "%"_tDataType
296+
} ElseIf '##class(%Dictionary.ClassDefinition).%ExistsId(tDataType) {
297+
Set tDataType = "%String"
298+
}
299+
Set tCustomProp.Type = tDataType
300+
If tDataType["%String" {
301+
Set tSC = tCustomProp.Parameters.SetAt("255","MAXLEN")
302+
Quit:$$$ISERR(tSC)
303+
}
304+
Set tDefault = tPropInfo."__getitem__"(2)
305+
If ""'=tDefault {
306+
Set tCustomProp.InitialExpression = $$$quote(tDefault)
307+
}
308+
Set tCustomProp.Required = tPropInfo."__getitem__"(3)
309+
310+
Set tSC = tCOSClass.Properties.Insert(tCustomProp)
311+
Quit:$$$ISERR(tSC)
312+
313+
#dim tMethod As %Dictionary.MethodDefinition = ##class(%Dictionary.MethodDefinition).%New()
314+
Set tMethod.Name = tPropName_"Set"
315+
Set tMethod.ReturnType = "%Status"
316+
Set tMethod.FormalSpec = "value:"_tDataType
317+
Do tMethod.Implementation.WriteLine(" Set ..%class."""_tPropName_""" = value")
318+
Do tMethod.Implementation.WriteLine(" Quit $$$OK")
319+
Set tSC = tCOSClass.Methods.Insert(tMethod)
320+
321+
Set tPropCat = "Python Attributes"
322+
Set tSETTINGSParamValue = tSETTINGSParamValue_","_tPropName_":"_tPropCat
323+
}
324+
Quit:$$$ISERR(tSC)
325+
278326
#dim tSETTINGSParam As %Dictionary.ParameterDefinition = ##class(%Dictionary.ParameterDefinition).%New()
279327
Set tSETTINGSParam.Name = "SETTINGS"
280328
Set tSETTINGSParam.Default = tSETTINGSParamValue

src/tests/registerFilesIop/bo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@ def OnMessage(self, pRequest):
128128

129129
class MyOperation(BusinessOperation):
130130

131+
my_empty_var : str
132+
my_none_var = None
133+
my_int_var :int = 0
134+
my_float_var : float = 0.0
135+
my_untyped_var = 0
136+
my_str_var = "foo"
137+
131138
def OnMessage(self, request):
132139
self.LOGINFO('hello')
133140
return MyResponse(request.StringValue)

src/tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_setup_succeeds(self):
3333
class TestComponentRegistration:
3434
@pytest.mark.parametrize("module,classname,iris_classname", [
3535
('bo', 'EmailOperation', 'UnitTest.EmailOperation'),
36-
# Add more test cases here
36+
('bo', 'MyOperation', 'UnitTest.MyOperation'),
3737
])
3838
def test_register_component(self, register_path, module, classname, iris_classname):
3939
_Utils.register_component(

0 commit comments

Comments
 (0)