package com.capspire.util;
import com.opentext.api.LAPI_DOCUMENTS;
import com.opentext.api.LLSession;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.Properties;
public class MoveUtility {
final static Properties props = new Properties();
static {
File fProps = new File("configuration.properties");
try {
InputStream is = new FileInputStream(fProps);
props.load(is);
is.close();
} catch (IOException ioe) {
throw new RuntimeException(String.format("Unable to initialize properties.", ioe.getLocalizedMessage()), ioe);
}
}
public static void main(String[] args) throws Exception {
final LLSession session = new LLSession(
props.getProperty("ll.host"),
Integer.parseInt(props.getProperty("ll.port")),
null,
props.getProperty("ll.user"), props.getProperty("ll.pass")
);
final LAPI_DOCUMENTS apiDoc = new LAPI_DOCUMENTS(session);
final String path = props.getProperty("file.input");
final String delimiter = "[^0-9]";
final File file = new File(path);
if (!file.exists()) {
throw new RuntimeException(String.format("File does not exist! %s", file.getAbsolutePath()));
}
if (!file.isFile()) {
throw new RuntimeException(String.format("Filesystem object %s is not a file!", file.getAbsolutePath()));
}
final Reader reader = new FileReader(new File(path));
final BufferedReader br = new BufferedReader(reader);
while (br.ready()) {
final String line = br.readLine();
final String[] cols = line.split(delimiter);
if (cols.length == 2) {
final int node = Integer.parseInt(cols[0]);
final int dest = Integer.parseInt(cols[1]);
try {
apiDoc.MoveObject(0, node, 0, dest);
check(session);
System.out.printf("Moved %s to %s%n", node, dest);
} catch (Exception e) {
System.err.printf("Failed to move %s to %s. Reason: %s%n", node, dest, e.getLocalizedMessage());
}
}
}
}
private static void check(final LLSession session) {
if (session.getStatus() != 0) {
throw new RuntimeException(String.format("LAPI Error! Status: %s, Message: %s, ApiError: %s",
session.getStatus(), session.getStatusMessage(), session.getApiError()));
}
}
}
Comments