发布新帖

查找

文章
· 二月 18, 2021 阅读大约需 3 分钟

jQueryを使用してIRISからJSONデータを取得する方法

jQuery($.getJSON と $.ajax)を使用した InterSystems IRIS データのJSON形式での取得方法をご紹介します。

以下にサンプルをご用意しました。

https://github.com/Intersystems-jp/REST_JSON_sample


サンプルには、次の内容が含まれます。

・REST + JSON
・REST + CORS

※それぞれ、$.getJSON と $.ajax で取得する方法を記載しています。

※サーバ側ではSelect文の実行結果をJSON_OBJECT関数を使用しJSON文字列で出力しています。
 関数については以下のドキュメントをご覧ください。
 JSON_OBJECT関数


使用手順は以下になります。

1. USERネームスペースに json.xml をインポート・コンパイル
 

2. テスト用データの作成(ターミナルで以下のコマンドを実行する)

    USER>do ##class(Sample.Person).Populate(200)


3. 初期設定(REST用)

   管理ポータル > セキュリティ管理 > ウェブ・アプリケーション

   新しいウェブ・アプリケーションを作成ボタンを押す

   名前 /csp/user/rest
   ネームスペース    USER
   ディスパッチ・クラス REST.Person

   保存ボタンを押す

4. test_json.html をWEBサーバに配置する

   例:
   C:\Inetpub\wwwroot                          <-- IIS ルート
   C:\InterSystems\IRIS\CSP\user       <-- cspフォルダ

5. test_json.htmlをブラウザで開く

   例:
   http://localhost/test_json.html
   http://localhost:52773/csp/user/test_json.html
    
    ※サンプル内のクロスドメイン対応URLは、http://127.0.0.1:52773/ を使用(PWS用サンプル)
 

6. テキストボックスに適当なID(1,2,100 など)を入力し、検索ボタンを押して出力結果を確認する。

 

★IRISでJSONを操作する基本情報については、こちらの記事をご覧ください(ビデオもご紹介しています)。

【はじめてのInterSystems IRIS】セルフラーニングビデオ:アクセス編:IRIS での JSON の操作

 


【注意】

IRIS 2025.1以降のバージョンでGitHubのサンプル(REST+CORS)を実行すると、以下のような CORS エラーになります(F12/開発者ツールで確認)。

Access to XMLHttpRequest at 'http://127.0.0.1/csp/user/rest/persons/2' from origin 'http://<IP Address>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.


これは、2025.1 以降のバージョンより、管理ポータルの Web アプリケーション設定 で受け入れるオリジンを制限することができるようになったことが関係しています。

管理ポータルの、[システム管理] > [セキュリティ] > [アプリケーション] > [ウェブ・アプリケーション] RESTアプリケーション(例:/csp/user/rest)より、
[Cross-Origin 設定] タブで、許可されるオリジンまたはヘッダを追加します。オリジンまたはヘッダを追加するには、対応するボックスに名前を入力して [新しく追加] をクリックします。

ワイルドカードのアスタリスク (*) を入力して、すべてのオリジンを許可することもできますが、この場合は、CORS ヘッダを処理する方法を定義する必要があります。
 

   

讨论 (0)0
登录或注册以继续
文章
· 二月 16, 2021 阅读大约需 2 分钟

FOREACH for Objectscript

As you know ObjectScript has neither FOREACH system command nor system function.
But it has a wide room for creativity.

The task is to loop over a global or local array and do something FOR EACH element.

There are 2 possible solutions:

  • creating a macro that generates the required code sequences
  • creating an Extended Command to perform the action. Both ways are presented here. The macro is a generic and quite flexible solution and easy to adapt if required.
##; ZFOREACHMACRO ; macro definitions
##; %key = variable provide to loop trough array
##; %arr = the gobal or local array to be looped on
##; %the method or routine to be executed for each node.
##; $$$foreach = forward loop $$$foreeachR = reverse loop
#define foreach(%key,%arr,%do) set %key="" for  set %key=$o(%arr(%key)) q:%key=""  do %do
#define foreachR(%key,%arr,%do) set %key="" for  set %key=$o(%arr(%key),-1) q:%key=""  do %do

You simply include the macro and apply it.
Example:

#include ZFOREACHMACRO   
test $$$foreach(key,^rcc,show)   
     quit
show zwrite @$zr,! quit   

Creating a command extension is available for all namespaces.

It needs to be included in %ZLANGC00.mac by #include ZZFOREACH
the related code is here:

