Created
January 27, 2017 19:25
-
-
Save julbrs/1348c8a2a1aa2d3b6bd9435ca1ab6749 to your computer and use it in GitHub Desktop.
Get File from an IInfoObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gbs.tools; | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.io.InputStream; | |
import java.util.logging.Logger; | |
import com.crystaldecisions.sdk.framework.CrystalEnterprise; | |
import com.crystaldecisions.sdk.framework.IEnterpriseSession; | |
import com.crystaldecisions.sdk.framework.ISessionMgr; | |
import com.crystaldecisions.sdk.occa.infostore.IFiles; | |
import com.crystaldecisions.sdk.occa.infostore.IInfoObject; | |
import com.crystaldecisions.sdk.occa.infostore.IInfoObjects; | |
import com.crystaldecisions.sdk.occa.infostore.IInfoStore; | |
import com.crystaldecisions.sdk.occa.infostore.IRemoteFile; | |
class GetInfoObjectFile{ | |
protected static Logger log = Logger.getLogger(GetInfoObjectFile.class.getName()); | |
protected static int METHOD = 1; | |
public static void main (String[] args) { | |
//LogController.setupLogger(); | |
String user = args[0]; | |
String password = args[1]; | |
String cms = args[2]; | |
String ids = args[3]; | |
String path = args[4]; | |
try { | |
System.out.println("Get infoobject file"); | |
ISessionMgr sm = CrystalEnterprise.getSessionMgr(); | |
IEnterpriseSession enterpriseSession = sm.logon(user, password, cms, "secEnterprise"); | |
IInfoStore iStore = (IInfoStore) enterpriseSession.getService("InfoStore"); | |
IInfoObjects objs = iStore.query("SELECT * FROM CI_INFOOBJECTS, CI_APPOBJECTS, CI_SYSTEMOBJECTS WHERE SI_ID IN (" + ids + ")"); | |
for(int i=0 ; i<objs.size(); i++) { | |
IInfoObject object = (IInfoObject) objs.get(i); | |
IRemoteFile repFile = null; | |
IFiles files = object.getFiles(); | |
for(int f=0; f<files.size(); f++) { | |
//IFile file = (IFile) object.getFiles().get(f); | |
repFile = (IRemoteFile) files.get(f); | |
if(METHOD==1) { | |
// method download | |
log.info("Save on disk "+object.getTitle() + "_" + repFile.getName() + " from repository: "+(repFile.download(path + object.getTitle() + "_" + repFile.getName())?"true":"false")); | |
} | |
else { | |
// IS method | |
InputStream is = repFile.getInputStream(); | |
FileOutputStream outputStream = new FileOutputStream(new File(path + object.getTitle() + "_" + repFile.getName())); | |
int read = 0; | |
byte[] bytes = new byte[1024]; | |
while ((read = is.read(bytes)) != -1) { | |
outputStream.write(bytes, 0, read); | |
} | |
} | |
repFile.commit(); | |
} | |
} | |
} | |
catch (Exception e) | |
{ | |
System.out.println(" Search error: " + e); | |
e.printStackTrace(); | |
System.exit(-1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment