API to Deserialize ORCHPROCESS table data


  1. package com.oimacademy.orchestration;
  2. import java.io.InputStream;
  3. import java.io.ObjectInputStream;
  4. import java.io.Serializable;
  5. import java.sql.Connection;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.ResultSetMetaData;
  9. import java.util.HashMap;
  10. import java.util.Iterator;
  11. import java.util.Map.Entry;
  12. import java.util.Set;
  13. import oracle.iam.platform.context.ContextAwareNumber;
  14. import oracle.iam.platform.context.ContextAwareString;
  15. import oracle.iam.platform.kernel.vo.EntityOrchestration;
  16. import oracle.iam.platform.kernel.vo.Orchestration;
  17. import oracle.iam.platform.kernel.vo.PostProcessOnlyBulkOrchestration;
  18. import com.oimacademy.connection.DataSource;
  19. public class DeserializeOrchestration {
  20.  public static void main(String[] args) throws Exception {
  21.   String statement1 = "select * from orchprocess where id=?";  
  22.   // String statement =
  23.   // "select id, orchestration from orchprocess where entitytype='User' and operation='CREATE' order by id";
  24.   // String statement =
  25.   // "select orchestration from orchprocess where id in (select processid from orchevents where name='UserModifyLDAPPreProcessHandler' and status='FAILED') order by id desc";
  26.   Connection conn = DataSource.getConnection();
  27.   System.out.println("Something");
  28.   // Read object from oracle
  29.   PreparedStatement pstmt = conn.prepareStatement(statement1);
  30.   pstmt.setLong(1, 138);
  31.   ResultSet rs = pstmt.executeQuery();
  32.   dumpRS(rs);
  33.   rs.close();
  34.   pstmt.close();
  35.   conn.close();
  36.   System.exit(0);
  37.  }
  38.  public static void dumpRS(ResultSet rs) throws Exception {
  39.   InputStream is = null;
  40.   ObjectInputStream oip = null;
  41.   rs.next();
  42.   ResultSetMetaData rsmd = rs.getMetaData();
  43.   for (int i = 0; i < rsmd.getColumnCount(); i++) {
  44.    String colName = rsmd.getColumnName(i + 1);
  45.    if (colName.equalsIgnoreCase("orchestration")) {
  46.     // is = rs.getBlob(1).getBinaryStream();
  47.     is = rs.getBinaryStream(colName);
  48.     oip = new ObjectInputStream(is);
  49.     Object o = oip.readObject();
  50.     if (o instanceof PostProcessOnlyBulkOrchestration) {
  51.      PostProcessOnlyBulkOrchestration object = (PostProcessOnlyBulkOrchestration) o;
  52.      System.out.println("Operation = " + object.getOperation());
  53.      System.out.println("Target = " + object.getTarget());
  54.      System.out.println("Action Result = " + object.getActionResult());
  55.      System.out.println("Context value = " + object.getContextVal());
  56.      printMap("Bulk Parameters: ", object.getBulkParameters());
  57.      printMap("Parameters: ", object.getParameters());
  58.      printMap("Inter event data: ", object.getInterEventData());
  59.     } else if (o instanceof EntityOrchestration) {
  60.      EntityOrchestration object = (EntityOrchestration) o;
  61.      System.out.println("EntityID = " + object.getEntityId());
  62.      System.out.println("EntityType = " + object.getEntityType());
  63.      System.out.println("Type = " + object.getType());
  64.      System.out.print("All Entity IDs: ");
  65.      for (int j = 0; j < object.getAllEntityId().length; j++) {
  66.       System.out.print(object.getAllEntityId()[j]);
  67.      }
  68.      System.out.println();
  69.     } else if (o instanceof Orchestration) {
  70.      Orchestration object = (Orchestration) o;
  71.      System.out.println("Operation = " + object.getOperation());
  72.      System.out.println("Target = " + object.getTarget());
  73.      // System.out.println("Action Result = " +
  74.      // object.getActionResult());
  75.      System.out.println("Context value = "+ object.getContextVal());
  76.      // printMap("Bulk Parameters: ",
  77.      // object.getBulkParameters());
  78.      printMap("Parameters: ", object.getParameters());
  79.      printMap("Inter event data: ", object.getInterEventData());
  80.     } else {
  81.      System.out.println("UNKNOWN ORCHESTRATION BLOB");
  82.     }
  83.    } else {
  84.     System.out.println(colName + " ===> " + rs.getString(colName));
  85.    }
  86.   }
  87.   oip.close();
  88.   is.close();
  89.  }
  90.  public static void printMap(String name,
  91.    HashMap<String, Serializable>[] marr) {
  92.   System.out.println("Dumping maps name = " + name);
  93.   for (int i = 0; i < marr.length; i++) {
  94.    System.out.println("Map element # " + i);
  95.    HashMap<String, Serializable> m = marr[i];
  96.    if (m == null) {
  97.     System.out.println("Null Map found");
  98.     continue;
  99.    }
  100.    Set<Entry<String, Serializable>> set = m.entrySet();
  101.    Iterator<Entry<String, Serializable>> it = set.iterator();
  102.    while (it.hasNext()) {
  103.     Entry<String, Serializable> e = it.next();
  104.     Object val = (Object) e.getValue();
  105.     String v = "";
  106.     if (val instanceof ContextAwareString) {
  107.      ContextAwareString cas = (ContextAwareString) val;
  108.      v = (String) cas.getObjectValue();
  109.     } else if (val instanceof ContextAwareNumber) {
  110.      ContextAwareNumber can = (ContextAwareNumber) val;
  111.      v = String.valueOf(((Long) can.getObjectValue()));
  112.     } else {
  113.      v = val.toString();
  114.     }
  115.     System.out.println("\t" + e.getKey() + " ---> " + v);
  116.    }
  117.   }
  118.  }
  119.  public static void printMap(String name, HashMap<String, Serializable> m) {
  120.   System.out.println("Dumping maps name = " + name);
  121.   if (m == null) {
  122.    System.out.println("Null Map found");
  123.    return;
  124.   }
  125.   Set<Entry<String, Serializable>> set = m.entrySet();
  126.   Iterator<Entry<String, Serializable>> it = set.iterator();
  127.   while (it.hasNext()) {
  128.    Entry<String, Serializable> e = it.next();
  129.    Object val = (Object) e.getValue();
  130.    String v = "";
  131.    if (val instanceof ContextAwareString) {
  132.     ContextAwareString cas = (ContextAwareString) val;
  133.     v = (String) cas.getObjectValue();
  134.    } else if (val instanceof ContextAwareNumber) {
  135.     ContextAwareNumber can = (ContextAwareNumber) val;
  136.     v = String.valueOf(((Long) can.getObjectValue()));
  137.    } else {
  138.     v = val.toString();
  139.    }
  140.    System.out.println("\t" + e.getKey() + " ---> " + v);
  141.   }
  142.  } 
  143. }

No comments:

Post a Comment