##; run $order() ascending or descending on global or local arrays  
##; pass semicolon separated parameter string ("%array;%do;%fwd,;%key")  
##; %array = global or local variable name  
##; %do = routine or method to be executed for each run   
##; %fwd = 1/-1 loop direction ascending / descending, default = 1   
##; %key = first key if existing  
ZZFOREACH(%par) public {  
 set %par=$lfs(%par,";")
 new %array,%do,%fwd,%key,%val
 set %array=$lg(%par,1),%do=$lg(%par,2),%fwd=$lg(%par,3),%key=$lg(%par,4)
 if '%fwd set %fwd=1
 if %key]"" set %key=$o(@%array@(%key),$s(%fwd<1:-1,1:1))
 for  set %key=$o(@%array@(%key),%fwd,%val) quit:%key=""  do @%do
 quit 1 
}

In addition to the macro, the command allows optionally to run zzFOREACH
from a provided starting point forward or backward.
Examples:

DEMO>zzforeach "^rcc;show^dump(%array,%key,%val)"
^rcc(1) = 1
^rcc(2) = 2
^rcc(3) = 3
^rcc(4) = 4
^rcc(5) = 5

or from subscript 3:

DEMO>zzforeach "^rcc;show^dump(%array,%key,%val);;3"
^rcc(3) = 3
^rcc(4) = 4
^rcc(5) = 5

or the same reverse:

DEMO>zzforeach "^rcc;show^dump(%array,%key,%val);-1;3"
^rcc(3) = 3
^rcc(2) = 2
^rcc(1) = 1

GitHub

1 Comment
讨论 (1)2
登录或注册以继续
文章
· 二月 15, 2021 阅读大约需 4 分钟

ルーチン・クラスメソッド内の特定処理でデータベースの特権を変更する方法

これは InterSystems FAQ サイトの記事です。


「特権ルーチンアプリケーション」を使用し、コード中に $system.Security.AddRoles()メソッドを使用してロールを付与する仕組みを利用します。

※ロールベースで必要な特権を付与するため、予め特定の特権を持ったロールを作成する必要があります。

詳細は、以下ドキュメントをご参照ください。
特権ルーチン・アプリケーション【IRIS
特権ルーチン・アプリケーションについて


例えば、特定ルーチン(またはクラスメソッド)実行時のみデータベースの更新を許可するための設定は、以下のとおりです。

(接続するデータベースに対してはREAD許可だけを持ち、あるルーチン実行時のみデータベースに対するREAD/WRITE許可を持つように設定します。)
 

1)  データベース:Aのリソース定義を確認する

 データベース:Aのリソースに %DB_%DEFAULT が設定されている場合は、独自リソースを作成します。

 (データベースに割り当てられたリソースの確認は、管理ポータル > [システム管理] > [構成] > [システム構成] > [ローカルデータベース] > リソース で確認できます)

 リソース作成は、管理ポータル > [システム管理] > [セキュリティ] > [リソース] > 新規リソース作成ボタン押下
 データベースリソースは命名規則があり、 %DB_データベース名 を指定します。

 例の場合は、 %DB_A を登録します。このとき、パブリック許可は全てチェックを外します。

 リソース作成が完了したら、管理ポータル > [システム管理] > [構成] > [システム構成] > [ローカルデータベース] から設定対象のデータベース設定を開き、リソース名を変更し、保存します。
 

2) READ許可のみを付与するロールを作成する

 管理ポータル > [システム管理] > [セキュリティ] > [ロール] > 新規ロール作成ボタン押下

 ロール名を記入し、保存します。(ロール名を R1 とします。)

 作成したロールに特権(リソースに対する許可の組み合わせ)を登録するため、追加ボタンを押下し、利用可能なリソース一覧から、1)で確認したリソース名を選択します。

 選択後、リソースの許可をRのみに変更し、ロールを保存します。
 

3) アクセスするユーザのログインロールを確認する。

 例では、ターミナルでのルーチン(またはクラスメソッド)実行で確認を行うため、ターミナルログイン時にユーザ認証を行うよう、適切なサービス(Windowsなら%Service_Console)の認証方法に「パスワード」を追加します。

 任意ユーザに対して、%Developerロールと 2) で作成したロールを付与します。
 

4) 特権ルーチンアプリケーションの作成

 実行時にREAD/WRITE許可を追加するための「特権ルーチンアプリケーション」を作成します。

 管理ポータル > [システム管理] > [セキュリティ] > [アプリケーション] > [特権ルーチンアプリケーション] > 作成用ボタン押下

 特権ルーチンアプリケーション名を指定し保存します。(特権ルーチンアプリケーション名を TR1 とします。)

 ルーチンタブを開き、ルーチン(またはクラスメソッド)があるデータベースの指定と、名前の指定を行います。

 続いて、アプリケーション・ロールタブを開き、データベース:A のDBロール(%DB_Aロール)を付与します。

 ※ DBロールはDBリソース作成時、自動的に作成されるロールで、DBリソースに対するREAD/WRITE許可を持つロールです。
 

