2017-12-01 2 views
0

GrailsでプログラミングされたWebアプリケーションを開発中です。特定のレポートを表示するためのページがあり、これらのレポートに添付ファイルを含めることができます。添付ファイルはdocumentumに格納されており、現在、ユーザーがクリックすると、添付ファイルが格納されているdocumentum内の場所へのリンクにすぎず、ユーザーに資格情報を入力するよう促します。私のアプリケーションは、設定ファイルに格納されているドキュメントの資格情報を持っているので、ユーザーが自分の資格情報を入力するのではなく、それらを使用します。リンクを取得するためにRESTfulなサービスを使用していますが、リンクを使用してユーザーのコンピュータに直接ダウンロードする方法を見つけようとしています。Grailsで認証を求めるプロンプトを表示せずにURLからコンテンツをダウンロードする

private def getFileInfo(def id, def subject) { 
    // product show view needs the following four lists to display the document information correctly 
    def ATRReportInstance = ATRReport.findByTrackingNumber(id) 
    def linkList = [] 
    def nameList = [] 
    def formatList = [] 
    def idList = [] 
    // open up a connection to the documentum server 
    def doc = connectToDocumentum() 

    if (!doc) return 
    def rest = doc.rest 
    def response = doc.response 
    if (response.status == 200) { 
    // retrieve the folder for this product (the name of this folder is the product's ID) 
    def rObjectId = rest.get(documentumServer + "/repositories/" + documentumfilestore + "?dql=select r_object_id from dm_folder where any r_folder_path='" + atrreportfolderpath + "/" + id + "'") { 
     auth authuser, authpass 
    } 
    // get the folder's ID from the folder object retrieved above 
    def folderObjectID 
    rObjectId.json.entries.each { 
     entry - > 
     folderObjectID = entry.content.properties.r_object_id 
    } 
    // get all of the documents in the product's MSDS folder using the folder ID retrieved above 
    def resp = rest.get(documentumServer + "/repositories/" + documentumfilestore + "?dql=select r_object_id, object_name, a_content_type, subject from cbs_document where any i_folder_id= '" + folderObjectID + "'") { 
     auth authuser, authpass 
    } 
    // cycle through the documents above to populate the four MSDS document information lists 
    def x = 0 
    resp.json.entries.each { 
     entry - > 
     if (entry.content.properties.subject == subject) { 
      // get the document's content object from the document's ID 
      def content = rest.get(documentumServer + "/repositories/" + documentumfilestore + "/objects/" + entry.content.properties.r_object_id + "/contents/content" + "?media-url-policy=local") { 
      auth authuser, authpass 
      } 
      if (entry.content.properties.r_object_id != null && ATRReportInstance.inactiveFiles != null && ATRReportInstance.inactiveFiles.contains(entry.content.properties.r_object_id.toString())) {} else { 
      linkList[x] = getLink(content.json.links, "enclosure") 
      if (linkList[x].contains("format=msg")) 
       linkList[x] = linkList[x].toString().substring(0, linkList[x].toString().indexOf("content-media")) + "content-media.msg" 

      formatList[x] = entry.content.properties.a_content_type 
      nameList[x] = entry.content.properties.object_name 
      idList[x] = entry.content.properties.r_object_id 
      x++ 
      } 
     } 
    } 
    return [linkList: linkList, nameList: nameList, formatList: formatList, idList: idList] 
    } else { 
    // return null if documentum is unavailable 
    flash.message = message(code: 'error.documentum.unavailable') 
    return null 
    } 
} 

私はうまくいくかもしれないURLに取ると、ユーザーにドキュメントをダウンロードすることができます別の関数を書いて考えていますが、私はGrailsの内、そのドキュメントを取得する方法を見つけ出すことはできません。

答えて

0

ここに実装した解決策があります。これは、構成ファイルにある認証情報を使用して、文書ファイルにファイルをダウンロードする方法です。

def exportAttachment() { 
 
    //uses parameters from gsp file 
 
    def url = params.url 
 
    def name = params.name 
 
    def format = params.format 
 
    def extension 
 

 
    //find proper extension 
 
    for (s in documentumExtMap) { 
 
    if (s.value.equals(format)) { 
 
     extension = s.key 
 
    } 
 
    } 
 

 
    def connection = new URL(url).openConnection() 
 
    def remoteAuth = "Basic " + "${authuser}:${authpass}".bytes.encodeBase64() 
 
    connection.setRequestProperty("Authorization", remoteAuth) 
 

 
    def dataStream = connection.inputStream 
 

 
    response.setContentType("application/octet-stream") 
 
    response.setHeader('Content-disposition', 'Attachment; filename=' + name + '.' + extension) 
 
    response.outputStream << dataStream 
 
    response.outputStream.flush() 
 
}

方法は、次の3つのパラメータがあります:URL、名前、フォーマットを。

Urlは、documentum内のファイルの場所です。

名は、ダウンロードクライアント側の名前

フォーマットがダウンロードされているファイルの種類です。私の場合は、ファイルに必要な適切な拡張子を取得するためにこれを使用しなければなりませんでした。

0

ログインをバイパスしたい場合は、SSOソリューションをセットアップするか(DCTMの作業が必要です)、提案どおりの機能を実行してください。ただし、これを行う際にはライセンス条項を考慮する必要があります。

関連する問題