Eduard Lebedyuk · Dec 21, 2017 go to post

Replacing "" with null seems like a better solution to me as " symbol is escaped to \", so "" should not be encountered in JSON, except for empty strings.

Eduard Lebedyuk · Dec 21, 2017 go to post

It seems to fail on second line of this code sample:

set prevspace="^"_$zu(96,12)
u 0::"^%X364"    ; Set mnemonic space
u 0::prevspace
Eduard Lebedyuk · Dec 21, 2017 go to post

Additional JSON functionality, such as JSON (de)serialization for arbitrary classes was at one point available but currently under review. It may appear in one of future versions. I've posted a workaround.

You can also check RESTForms - REST API  for your persistent classes, it does support JSON (de)serialization. Another article about RESTForms.

Eduard Lebedyuk · Dec 21, 2017 go to post

You can convert object to dynamic object and output it to JSON:

zn "samples"
set per = ##class(Sample.Person).%OpenId(1)
set obj = ##class(%ZEN.Auxiliary.altJSONProvider).%ObjectToAET(per)
write obj.%ToJSON()

Also check %ObjectToJSON in %ZEN.Auxiliary.altJSONProvider class.

Eduard Lebedyuk · Dec 20, 2017 go to post

1. There's no need to instantiate tResponse, it would be reinstantiated later anyway.

2. Please post ConsultaPaciente method from your class specified in WebServiceClientClass setting.

Eduard Lebedyuk · Dec 20, 2017 go to post

2016.2 supports Atelier, so you need to either install new 2016.2 instance or update to 2016.2.

Install atelier by following these instructions.

UPD. Sandbox means you only need sample data? You can install new 2016.2 instance. It takes 10 minutes tops.

Eduard Lebedyuk · Dec 20, 2017 go to post

Another example - lets say you want to delete several files and check that all is fine:

ClassMethod MassDelete()
{
  #dim sc As %Status = $$$OK

  // Deletes the file. Returns true if it succeeds and false otherwise.
  // Pass return by reference to obtain the low level return value in case of errors
  #define del(%file,%return) ##class(%File).Delete(%file,%return)

  set file1 = "file1.txt"
  set file2 = "file2.txt"
  if (('$$$del(file1, .return1)) | ('$$$del(file2, .return2))) {
    set sc = $$$ERROR($$$GeneralError, "Files '%1', '%2' deletion failed with codes: %3, %4", file1, file2, $get(return1), $get(return2))
  }
  quit sc
}

In case of "||" if the first delete was successful , the second delete would not be called. Use '|' to attempt both deletes 

Eduard Lebedyuk · Dec 20, 2017 go to post

Can you show us your code?

To use XML reader you need to call Correlate method, which correlates any specified XML element to class.

Eduard Lebedyuk · Dec 15, 2017 go to post

This assures that all expressions are valid.

More importantly this assures that all expressions were executed.

Eduard Lebedyuk · Dec 15, 2017 go to post

You shouldn't create TestCsv.Csv class. CSVTOCLASS method would create the class you specified as a last argument automatically. After that you need to open  that new class, it would have an Import method. Call it with your file to actually import data.

Eduard Lebedyuk · Dec 14, 2017 go to post

Generally it goes like this:

<scope>
Do stuff, maybe throw exceptions (or just set status variable to error status)
<faulthandlers>
<catchall>
Process errors. context.%LastError contains your error
</catchall>
</faulthandlers>
</scope>

Check docs for these elements, there are several examples available:

Also, check EnsLib.ebXML.Process.MessageSender for example.

Eduard Lebedyuk · Dec 14, 2017 go to post

Try

set rowtype = "Code VARCHAR(2),Name VARCHAR(9)"
set filename = "c:\temp\Country.csv" 
do ##class(%SQL.Util.Procedures).CSVTOCLASS(2, .rowtype, filename,,,,"Test.CSV")

And check new Test.CSV class for import methods.

Eduard Lebedyuk · Dec 12, 2017 go to post

You have compilation error(s). That's why one or more methods are not generated, so instead methods in Ens.BusinessOperation gets called. These methods are returning not implemented error.

To start with 

 Extends (Ens.BusinessOperation, )

should be:

 Extends Ens.BusinessOperation

You can check which exact method has not been generated in Ensemble Event Log.

UPD. [@Rajiv Bhatia] solution is correct, my bad. Should have read your code.

Eduard Lebedyuk · Dec 12, 2017 go to post

 I feel the whole approach violates the statelessness of a REST architecture?

The request itself is stateless. For example session tracking is okay within REST despite the fact that session exists between requests. Here's how I understand violation of REST statelessness: let's say you have a newsfeed API /news and you return news in chunks of 20 elements. Users are authenticated.

