Eclipseplugins
SendCheckInfoEmail.java
1 package com.proalpha.pds.util;
2 
3 import java.io.StringWriter;
4 import java.io.UnsupportedEncodingException;
5 import java.net.URLEncoder;
6 import java.util.Iterator;
7 
8 import javax.xml.datatype.XMLGregorianCalendar;
9 
10 import org.eclipse.jface.viewers.ISelection;
11 import org.eclipse.jface.viewers.IStructuredSelection;
12 import org.eclipse.swt.program.Program;
13 
14 import com.proalpha.pds.jaxb.DsDSConsistencyChecks.TtDSCheck.TtDSSubCheck.TtDSLogEntryRepos;
15 import com.proalpha.pds.jaxb.DsDSConsistencyChecks.TtDSCheck.TtDSSubCheck.TtDSLogEntrySrc;
16 
17 public class SendCheckInfoEmail {
18 
19  private String objectID = "";
20  private String checkID = "";
21  private String subCheckID = "";
22  private String description = "";
23  private String srcStatement = "";
24  private String line = "";
25  private String module = "";
26  private String reported;
27 
28  public void send(ISelection selection, String paProjectName) {
29  Object object;
30  Iterator<?> it = ((IStructuredSelection) selection).iterator();
31  StringWriter body = new StringWriter();
32 
33  while (it.hasNext()) {
34 
35  object = it.next();
36 
37  if (object instanceof TtDSLogEntrySrc) {
38  TtDSLogEntrySrc entrySrc = (TtDSLogEntrySrc) object;
39  setObjectID(entrySrc.getSourceFileName());
40  setCheckID(entrySrc.getDSCheckID());
41  setSubCheckID(entrySrc.getDSSubCheckID());
42  setReported(entrySrc.getReportedFirst());
43  setSrcStatement(entrySrc.getStatement());
44  setLine(entrySrc.getSourceFileLine());
45  setModule(entrySrc.getModule());
46  setDescription(entrySrc.getLogEntryDescription());
47  } else if (object instanceof TtDSLogEntryRepos) {
48  TtDSLogEntryRepos entryRepos = (TtDSLogEntryRepos) object;
49  setObjectID(entryRepos.getOwningID());
50  setCheckID(entryRepos.getDSCheckID());
51  setSubCheckID(entryRepos.getDSSubCheckID());
52  setReported(entryRepos.getReportedFirst());
53  setSrcStatement("");
54  setLine(0);
55  setModule(entryRepos.getModule());
56  setDescription(entryRepos.getLogEntryDescription());
57  }
58 
59  appendLine(body, getReported());
60  appendLine(body, "CheckID:\t" + getCheckID());
61  appendLine(body, "SubCheckID:\t" + getSubCheckID());
62  appendLine(body, getModule());
63  appendLine(body, getObjectID());
64  appendLine(body, getLine());
65  appendLine(body, "");
66  appendLine(body, getDescription());
67  appendLine(body, "");
68  appendLine(body, getSrcStatement());
69  }
70 
71  String subject = paProjectName + " : " + getSubCheckID() + " (" + getCheckID() + ")";
72  String mailto = "mailto:" + "?subject=" + enc(subject) + "&body=" + enc(body.toString());
73  Program.launch(mailto);
74  }
75 
76  private void appendLine(StringWriter body, String str)
77  {
78  body.append(str).append(System.lineSeparator());
79  }
80 
81  private String enc(String p) {
82  if (p == null)
83  p = "";
84  try {
85  return URLEncoder.encode(p, "UTF-8").replace("+", "%20");
86  } catch (UnsupportedEncodingException e) {
87  throw new RuntimeException();
88  }
89  }
90 
94  private String getDescription() {
95  return description;
96  }
97 
101  private String getModule() {
102  return module;
103  }
104 
108  private String getLine() {
109  return line;
110  }
111 
115  private String getObjectID() {
116  return objectID;
117  }
118 
122  private String getReported() {
123  return reported;
124  }
125 
129  private String getSrcStatement() {
130  return srcStatement;
131  }
132 
136  private String getSubCheckID() {
137  return subCheckID;
138  }
139 
143  private String getCheckID() {
144  return checkID;
145  }
146 
147  private void setDescription(String description) {
148 
149  this.description = "Description:\t" + System.lineSeparator() + description;
150 
151  }
152 
153  private void setModule(String module) {
154 
155  this.module = "Module:\t" + module;
156 
157  }
158 
159  private void setLine(Integer line) {
160  if (line != null) {
161  this.line = "Line:\t\t" + String.valueOf(line);
162  }
163  }
164 
165  private void setObjectID(String objectID) {
166 
167  this.objectID = "Object:\t\t" + objectID;
168 
169  }
170 
171  private void setReported(XMLGregorianCalendar calendar) {
172 
173  this.reported = "Reported:\t" + calendar.getDay() + "."
174  + calendar.getMonth() + "." + calendar.getYear();
175  }
176 
177  private void setSrcStatement(String srcStatement) {
178 
179  this.srcStatement = "Code Fragment: " + System.lineSeparator() + srcStatement;
180 
181  }
182 
183  private void setSubCheckID(String subCheckID) {
184 
185  this.subCheckID = subCheckID;
186  }
187 
188  private void setCheckID(String checkID) {
189 
190  this.checkID = checkID;
191  }
192 }