예제 #1
0
	/**
	 *  普通版填写包的公共部分
	 * @param root	开始节点
	 * @param map	参数map
	 * @param sCycName	循环节点名
	 * @return
	 */
	public Element writeptPublicNode(Element root,HashMap map,String sCycName)
	{
		Element node=null;
		try
		{
			String sName="";
			String sValue="";
			List list=root.getChildren();
			for(int i=0;i<list.size();i++)
			{
				node=(Element)list.get(i);
				sName=node.getName();
				sName=sName.trim();
				sValue=(String)map.get(sName);
				//System.err.println("sName:"+sName+":"+sValue);
				if(sCycName.equals(sName)&&(root.getName()).trim().equals("ReqParamSet"))
				{
					//System.err.println("find cyc node:"+sName );
					return node;
				}
				else if(sValue!=null && !"".equals(sValue) )
					node.setText(sValue);
				node=writeptPublicNode(node,map,sCycName);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
			System.err.println("error:"+ex.getMessage());
		}
		return node;
	}
예제 #2
0
	/*
	 * 递归完成查找
	 * para: Element root 开始查找节点
	 */
	public Element findNode(Element root,String sNodeName)
	{
		Element node =null;
		try
		{
			String sName="";
			List list=root.getChildren();
			for(int i=0;i<list.size();i++)
			{
				node=(Element)list.get(i);
				sName=node.getName();
				sName=sName.trim();
				//System.err.println("node name:"+sName+"-"+sNodeName);
				if(sName.equals(sNodeName))
				{
					System.err.println("find the node:"+sName);
					return node;
				}
				node=findNode(node,sNodeName);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
			System.err.println("error:"+ex.getMessage());
		}
		return node;
	}
예제 #3
0
  /** Reads the XML data and create the data */
  public void readDOMDataElement(Element element, IDataSets datasets) {
    // start with source data
    for (Object child : CodeFragment.getDataElementsOfType(CodeFragment.TYPE.SOURCE, element)) {
      Element code = (Element) child;
      try {
        collectSourceDataFromDOM(code, datasets);
      } catch (Exception e) {
        e.printStackTrace();
        Util.errorMessage(
            "Failed to load source "
                + code.getAttributeValue("name")
                + ", error "
                + e.getMessage());
      }
    }

    // process the data
    for (Object child : CodeFragment.getDataElementsOfType(CodeFragment.TYPE.GENERATED, element)) {
      Element code = (Element) child;
      try {
        processDataFromDOM(code, datasets);
      } catch (Exception e) {
        e.printStackTrace();
        Util.errorMessage("Failed to run process " + e.getMessage());
      }
    }
  }
예제 #4
0
  /**
   * Processes the messages from the server
   *
   * @param message
   */
  private synchronized void processServerMessage(String message) {
    SAXBuilder builder = new SAXBuilder();
    String what = new String();
    Document doc = null;

    try {
      doc = builder.build(new StringReader(message));
      Element root = doc.getRootElement();
      List childs = root.getChildren();
      Iterator i = childs.iterator();
      what = ((Element) i.next()).getName();
    } catch (Exception e) {
    }

    if (what.equalsIgnoreCase("LOGIN") == true) _login(doc);
    else if (what.equalsIgnoreCase("LOGOUT") == true) _logout(doc);
    else if (what.equalsIgnoreCase("MESSAGE") == true) _message(doc);
    else if (what.equalsIgnoreCase("WALL") == true) _wall(doc);
    else if (what.equalsIgnoreCase("CREATEGROUP") == true) _creategroup(doc);
    else if (what.equalsIgnoreCase("JOINGROUP") == true) _joingroup(doc);
    else if (what.equalsIgnoreCase("PARTGROUP") == true) _partgroup(doc);
    else if (what.equalsIgnoreCase("GROUPMESSAGE") == true) _groupmessage(doc);
    else if (what.equalsIgnoreCase("KICK") == true) _kick(doc);
    else if (what.equalsIgnoreCase("LISTUSER") == true) _listuser(doc);
    else if (what.equalsIgnoreCase("LISTGROUP") == true) _listgroup(doc);
  }
예제 #5
0
 /**
  * Process Message from server
  *
  * @param doc
  */
 private void _message(Document doc) {
   Element root = doc.getRootElement();
   Element message = root.getChild("message");
   String sender = message.getChild("sender").getText();
   String mesg = message.getChild("mesg").getText();
   sendMessage(NORMAL, sender + ": " + mesg);
 }
예제 #6
0
  protected String getRallyAPIError(String responseXML) {
    String errorMsg = "";

    try {

      org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder();
      org.jdom.Document doc = bSAX.build(new StringReader(responseXML));
      Element root = doc.getRootElement();

      XPath xpath = XPath.newInstance("//Errors");
      List xlist = xpath.selectNodes(root);

      Iterator iter = xlist.iterator();
      while (iter.hasNext()) {

        Element item = (Element) iter.next();
        errorMsg = item.getChildText("OperationResultError");
      }

    } catch (Exception e) {
      errorMsg = e.toString();
    }

    return errorMsg;
  }
예제 #7
0
 public void save(boolean forcenew) {
   String filename = "";
   if ((m_filename.length() == 0) || forcenew) {
     FileDialog dialog = new FileDialog(new Shell(), SWT.SAVE);
     if (dialog.open() == null) {
       return;
     }
     filename = dialog.getFilterPath() + "/" + dialog.getFileName();
   } else {
     filename = m_filename;
   }
   FileOutputStream fileoutputstream;
   try {
     fileoutputstream = new FileOutputStream(filename);
     writeToStream(fileoutputstream);
     m_filename = filename;
     Element element = new Element("com.metaaps.eoclipse.workflow.filename");
     element.setAttribute("filename", m_filename);
     Util.setConfiguration(element, "filename");
   } catch (FileNotFoundException e) {
     e.printStackTrace();
     Util.errorMessage("Could not access file");
   } catch (IOException e) {
     e.printStackTrace();
     Util.errorMessage("Could not save file");
   }
 }
예제 #8
0
 /**
  * Process kick from server
  *
  * @param doc
  */
 private void _kick(Document doc) {
   Element root = doc.getRootElement();
   Element kick = root.getChild("kick");
   String user = kick.getChild("user").getText();
   String answer = kick.getChild("answer").getText();
   if (answer.equals("OK") == true) sendMessage(SERVER, user + " was kicked from " + _group);
 }
예제 #9
0
	public boolean read(String strRoute, String strElement, int flag) {
		//SAXBuilder builder=new SAXBuilder();
		strText = null;
		try {
			String[] route = new String[4];

			String str = null;
			Document doc = builder.build(xmlFileName);
			Element root = doc.getRootElement();
			Element element = root;

			//创建一个拆分字符串内容的对象,每次返回一项
			StringTokenizer st = new StringTokenizer(strRoute, ":");
			str = st.nextToken();

			while (st.hasMoreTokens()) {
				str = st.nextToken();
				element = element.getChild(str);
			}

			//mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,str);
			element = (Element) element.getParent();
			/*
			 * while(flag!=1) { if(element.removeChild(str))
			 * mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"deleted "+str);
			 * else mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"not
			 * deleted");
			 * 
			 * flag--; }
			 */
			//	mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,element.getName());
			strText = element.getChild(str).getChild(strElement).getText();

		} catch (JDOMException jdome) {
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, xmlFileName
					+ " is not well-formed");

		} catch (IOException ioe) {
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, ioe);

		} catch (NullPointerException nullpe) {
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, "not founded"
					+ "\n" + nullpe);

		} catch (Exception e) {
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, "read no succeed"
					+ "\n" + e);

		}

		if (strText == null) {
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, "not founded");
			return false;
		} else {
			//	mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"strText="+strText);
			return true;
		}

	}