REST way:

  • GET /news/1 - returns first 20 elements
  • GET /news/2 - returns elements 21-40
  • etc.

Not a REST way:

  • GET /news/next - returns first 20 elements
  • GET /news/next - returns elements 21-40
  • etc.

Now, the second approach violates REST principles because request itself - /news/next does not contain enough information to process it. Server should track how much pages each client received, and which page to return next.

To sum up: statelessness in REST means that request itself is enough to determine what do we need to do  with it and request does not require pulling any additional information about previous requests from the same client.

Eduard Lebedyuk · Dec 12, 2017 go to post

I did not test this approach, but something along these lines can help. The general idea is that SAX parser can validate against the XML schema, and we can use that.

1. Generate schema from your XML enabled classes.

2. Call %XML.Reader:Open method, and provide it with your xml data and schema:

#include %occSAX
set reader = ##class(%XML.Reader).%New()
set reader.SAXSchemaSpec = "/path/to/schema.xsd" // "maybe "file:///path/to/schema.xsd"
set reader.SAXFlags = $$$SAXFULLDEFAULT
set sc = reader.OpenString("<xml/>")
w $System.Status.GetErrorText(sc)


3. sc should contain errors, $$$SAXFULLDEFAULT is defined in %occSAX and contains several possible values:

#; ------------------------------------------------------------------------
#; Bit flags for %XML.SAX.Parser feature selection (flags argument)
#; ------------------------------------------------------------------------
 
#; Specify this value if you want to accept the SAX defaults (see below)
#;
#define SAXDEFAULTS 27
 
#; Specify this value if you want the SAX defaults plus namespaces prefixes/
#define SAXFULLDEFAULT 95
 
#;
#; Specify this bit if you want the parser to perform validation
 
#; http://xml.org/sax/features/validation 
#; On: Report all validation errors. (default) 
#; Off: Do not report validation errors. 
 
#define SAXVALIDATION 1
 
#;
#; Specify this bit if you want the parser to recognize namespaces
 
#; http://xml.org/sax/features/namespaces 
#; On: Perform Namespace processing (default) 
#; Off: Optionally do not perform Namespace processing 
 
#define SAXNAMESPACES 2
 
#;
#; Specify this bit if you want the parser to process namespace prefixes
 
#; http://xml.org/sax/features/namespace-prefixes 
#; On: Report the original prefixed names and attributes used for Namespace declarations 
#; Off: Do not report attributes used for Namespace declarations, and optionally do not report original prefixed names (default)
 
#define SAXNAMESPACEPREFIXES 4
 
#;
#; Specify this bit if you want the parser to perform validation dynamically
 
#; http://apache.org/xml/features/validation/dynamic 
#; On: The parser will validate the document only if a grammar is specified. (http://xml.org/sax/features/validation must be true) (default)
#; Off: Validation is determined by the state of the http://xml.org/sax/features/validation feature
 
#define SAXVALIDATIONDYNAMIC 8
 
#;
#; Specify this bit if you want the parser to recognize schemas
 
#; http://apache.org/xml/features/validation/schema 
#; On: Enable the parser's schema support. (default) 
#; Off: Disable the parser's schema support. 
#define SAXVALIDATIONSCHEMA 16
 
#; Specify this bit if you want the parser to perform full schema checking
 
#; http://apache.org/xml/features/validation/schema-full-checking
#; On: Enable full schema constraint checking, including checking which may be time-consuming or memory intensive. Currently, particle unique attribution constraint checking and particle derivation resriction checking are controlled by this option
#; Off: Disable full schema constraint checking (default). 
 
#define SAXVALIDATIONSCHEMAFULLCHECKING 32
 
#; http://apache.org/xml/features/validation/cache-grammarFromParse
#; On: Cache the grammar in the pool for re-use in subsequent parses
#; Off: Do not cache the grammar in the pool (default)
#; If set to true, the http://apache.org/xml/features/validation/use-cachedGrammarInParse is also set to true automatically.
#define SAXVALIDATIONREUSEGRAMMAR 64
 
#; Flags to force SAX not to validate but DO recognize namespaces and prefixes
#define SAXNOVALIDATION $$$SAXNAMESPACES+$$$SAXNAMESPACEPREFIXES

SAXFULLDEFAULT = All flags except SAXVALIDATIONSCHEMAFULLCHECKING.

Maybe try change the flags , but defaults seems to do what you need.

If you actually try this approach can you please post if it works or not?

Eduard Lebedyuk · Dec 10, 2017 go to post

Benjamin's link reads

https://sourceforge.net/projects/onforme/

but points to

https://sourceforge.net/projects/onforme/%C2%A0