go to post Eduard Lebedyuk · Apr 20, 2017 Do you want to serve arbitrary files? I think you can use stream server for that: /// Return physical file contents /// name - full path to file ClassMethod serve(name) As %Status { #dim sc As %Status = $$$OK #dim %response As %CSP.Response //kill %request.Data set %request.Data("STREAMOID",1)= ##class(%CSP.StreamServer).Encrypt(##class(%CSP.StreamServer).GetOidForFile(name)) if ##class(%CSP.StreamServer).OnPreHTTP() { set %response.Headers("Content-Disposition")="attachment; filename*=UTF-8''" _ ##class(%CSP.Page).EscapeURL(##class(%File).GetFilename(name), "UTF8") set sc = ##class(%CSP.StreamServer).OnPage() } quit sc } Also parameter cannot be assigned.
go to post Eduard Lebedyuk · Apr 20, 2017 Please clarify the following points:How does the code breaks? What error do you receive? At what point?Can you show a sample row?
go to post Eduard Lebedyuk · Apr 20, 2017 Files in OS by themselves do not have Content-Type attribute (streams, in web context can have Content-Type attribute). However, knowing file extension Caché has FileClassify utility method that can determine content type. Here's the wrapper I usually use: /// Determine file mime type /// name - full path to file ClassMethod getFileType(name) As %String { set ext = $zcvt($p(name, ".", *), "U") do ##class(%CSP.StreamServer).FileClassify(ext, .type , .bin, .charset) set ext = "/" _ ext _ "/" if ext = "/RTF/" { set type = "application/rtf" } return type } Or you can additional types into: set ^%SYS("CSP","MimeFileClassify", ext) = $lb(type, bin, charset)
go to post Eduard Lebedyuk · Apr 20, 2017 It's better to use stream wrappers instead of open/use directly.I'm not sure what's the correct way to set codepage with open command.
go to post Eduard Lebedyuk · Apr 20, 2017 Extra curly brace is there by design.Seems like strings starting from {, are json-parsed.
go to post Eduard Lebedyuk · Apr 20, 2017 That's, I think is an unrelated issue. This SQL: SELECT JSON_OBJECT('id': '{{}') Also throws the same error: [SQLCODE: <-400>:<Fatal error occurred>] [%msg: <Unexpected error occurred in JSON_OBJECT() function execution of <JSON_OBJECT>.%FromJSON({{}).Parsing error :: Line 1 Offset 2>] Seems like some data escaping is required. Very simple escaping (this query executes successfully): SELECT JSON_OBJECT('id': ' '||'{{}')
go to post Eduard Lebedyuk · Apr 20, 2017 Use translate table: ClassMethod create(file) As %Status { set stream = ##class(%Stream.FileCharacter).%New() set stream.TranslateTable = "CP874" set sc = stream.LinkToFile(file) quit:$$$ISERR(sc) sc do stream.WriteLine("Hello") quit stream.%Save() }
go to post Eduard Lebedyuk · Apr 19, 2017 If you're running your SOAP service with a custom listener, specify SSLConfig setting for the ensemble business host (Should be in Connection category).If you're running your SOAP service on the main web server, you should enable SSL for a web server. It's usually done by installing external web server and configuring SSL there.
go to post Eduard Lebedyuk · Apr 19, 2017 After you receive base64 string decode it: set text="Hello @" set text = $zcvt(text, "O", "UTF8") set base64text = $system.Encryption.Base64Encode(text) wrile base64text >SGVsbG8gQA== set decoded = $system.Encryption.Base64Encode(base64text) set decoded = $zcvt(text, "I", "UTF8") write decoded >Hello @
go to post Eduard Lebedyuk · Apr 19, 2017 Great article, Fabio! The problem can be that when data changes, then the whole record is copied, i.e. also data which does not change. That can be solved by checking m%<property> value. It has false positives sometimes (when you change value back, i.e.: a-b-a) and calling log code only if property value has changed. Forgot that it's only about object access. Still, you have old and new value, so: Do %code.WriteLine($Char(9,9,9)_"Set tOldValue = {"_tProperty.SqlFieldName_"*O}") Do %code.WriteLine($Char(9,9,9)_"Set tNewValue = {"_tProperty.SqlFieldName_"*N}") Do %code.WriteLine($Char(9,9,9)_"if {" _ tProperty.SqlFieldName _ "*C},tOldValue'=tNewValue {") All data changes are logged in a common table. Why not generate a separate log table for each class, inheriting from logged class, so 1 change == 1 record in log table. It also gives you the possibility of writing "easy" diff tool, so audit results can be displayed conveniently. If table person has a column "photo" with binary data (stream) containing the photography then each and every time yhe user changes the picture the role stream is recorded (consuming disk space). That problem can be solved by creating immutable stream-containing class. /// Immutable wrapper for stream Class User.Document Extends %Persistent { /// Global identifier to give to user (prevent id traversal) Property guid As %String [ InitialExpression = {$system.Util.CreateGUID()}, Required ]; /// Creation date time Property createDateTime As %TimeStamp [ InitialExpression = {$ZDATETIME($ZTIMESTAMP, 3, 1, 3)}; /// File name as supplied by user (only for display purposes) Property fileName As %String(MAXLEN =1000) [ Required ]; /// File stream Property content As %FileBinaryStream; /// User who uploaded the file Property user As %String [ InitialExpression = {$username} ]; /// Add new stream /// realName - real name of a stored file /// suppliedName - name supplied by user, used only for display purposes /// stream - stream with data Method %OnNew(realName As %String = "", suppliedName As %String = "", stream As %Stream.Object = {##class(%FileBinaryStream).%New()}) As %Status [ Private, ServerOnly = 1 ] { #dim sc As %Status = $$$OK set ..fileName = ##class(%File).GetFilename(suppliedName) set ..content.Filename = realName set sc = ..content.CopyFromAndSave(stream) quit sc } /// Serve file on web Method serve() As %Status { #dim sc As %Status = $$$OK #dim %response As %CSP.Response kill %request.Data set %request.Data("STREAMOID",1)= ##class(%CSP.StreamServer).Encrypt(..content.%Oid()) if ##class(%CSP.StreamServer).OnPreHTTP() { set %response.Headers("Content-Disposition")="attachment; filename*=UTF-8''"_##class(%CSP.Page).EscapeURL(..fileName,"UTF8") set st = ##class(%CSP.StreamServer).OnPage() } quit sc } That way your audit log table would contain only id references.
go to post Eduard Lebedyuk · Apr 19, 2017 Fixed the link to a correct article and I hadn't wrote about 7z problem even there. So here it is:Document files (docx, xlsx, pptx) zipped with 7z on linux cannot be opened by Microsoft Office on Windows.
go to post Eduard Lebedyuk · Apr 19, 2017 It does. Foreach = row/object indicates that object access calls triggers.
go to post Eduard Lebedyuk · Apr 19, 2017 Zip is also available on windows. I got some problems when using 7z on linux, so I'd like to recommend zip on both linux and windows. Code.
go to post Eduard Lebedyuk · Apr 18, 2017 You can combine triggers and method generators into trigger generators like this: Class User.Class1 Extends %Persistent { Property prop1 As %String; Property prop2 As %String; Trigger NewTrigger [ CodeMode = objectgenerator, Event = INSERT, Time = AFTER ] { #dim class As %Dictionary.CompiledClass = %compiledclass set proplist = "" for i=1:1:class.Properties.Count() { #dim prop As %Dictionary.CompiledProperty = class.Properties.GetAt(i) if prop.Internal || prop.Calculated || prop.ReadOnly || prop.Private || prop.Identity || prop.MultiDimensional continue set proplist = proplist _ $lb(prop.Name) } do %code.WriteLine($$$TAB _ "set ^dbg($i(^dbg)) = $lb({" _$lts(proplist, "},{") _ "})") quit $$$OK } /// do ##class(User.Class1).Test() ClassMethod Test() { do ..%KillExtent() kill ^dbg &sql(INSERT INTO Class1 (prop1, prop2) Values ('Alice', 1)) &sql(INSERT INTO Class1 (prop1, prop2) Values ('Bob' , 2)) zw ^dbg } Test: do ##class(User.Class1).Test() ^dbg=2 ^dbg(1)=$lb("Alice",1) ^dbg(2)=$lb("Bob",2) Here's whats going on during compilation. Build list of all relevant properties and write them into proplist variable. Generate trigger code: set ^dbg($i(^dbg)) = $lb({prop1}, {prop2}) And at runtime only set ^dbg gets hit That said I'd have automatically generated some log class and called method log there, passing all properties. Some docs: TriggersGeneratorsProperties methodsIterating through all properties of an object
go to post Eduard Lebedyuk · Apr 17, 2017 Just redefine the trigger with the same name in a child class: Class FormsDev.NewClass1 Extends %Persistent { Property Name As %String; Trigger Insert [ Event = INSERT ] { Set ^dbg = {Name} } /// do ##class(FormsDev.NewClass1).Test() ClassMethod Test() { Kill ^FormsDev.NewClass1D, ^dbg, ^dbg2 &sql(INSERT INTO FormsDev.NewClass1 (Name) Values ('Alice')) &sql(INSERT INTO FormsDev.NewClass2 (Name) Values ('Bob')) zw ^dbg, ^dbg2 } } and child class: Class FormsDev.NewClass2 Extends FormsDev.NewClass1 { Trigger Insert [ Event = INSERT ] { Set ^dbg2 = {Name} } } Test: >do ##class(FormsDev.NewClass1).Test() ^dbg="Alice" ^dbg2="Bob" Also, if you change trigger name, both would be executed. For example Insert in NewClass1: Trigger Insert [ Event = INSERT ] { Set ^dbg($i(^dbg)) = {Name} } And Insert2 in NewClass2: Trigger Insert2 [ Event = INSERT ] { Set ^dbg2($i(^dbg2)) = {Name} } Would result in: >do ##class(FormsDev.NewClass1).Test() ^dbg=2 ^dbg(1)="Alice" ^dbg(2)="Bob" ^dbg2=1 ^dbg2(1)="Bob"
go to post Eduard Lebedyuk · Apr 12, 2017 Whitelist ip's with access to management postal1. Open <install dir>/CSP/bin/CSP.ini2. Set System_Manager.
go to post Eduard Lebedyuk · Apr 12, 2017 Breaks maybe? AFAIK break points are unaffected by compilation.