import com.crystaldecisions.sdk.framework.CrystalEnterprise;
import com.crystaldecisions.sdk.framework.IEnterpriseSession;
import com.crystaldecisions.sdk.framework.ISessionMgr;
import com.crystaldecisions.sdk.occa.infostore.IInfoObject;
import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
/**
* SAP BusinessObjects 4.3 SP4 - 그룹 조회 CLI 프로그램
* (설정 파일 없이 소스 내 상수로 동작)
*
* 사용법:
* java -cp ".:lib/*" BOGroupViewer
*/
public class BOGroupViewer {
// ══════════════════════════════════════════════
// ★ 여기만 수정하세요
// ══════════════════════════════════════════════
private static final String BO_SERVER = "your-cms-hostname"; // CMS 서버명 (포트 불필요)
private static final String BO_USER = "Administrator";
private static final String BO_PASS = "your_password";
private static final String BO_AUTH = "secEnterprise"; // secEnterprise | secLDAP | secWinAD | secSAPR3
private static final String ADMIN_QUERY =
"SELECT SI_ID, SI_NAME, SI_DESCRIPTION, SI_GROUP_KIND, SI_USERCOUNT, SI_CUID" +
" FROM CI_SYSTEMOBJECTS" +
" WHERE SI_KIND='UserGroup'" +
" ORDER BY SI_NAME";
private static final int PAGE_SIZE = 500;
// ══════════════════════════════════════════════
// ANSI 색상
private static final String RESET = "\033[0m";
private static final String BOLD = "\033[1m";
private static final String CYAN = "\033[36m";
private static final String GREEN = "\033[32m";
private static final String YELLOW = "\033[33m";
private static final String RED = "\033[31m";
private static final String GRAY = "\033[90m";
private static final String WHITE = "\033[97m";
public static void main(String[] args) {
printBanner();
IEnterpriseSession session = null;
try {
// ── 1. 로그인 ──────────────────────────────────
step("로그인 중... [" + BO_SERVER + " / " + BO_USER + "]");
ISessionMgr mgr = CrystalEnterprise.getSessionMgr();
session = mgr.logon(BO_USER, BO_PASS, BO_SERVER, BO_AUTH);
ok("로그인 성공");
// ── 2. InfoStore 취득 ──────────────────────────
IInfoStore store = (IInfoStore) session.getService("", "InfoStore");
// ── 3. 쿼리 실행 ──────────────────────────────
step("쿼리 실행 중...");
step(" " + GRAY + ADMIN_QUERY + RESET);
IInfoObjects results = (IInfoObjects)
store.query(ADMIN_QUERY + " PAGESIZE " + PAGE_SIZE);
ok("조회 완료 — " + results.size() + "건");
// ── 4. 결과 출력 ──────────────────────────────
printTable(results);
} catch (Exception e) {
error("오류: " + e.getMessage());
e.printStackTrace();
} finally {
if (session != null) {
try { session.logoff(); info("로그오프 완료"); }
catch (Exception ignored) {}
}
}
}
// ── 테이블 출력 ────────────────────────────────
private static void printTable(IInfoObjects objs) throws Exception {
String fmt = "%-8s %-32s %-16s %-6s %-36s%n";
String line = repeat("─", 108);
System.out.println();
System.out.println(CYAN + BOLD + " BO 그룹 목록" + RESET);
System.out.println(CYAN + " " + line + RESET);
System.out.printf(" " + BOLD + fmt + RESET,
"SI_ID", "SI_NAME", "SI_GROUP_KIND", "COUNT", "SI_CUID");
System.out.println(CYAN + " " + line + RESET);
int idx = 0;
for (Object obj : objs) {
IInfoObject io = (IInfoObject) obj;
String siId = String.valueOf(io.getID());
String siName = safe(io.getTitle());
String siDesc = safe(io.getDescription());
String siKind = prop(io, "SI_GROUP_KIND");
String siCount = prop(io, "SI_USERCOUNT");
String siCuid = safe(io.getCUID());
String color = (idx % 2 == 0) ? WHITE : GRAY;
System.out.printf(" " + color + fmt + RESET,
siId, trunc(siName, 32), siKind, siCount, siCuid);
if (!siDesc.isEmpty()) {
System.out.printf(" " + GRAY + "%-8s ↳ %s%n" + RESET, "", trunc(siDesc, 90));
}
idx++;
}
System.out.println(CYAN + " " + line + RESET);
System.out.println(GREEN + BOLD + " 총 " + objs.size() + "개 그룹" + RESET);
System.out.println();
}
private static String prop(IInfoObject io, String key) {
try {
Object v = io.properties().getProperty(key);
return v != null ? String.valueOf(v) : "—";
} catch (Exception e) { return "—"; }
}
private static String safe(String s) {
return (s == null || s.trim().isEmpty()) ? "" : s.trim();
}
private static String trunc(String s, int max) {
if (s == null) return "";
return s.length() > max ? s.substring(0, max - 1) + "…" : s;
}
private static String repeat(String ch, int n) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) sb.append(ch);
return sb.toString();
}
private static void step(String m) { System.out.println(CYAN + "[*] " + m + RESET); }
private static void ok (String m) { System.out.println(GREEN + "[✓] " + m + RESET); }
private static void info(String m) { System.out.println(GRAY + "[i] " + m + RESET); }
private static void error(String m){ System.out.println(RED + "[✗] " + m + RESET); }
private static void printBanner() {
System.out.println(CYAN + BOLD);
System.out.println(" ╔══════════════════════════════════════════════╗");
System.out.println(" ║ SAP BusinessObjects 4.3 SP4 ║");
System.out.println(" ║ Group Viewer — BO Java SDK ║");
System.out.println(" ╚══════════════════════════════════════════════╝");
System.out.println(RESET);
}
}