import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class Executor {
//configValues
public static String serverPath="C:\\tibco\\tss\\6.5.3";
public static String bootStrapPw= "spotfire";
public static String authentication="Library Administrator,API User,Impersonator";
public static String serverDrive=null;
public static String tomcatBinDirForCmd =null;
public static String tomcatBinPath=null;
public static String groupsDir=null;
public static void main(String[] args) {
// TODO Auto-generated method stub
CreatePath createPath = new CreatePath();
GroupFileEditor editor = new GroupFileEditor();
SpotfireCommands command = new SpotfireCommands();
//사용할 변수들 초기화
tomcatBinPath=createPath.createTomcatBinDir(serverPath);
groupsDir=createPath.CreateGroupsDir(tomcatBinPath);
serverDrive=createPath.ExtractServerDrive(serverPath);
tomcatBinDirForCmd= createPath.CreateTomcatBinDirForCmd(tomcatBinPath);
//baseCommand
String baseCommand=command.CreateBaseCmd(serverDrive, tomcatBinDirForCmd);
// DB Select 로 받을 사용자 정보
List<String> users = new ArrayList<String>();
users.add("guirim3");
users.add("guirim4");
//auth 권한 리스트
String[] auths=authentication.split(",");
//Export 수행 (overwrite)
command.ExportCommand(baseCommand,bootStrapPw);
Path path =Paths.get(groupsDir);
// 1. Groups.txt 파일존재여부 확인
if(Files.exists(path)){
//리스트의 모든사용자
for(String tempUser : users ) {
//신규사용자를 Create 하기
command.CreateUserCmd(baseCommand,bootStrapPw,tempUser,tempUser);
}
//생성된 사용자를 그룹에 추가하기
editor.Writer(groupsDir, users,auths);
//Import 수행
command.ImportCommand(baseCommand,bootStrapPw);
}
}
}
import java.util.ArrayList;
import java.util.List;
public class CreatePath {
public String CreateGroupsDir(String tomcatBinPath){
return tomcatBinPath.concat("\\groups.txt");
}
public String ExtractServerDrive(String serverPath){
return serverPath.substring(0, 2);
}
public String createTomcatBinDir(String serverPath) {
// TODO Auto-generated method stub
return serverPath.concat("\\tomcat\\bin");
}
public String CreateTomcatBinDirForCmd(String tomcatBinPath){
return tomcatBinPath.replace("\\", "/");
}
}
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
public class GroupFileEditor {
public void Writer(String groupsDir, List<String> users,String[] auths) {
// TODO Auto-generated method stub
try {
FileWriter fileWriter = new FileWriter(groupsDir,true);
BufferedWriter buffWrite = new BufferedWriter(fileWriter);
for(int authIndex=0;authIndex<auths.length;authIndex++){
for(int userIndex=0;userIndex<users.size();userIndex++){
buffWrite.write(TextGenerator(auths[authIndex],users.get(userIndex)));
buffWrite.newLine();
}
}
buffWrite.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private String TextGenerator(String auth, String user) {
// TODO Auto-generated method stub
return auth+" ; SPOTFIRE ; ; ; "+user+" ; SPOTFIRE ; user";
}
}