1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Cognos Analytics にファイルダウンロード用のページを作成する

Last updated at Posted at 2019-07-29

#Cognosでファイルダウンロード用のページを作成する意義
Cognos AnalyticsでExcelやPDF形式でレポートをスケジュール実行すると、結果ファイルはコンテントストアに保存されます。
実はCognosは大量データのファイルの生成に向いておらず、もの凄い時間と負荷がかかるし、コンテントストアが重くなるし、良い事ないので、単に決まったデータを定期的にダウンロードしたいだけであれば、SQLかJavaプログラムを自分で書いてファイルに出力してよ、というガイドをする事があります。
そういう時に、ファイル出力は自前のプログラムでやる方が良いと理解したが、ダウンロード用のページはCognos画面上に作りたい、という要件になる事が良くあります。

こんなイメージであればできますので、というやり方の例を紹介します。
「ダウンロード」ボタンを新規に作成し、クリックするとCognosのポータルページの画面内に、ダウンロード可能なファイルの一覧が表示され、ファイル名をクリックするとダウンロードができます。
※ファイルは、Cognosサーバーのフォルダ上に置いているだけなので、Cognosに負荷かかりません。
001.PNG

#実装手順
①ファイル配置するディレクトリの作成
ダウンロード用のファイルを配置するディレクトリを、Cognos Analyticsサーバー上の以下場所に作成。
/opt/ibm/cognos/analytics/webcontent/downloadFiles

②/opt/ibm/cognos/analytics/webcontent/servlet/FileDownload.jsp の作成
FileDownload.jsp の内容は以下

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.io.File"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<h2>ファイルダウンロード</h2>
<%
String filePath = "../webcontent/downloadFiles";
String filePath2 = "./downloadFiles";
String[] files = new String[0];
        try {
                Process p = Runtime.getRuntime().exec("ls " + filePath);
                p.waitFor();
                java.io.BufferedInputStream bis = new java.io.BufferedInputStream(p.getInputStream());
                java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
                byte[] b = new byte[1024];
                int len = -1;
                while( (len=bis.read(b, 0, 1024)) != -1 ) {
                        baos.write(b, 0, len);
                }
                String res = baos.toString("MS932");
                String[] tmp = res.split("\n");
                files = tmp;
        } catch(Exception ex) {}
        File dir = new File(filePath);
        String path = dir.getAbsolutePath();
%>
        <table border="1">
        <tr style="background-color:silver;">
                <th width="300px;">ダウンロードファイル一覧</th>
        </tr>
<%
        for(int i=0; i< files.length ; i ++) {
%>
        <tr>
                <td>
                        <%
                        out.println("<a href=." + filePath2 + "/" + files[i] + ">"+files[i]+"</a>");
                        %>
                </td>
        </tr>
<%
        }
%>
        </table>
</body>
</html>

③「ダウンロード」ボタン生成用のspec.jsonファイルの作成と取り込み
自分のPC上に「FileDownload」フォルダを作成し、以下のファイルとフォルダを作成。
002.PNG

imagesフォルダの配下には、ダウンロードボタンのイメージファイルを置く。
※ファイルは任意のものを用意。今回はCognosサーバーから取得したupload-export_32.pngファイルを使用している。

spec.jsonの中身は以下。エディタでUTF-8で保存している。

{
	"name":"File_Download_Button",
	"schemaVersion": "1.0",
	"extensions": [
	{
		"perspective": "common",
		"comment": "There is a special meta perspective called COMMON. Adding contributions to this perspective will cause the extension to be applied to All perspectives.",
		"features": [{
			"id": "sample.common.button.FileDownload",
			"toolItems": [
			{
				"comment": "This code adds a button to download files.",
				"id": "sample.iframeOpener.website",
				"containerId": "com.ibm.bi.glass.navbarLeadingGroup",
				"label": "ダウンロード",
				"type": "Button",
				"icon": "images/upload-export_32.png",
				"weight": 900,
				"comment": "The greater the weight, the higher the item will appear in the container.",
				"actionController": "bi/glass/api/IFrameOpener",
				"options": {
					"url": "/servlet/FileDownload.jsp",
					"title":"ダウンロード"
				}
			}
			]
		}]
	}]}

「FileDownload」フォルダをZIP化し、FileDownload.zipファイルを、Cognosポータルの「管理」→「カスタマイズ」→「拡張」でアップロードする。
003.PNG

以上で完了です。
ログインすると「ダウンロード」ボタンが表示されるので、クリックするとdownloadFilesフォルダ配下に存在するファイルが一覧されて、クリックするとダウンロード可能となります。
001.PNG

是非ご活用ください。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?