예제 #10
0
 /**
  * Process Partgroup from server
  *
  * @param doc
  */
 private void _partgroup(Document doc) {
   Element root = doc.getRootElement();
   Element part = root.getChild("partgroup");
   String group = part.getChild("group").getText();
   String answer = part.getChild("answer").getText();
   if (group.equals(_group) == true) {
     sendMessage(SERVER, group + ": " + answer);
   }
 }
예제 #11
0
 /**
  * Process Creategroup from server
  *
  * @param doc
  */
 private void _creategroup(Document doc) {
   Element root = doc.getRootElement();
   Element create = root.getChild("creategroup");
   String group = create.getChild("group").getText();
   String answer = create.getChild("answer").getText();
   sendMessage(SERVER, "Group creation is: " + answer);
   if (answer.equals("OK") == true) {
     sendMessage(SERVER, "Group " + group + " joined.");
     _group = group;
   }
 }
예제 #12
0
 /**
  * Process Joingroup from server
  *
  * @param doc
  */
 private void _joingroup(Document doc) {
   Element root = doc.getRootElement();
   Element join = root.getChild("joingroup");
   String group = join.getChild("group").getText();
   String answer = join.getChild("answer").getText();
   sendMessage(SERVER, "JoinGroup: " + answer);
   if (answer.equals("OK") == true) {
     sendMessage(SERVER, "Group " + group + " joined.");
     _group = group;
   }
 }