5) コード内でロールを付与する。

 4)で作成した特権ルーチン名を使用して、以下メソッドを追記します。

  set st=$system.Security.AddRoles("TR1")

 
【実行例】

st() public {
 try {
   new $roles
   write "現在の値:",^ABC,!
   set st=$system.Security.AddRoles("TR1"// ロールの追加
   write $roles,!
   set ^ABC="変更"
   write "現在の値(更新後):",^ABC,!
 }
 catch ex {
   zwrite ex
 }
}


《ターミナル実行例》

A>set ^ABC="かきくけこ"   // ログイン時、READ許可のみのためエラー発生
SET ^ABC="かきくけこ"
^
<PROTECT> ^ABC,c:\intersystems\cache\mgr\a\
A>write ^ABC
テスト
A>do st^Test()    // ルーチン実行期間のみ更新可
現在の値:テスト
%Developer,%DB_A,R1
現在の値(更新後):変更
讨论 (0)0
登录或注册以继续
文章
· 二月 8, 2021 阅读大约需 2 分钟

Websocket Client Embedded Python

This is a demo to make use of a simple WebSocket Client with Embedded Python in IRIS.

How to Test it

  • Run an Iris Session in Docker
  • Select your WebSocket Echo Server
  • Enter the text you want to send or generate it
  • Send it and see the result
$ docker-compose exec iris iris session iris "##class(rccpy.WSockPy).Run()"

*** Welcome to WebSocket Embedded Python Demo ***

Collecting websocket-client
Using cached https://files.pythonhosted.org/packages/4c/5f/f61b420143ed1c8dc69f9eaec5ff1ac36109d52c80de49d66e0c36c3dfdf/websocket_client-0.57.0-py2.py3-none-any.whl
Collecting six (from websocket-client)
Using cached https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl
Installing collected packages: six, websocket-client
Successfully installed six-1.15.0 websocket-client-0.57.0

%%%%%%

Known Hosts (*=Exit) [1]:
1 ws://echo.websocket.org/
2 --- server 2 ----
3 --- server 3 ----
select (1): 1 ==> ws://echo.websocket.org/
Python Connection Object:#
Enter text to get echoed from WebSocketClient Service
Terminate with * at first position
or get generated text by %
or append new text with @

1 hi this is python
2 from IRIS
3 *

Select action for WebSocket Service
Send+Listen(S),New Text(N),Exit(X) [S]S
%%%%%%%%%%%%%%%%%%%%%%%%%%

******* Submit 2 Lines *******
1 send> hi this is python
recv< hi this is python
2 send> from IRIS
recv< from IRIS

Select action for WebSocket Service
Send+Listen(S),New Text(N),Exit(X) [S]n
%%%%%%%%%%%%%%%%%%%%%%%%%%
Enter text to get echoed from WebSocketClient Service
Terminate with * at first position
or get generated text by %
or append new text with @

1 with some more text
2 %
2 * Lorem ipsum dolor sit amet, consectetuer adipiscing
3 * elit, sed diam nonummy nibh euismod tincidunt ut
. . . .
32 * un simplificat Angles, quam
33 * un skeptic Cambridge amico dit me que Occidental es.
34 *

Select action for WebSocket Service
Send+Listen(S),New Text(N),Exit(X) [S]s
%%%%%%%%%%%%%%%%%%%%%%%%%%

******* Submit 33 Lines *******
1 send> with some more text
recv< with some more text
2 send> Lorem ipsum dolor sit amet, consectetuer adipiscing
recv< Lorem ipsum dolor sit amet, consectetuer adipiscing
3 send> elit, sed diam nonummy nibh euismod tincidunt ut
recv< elit, sed diam nonummy nibh euismod tincidunt ut
. . . .
32 send> un simplificat Angles, quam
recv< un simplificat Angles, quam
33 send> un skeptic Cambridge amico dit me que Occidental es.
recv< un skeptic Cambridge amico dit me que Occidental es.

Select action for WebSocket Service
Send+Listen(S),New Text(N),Exit(X) [S]x
%%%%%%%%%%%%%%%%%%%%%%%%%%

$

Hints

%SYS.Python.html is a preliminary class docu to see available functions

run time: If the standard Python module is not yet installed this is the first action and happens only once.

GitHub

讨论 (0)1
登录或注册以继续
文章
· 二月 2, 2021 阅读大约需 9 分钟

Caché データベースブロックの内部構造、パート 2

この記事は Caché データベースの内部構造を説明したこちらの記事の続編です。 そちらの記事では、様々なブロックタイプ、それぞれのつながりやグローバルとの関係について説明しました。 純粋に理論を述べた記事でした。 ブロックツリーを視覚化するのに役立つプロジェクトを作成しましたので、この記事ではその仕組みを詳しく説明します。

讨论 (0)2
登录或注册以继续