Revision: 15540
Author: pavel.slegr
Date: Mon Nov 29 04:35:58 2010
Log: roadmap plan refactoring
http://code.google.com/p/mobicents/source/detail?r=15540

Added:
/tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/MailSender.java /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/RoadmapPlan.java /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/RoadmapPlanBuilder.java /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/RoadmapPlanEntry.java /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/RoadmapPlanFactory.java /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/RoadmapPlanMaker.java
Modified:
 /tools/productization/branches/trackertool_thin/conf/trackertool.properties
/tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/RoadmapBuilderFactory.java

=======================================
--- /dev/null
+++ /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/MailSender.java Mon Nov 29 04:35:58 2010
@@ -0,0 +1,116 @@
+package org.mobicents.gcode.trackertool.roadmap.plan;
+
+import java.util.*;
+import java.io.*;
+import javax.mail.*;
+import javax.mail.internet.*;
+import javax.activation.*;
+
+public class MailSender
+{
+
+ public static void main(String[] args) {
+  if (args.length != 5)
+  {
+      System.out.println("usage: java sendfile <to> <from> <smtp> <file>");
+      System.exit(1);
+  }
+
+  String to = args[0];
+  String from = args[1];
+  String host = args[2];
+  String filename = args[3];
+  String msgText1 = "Sending a file.\n";
+  String subject = "Sending a file";
+
+  MailSender sender = new MailSender();
+ sender.sendMailWithFileAttachment(to, from, host, subject, msgText1, filename);
+
+ }
+
+ public void sendMailWithFileAttachment(String to, String from, String host,String subject,String msg,File file){
+        List<File> files = new ArrayList<File>();
+        files.add(file);
+        this.sendMailWithFileAttachment_(to, from, host, subject, msg, files);
+
+ }
+
+ public void sendMailWithFileAttachment(String to, String from, String host,String subject,String msg,String filename){
+        File file = new File(filename);
+        List<File> files = new ArrayList<File>();
+        files.add(file);
+        this.sendMailWithFileAttachment_(to, from, host, subject, msg, files);
+
+ }
+
+ public void sendMailWithFileAttachments(String to, String from, String host,String subject,String msg,List<File> files){
+        this.sendMailWithFileAttachment_(to, from, host, subject, msg, files);
+ }
+
+
+
+
+ private void sendMailWithFileAttachment_(String to, String from, String host,String subject,String textMessage,List<File> fileAttachments){
+
+  // create some properties and get the default Session
+  Properties props = System.getProperties();
+  props.put("mail.smtp.host", host);
+
+  Session session = Session.getInstance(props, null);
+
+  try
+  {
+      // create a message
+      MimeMessage msg = new MimeMessage(session);
+      msg.setFrom(new InternetAddress(from));
+      InternetAddress[] address = {new InternetAddress(to)};
+      msg.setRecipients(Message.RecipientType.TO, address);
+      msg.setSubject(subject);
+
+      // create and fill the first message part
+      MimeBodyPart mbp1 = new MimeBodyPart();
+      mbp1.setText(textMessage);
+
+
+      // create the Multipart and add its parts to it
+      Multipart mp = new MimeMultipart();
+      mp.addBodyPart(mbp1);
+
+
+      for(File attachment : fileAttachments){
+          // create the second message part
+          MimeBodyPart mbp2 = new MimeBodyPart();
+
+          // attach the files to the message
+          FileDataSource fds = new FileDataSource(attachment);
+          mbp2.setDataHandler(new DataHandler(fds));
+          mbp2.setFileName(fds.getName());
+
+          // add body part to multipart
+          mp.addBodyPart(mbp2);
+
+
+      }
+
+      // add the Multipart to the message
+      msg.setContent(mp);
+
+      // set the Date: header
+      msg.setSentDate(new Date());
+
+      // send the message
+      Transport.send(msg);
+
+  }
+  catch (MessagingException mex)
+  {
+      mex.printStackTrace();
+      Exception ex = null;
+      if ((ex = mex.getNextException()) != null) {
+         ex.printStackTrace();
+      }
+  }
+    }
+
+}
+
=======================================
--- /dev/null
+++ /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/RoadmapPlan.java Mon Nov 29 04:35:58 2010
@@ -0,0 +1,36 @@
+package org.mobicents.gcode.trackertool.roadmap.plan;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class RoadmapPlan {
+
+       List<RoadmapPlanEntry> planEntries;
+       private String component;
+
+       public RoadmapPlan(String component) {
+               this.component = component;
+               this.planEntries = new ArrayList<RoadmapPlanEntry>();
+       }
+
+       public List<RoadmapPlanEntry> getPlanEntries() {
+               return planEntries;
+       }
+
+       public void setPlanEntries(List<RoadmapPlanEntry> planEntries) {
+               this.planEntries = planEntries;
+       }
+
+       public void addPlanEntry(RoadmapPlanEntry planEntry){
+               this.planEntries.add(planEntry);
+       }
+
+       public void removePlanEntry(RoadmapPlanEntry planEntry){
+               this.planEntries.remove(planEntry);
+       }
+
+       public String getComponent() {
+               return component;
+       }
+
+}
=======================================
--- /dev/null
+++ /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/RoadmapPlanBuilder.java Mon Nov 29 04:35:58 2010
@@ -0,0 +1,136 @@
+package org.mobicents.gcode.trackertool.roadmap.plan;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.mobicents.gcode.trackertool.Template;
+import org.mobicents.gcode.trackertool.TrackerTool;
+import org.mobicents.gcode.trackertool.TrackertoolProperties;
+import org.mobicents.gcode.trackertool.roadmap.Roadmap;
+import org.mobicents.gcode.trackertool.roadmap.RoadmapBuilderFactory;
+import org.mobicents.gcode.trackertool.roadmap.RoadmapEntries;
+import org.mobicents.gcode.trackertool.roadmap.RoadmapEntry;
+
+
+
+
+public class RoadmapPlanBuilder {
+
+       TrackerTool trackerTool;
+       TrackertoolProperties properties;
+
+       static Logger logger = Logger.getLogger(RoadmapPlanBuilder.class);
+
+
+
+       public RoadmapPlanBuilder() {
+               trackerTool = new TrackerTool();
+               properties = TrackertoolProperties.getInstance();
+
+
+       }
+
+
+       public File loadTemplatePlanEntryFile() throws IOException {
+ String location = properties.loadProperty("roadmap.template.file.location"); + String filename = properties.loadProperty("roadmap.template.file.planentry.filename"); + File templateFile = new File(System.getProperty("user.dir") + location + System.getProperty("file.separator")+filename);
+               logger.debug("templatefile abs path:" + 
templateFile.getAbsolutePath());
+               return templateFile;
+       }
+
+       public File loadTemplatePlanFile() throws IOException {
+ String location = properties.loadProperty("roadmap.template.file.location"); + String filename = properties.loadProperty("roadmap.template.file.plan.filename"); + File templateFile = new File(System.getProperty("user.dir") + location + System.getProperty("file.separator")+filename);
+               logger.debug("templatefile abs path:" + 
templateFile.getAbsolutePath());
+               return templateFile;
+       }
+
+       public String getRoadmapPlanFilesLocation() throws IOException {
+               return 
properties.loadProperty("roadmap.plan.roadmap.filelist.location");
+       }
+
+       public List<Roadmap> buildRoadmapPlan(){
+               try {
+                       logger.info(">>> building RoadmapPlan - start");
+                       List<Roadmap> roadmapList = new ArrayList<Roadmap>();
+
+                       // get all RoadmapEtries, we want to create roadmap for
+                       RoadmapEntries roadmapEntries = new RoadmapEntries();
+ Map<String, List<RoadmapEntry>> groupsOfComponents = roadmapEntries.getGroupsOfComponentsSortedRoadmapEntries();
+
+                       for (String component : groupsOfComponents.keySet()) {
+ List<RoadmapEntry> listOfRoadmapEntries = groupsOfComponents.get(component);
+                               //create RoadmapPlan
+ RoadmapPlan roadmapPlan = RoadmapPlanFactory.createRoadmapPlan(component);
+                               for(RoadmapEntry roadmapEntry : 
listOfRoadmapEntries) {
+ RoadmapPlanEntry planEntry = RoadmapPlanFactory.createRoadmapPlanEntry(roadmapEntry.getRoadmapDate(),roadmapEntry.getVersion(),roadmapEntry.getRelease_type());
+                                       roadmapPlan.addPlanEntry(planEntry);
+                               }
+
+                               // process roadmap plans here
+                               // create substitutes map
+                               StringBuffer roadmapPlanEntryBuffer = new 
StringBuffer();
+                               for(RoadmapPlanEntry roadmapPlanEntry : 
roadmapPlan.getPlanEntries()){
+ Map<String,String> substituetesRoadmapPlansEntry = new HashMap<String, String>(); + substituetesRoadmapPlansEntry.put("${plan.version}", roadmapPlanEntry.getReleaseVersion()); + substituetesRoadmapPlansEntry.put("${originally.planned.date}", roadmapPlanEntry.getOriginallyPlanned()); + substituetesRoadmapPlansEntry.put("${actual.release.date}", roadmapPlanEntry.getLastReleaseDate()); + substituetesRoadmapPlansEntry.put("${released.on}", roadmapPlanEntry.getReleasedOn()); + substituetesRoadmapPlansEntry.put("${days.to.release}", String.valueOf(roadmapPlanEntry.getDaysToRelease())); + substituetesRoadmapPlansEntry.put("${delay}", String.valueOf(roadmapPlanEntry.getDaysOfDelay())); + substituetesRoadmapPlansEntry.put("${original.delay}", String.valueOf(roadmapPlanEntry.getDaysOfOriginalDelay()));
+
+
+
+ Template templatePE = new Template(loadTemplatePlanEntryFile(),substituetesRoadmapPlansEntry);
+                                       
roadmapPlanEntryBuffer.append(templatePE.toTemplateString());
+                               }
+
+                               StringBuffer roadmapPlanBuffer = new 
StringBuffer();
+ Map<String,String> substituetesRoadmapPlan = new HashMap<String, String>(); + substituetesRoadmapPlan.put("${template.RoadmapPlanEntryTemplate}", roadmapPlanEntryBuffer.toString());
+                               
substituetesRoadmapPlan.put("${template.component}", component);
+ Template templateP = new Template(loadTemplatePlanFile(),substituetesRoadmapPlan);
+                               
roadmapPlanBuffer.append(templateP.toTemplateString());
+
+                               // handle roadmap plans location
+                               String rpLocation = 
getRoadmapPlanFilesLocation();
+ File rpLocationDir = new File(System.getProperty("user.dir") + rpLocation);
+                               if(!rpLocationDir.exists()) {
+                                       rpLocationDir.mkdir();
+                               }
+                               else if(!rpLocationDir.isDirectory()) {
+                                       throw new Exception ("Not a directory");
+                               }
+                               // write to the roadmap
+                               RoadmapBuilderFactory builderFactory = new 
RoadmapBuilderFactory();
+ File roadmapPlanFile = new File(rpLocationDir + System.getProperty("file.separator")+component+"-roadmap-plan.html");
+                               if(!roadmapPlanFile.exists()) {
+                                       logger.debug("Roadmap Plan file doesn't 
exist, will create new one");
+                                       logger.debug("with path: " + 
roadmapPlanFile.getAbsolutePath());
+                                       roadmapPlanFile.createNewFile();
+                               }
+                               
builderFactory.writeRoadmapPlan(roadmapPlanFile, roadmapPlanBuffer);
+                               roadmapList.add(new 
Roadmap(roadmapPlanBuffer,roadmapPlanFile));
+
+                       }
+                       logger.info(">>> building RoadmapPlan - end");
+                       return roadmapList;
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+                       return null;
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+                       return null;
+               }
+       }
+}
=======================================
--- /dev/null
+++ /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/RoadmapPlanEntry.java Mon Nov 29 04:35:58 2010
@@ -0,0 +1,51 @@
+package org.mobicents.gcode.trackertool.roadmap.plan;
+
+
+public class RoadmapPlanEntry {
+
+       private String originallyPlanned;
+       private String releasedOn;
+       private int daysToRelease;
+       private int daysOfDelay;
+       private int daysOfOriginalDelay;
+       private String releaseVersion;
+       private String lastReleaseDate;
+
+
+ public RoadmapPlanEntry(String originallyPlanned,String lastReleaseDate,String releasedOn,int daysToRelease,int daysOfDelay,int daysOfOriginalDelay, String version) {
+               this.originallyPlanned = originallyPlanned;
+               this.releasedOn = releasedOn;
+               this.daysToRelease = daysToRelease;
+               this.daysOfDelay = daysOfDelay;
+               this.daysOfOriginalDelay = daysOfOriginalDelay;
+               this.releaseVersion = version;
+               this.lastReleaseDate = lastReleaseDate;
+       }
+       public String getOriginallyPlanned() {
+               return originallyPlanned;
+       }
+       public String getReleasedOn() {
+               return releasedOn;
+       }
+       public int getDaysToRelease() {
+               return daysToRelease;
+       }
+       public int getDaysOfDelay() {
+               return daysOfDelay;
+       }
+       public int getDaysOfOriginalDelay() {
+               return daysOfOriginalDelay;
+       }
+       public void setDaysOfOriginalDelay(int daysOfOriginalDelay) {
+               this.daysOfOriginalDelay = daysOfOriginalDelay;
+       }
+       public String getReleaseVersion() {
+               return releaseVersion;
+       }
+       public String getLastReleaseDate() {
+               return lastReleaseDate;
+       }
+
+
+
+}
=======================================
--- /dev/null
+++ /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/RoadmapPlanFactory.java Mon Nov 29 04:35:58 2010
@@ -0,0 +1,88 @@
+package org.mobicents.gcode.trackertool.roadmap.plan;
+
+import java.util.Date;
+
+import org.mobicents.gcode.trackertool.TrackerToolUtils;
+import org.mobicents.gcode.trackertool.roadmap.RoadmapDate;
+
+public class RoadmapPlanFactory {
+
+       public static RoadmapPlan createRoadmapPlan(String component){
+               return new RoadmapPlan(component);
+       }
+
+ public static RoadmapPlanEntry createRoadmapPlanEntry (RoadmapDate roadmapDate, String version, String releaseType){
+               int daysToRelease = 0;
+               int daysOfDelay = 0;
+               int daysOfOriginalDelay = 0;
+
+               //build version + release
+               int version_indexOf = version.indexOf("-");
+               String version_sanitized = version.substring(version_indexOf 
+1);
+               int release_indexOf = releaseType.lastIndexOf("-");
+               String release_sanitized = 
releaseType.substring(release_indexOf +1);
+
+               String releaseVersion = version_sanitized + "-" + 
release_sanitized;
+
+
+
+               Date currentdate = new Date();
+               long currentDateMilliSec = currentdate.getTime();
+
+               //  before release
+               if(roadmapDate.getReleasedOn() == null){
+                       // count days to release
+ long lastReleaseDateMilliSec = roadmapDate.getLastReleaseDate().getTime(); + long diffDaysDaysToRelease = (lastReleaseDateMilliSec - currentDateMilliSec) / (24 * 60 * 60 * 1000); + System.out.println("Time in days to release: " + diffDaysDaysToRelease + " days.");
+
+                       if(diffDaysDaysToRelease >= 0 ){
+                               daysToRelease = Math.abs((int) 
diffDaysDaysToRelease);
+                       }
+                       else{
+                               daysOfDelay = Math.abs((int) 
diffDaysDaysToRelease);
+                       }
+
+                       // count original delay
+ long firstReleaseDateMilliSec = roadmapDate.getOriginallyPlannedDate().getTime(); + long diffDaysOriginalDelay = (firstReleaseDateMilliSec - currentDateMilliSec) / (24 * 60 * 60 * 1000); + System.out.println("Time in days of originall plan delay: " + diffDaysOriginalDelay + " days.");
+
+                       if(diffDaysOriginalDelay < 0 ){
+                               daysOfOriginalDelay = Math.abs((int) 
diffDaysOriginalDelay);
+                       }
+               }
+               // already released
+               else {
+                       long releasedDateMilliSec = 
roadmapDate.getReleasedOn().getTime();
+
+                       // count days of delay
+ long lastReleaseDateMilliSec = roadmapDate.getLastReleaseDate().getTime(); + long diffDaysOfDelay = (releasedDateMilliSec - lastReleaseDateMilliSec) / (24 * 60 * 60 * 1000); + System.out.println("Time in days to release: " + diffDaysOfDelay + " days.");
+                       daysOfDelay = Math.abs((int) diffDaysOfDelay);
+                       if(daysOfDelay <= 0){
+                               daysOfDelay = 0;
+                       }
+
+                       // count original delay
+ long firstReleaseDateMilliSec = roadmapDate.getOriginallyPlannedDate().getTime(); + long diffDaysOriginalDelay = (releasedDateMilliSec - firstReleaseDateMilliSec) / (24 * 60 * 60 * 1000); + System.out.println("Time in days of original plan delay: " + diffDaysOriginalDelay + " days.");
+                       daysOfOriginalDelay = Math.abs((int) 
diffDaysOriginalDelay);
+                       if(daysOfOriginalDelay <= 0){
+                               daysOfOriginalDelay = 0;
+                       }
+               }
+
+
+
+               //TODO finish
+               return new RoadmapPlanEntry(
+                               roadmapDate.getOriginallyPlannedDateString(),
+                               
TrackerToolUtils.formatRoadmapDate(roadmapDate.getLastReleaseDate()),
+                               roadmapDate.getReleasedOnString(),
+                               
daysToRelease,daysOfDelay,daysOfOriginalDelay,releaseVersion);
+       }
+
+}
=======================================
--- /dev/null
+++ /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/plan/RoadmapPlanMaker.java Mon Nov 29 04:35:58 2010
@@ -0,0 +1,42 @@
+package org.mobicents.gcode.trackertool.roadmap.plan;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.mobicents.gcode.trackertool.roadmap.Roadmap;
+
+
+public class RoadmapPlanMaker {
+
+
+       public static void main(String[] args) {
+               try {
+                       new RoadmapPlanMaker().makePlan();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+
+       public void makePlan(){
+               List<Roadmap> roList = new 
RoadmapPlanBuilder().buildRoadmapPlan();
+               MailSender mailSender = new MailSender();
+                 String to = "[email protected]";
+                 //String to = "[email protected]";
+                 String from = "[email protected]";
+                 String host = "smtp.corp.redhat.com";
+ String msg = "This is report for mobicents-core to check, how is the status with roadmaps and plans";
+                 String subject = "mobicents roadmap plan report";
+
+                 List<File> attachments = new ArrayList<File>();
+                 for(Roadmap roadmap : roList){
+                         File attachment = roadmap.getRoadmapFile();
+                         attachments.add(attachment);
+                 }
+
+ mailSender.sendMailWithFileAttachments(to, from, host, subject, msg, attachments);
+
+       }
+
+
+}
=======================================
--- /tools/productization/branches/trackertool_thin/conf/trackertool.properties Thu Nov 25 05:43:22 2010 +++ /tools/productization/branches/trackertool_thin/conf/trackertool.properties Mon Nov 29 04:35:58 2010
@@ -45,8 +45,6 @@
 roadmap.template.file.fix.filename=RoadmapFixTemplate.xml
 roadmap.template.file.main.filename=RoadmapMainTemplate.xml
 roadmap.template.file.released.filename=RoadmapReleasedDivTemplate.xml
-roadmap.template.file.plan.filename=RoadmapPlanTemplate.xml
-roadmap.template.file.planentry.filename=RoadmapPlanEntryTemplate.xml
roadmap.template.roadmap.filelist.location=/trackertool-core/src/main/resources/g-app-templates roadmap.template.roadmap.filelist.filenames=mss-roadmap-template.html,slee-roadmap-template.html,mms-roadmap-template.html,diameter-roadmap-template.html,ssf-roadmap-template.html,msps-roadmap-template.html
 roadmap.template.name.mss-roadmap-template=mss
@@ -66,6 +64,10 @@
 #roadmap incubator properties
roadmap.incubator.location=/trackertool-core/src/main/resources/incubator-templates

+#roadmap plan properties
+roadmap.plan.roadmap.filelist.location=/trackertool-core/src/main/resources/roadmap-plans
+roadmap.template.file.plan.filename=RoadmapPlanTemplate.xml
+roadmap.template.file.planentry.filename=RoadmapPlanEntryTemplate.xml


 ##################
=======================================
--- /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/RoadmapBuilderFactory.java Mon Nov 1 07:47:48 2010 +++ /tools/productization/branches/trackertool_thin/trackertool-core/src/main/java/org/mobicents/gcode/trackertool/roadmap/RoadmapBuilderFactory.java Mon Nov 29 04:35:58 2010
@@ -43,10 +43,10 @@
        }


- public void writeRoadmap (File roadmapFileTemplate,StringBuffer bufferRoadmap,boolean isIncubator) { + public void writeRoadmap (File roadmapFileTemplate,StringBuffer bufferRoadmap,boolean isPathAbsolute) {
                try {
                        File absRoadmapFileTemplate;
-                       if(isIncubator) {
+                       if(isPathAbsolute) {
absRoadmapFileTemplate = new File (roadmapFileTemplate.getAbsolutePath());
                        }
                        else {
@@ -80,4 +80,18 @@
                        e.printStackTrace();
                }
        }
-}
+
+ public void writeRoadmapPlan (File roadmapFilePlan,StringBuffer bufferRoadmap) {
+               try {
+ BufferedWriter out = new BufferedWriter(new FileWriter(roadmapFilePlan));
+               out.write(bufferRoadmap.toString() + "\n");
+               out.close();
+           } catch (IOException e) {
+               e.printStackTrace();
+           } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+       }
+
+}

Reply via email to