From 38aee9dbfbb414a347797fb199b08f281a00fbfb Mon Sep 17 00:00:00 2001 From: kelvingoodson Date: Tue, 2 Feb 2010 15:12:33 +0000 Subject: basically complete but needs error handling and tidying git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@905668 13f79535-47bb-0310-9956-ffa450edef68 --- .../jagg/src/main/java/services/PlanView.java | 4 +- .../jagg/src/main/java/services/PlanViewImpl.java | 241 +++++++++++++-------- .../jagg/src/main/resources/JiraSideband.xml | 32 +++ .../jagg/src/main/resources/uiservices/plan.html | 38 ++-- 4 files changed, 204 insertions(+), 111 deletions(-) (limited to 'sandbox/kgoodson/jagg') diff --git a/sandbox/kgoodson/jagg/src/main/java/services/PlanView.java b/sandbox/kgoodson/jagg/src/main/java/services/PlanView.java index 101e1d1e01..ffb68270da 100644 --- a/sandbox/kgoodson/jagg/src/main/java/services/PlanView.java +++ b/sandbox/kgoodson/jagg/src/main/java/services/PlanView.java @@ -31,6 +31,8 @@ import com.example.ipo.jaxb.Plan; public interface PlanView { Plan get(); - void post(String newMSName,String msChoice, String jira); + Plan getLite(); // don't go off to issue site - use cached properties + void postNewWorkItem(String msChoice, String jira); + void postNewMilestone(String newMSName); } \ No newline at end of file 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) 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) 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> 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> 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 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 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 diff --git a/sandbox/kgoodson/jagg/src/main/resources/JiraSideband.xml b/sandbox/kgoodson/jagg/src/main/resources/JiraSideband.xml index d7a473763e..783e97810f 100644 --- a/sandbox/kgoodson/jagg/src/main/resources/JiraSideband.xml +++ b/sandbox/kgoodson/jagg/src/main/resources/JiraSideband.xml @@ -48,6 +48,30 @@ Unassigned + + TUSCANY-1256 + + NullPointerException when component reference has target of composite reference + Resolved + Simon Nash + + + + TUSCANY-1258 + + WS services fail with: TransformationException: No wrapper handler is provided for databinding: null + Closed + Unassigned + + + + TUSCANY-1129 + + Multiple Inheritance Broken In Generator Templates + Open + Unassigned + + @@ -74,6 +98,14 @@ Unassigned + + TUSCANY-1257 + + DatabindingTestCase fails with java.lang.IllegalArgumentException + Resolved + Raymond Feng + + diff --git a/sandbox/kgoodson/jagg/src/main/resources/uiservices/plan.html b/sandbox/kgoodson/jagg/src/main/resources/uiservices/plan.html index a26049f958..2b33988c00 100644 --- a/sandbox/kgoodson/jagg/src/main/resources/uiservices/plan.html +++ b/sandbox/kgoodson/jagg/src/main/resources/uiservices/plan.html @@ -36,7 +36,10 @@ } ms = plan.milestone.list; var mscontent = ""; - var mschoice = 'in Milestone

"; - mschoice += ''; + mschoice += ''; document.getElementById('milestones').innerHTML='

' + mscontent; - - - var newmscontent = - '
'+ - '
'+ - 'Add new Work Item for JIRA: '+ 'in Milestone '+mschoice+ - '
'+ - '
Add New Milestone '+ - '
'+ - '' - '
'; - document.getElementById('addPlanData').innerHTML=newmscontent; + document.getElementById('mschoice').innerHTML=mschoice; return; } @@ -106,7 +98,6 @@ function plan_postNewWorkItem_response() { - // refresh planView.getLite().addCallback(plan_getResponse); } @@ -136,8 +127,21 @@ - - +
+
+ + + + +
+
+
+ Add New Milestone +
+ +
+
+
\ No newline at end of file -- cgit v1.2.3