예제 #13
0
  public List getUserList() {
    List<Map> list = new ArrayList<Map>();

    try {

      /*
      String apiUrl=rallyApiHost+"/user?query="+
      	"((TeamMemberships%20%3D%20https%3A%2F%2Frally1.rallydev.com%2Fslm%2Fwebservice%2F1.34%2Fproject%2F6169133135)%20or%20"+
      	"(TeamMemberships%20%3D%20https%3A%2F%2Frally1.rallydev.com%2Fslm%2Fwebservice%2F1.34%2Fproject%2F6083311244))"+
      	"&fetch=true&order=Name&start=1&pagesize=100";
      */

      String apiUrl =
          rallyApiHost
              + "/user?query=(Disabled%20=%20false)"
              + "&fetch=true&order=Name&start=1&pagesize=100";

      log.info("apiUrl=" + apiUrl);

      String responseXML = getRallyXML(apiUrl);

      org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder();
      org.jdom.Document doc = bSAX.build(new StringReader(responseXML));
      Element root = doc.getRootElement();

      XPath xpath = XPath.newInstance("//Object");
      List xlist = xpath.selectNodes(root);

      Iterator iter = xlist.iterator();
      while (iter.hasNext()) {

        Map map = new HashMap();

        Element item = (Element) iter.next();

        String userRef = item.getAttribute("ref").getValue();
        String userName = item.getAttribute("refObjectName").getValue();
        String userObjectId = item.getChildText("ObjectID");

        map.put("userRef", userRef);
        map.put("userObjectId", userObjectId);
        map.put("userName", userName);

        list.add(map);
      }

    } catch (Exception ex) {
      log.error("", ex);
    }

    return list;
  }
예제 #14
0
  /**
   * Process listuser from server
   *
   * @param doc
   */
  private void _listuser(Document doc) {
    StringBuffer userlist = new StringBuffer();

    Element root = doc.getRootElement();
    Element list = root.getChild("listuser");
    List users = list.getChildren("user");
    Iterator i = users.iterator();
    while (i.hasNext()) {
      userlist.append(((Element) i.next()).getText());
      userlist.append("\n");
    }
    sendMessage(SERVER, "Users: \n" + userlist);
  }
예제 #15
0
  public void readDOMElement(Element element) {
    String label = element.getAttribute("name").getValue();
    m_name = label;
    Attribute idelement = element.getAttribute("id");
    if (idelement != null) {
      setId(idelement.getValue());
    }
    Element datasetselements = (Element) element.getChild(IDataSets.class.getName());
    readDOMDataElement(datasetselements, getDataSets());

    Element exportselements = (Element) element.getChild(IExportItem.class.getName());
    if (exportselements != null) {}
  }
예제 #16
0
 public void fillDOMElement(Element element) {
   element.setAttribute("name", getLabel());
   element.setAttribute("id", getId());
   for (Object obj : getChildren()) {
     if (obj instanceof IDataSets) {
       Element dataset = new Element(IDataSets.class.getName());
       element.addContent(dataset);
       for (Object dataobj : ((IDataSets) obj).getChildren()) {
         if (dataobj instanceof IDataContent) {
           CodeFragment code = ((IDataContent) dataobj).getCode();
           dataset.addContent(code);
         }
       }
     }
   }
 }
