Skip to content

Commit 39522db

Browse files
committed
Change signature in Adaptor:Import to put pInObject in first place.
1 parent a4b5bfc commit 39522db

5 files changed

Lines changed: 18 additions & 87 deletions

File tree

Serialization/OPNLib/Serialize/Adaptor.cls

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ Method Export(pMapTemplatesClass As %String = "", pMethodMap As %String = "", pI
2929

3030
return $$$NULLOREF
3131
}
32-
/// It imports the data from pInObject to the instance that is calling the method
33-
/// pInObject will be an object (%DynamicObject, %XML,...) with data to load to current object through the mechanism established by pMethodMap implemented in pMapTemplatesClass
34-
/// pMethodMap - Method chosen to import data. That method implements the logic to import data in this type of objects. Depending on the logic that data could come in different formats.
35-
/// By default, if no pMethodMap is indicated, it will use <b>importStd</b> that expects the import data in JSON format
36-
/// pMapTemplatesClass - Class in which it is the pMethodMap.
37-
/// This class could contain other methods to import/export data from this type of objects using different mechanisms and/or formats.
38-
/// By default, if no pMapTemplatesClass is indicated, and no pMethodMap, it'll be used <b>importStd</b>
39-
/// pDrillDown - Indicates the levels to follow the chain of references if the object include references to other objects, arrays/list of objects or relationships.
32+
/// It imports the data from <var>pInObject</var> to the instance that is calling the method
33+
/// <var>pInObject</var> will be an object (%DynamicObject, %XML,...) with data to load to current object through the mechanism established by pMethodMap implemented in pMapTemplatesClass
34+
/// <var>pDrillDown</var> - Indicates the levels to follow the chain of references if the object include references to other objects, arrays/list of objects or relationships.
4035
/// -1 (default): Apply DrillDown defined in the MAP for each property
4136
/// 0 : No drill down (but include OREF if EXPTINCLUDEORED=1 in the object class definition)
42-
/// pArgs - Included for flexibility.
37+
/// <var>pMapTemplatesClass</var> - Class in which it is the pMethodMap.
38+
/// This class could contain other methods to import/export data from this type of objects using different mechanisms and/or formats.
39+
/// By default, if no pMapTemplatesClass is indicated, and no pMethodMap, it'll be used <b>importStd</b>
40+
/// <var>pMethodMap</var> - Method chosen to import data. That method implements the logic to import data in this type of objects. Depending on the logic that data could come in different formats.
41+
/// By default, if no pMethodMap is indicated, it will use <b>importStd</b> that expects the import data in JSON format
42+
/// <var>pArgs</var> - Included for flexibility.
4343
/// - pArg(1) : <MAP to use> Used for export/import default mechanism. Includes the MAP name to use to export/import.
4444
/// If pArg(1) is null, it'll be used the default MAP (as defined in EXPTDEFAULTMAP parameter of object class definition)
45-
Method Import(pMapTemplatesClass As %String = "", pMethodMap As %String = "", pInObject As %RegisteredObject = "",pDrillDown as %Integer=-1,ByRef pArgs...) As %Status
45+
Method Import(pInObject As %RegisteredObject = "", pDrillDown as %Integer=-1, pMapTemplatesClass As %String = "", pMethodMap As %String = "", ByRef pArgs...) As %Status
4646
{
4747
#dim tSC as %Status=0
4848
#dim e as %Exception.General
Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
///Just an example. We could use whatever class to gather several methods to export/import data for one or several classes
2+
/// For example, an export/import method to/from JSON/CSV/XML,... that count on a set of several common properties (FirstName, LastName, DOB, ZIP)
3+
/// could be used for several classes
14
Class SampleApps.Serialize.CustomMaps
25
{
36

@@ -18,76 +21,4 @@ ClassMethod importTestJSON(ByRef pObject as %RegisteredObject,pInObject as %Regi
1821
}
1922
quit $$$OK
2023
}
21-
22-
ClassMethod ExpMapTestingCustomMAP1(ByRef pObject as SampleApps.Serialize.MapTesting,pInObject as %RegisteredObject,Output pOutputObject as %RegisteredObject, pDrillDown as %Integer=-1, pArgs...) as %RegisteredObject
23-
{
24-
#dim pOutputObject as %Library.DynamicObject
25-
26-
set tJSON = pObject.exportStd(pObject,,.pOutputObject,pDrillDown,"MAP1")
27-
28-
return tJSON
29-
30-
}
31-
32-
ClassMethod ImpMapTestingCustomMAP1(ByRef pObject as SampleApps.Serialize.MapTesting,pInObject as %DynamicObject, pDrillDown as %Integer=-1,pArgs...) as %Status
33-
{
34-
set tSC = pObject.importStd(.pObject,pInObject,pDrillDown,"MAP1")
35-
quit tSC
36-
}
37-
38-
/// Just an example.
39-
/// This method can be used with gral Export, to get data info in XML format within a stream (in this case using %XML.Adaptor functionality)
40-
ClassMethod ExpPersistObjectXML(ByRef pObject as SampleApps.Serialize.PersistObject,pInObject as %RegisteredObject,Output pOutputObject as %RegisteredObject, pDrillDown as %Integer=-1, pArgs...) as %RegisteredObject
41-
{
42-
set tXMLstream = ##class(%Stream.GlobalCharacter).%New()
43-
44-
if $IsObject(pObject) && (##class(%Dictionary.CompiledClass).%OpenId(pObject.%ClassName(1)).Super["%XML.Adaptor")
45-
{
46-
set %response.ContentType = "text/xml"
47-
set %response.CharSet = "utf-8"
48-
do pObject.XMLExportToStream(.tXMLstream)
49-
set pOutputObject = tXMLstream
50-
return tXMLstream
51-
}
52-
else
53-
{
54-
do tXMLstream.Write("<status>No input data or object class doesn't inherit from %XML.Adaptor</status>")
55-
set pOutputObject = tXMLstream
56-
}
57-
quit tXMLstream
58-
}
59-
60-
ClassMethod ImpPersistObjectXML(ByRef pObject as SampleApps.Serialize.PersistObject,pInObject as %Stream.GlobalCharacter, pDrillDown as %Integer=-1,pArgs...) as %Status
61-
{
62-
#dim tXMLreader as %XML.Reader
63-
#dim tSC as %Status=$$$OK
64-
#dim tObject as SampleApps.Serialize.PersistObject
65-
#dim e as %Exception.General
66-
67-
// We should populate incoming pObject with XML content.. Current logic based on XMLReader creates from scratch the objects which makes very difficult to use that logic
68-
// But we use it as it's an example
69-
try
70-
{
71-
set tXMLreader = ##class(%XML.Reader).%New()
72-
do tXMLreader.OpenStream(pInObject)
73-
do tXMLreader.Correlate("PersistObject","SampleApps.Serialize.PersistObject")
74-
do tXMLreader.Next(.tObject,.tSC)
75-
76-
set pObject.cod = tObject.cod
77-
set pObject.start = tObject.start
78-
set pObject.yearEnd = tObject.yearEnd
79-
set pObject.description = tObject.description
80-
set pObject.colours = tObject.colours
81-
if $IsObject(tObject.document) && (tObject.document.Size>0)
82-
{
83-
do pObject.document.CopyFrom(tObject.document)
84-
}
85-
}
86-
catch e
87-
{
88-
set tSC = e.AsStatus()
89-
}
90-
91-
quit tSC
92-
}
9324
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Class SampleApps.Serialize.MapTesting.generatedMAP1 Extends OPNLib.Serialize.Template
22
{
33
Parameter EXPTASSOCIATEDCLASS = "SampleApps.Serialize.MapTesting";
4-
Parameter EXPTMAP = "MAP0";
4+
Parameter EXPTMAP = "MAP1";
55
}

Serialization/SampleApps/Serialize/REST.cls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ ClassMethod IngestJSON(pClass as %String="",pDrillDownLevel as %Integer=-1,pMAP
165165
if (pClass'="")&&(tJSON.%Size()'=0)&&(##class(%Dictionary.CompiledClass).%OpenId(pClass).Super["OPNLib.Serialize.Adaptor")
166166
{
167167
set tObjRef = $classmethod(pClass,"%New")
168-
set:$IsObject(tObjRef) tSC = tObjRef.Import(,,tJSON,pDrillDownLevel,pMAP)
168+
set:$IsObject(tObjRef) tSC = tObjRef.Import(tJSON,pDrillDownLevel,,,pMAP)
169169
set tSC = tObjRef.%Save()
170170
set tNewID = tObjRef.%Id()
171171
write "{""newID"":"_tNewID_",""status"":"""_tSC_"""}"
@@ -192,7 +192,7 @@ ClassMethod UpdateJSON(pClass as %String="", pId as %String="") as %Status
192192
if (pClass'="")&&(pId'="")&&(tJSON.%Size()'=0)&&(##class(%Dictionary.CompiledClass).%OpenId(pClass).Super["OPNLib.Serialize.Adaptor")
193193
{
194194
set tObjRef = $classmethod(pClass,"%OpenId",pId)
195-
set:$IsObject(tObjRef) tSC = tObjRef.Import(,,tJSON,0)
195+
set:$IsObject(tObjRef) tSC = tObjRef.Import(tJSON,0)
196196
set tSC = tObjRef.%Save()
197197
write "{""ID"":"_pId_",""status"":"""_tSC_"""}"
198198
}
@@ -225,7 +225,7 @@ ClassMethod IngestSerialization(pTemplateClass as %String="",pImportMethod as %S
225225
set tObjRef = $classmethod(pClass,"%New")
226226
if $IsObject(tObjRef)
227227
{
228-
set tSC = tObjRef.Import(pTemplateClass,pImportMethod,%request.Content,pDrillDownLevel)
228+
set tSC = tObjRef.Import(%request.Content,pDrillDownLevel,pTemplateClass,pImportMethod)
229229
set:(tSC=1) tSC = tObjRef.%Save()
230230
set tNewID = tObjRef.%Id()
231231
write "{""newID"":"_tNewID_",""status"":"""_tSC_"""}"

Serialization/SampleApps/Serialize/TestMethods.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ClassMethod Test(pId as %Integer=50)
99
set tObj = m.Export(,,,,1)
1010

1111
set m2 = ##class(SampleApps.Serialize.MapTesting).%New()
12-
do m2.Import(,,tObj,1)
12+
do m2.Import(tObj,1)
1313
set tSC = m2.%Save()
1414

1515
write !,"Saving MapTesting ID: "_m2.%Id()

0 commit comments

Comments
 (0)