ossiejhmoore

Untitled

Apr 15th, 2015
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.75 KB | None | 0 0
  1. package com.capspire.util;
  2.  
  3. import com.opentext.api.LAPI_DOCUMENTS;
  4. import com.opentext.api.LLSession;
  5. import java.io.BufferedReader;
  6. import java.io.File;
  7. import java.io.FileInputStream;
  8. import java.io.FileReader;
  9. import java.io.IOException;
  10. import java.io.InputStream;
  11. import java.io.Reader;
  12. import java.util.Properties;
  13.  
  14. public class MoveUtility {
  15.  
  16.     final static Properties props = new Properties();
  17.  
  18.     static {
  19.         File fProps = new File("configuration.properties");
  20.         try {
  21.             InputStream is = new FileInputStream(fProps);
  22.             props.load(is);
  23.             is.close();
  24.         } catch (IOException ioe) {
  25.             throw new RuntimeException(String.format("Unable to initialize properties.", ioe.getLocalizedMessage()), ioe);
  26.         }
  27.     }
  28.  
  29.     public static void main(String[] args) throws Exception {
  30.         final LLSession session = new LLSession(
  31.                 props.getProperty("ll.host"),
  32.                 Integer.parseInt(props.getProperty("ll.port")),
  33.                 null,
  34.                 props.getProperty("ll.user"), props.getProperty("ll.pass")
  35.         );
  36.         final LAPI_DOCUMENTS apiDoc = new LAPI_DOCUMENTS(session);
  37.  
  38.         final String path = props.getProperty("file.input");
  39.         final String delimiter = "[^0-9]";
  40.         final File file = new File(path);
  41.         if (!file.exists()) {
  42.             throw new RuntimeException(String.format("File does not exist! %s", file.getAbsolutePath()));
  43.         }
  44.         if (!file.isFile()) {
  45.             throw new RuntimeException(String.format("Filesystem object %s is not a file!", file.getAbsolutePath()));
  46.         }
  47.         final Reader reader = new FileReader(new File(path));
  48.         final BufferedReader br = new BufferedReader(reader);
  49.         while (br.ready()) {
  50.             final String line = br.readLine();
  51.             final String[] cols = line.split(delimiter);
  52.             if (cols.length == 2) {
  53.                 final int node = Integer.parseInt(cols[0]);
  54.                 final int dest = Integer.parseInt(cols[1]);
  55.                 try {
  56.                     apiDoc.MoveObject(0, node, 0, dest);
  57.                     check(session);
  58.                     System.out.printf("Moved %s to %s%n", node, dest);
  59.                 } catch (Exception e) {
  60.                     System.err.printf("Failed to move %s to %s. Reason: %s%n", node, dest, e.getLocalizedMessage());
  61.                 }
  62.             }
  63.         }
  64.     }
  65.  
  66.     private static void check(final LLSession session) {
  67.         if (session.getStatus() != 0) {
  68.             throw new RuntimeException(String.format("LAPI Error! Status: %s, Message: %s, ApiError: %s",
  69.                     session.getStatus(), session.getStatusMessage(), session.getApiError()));
  70.         }
  71.     }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment