1    package com.instantbank.collections.collectionsActivities.web;
2    
3    import java.io.ByteArrayInputStream;
4    import java.text.SimpleDateFormat;
5    import java.util.Date;
6    import oracle.xml.parser.v2.DOMParser;
7    import oracle.xml.parser.v2.XMLDocument;
8    import oracle.xml.parser.v2.XMLNode;
9    import org.w3c.dom.Element;
10   import org.w3c.dom.NodeList;
11   import com.instantbank.collections.util.InstantbankException;
12   import com.instantbank.collections.util.StringFormat;
13   
14   /**
15    * A Bean class.
16    * <P>
17    *
18    * @author Indudata
19    */
20   public class ActionResultHistoryTransformer {
21   
22     private String actionResultHistoryXmlString;
23     private XMLDocument actionResultHistoryXml;
24   
25   
26     /**
27      * Constructor
28      */
29     public ActionResultHistoryTransformer() { }
30   
31   
32     public void setData(String actionResultHistoryXmlString) throws InstantbankException {
33       DOMParser docParser = new DOMParser();
34       ByteArrayInputStream stream = null;
35       try {
36         this.actionResultHistoryXmlString = actionResultHistoryXmlString;
37         stream = new ByteArrayInputStream(actionResultHistoryXmlString.getBytes());
38         docParser.setValidationMode(false);
39         docParser.parse(stream);
40         actionResultHistoryXml = docParser.getDocument();
41       }
42       catch(Exception e) {
43       }
44     }
45   
46   
47     public String getHistoryArray() throws InstantbankException {
48   
49       Date auxDate1;
50       Date auxDate2;
51       Long auxLong = new Long(0);
52       Date currentDate;
53       Integer dayLoop;
54       String displayOnDefault;
55       String historyArray = "";
56       int index;
57       String nextReviewDate;
58       XMLNode node;
59       NodeList nodeList;
60       String promiseDate;
61       Element root;
62       Integer timeLoop;
63       SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
64       SimpleDateFormat sdf2 = new SimpleDateFormat("MM-dd-yyyy HH:mm");
65       String show = "true";
66       try {
67         root = actionResultHistoryXml.getDocumentElement();
68         nodeList = root.getChildNodes();
69   
70         for(index = 0; index < nodeList.getLength(); index++) {
71           node = (XMLNode)nodeList.item(index);
72           if((node.valueOf("./promisedate") != null) && (!node.valueOf("./promisedate").equals(""))) {
73             nextReviewDate = sdf.format(sdf2.parse(node.valueOf("./promisedate")));
74           }
75           else if(((node.valueOf("./timeloop") == null) || (node.valueOf("./timeloop").equals(""))) && ((node.valueOf("./dayloop") == null) || (node.valueOf("./dayloop").equals("")))) {
76             nextReviewDate = "";
77           }
78           else if((node.valueOf("./timeloop") == null) || (node.valueOf("./timeloop").equals(""))) {
79             auxDate1 = sdf2.parse(node.valueOf("./postingdate"));
80             auxDate2 = new Date(auxDate1.getTime() + ((new Long(node.valueOf("./dayloop"))).longValue() * 60000));
81             nextReviewDate = sdf.format(auxDate2);
82           }
83           else if((node.valueOf("./dayloop") == null) || (node.valueOf("./dayloop").equals(""))) {
84             auxDate1 = sdf2.parse(node.valueOf("./postingdate"));
85             auxDate2 = new Date(auxDate1.getTime() + ((new Long(node.valueOf("./timeloop"))).longValue() * 60000));
86             nextReviewDate = sdf.format(auxDate2);
87           }
88           else {
89             auxDate1 = sdf2.parse(node.valueOf("./postingdate"));
90             auxDate2 = new Date(auxDate1.getTime() + ((new Long(node.valueOf("./timeloop"))).longValue() * 60000) + ((new Long(node.valueOf("./dayloop"))).longValue() * 60000));
91             nextReviewDate = sdf.format(auxDate2);
92           }
93           auxDate1 = sdf.parse(node.valueOf("./postingdate"));
94           currentDate = sdf.parse(node.valueOf("./currentdate"));
95           if((node.valueOf("./daystodisplay") != null) && (!node.valueOf("./daystodisplay").equals(""))) {
96             auxLong = new Long(node.valueOf("./daystodisplay"));
97           }
98           auxDate2 = new Date(auxDate1.getTime() + ((auxLong).longValue() * 60000 * 60 * 24));
99           if(currentDate.getTime() > auxDate2.getTime()) {
100            displayOnDefault = "N";
101          }
102          else {
103            displayOnDefault = "Y";
104          }
105          historyArray += "activities[" + (new Integer(index)).toString() +
106            "] = new Activity(\"" + node.valueOf("./postingdate") +
107            "\", \"" + node.valueOf("./operator") +
108            "\", \"" + StringFormat.toSafeHTMLString(node.valueOf("./action")) +
109            "\", \"" + StringFormat.toSafeHTMLString(node.valueOf("./result")) +
110            "\", \"" + nextReviewDate +
111            "\", \"" + node.valueOf("./letter") +
112            "\", \"" + node.valueOf("./contact") +
113            "\", \"" + displayOnDefault +
114            "\", \"" + show +
115            "\", \"" + getComments(index) + "\");\n";
116        }
117      }
118      catch(Exception e) {
119        e.printStackTrace();
120      }
121      return historyArray;
122    }
123  
124  
125    /**
126     * Return comments for a node
127     *
128     * @param nodeIdx Description of the Parameter
129     * @return The comments value
130     */
131    public String getComments(int nodeIdx) {
132      // 09252002 tjm - per cr2002072501.0, need to show all comments
133      String comment = "";
134      try {
135        Element root = actionResultHistoryXml.getDocumentElement();
136        NodeList nodeList = root.getChildNodes();
137  
138        XMLNode node = (XMLNode)nodeList.item(nodeIdx);
139        comment = StringFormat.toSafeJavaString(node.valueOf("./comments"));
140      }
141      catch(Exception e) {
142        e.printStackTrace();
143      }
144      return comment;
145    }
146  
147  
148    public int getLength() {
149      int size = 0;
150      try {
151        Element root = actionResultHistoryXml.getDocumentElement();
152        NodeList nodeList = root.getChildNodes();
153        size = nodeList.getLength();
154      }
155      catch(Exception e) {
156        e.printStackTrace();
157      }
158      return size;
159    }
160  }
161  
162