KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tdsecurities > itracker > converter > IssueConverter


1 /**
2  * Copyright (c) 2003 TD Securities
3  * Created on Dec 31, 2003
4  */

5 package com.tdsecurities.itracker.converter;
6
7 import java.sql.PreparedStatement JavaDoc;
8 import java.sql.ResultSet JavaDoc;
9 import java.sql.SQLException JavaDoc;
10 import java.sql.Timestamp JavaDoc;
11 import java.sql.Types JavaDoc;
12 import java.util.Date JavaDoc;
13
14 import org.apache.log4j.Logger;
15
16 import com.tdsecurities.itracker.common.DataSourceManager;
17
18 /**
19  * @author pardec2
20  * @version $Id$
21  */

22 public class IssueConverter extends BasicConverter
23 {
24     private static final String JavaDoc SOURCE_SQL = "select * from bug";
25     private static final String JavaDoc TARGET_SQL = "insert into issuebean (id,severity,status,resolution,description,create_date,last_modified,target_version_id,creator_id,owner_id,project_id) values (?,?,?,?,?,?,?,?,?,?,?)";
26     private static final String JavaDoc LAST_ID_SQL = "select max(id) from issuebean";
27
28     private int historyId = 1;
29     private Logger log = Logger.getLogger(IssueConverter.class);
30     
31     protected String JavaDoc getSourceQuery()
32     {
33         return SOURCE_SQL;
34     }
35     
36     protected String JavaDoc getTargetQuery()
37     {
38         return TARGET_SQL;
39     }
40
41     protected String JavaDoc getIdStoreName()
42     {
43         return "issue";
44     }
45
46     protected String JavaDoc getLastIdQuery()
47     {
48         return LAST_ID_SQL;
49     }
50
51     protected int prepareTargetStatement(PreparedStatement JavaDoc targetStmt, ResultSet JavaDoc rs) throws Exception JavaDoc
52     {
53         long now = (new Date JavaDoc()).getTime();
54         int col = 1;
55         targetStmt.setInt(col++, rs.getInt("bug_id"));
56         targetStmt.setInt(col++, getSeverity( rs.getInt("priority")));//severity
57
targetStmt.setInt(col++, getStatus( rs));//status
58
targetStmt.setString(col++, getResolution(rs.getInt("resolution_id")));
59         targetStmt.setString(col++, rs.getString("summary"));
60         targetStmt.setTimestamp(col++, getDate(rs,"date"));
61         targetStmt.setTimestamp(col++, new Timestamp JavaDoc(now));
62         targetStmt.setInt(col++, rs.getInt("group_id"));
63         setInt(targetStmt, rs, col++, "submitted_by");
64         setInt(targetStmt, rs, col++, "assigned_to");
65         targetStmt.setInt(col++, rs.getInt("group_id"));
66         return BasicConverter.OK;
67     }
68     
69     protected void additionalProcessing(PreparedStatement JavaDoc stmt, ResultSet JavaDoc rs)
70         throws SQLException JavaDoc
71     {
72         StringBuffer JavaDoc buf = new StringBuffer JavaDoc("insert into issue_component_rel ( issue_id, component_id) values (");
73         buf.append(rs.getInt("bug_id")).append(",");
74         buf.append(rs.getInt("category_id")).append(")");
75         if( rs.getInt("category_id") != 0)
76         {
77             executeUpdate(DataSourceManager.ITRACKER, buf.toString());
78         }
79
80         buf = new StringBuffer JavaDoc("insert into issue_version_rel ( issue_id, version_id) values (");
81         buf.append(rs.getInt("bug_id")).append(",");
82         buf.append(rs.getInt("group_id")).append(")");
83         executeUpdate(DataSourceManager.ITRACKER, buf.toString());
84
85         buf = new StringBuffer JavaDoc("insert into issuehistorybean (id,description,status,create_date,last_modified,issue_id,user_id) values (");
86         buf.append(historyId++).append(",'");
87         buf.append(cleanString(rs.getString("details"))).append("',");
88         buf.append(1).append(",'");
89         buf.append(getFormattedDate(rs, "date")).append("','");
90         buf.append(getFormattedDate(rs, "date")).append("',");
91         buf.append(rs.getInt("bug_id")).append(",");
92         buf.append(rs.getInt("submitted_by")).append(")");
93         executeUpdate(DataSourceManager.ITRACKER, buf.toString());
94     }
95
96     protected void setInt(PreparedStatement JavaDoc stmt, ResultSet JavaDoc rs, int col, String JavaDoc key)
97         throws SQLException JavaDoc
98     {
99         if( rs.getInt(key) == 0)
100         {
101             stmt.setNull(col, Types.INTEGER);
102         }
103         else
104         {
105             stmt.setInt(col, rs.getInt(key));
106         }
107     }
108
109     protected void preConversionProcessing()
110     {
111         log.info("Converting issues...");
112         executeUpdate(DataSourceManager.ITRACKER, "delete from issuebean");
113         executeUpdate(DataSourceManager.ITRACKER, "delete from issuehistorybean");
114         executeUpdate(DataSourceManager.ITRACKER, "delete from issue_component_rel");
115         executeUpdate(DataSourceManager.ITRACKER, "delete from issue_version_rel");
116     }
117     
118     protected void postConversionProcessing()
119     {
120         log.info("Converted issues.");
121     }
122
123     protected int getSeverity(int priority)
124     {
125         int severity = 5;
126         severity = 6 - (int)Math.ceil( (float)priority/2f);
127         return severity;
128     }
129     
130     protected int getStatus(ResultSet JavaDoc rs)
131         throws SQLException JavaDoc
132     {
133         int status = rs.getInt("status_id");
134         int newStatus = 0;
135         switch(status)
136         {
137             case 1: newStatus = 100; break;
138             case 3: newStatus = 500; break;
139             case 100: newStatus = 100; break;
140             case 101: newStatus = 300; break;
141             case 102: newStatus = 330; break;
142             case 105: newStatus = 320; break;
143             case 106: newStatus = 340; break;
144             default: newStatus = 100; break;
145         }
146         if( newStatus == 100)
147         {
148             int owner = rs.getInt("assigned_to");
149             if( owner != 0 && !rs.wasNull())
150             {
151                 newStatus = 300;
152             }
153         }
154         return newStatus;
155     }
156     
157     protected String JavaDoc getResolution(int resolution)
158     {
159         switch(resolution)
160         {
161             case 1: return "Fixed";//Fixed
162
case 2: return "Invalid";//Invalid
163
case 3: return "Won't fix";//Wont Fix
164
case 4: return "Postponed";//Later
165
case 5: return "Postponed";//Remind
166
case 6: return "Works for me";//Works For Me
167
case 100: return "";//None
168
case 101: return "Duplicate";//Duplicate
169
default: return "";
170         }
171     }
172 }
173
Popular Tags