예제 #17
0
	/**
	 * 
	 * @param 普通版list	参数列表
	 */
	public void writeptParaList(ArrayList list)
	{
		
		try {
			String sCaseName="";
			String sItem="";
			String sCycName="";
			HashMap map=null;
			Document doc = builder.build(xmlFileName);
			Element root = doc.getRootElement();
			Element element = root;
			Element cycNode=null;
			
			map=(HashMap)list.get(0);	//参数文件map
			sItem="Description";
			sCaseName=(String)map.get(sItem);
			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, "Description=" + sCaseName );
		
			sItem="CysName";
			sCycName=(String)map.get(sItem);
			
			map=(HashMap)list.get(1);	//public 参数map
			cycNode=writeptPublicNode(element,map,sCycName);
			
			if( writeCycNode(cycNode,list)==false)	//循环 参数
			  System.err.println(" write cyc node fail");
			
			XMLOutputter outputter = new XMLOutputter("", false, "GB2312");
			PrintWriter out = new PrintWriter(new BufferedWriter(
					new FileWriter(xmlFileName)));

			Document myDocument = root.getDocument();
			outputter.output(myDocument, out);
			out.close();

		} catch (JDOMException jdome) {
			jdome.printStackTrace();
		} catch (IOException ioe) {
			ioe.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
예제 #18
0
  public List getProjectList() {
    List<Map> list = new ArrayList<Map>();

    try {

      String apiUrl = rallyApiHost + "/project?" + "fetch=true&order=Name&start=1&pagesize=200";

      log.info("rallyApiUrl:" + apiUrl);

      String responseXML = getRallyXML(apiUrl);

      org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder();
      org.jdom.Document doc = bSAX.build(new StringReader(responseXML));
      Element root = doc.getRootElement();

      XPath xpath = XPath.newInstance("//Object");
      List xlist = xpath.selectNodes(root);

      Iterator iter = xlist.iterator();
      while (iter.hasNext()) {

        Map map = new HashMap();

        Element item = (Element) iter.next();
        String objId = item.getChildText("ObjectID");
        String name = item.getChildText("Name");
        String state = item.getChildText("State");

        map.put("objId", objId);
        map.put("name", name);
        map.put("state", state);

        list.add(map);
      }

    } catch (Exception ex) {
      log.error("ERROR: ", ex);
    }

    return list;
  }
예제 #19
0
  private void collectSourceDataFromDOM(Element code, IDataSets dataset) throws Exception {
    // get code fragment
    CodeFragment.TYPE type = CodeFragment.TYPE.valueOf(code.getAttributeValue("type"));
    if (type == CodeFragment.TYPE.SOURCE) {
      String dataname = code.getAttributeValue("name");
      String dataid = code.getAttributeValue("dataid");
      // check import method and reader
      Element importelement = code.getChild(IImport.class.getName());
      Element readerelement = code.getChild(IReader.class.getName());
      // get URI
      String URI = importelement.getAttributeValue("URI");
      String scheme = (new URI(URI)).getScheme();
      // look for a suitable import method
      IImports allimports = WorkFlowManager.getInstance().getImports();
      IImportMethod importmethod = allimports.findImport(scheme);
      if (importmethod == null) {
        Util.errorMessage("Could not find suitable import for scheme '" + scheme + "'");
        return;
      }
      IImport method = importmethod.getImport();
      method.setURI(URI);
      // get reader
      String readername = readerelement.getAttributeValue("name");
      String format = readerelement.getAttributeValue("format");
      String readertype = readerelement.getAttributeValue("datatype");
      IReaders allreaders = WorkFlowManager.getInstance().getReaders();
      IReader reader = allreaders.findReaderWithName(readername);
      if (reader == null) {
        Util.errorMessage("Could not find reader " + readername);
        return;
      }
      reader.setType(readertype);
      reader.setDataFormat(format);
      reader.setType(readertype);

      dataset.importDataContent(method, reader, dataname, dataid);
    }
  }
예제 #20
0
	/** 
	 * 
	 * @param map	需要写入的参数map
	 * @param start 开始节点
	 * @param bNew  是否新增节点再写入参数
	 * @return
	 */
	public void writeParaMap(Element start,HashMap map)
	{
		try
		{
			String sName="";
			String sValue="";
			Element node=null;
			List list=start.getChildren();
			for(int i=0;i<list.size();i++)
			{
				node=(Element)list.get(i);
				sName=node.getName();
				sName=sName.trim();
				sValue=(String)map.get(sName);
				if(sValue!=null && !"".equals(sValue) );
					node.setText(sValue);
			}
		}catch(Exception ex)
		{
			ex.printStackTrace();
			System.err.println("error:"+ex.getMessage());
		}
		return ;
	}
예제 #21
0
 /**
  * Process Groupmessage from server
  *
  * @param doc
  */
 private void _groupmessage(Document doc) {
   Element root = doc.getRootElement();
   Element message = root.getChild("groupmessage");
   String group = message.getChild("group").getText();
   String sender = message.getChild("sender").getText();
   String mesg = message.getChild("mesg").getText();
   if (group.equals(_group) == true) {
     sendMessage(NORMAL, group + "(" + sender + "): " + mesg);
   }
 }
예제 #22
0
 public Document getDoc() {
   Element root = new Element("isotime");
   Document doc = new Document(root);
   // un noeud game
   Element node1 = new Element("time");
   node1.setAttribute("beginTime", String.valueOf(beginTime));
   // Actualisation of acctualTime
   node1.setAttribute("day", String.valueOf(getDay()));
   node1.setAttribute("hour", String.valueOf(getHour()));
   node1.setAttribute("min", String.valueOf(getMin()));
   node1.setAttribute("sec", String.valueOf(getSec()));
   root.addContent(node1);
   return doc;
 }
예제 #23
0
  /**
   * Process listgroup from server
   *
   * @param doc
   */
  private void _listgroup(Document doc) {
    StringBuffer grouplist = new StringBuffer();

    Element root = doc.getRootElement();
    Element list = root.getChild("listgroup");
    List groups = list.getChildren("group");
    Iterator i = groups.iterator();
    while (i.hasNext()) {
      Element temp = (Element) i.next();
      grouplist.append(temp.getChild("name").getText());
      grouplist.append("\t");
      grouplist.append(temp.getChild("description").getText());
      grouplist.append("\n");
    }
    sendMessage(SERVER, "Groups: \n" + grouplist);
  }
예제 #24
0
	/**
	 *  新增循环节点
	 * @param cycNode 循环节点
	 * @return
	 */
	public Element addCycNode(Element cycNode)
	{
		Element node=cycNode;
		Element child=null;
		Element newNode=null;
		Element tmpNode=null;
		String sName="";
		if(cycNode==null)
			return newNode;
		newNode=new Element(node.getName());
		node.getParent().addContent(newNode);
		List cList=node.getChildren();
		for(int i=0;i<cList.size();i++)
		{
			child=(Element)cList.get(i);
			sName=child.getName();
			sName=sName.trim();
			tmpNode=new Element(sName);
			newNode.addContent(tmpNode);
		}
		return newNode;
	}
예제 #25
0
	//改写XML文件的某一元素的值
	//strRoute为XML文件从根元素开始到该元素的父元素的路径
	//strElement为需要读取的元素
	//flag为当XML含有多个同名元素时,需要改写元素所处的序号
	public void write(String strRoute, String strElement, String strSet,
			int flag) {
		//SAXBuilder builder=new SAXBuilder();
		try {
			String str = null;
			Document doc = builder.build(xmlFileName);
			Element root = doc.getRootElement();
			Element element = root;

			StringTokenizer st = new StringTokenizer(strRoute, ":");
			str = st.nextToken();

			while (st.hasMoreTokens()) {
				str = st.nextToken();
				//mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,str);
				element = element.getChild(str);

			}

			//	mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"test :"+str);
			element = (Element) element.getParent();

			//若需要改写的不是XML文件的第一个同名元素,则获取该元素
			//方法为:将之前的元素依次移到后面,需要改写的元素前移至第一个
			/*
			 * if(flag>1) { int j=flag; while(j!=1) {
			 * 
			 * Element tmp=element.getChild(str);
			 * element.addContent(tmp.detach()); j--; } }
			 */
			element = element.getChild(str).getChild(strElement);

			//	mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,"gettxt
			// "+element.getText());

			element.setText(strSet);

			//若需要改写的不是XML文件的第一个同名元素
			//上面改变了次序,需要在成功改写后恢复原有次序
			/*
			 * if(flag!=1) {
			 * 
			 * java.util.List children=element.getChildren(); Iterator
			 * iterator=children.iterator(); int count=0;
			 * while(iterator.hasNext()) { Element
			 * child=(Element)iterator.next(); count++; }
			 * 
			 * System.out.println("count"+count);
			 * 
			 * k=(count+1-flag)%count;
			 * 
			 * while(k!=0) { Element tmp=element.getChild(str);
			 * element.addContent(tmp.detach()); k--; } }
			 *  
			 */
			XMLOutputter outputter = new XMLOutputter("", false, "GB2312");
			PrintWriter out = new PrintWriter(new BufferedWriter(
					new FileWriter(xmlFileName)));

			Document myDocument = root.getDocument();

			outputter.output(myDocument, out);
			out.close();

		} catch (JDOMException jdome) {
			jdome.printStackTrace();
//			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, xmlFileName
//					+ " is not well-formed\n");

		} catch (IOException ioe) {
			ioe.printStackTrace();
//			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP, ioe);

		} catch (Exception e) {
			e.printStackTrace();
//			mypage.FcfeMain.wR(mypage.FcfeMain.SIM_APP_ERP,
//					"write not succeed\n");

		}

	}
예제 #26
0
  public List getUserTimeSpentByDate(String userObjectId, String startDate, String endDate) {
    List list = new ArrayList();

    log.info("userObjectId=" + userObjectId);
    log.info("startDate=" + startDate);
    log.info("endDate=" + endDate);

    try {

      String apiUrl =
          rallyApiHost
              + "/timeentryvalue?query=((TimeEntryItem.User.ObjectId%20=%20"
              + userObjectId
              + ")"
              + "%20and%20((DateVal%20%3E=%20"
              + startDate
              + ")%20and%20(DateVal%20%3C=%20"
              + endDate
              + ")))"
              + "&start=1&pagesize=100&fetch=true";

      log.info("apiUrl=" + apiUrl);

      String responseXML = getRallyXML(apiUrl);

      log.info("responseXML=" + responseXML);

      org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder();
      org.jdom.Document doc = bSAX.build(new StringReader(responseXML));
      Element root = doc.getRootElement();

      XPath xpath = XPath.newInstance("//Object");
      List xlist = xpath.selectNodes(root);

      Iterator iter = xlist.iterator();
      while (iter.hasNext()) {

        // Map map=new HashMap();

        Element item = (Element) iter.next();

        String hours = item.getChildText("Hours");

        Element timeEntryItemElement = item.getChild("TimeEntryItem");
        String timeEntryItemRef = timeEntryItemElement.getAttributeValue("ref");

        Map map = getUserStoryTaskMap(timeEntryItemRef);

        String checkTaskId = (String) map.get("taskFormattedId");

        boolean isExist = false;
        for (int i = 0; i < list.size(); i++) {
          Map existMap = (Map) list.get(i);

          log.info("existMap=" + existMap);

          String existTaskId = (String) existMap.get("taskFormattedId");

          log.info("existTaskId=" + existTaskId);
          log.info("checkTaskId=" + checkTaskId);

          if (existTaskId != null && existTaskId.equals(checkTaskId)) {
            isExist = true;
            String existHours = (String) existMap.get("hours");
            double eHour = 0.0D;
            if (!"".equals(existHours)) {
              eHour = Double.parseDouble(existHours);
            }
            double nHour = 0.0D;

            if (!"".equals(hours)) {
              nHour = Double.parseDouble(hours);
            }

            log.info("nHour=" + nHour);
            log.info("eHour=" + eHour);

            nHour += eHour;
            log.info("2 nHour=" + nHour);
            existMap.put("hours", "" + nHour);

            break;
          }
        }

        if (!isExist) {
          map.put("hours", hours);
          list.add(map);
        }

        log.info("hours=" + hours);
        log.info("timeEntryItemRef=" + timeEntryItemRef);

        // list.add(map);

      }

      Collections.sort(
          list,
          new Comparator<Map<String, String>>() {
            public int compare(Map<String, String> m1, Map<String, String> m2) {
              if (m1.get("projectName") == null || m2.get("projectName") == null) return -1;
              return m1.get("projectName").compareTo(m2.get("projectName"));
            }
          });

      // Sum up the total time
      double totalTaskEstimate = 0.0D;
      double totalTaskRemaining = 0.0D;
      double totalHours = 0.0D;
      for (int i = 0; i < list.size(); i++) {
        Map map = (Map) list.get(i);

        log.info("taskEstimate=" + (String) map.get("taskEstimate"));
        log.info("taskRemaining=" + (String) map.get("taskRemaining"));
        log.info("hours=" + (String) map.get("hours"));

        log.info("map==" + map);

        try {
          double taskEstimate = Double.parseDouble((String) map.get("taskEstimate"));
          double taskRemaining = Double.parseDouble((String) map.get("taskRemaining"));
          double hours = Double.parseDouble((String) map.get("hours"));

          totalTaskEstimate += taskEstimate;
          totalTaskRemaining += taskRemaining;
          totalHours += hours;
        } catch (Exception e) {
          log.info("ERROR in parsing number" + e);
        }
      }

      Map firstMap = new HashMap();

      firstMap.put("taskFormattedId", "");
      firstMap.put("taskName", "");
      firstMap.put("taskState", "");
      firstMap.put("owner", "");
      firstMap.put("taskEstimate", "" + totalTaskEstimate);
      firstMap.put("taskRemaining", "" + totalTaskRemaining);
      firstMap.put("hours", "" + totalHours);
      firstMap.put("projectName", "");
      firstMap.put("iterationName", "");

      list.add(0, firstMap);

    } catch (Exception ex) {
      log.error("", ex);
    }

    return list;
  }
예제 #27
0
  public List getIterationList(String projectId) {
    List<Map> list = new ArrayList<Map>();

    try {

      String apiUrl =
          rallyApiHost
              + "/iteration?"
              + "project="
              + rallyApiHost
              + "/project/"
              + projectId
              + "&fetch=true&order=Name%20desc&start=1&pagesize=100";

      String checkProjectRef = rallyApiHost + "/project/" + projectId;

      log.info("rallyApiUrl:" + apiUrl);
      log.info("checkProjectRef:" + checkProjectRef);

      String responseXML = getRallyXML(apiUrl);

      SimpleDateFormat ISO8601FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
      Date currentDate = new Date();

      org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder();
      org.jdom.Document doc = bSAX.build(new StringReader(responseXML));
      Element root = doc.getRootElement();

      XPath xpath = XPath.newInstance("//Object");
      List xlist = xpath.selectNodes(root);

      Iterator iter = xlist.iterator();
      while (iter.hasNext()) {

        Map map = new HashMap();

        Element item = (Element) iter.next();
        String objId = item.getChildText("ObjectID");
        String name = item.getChildText("Name");
        String state = item.getChildText("State");

        String startDateStr = item.getChildText("StartDate");
        String endDateStr = item.getChildText("EndDate");

        Date startDate = ISO8601FORMAT.parse(startDateStr);
        Date endDate = ISO8601FORMAT.parse(endDateStr);

        boolean isCurrent = false;

        int startCheck = startDate.compareTo(currentDate);
        int endCheck = endDate.compareTo(currentDate);

        if (startCheck < 0 && endCheck > 0) {
          isCurrent = true;
        }

        log.info("name=" + name + " isCurrent=" + isCurrent);

        String releaseRef = item.getAttribute("ref").getValue();

        // In child project, parent object have to be filiered
        Element projectElement = item.getChild("Project");
        String projectRef = projectElement.getAttributeValue("ref");

        if (projectRef.equals(checkProjectRef)) {

          map.put("objId", objId);
          map.put("rallyRef", releaseRef);
          map.put("name", name);
          map.put("state", state);
          map.put("isCurrent", "" + isCurrent);

          list.add(map);
        }
      }

      log.info("-----------");

    } catch (Exception ex) {
      log.error("ERROR: ", ex);
    }

    return list;
  }
예제 #28
0
  // public List getUserStoryList(String sessionId,String iterationId,ServletOutputStream out) {
  public List getUserStoryList(String sessionId, String iterationId, PrintWriter out) {

    List<Map> list = new ArrayList<Map>();

    statusMap.put(sessionId, "0");

    try {

      String apiURL =
          rallyApiHost
              + "/hierarchicalrequirement?"
              + "query=(Iteration%20=%20"
              + rallyApiHost
              + "/iteration/"
              + iterationId
              + ")&fetch=true&start=1&pagesize=100";

      log.info("getUserStoryList apiURL=" + apiURL);

      String responseXML = getRallyXML(apiURL);

      org.jdom.input.SAXBuilder bSAX = new org.jdom.input.SAXBuilder();
      org.jdom.Document doc = bSAX.build(new StringReader(responseXML));
      Element root = doc.getRootElement();

      XPath xpath = XPath.newInstance("//Object");
      List xlist = xpath.selectNodes(root);

      int totalSteps = xlist.size() + 1;
      int currentStep = 0;

      List taskRefLink = new ArrayList();

      Iterator iter = xlist.iterator();
      while (iter.hasNext()) {
        double totalTimeSpent = 0.0D;

        Map map = new HashMap();

        Element item = (Element) iter.next();
        String objId = item.getChildText("ObjectID");
        String name = item.getChildText("Name");
        String planEstimate = item.getChildText("PlanEstimate");
        String formattedId = item.getChildText("FormattedID");

        String taskActualTotal = item.getChildText("TaskActualTotal");
        String taskEstimateTotal = item.getChildText("TaskEstimateTotal");
        String taskRemainingTotal = item.getChildText("TaskRemainingTotal");
        String scheduleState = item.getChildText("ScheduleState");

        Element ownerElement = item.getChild("Owner");

        String owner = "";
        String ownerRef = "";

        if (ownerElement != null) {
          owner = ownerElement.getAttributeValue("refObjectName");
        }

        Element taskElements = item.getChild("Tasks");
        // List taskElementList=taskElements.getContent();
        List taskElementList = taskElements.getChildren();

        List taskList = new ArrayList();

        log.info("taskElements.getChildren=" + taskElements);
        log.info("taskList=" + taskElementList);

        for (int i = 0; i < taskElementList.size(); i++) {
          Element taskElement = (Element) taskElementList.get(i);

          String taskRef = taskElement.getAttributeValue("ref");

          String[] objectIdArr = taskRef.split("/");
          String objectId = objectIdArr[objectIdArr.length - 1];

          log.info("objectId=" + objectId);

          // Map taskMap=getTaskMap(taskRef);
          Map taskMap = getTaskMapBatch(objectId);

          double taskTimeSpentTotal =
              Double.parseDouble((String) taskMap.get("taskTimeSpentTotal"));
          totalTimeSpent += taskTimeSpentTotal;
          taskList.add(taskMap);
        }

        map.put("type", "userstory");
        map.put("formattedId", formattedId);
        map.put("name", name);
        map.put("taskStatus", scheduleState);
        map.put("owner", owner);
        map.put("planEstimate", planEstimate);
        map.put("taskEstimateTotal", taskEstimateTotal);
        map.put("taskRemainingTotal", taskRemainingTotal);
        map.put("taskTimeSpentTotal", "" + totalTimeSpent);

        list.add(map);
        list.addAll(taskList);

        ++currentStep;
        double percentage = 100.0D * currentStep / totalSteps;
        String status = "" + Math.round(percentage);
        statusMap.put(sessionId, status);

        out.println("<script>parent.updateProcessStatus('" + status + "%')</script>" + status);
        out.flush();
        log.info("out.flush..." + status);

        // log.info("status="+status+" sessionId="+sessionId);
        // log.info("L1 statusMap="+statusMap+" "+statusMap.hashCode());

      }

      double planEstimate = 0.0D;
      double taskEstimateTotal = 0.0D;
      double taskRemainingTotal = 0.0D;
      double taskTimeSpentTotal = 0.0D;
      Map iterationMap = new HashMap();
      for (Map map : list) {
        String type = (String) map.get("type");

        String planEstimateStr = (String) map.get("planEstimate");

        log.info("planEstimateStr=" + planEstimateStr);

        if ("userstory".equals(type)) {

          if (planEstimateStr != null) {
            planEstimate += Double.parseDouble(planEstimateStr);
          }
          taskEstimateTotal += Double.parseDouble((String) map.get("taskEstimateTotal"));
          taskRemainingTotal += Double.parseDouble((String) map.get("taskRemainingTotal"));
          taskTimeSpentTotal += Double.parseDouble((String) map.get("taskTimeSpentTotal"));
        }
      }

      apiURL = rallyApiHost + "/iteration/" + iterationId + "?fetch=true";
      log.info("iteration apiURL=" + apiURL);
      responseXML = getRallyXML(apiURL);

      bSAX = new org.jdom.input.SAXBuilder();
      doc = bSAX.build(new StringReader(responseXML));
      root = doc.getRootElement();

      xpath = XPath.newInstance("//Iteration");
      xlist = xpath.selectNodes(root);

      String projName = "";
      String iterName = "";
      String iterState = "";

      iter = xlist.iterator();
      while (iter.hasNext()) {
        Element item = (Element) iter.next();

        iterName = item.getChildText("Name");
        iterState = item.getChildText("State");
        Element projElement = item.getChild("Project");
        projName = projElement.getAttributeValue("refObjectName");
      }

      iterationMap.put("type", "iteration");
      iterationMap.put("formattedId", "");
      iterationMap.put("name", projName + " - " + iterName);
      iterationMap.put("taskStatus", iterState);
      iterationMap.put("owner", "");

      iterationMap.put("planEstimate", "" + planEstimate);
      iterationMap.put("taskEstimateTotal", "" + taskEstimateTotal);
      iterationMap.put("taskRemainingTotal", "" + taskRemainingTotal);
      iterationMap.put("taskTimeSpentTotal", "" + taskTimeSpentTotal);

      list.add(0, iterationMap);

      statusMap.put(sessionId, "100");

      log.info("L2 statusMap=" + statusMap);

      log.info("L2 verify=" + getProcessStatus(sessionId));
      log.info("-----------");

      // String jsonData=JsonUtil.encodeObj(list);
      String jsonData = JSONValue.toJSONString(list);

      out.println("<script>parent.tableResult=" + jsonData + "</script>");
      out.println("<script>parent.showTableResult()</script>");

    } catch (Exception ex) {
      log.error("ERROR: ", ex);
    }

    return list;
  }
예제 #29
0
 /**
  * Process Logout from server
  *
  * @param doc
  */
 private void _logout(Document doc) {
   Element root = doc.getRootElement();
   Element logout = root.getChild("logout");
   String answer = logout.getChild("answer").getText();
   sendMessage(SERVER, "Logout is: " + answer);
 }
예제 #30
0
 /**
  * Process Wall from server
  *
  * @param doc
  */
 private void _wall(Document doc) {
   Element root = doc.getRootElement();
   Element wall = root.getChild("wall");
   String mesg = wall.getChild("mesg").getText();
   sendMessage(SERVER, mesg);
 }