Alfresco勉強会#42 JavaScript Consoleをプログラムから使用する

88fe1a9048ec5e374b2c37e76fbdbe7a?s=47 Jun TERASHITA
February 21, 2018

Alfresco勉強会#42 JavaScript Consoleをプログラムから使用する

第42回Alfresco勉強会で発表した内容です。管理ツールのUIからそのまま使っても十分便利なJavaScript Consoleをプログラムから使用する方法をご紹介しました。

88fe1a9048ec5e374b2c37e76fbdbe7a?s=128

Jun TERASHITA

February 21, 2018
Tweet

Transcript

  1. 5.

     ˜  +BWB4DSJQUΛ࣮ߦ͍ͯ͠Δ෦෼ͷ8FC4DSJQU w 63-ɿIUUQMPDBMIPTUBMGSFTDPTFSWJDFEFGNFKTDPOTPMFFYFDVUF 1045͢Δ+40/ આ໌ TDSJQU ࣮ߦ͍ͨ͠+BWB4DSJQU

    SVOBT +BWB4DSJQUͷ࣮ߦϢʔβ USBOTBDUJPO SFBEPOMZ·ͨ͸SFBEXSJUF UFNQMBUF ݁ՌΛ੔ܗ͍ͨ͠৔߹ʹ࢖༻͢ΔʢۭͰ΋Α͍ʣ EPDVNFOU/PEF3FG /PEF3FGΛࢦఆ͢Δͱ+BWB4DSJQUͷதͰEPDVNFOUͱ͍͏ 4DSJQU/PEFͱͯ͠ࢀরͰ͖ΔʢۭͰ΋Α͍ʣ TQBDF/PEF3FG /PEF3FGΛࢦఆ͢Δͱ+BWB4DSJQUͷதͰTQBDFͱ͍͏ 4DSJQU/PEFͱͯ͠ࢀরͰ͖ΔʢۭͰ΋Α͍ʣ VSMBSHT ΫΤϦύϥϝʔλͷܗͰࢦఆ͢Δͱ+BWB4DSJQUͷதͰBSHTύ ϥϝʔλ໊ͱͯ͠ࢀরͰ͖ΔʢۭͰ΋Α͍ʣ
  2. 6.

     ˜  8FC4DSJQUʹ+BWB4DSJQUΛ1045࣮ͯ͠ߦͤ͞Δ w 3VCZͰ΋1ZUIPOͰ΋ͳΜͰ΋Α͍ͷͰ+BWB4DSJQUϑΝΠϧΛ8FC4DSJQUʹ1045ͯ݁͠ՌΛ ड͚औΔεΫϦϓτΛ࡞੒͢Ε͹Α͍ w 3VCZͷྫɿ+BWB4DSJQUͷϑΝΠϧ໊ͱ࣮ߦϢʔβΛҾ਺Ͱ༩͑Δ require

    'json' require 'net/https' ALFRESCO_ADDRESS="http://localhost:8080/alfresco/service/de/fme/jsconsole/execute" def exec_js_console if ARGV.length < 2 abort "specify js script file and running user" end js_file_name = ARGV[0] #Ҿ਺͔ΒJavaScriptͷϑΝΠϧ໊Λऔಘ running_user = ARGV[1] #Ҿ਺͔Β࣮ߦϢʔβΛऔಘ #build json post_json_hash = {} post_json_hash["template"] = "" post_json_hash["transaction"] = “readonly" post_json_hash["urlargs"] = "" post_json_hash["documentNodeRef"] = "" post_json_hash["spaceNodeRef"] = "" post_json_hash["runas"] = running_user ʻ࣍ϖʔδʹଓ͘ʼ
  3. 7.

     ˜  8FC4DSJQUʹ+BWB4DSJQUΛ1045࣮ͯ͠ߦͤ͞Δʢଓ͖ʣ ʻલϖʔδ͔Βͷଓ͖ʼ #read js file and set

    to script (with escape) File.open(js_file_name) do |file| post_json_hash["script"] = file.read #ࢦఆͨ͠JavaScriptͷίʔυΛ֨ೲ end #post it to alfresco uri = URI.parse(ALFRESCO_ADDRESS) http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Post.new(uri.path) req.basic_auth "admin", "admin" req["Content-Type"] = "application/json" req.body = JSON.generate(post_json_hash) res = http.request(req) resultJson = JSON.parse(res.body) puts resultJson[“printOutput"] #݁Ռ֬ೝͷͨΊϨεϙϯεϘσΟͷprintOutputΛग़ྗ end exec_js_console
  4. 11.