diff options
Diffstat (limited to 'sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java')
-rw-r--r-- | sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java | 67 |
1 files changed, 60 insertions, 7 deletions
diff --git a/sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java b/sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java index 5c4f115a6c..79d835ecb2 100644 --- a/sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java +++ b/sandbox/kgoodson/jagg/src/main/java/services/PlanViewImpl.java @@ -20,6 +20,7 @@ package services; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -29,6 +30,7 @@ import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.Unmarshaller; +import javax.xml.bind.Marshaller; import org.oasisopen.sca.annotation.Init; import org.xml.sax.InputSource; @@ -55,7 +57,6 @@ public class PlanViewImpl implements PlanView { @Init public void init() { - } private Plan getPlan() { @@ -70,7 +71,7 @@ public class PlanViewImpl implements PlanView { // Reader r = new XMLReader() // InputSource s = new InputSource(r); - _p = ((JAXBElement<Plan>) m.unmarshal(inputFile)).getValue(); + _p = (Plan)m.unmarshal(inputFile); augment_plan(_p); } catch (Exception e) { e.printStackTrace(); @@ -99,11 +100,6 @@ public class PlanViewImpl implements PlanView { JAXBContext jaxbContext = JAXBContext .newInstance("com.example.ipo.jaxb"); Unmarshaller m2 = jaxbContext.createUnmarshaller(); - - // File inputFile = new File("src/main/resources/exampleJira.xml") - // .getAbsoluteFile(); - // - // RSS j = ((JAXBElement<RSS>) m2.unmarshal(inputFile)).getValue(); InputStream is = null; RSS j; try{ @@ -118,6 +114,7 @@ public class PlanViewImpl implements PlanView { 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(); @@ -148,4 +145,60 @@ public class PlanViewImpl implements PlanView { return modelplan; } + private Milestone getMS(String id) { + + Milestone m = null; + Plan p = getPlan(); + for(Milestone mi : p.getMilestone()) { + if(id.equals(mi.getID())) { + m = mi; + break; + } + } + 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; + } + + Milestone m = getMS(msName); + WorkItem wi = new WorkItem(); + wi.setJira(jira); + m.getWorkItem().add(wi); + + writePlan(); + } + + private void writePlan() + { + 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); + + + m.marshal(getPlan(), fos); + } catch (Exception e) { + e.printStackTrace(); + } finally { + + } + } + + }
\ No newline at end of file |