-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Major clean-up of code #1
base: master
Are you sure you want to change the base?
Conversation
- Rename toJSON() to toJSONObject() - Code formatting and consistency changes - Refactor population utilities - General code cleanup
|
||
set tSC = $$$ADDSC(tSC,..CreateWidget("Waterproof Widget", 10.99, 10, "This widget is waterproof to a depth of 100m for up to 7 hours")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored the population tools to split up the object creation from the object definition, as well as adding better error handling and more formatting consistency.
WidgetsDirect/REST/Dispatch.cls
Outdated
set tSC = $$$OK | ||
set widgetAry = [] | ||
|
||
&SQL(DECLARE WidgetCursor CURSOR FOR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use more descriptive cursor names
- Check
SQLCODE
for errors - Avoid reuse of
Id
in both cursor loops - Handle errors from calls to
%OpenId()
WidgetsDirect/REST/Dispatch.cls
Outdated
QUIT tSC | ||
set retObj = {} | ||
|
||
if '##class(User.Widget).%ExistsId(WidgetId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Cleanly report case where the requested widget doesn't exist
- Cleanly handle cases where we fail to open a widget that does exist
WidgetsDirect/REST/Dispatch.cls
Outdated
|
||
set widgetClass = "User.Widget" | ||
set internalWidgetId = WidgetId | ||
if ($extract(WidgetId,1) = "W") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not changed this, but I think we should have a dedicated widgetType
property on the returned data.
WidgetsDirect/REST/Dispatch.cls
Outdated
SET retObj = {} | ||
set retObj = {} | ||
|
||
set widgetClass = "User.Widget" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Clean up widget class detection
- Cleanly handle widgets that don't exist
- Improve error handling for multiple issues
WidgetsDirect/REST/Dispatch.cls
Outdated
set retObj = {} | ||
set tSC = $$$OK | ||
|
||
if '##class(User.Widget).%ExistsId(WidgetId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Cleaner handling of widgets that don't exist
- Clean up formatting
- Clean up error handling
do widgetAry.%Push(widgetObj.toJSON(1)) | ||
} | ||
&SQL(CLOSE WidgetCurs) | ||
set %response.ContentType = "application/json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not clear why these methods are present here AND in the other class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an issue in InterSystems IRIS handling the map route to send all /widgets/... requests to the sub class. So they were moved back into the top Dispatch class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ocorrea7, might it make more sense to have shell methods rather than duplicating the actual code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A shell method in one of the classes that calls the class method in the other? Yeah, that's probably cleaner. Then add a comment saying this is temporary to support the current version of IRIS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ocorrea7, I added the shell methods in the base class and an XML comment to indicate that some versions of InterSystems Cache/IRIS have a bug that prevent the Map
from working as expected.
@@ -6,32 +6,34 @@ Class UnitTest.Transaction Extends UnitTest.Abstract | |||
Method OnBeforeAllTests() As %Status | |||
{ | |||
tstart | |||
if ..Manager.Debug set %debug=1 | |||
if ..Manager.Debug { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code formatting
WidgetsDirect/User/WWWidget.cls
Outdated
@@ -14,7 +14,7 @@ Property Barcode As %String; | |||
|
|||
Property Location As %String; | |||
|
|||
Method toJSON(traverseRelationships As %Boolean = 0) As %String | |||
Method toJSONObject(traverseRelationships As %Boolean = 0) As %Library.DynamicObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change method name and signature to capture what this method is actually doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think calling this "toDynamicObject" (here and elsewhere) might be clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -29,27 +29,25 @@ Method toJSON(traverseRelationships As %Boolean = 0) As %String | |||
quit jsonReturn | |||
} | |||
|
|||
Method fromJSON(json As %String) As %String | |||
Method fromJSON(json As %String) As %Status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Fix method signature to indicate what we were returning
- Use classmethod directly instead of {}.%FromJSON()
WidgetsDirect/User/Widget.cls
Outdated
@@ -14,7 +14,7 @@ Property Deleted as %Boolean; | |||
|
|||
Relationship Accessories As User.WidgetAccessoryLink [ Cardinality = many, Inverse = Widget ]; | |||
|
|||
Method toJSON(traverseRelationships As %Boolean = 0) As %String | |||
Method toJSONObject(traverseRelationships As %Boolean = 0) As %Library.DynamicObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Fix method name/signature
- Clean up code and make it clearer
} | ||
|
||
quit jsonReturn | ||
} | ||
|
||
Method fromJSON(json As %String) As %String | ||
Method fromJSON(json As %String) As %Status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Fix method signature
- Avoid classmethod call on instance
- Clean up formatting
@@ -20,7 +20,7 @@ Property SKU As %String; | |||
|
|||
Relationship Widgets As User.WidgetAccessoryLink [ Cardinality = many, Inverse = Accessory ]; | |||
|
|||
Method toJSON(traverseRelationships As %Boolean = 0) As %String | |||
Method toJSONObject(traverseRelationships As %Boolean = 0) As %Library.DynamicObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Change name/method signature
- Code cleanup
@@ -2,7 +2,7 @@ | |||
Class Util.Build { | |||
|
|||
/// This is a build manifest. Here we describe build steps in XML format. | |||
XData BuildManifest | |||
XData BuildManifest [ XMLNamespace = INSTALLER ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor code cleanup/formatting
I've added method-level comments as to what I did for each class. |
WidgetsDirect/REST/Dispatch.cls
Outdated
} | ||
do widgetAry.%Push(widgetObj.toJSONObject(1)) | ||
} | ||
if (SQLCODE && (SQLCODE '= 100)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if (SQLCODE < 0) would be clearer (here and elsewhere)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
WidgetsDirect/User/WWWidget.cls
Outdated
@@ -14,7 +14,7 @@ Property Barcode As %String; | |||
|
|||
Property Location As %String; | |||
|
|||
Method toJSON(traverseRelationships As %Boolean = 0) As %String | |||
Method toJSONObject(traverseRelationships As %Boolean = 0) As %Library.DynamicObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think calling this "toDynamicObject" (here and elsewhere) might be clearer.
@@ -29,27 +29,25 @@ Method toJSON(traverseRelationships As %Boolean = 0) As %String | |||
quit jsonReturn | |||
} | |||
|
|||
Method fromJSON(json As %String) As %String | |||
Method fromJSON(json As %String) As %Status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps highlight that json could also be a stream (because %FromJSON supports that - this would be handy in some of the REST APIs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current REST code is reading from the incoming content stream, so I've left that aspect of the code in place.
WidgetsDirect/REST/Dispatch.cls
Outdated
@@ -4,184 +4,221 @@ Class REST.Dispatch Extends %CSP.REST | |||
|
|||
XData UrlMap [ XMLNamespace = "http://www.widgetsdirect.com/urlmap" ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be the standard UrlMap XML namespace, http://www.intersystems.com/urlmap (here and elsewhere) - with that in place Studio will suggest the right elements/attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
- Whitespace cleanup - Fix some typos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for cleaning things up
toJSON()
totoDynamicObject()