summaryrefslogtreecommitdiffstats
path: root/sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java241
1 files changed, 148 insertions, 93 deletions
diff --git a/sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java b/sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java
index 79d835ecb2..56f3b56ca2 100644
--- a/sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java
+++ b/sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java
@@ -20,11 +20,16 @@
package services;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import java.sql.Date;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.List;
import javax.xml.bind.JAXBContext;
@@ -51,8 +56,9 @@ import com.sun.syndication.io.XmlReader;
public class PlanViewImpl implements PlanView {
- private com.example.ipo.jaxb.Plan _p = null;
+ // private com.example.ipo.jaxb.Plan _p = null;
static String rssPrefix = "http://issues.apache.org/jira/si/jira.issueviews:issue-xml/";
+ static String planFile="src/main/resources/jiraSideBand.xml";
// TUSCANY-1178/TUSCANY-1178.xml
@Init
@@ -60,95 +66,97 @@ public class PlanViewImpl implements PlanView {
}
private Plan getPlan() {
- if (_p == null) {
-
- try {
- JAXBContext jaxbContext = JAXBContext
- .newInstance("com.example.ipo.jaxb");
- Unmarshaller m = jaxbContext.createUnmarshaller();
- File inputFile = new File("src/main/resources/jiraSideBand.xml")
- .getAbsoluteFile();
-
-// Reader r = new XMLReader()
-// InputSource s = new InputSource(r);
- _p = (Plan)m.unmarshal(inputFile);
- augment_plan(_p);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
-
- }
-
+ Plan p = null;
+ try {
+ p = readPlan();
+ augmentPlan(p);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ // FIXME
}
- return _p;
-
+ return p;
}
- private void augment_plan(Plan plan) {
+ private void augmentPlan(Plan plan) {
for(Milestone m : plan.getMilestone()) {
for (WorkItem wi: m.getWorkItem()) {
- String jira = wi.getJira();
- if(jira != null) {
- String feed = rssPrefix += jira + "/" + jira + ".xml";
- JiraData jd = new JiraData();
- wi.setJiraData(jd);
- jd.setID(jira);
-
- try {
- JAXBContext jaxbContext = JAXBContext
- .newInstance("com.example.ipo.jaxb");
- Unmarshaller m2 = jaxbContext.createUnmarshaller();
- InputStream is = null;
- RSS j;
- try{
- URL url = new URL("http://issues.apache.org/jira/si/jira.issueviews:issue-xml/"+jira+"/"+jira+".xml");
- is = url.openStream();
- j = ((JAXBElement<RSS>) m2.unmarshal(is)).getValue();
- }
- finally {
- if(is != null) is.close();
+ augmentWorkItem(wi);
+
+ }
+ }
+ }
+
+ private void augmentWorkItem(WorkItem wi) {
+ String jira = wi.getJira();
+ if(jira != null) {
+ String feed = rssPrefix += jira + "/" + jira + ".xml";
+ JiraData jd = new JiraData();
+ wi.setJiraData(jd);
+ jd.setID(jira);
+
+ try {
+ JAXBContext jaxbContext = JAXBContext
+ .newInstance("com.example.ipo.jaxb");
+ Unmarshaller m2 = jaxbContext.createUnmarshaller();
+ InputStream is = null;
+ RSS jfeed = null;
+ try{
+ URL url = new URL("http://issues.apache.org/jira/si/jira.issueviews:issue-xml/"+jira+"/"+jira+".xml");
+ is = url.openStream();
+ jfeed = ((JAXBElement<RSS>) m2.unmarshal(is)).getValue();
+ }
+ catch (FileNotFoundException e) {
+ String note = wi.getNote();
+ note += ": attempt to reference non-existent JIRA " + jira;
+ wi.setNote(note);
+ wi.setJira(null);
+ wi.setJiraData(null);
+ }
+ finally {
+ if(is != null) is.close();
+ }
+
+ if(jfeed != null) {
+ Item i = jfeed.getChannel().getItem();
+ List<JAXBElement<?>> c = i.getContent();
+ // TODO see if there's a better way to get this data out
+ for (JAXBElement<?> element : c) {
+ if("title".equals(element.getName().getLocalPart())) {
+ String jtitle = (String)element.getValue();
+ jd.setTitle(jtitle.substring(jtitle.indexOf(']')+1, jtitle.length()));
}
-
- Item i = j.getChannel().getItem();
- System.out.println(i.toString());
- List<JAXBElement<?>> c = i.getContent();
- // TODO see if there's a better way to get this data out
- for (JAXBElement<?> element : c) {
- if("title".equals(element.getName().getLocalPart())) {
- String jtitle = (String)element.getValue();
- jd.setTitle(jtitle.substring(jtitle.indexOf(']')+1, jtitle.length()));
- }
- else if("status".equals(element.getName().getLocalPart())){
- jd.setStatus((String)element.getValue());
- }
- else if("assignee".equals(element.getName().getLocalPart())) {
- jd.setAssignedTo((String)element.getValue());
- }
+ else if("status".equals(element.getName().getLocalPart())){
+ jd.setStatus((String)element.getValue());
}
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
-
+ else if("assignee".equals(element.getName().getLocalPart())) {
+ jd.setAssignedTo((String)element.getValue());
+ }
}
}
-
- }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+
+ }
}
}
public Plan get() {
- com.example.ipo.jaxb.Plan modelplan = getPlan();
+ Plan p = getPlan();
+ return p;
+ }
- // dto.Plan dtoplan = new dto.Plan(modelplan);
- return modelplan;
+ public Plan getLite() {
+ Plan p = readPlan();
+ return p;
}
- private Milestone getMS(String id) {
+ private Milestone getMS(Plan p, String id) {
Milestone m = null;
- Plan p = getPlan();
for(Milestone mi : p.getMilestone()) {
if(id.equals(mi.getID())) {
m = mi;
@@ -158,47 +166,94 @@ public class PlanViewImpl implements PlanView {
return m;
}
- public void post(String newMSName,String msChoice, String jira) {
-
- String msName = msChoice;
- Plan p = getPlan();
- if(!"".equals(newMSName)) {
- List<Milestone> mis = p.getMilestone();
- Milestone newm = new Milestone();
- newm.setID(newMSName);
- mis.add(new Milestone());
- msName = newMSName;
- }
+ public void postNewWorkItem(String msid, String jira) {
- Milestone m = getMS(msName);
+ Plan p = readPlan();
+ Milestone m = getMS(p,msid);
WorkItem wi = new WorkItem();
wi.setJira(jira);
+ augmentWorkItem(wi);
m.getWorkItem().add(wi);
-
- writePlan();
+ writePlan(p);
}
- private void writePlan()
+ public void postNewMilestone(String msid) {
+ Plan p = readPlan();
+ if(getMS(p, msid) == null) {
+ List<Milestone> mis = p.getMilestone();
+ Milestone newm = new Milestone();
+ newm.setID(msid);
+ mis.add(newm);
+ writePlan(p);
+ }
+ }
+
+
+ private void writePlan(Plan p)
{
+ FileOutputStream fos = null;
+ String dbPath = null;
+ File existingFile = null;
+ File newFile= null;
+ String backupPath = null;
+
try {
JAXBContext jaxbContext = JAXBContext
.newInstance("com.example.ipo.jaxb");
Marshaller m = jaxbContext.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
- File oldInputFile = new File("src/main/resources/jiraSideBand.xml").getAbsoluteFile();
- String oldPath = oldInputFile.getAbsolutePath();
- oldInputFile.renameTo(new File(oldPath+".old"));
- File outputFile = new File("src/main/resources/jiraSideBand.xml").getAbsoluteFile();
- FileOutputStream fos = new FileOutputStream(outputFile);
+
+ existingFile = new File(planFile).getAbsoluteFile();
+ dbPath = existingFile.getAbsolutePath();
+
+
+ String tempPath = dbPath.substring(0,dbPath.indexOf(".xml"))+".tmp.xml";
+ backupPath = dbPath.substring(0,dbPath.indexOf(".xml"));
+ DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
+ String timestamp = df.format(Calendar.getInstance().getTime());
+ backupPath+= timestamp;
+ backupPath+=".xml";
+
+ newFile = new File(tempPath).getAbsoluteFile();
+ fos = new FileOutputStream(newFile);
- m.marshal(getPlan(), fos);
+ m.marshal(p, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
-
+
}
+
+
+ if(fos!=null)
+ try {
+ fos.close();
+
+ new File(dbPath).renameTo(new File(backupPath));
+ newFile.renameTo(new File(dbPath));
+
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
-
+
+ private Plan readPlan()
+ {
+ Plan p = null;
+ try {
+ JAXBContext jaxbContext = JAXBContext
+ .newInstance("com.example.ipo.jaxb");
+ Unmarshaller m = jaxbContext.createUnmarshaller();
+
+ File inputFile = new File(planFile).getAbsoluteFile();
+ p = (Plan)m.unmarshal(inputFile);
+ } catch(Exception e) {
+ // FIXME
+ }
+ return p;
+ }
} \ No newline at end of file