public String _path(String args[]) { List<String> list = new ArrayList<String>(); for (int i = 1; i < args.length; i++) { list.addAll(Processor.split(args[i])); } return Processor.join(list, File.pathSeparator); }
/** * Finds all files in folder and in it's sub-tree of specified depth. * * @param file Starting folder * @param maxDepth Depth of the tree. If 1 - just look in the folder, no sub-folders. * @param filter file filter. * @return List of found files. */ public static List<VisorLogFile> fileTree(File file, int maxDepth, @Nullable FileFilter filter) { if (file.isDirectory()) { File[] files = (filter == null) ? file.listFiles() : file.listFiles(filter); if (files == null) return Collections.emptyList(); List<VisorLogFile> res = new ArrayList<>(files.length); for (File f : files) { if (f.isFile() && f.length() > 0) res.add(new VisorLogFile(f)); else if (maxDepth > 1) res.addAll(fileTree(f, maxDepth - 1, filter)); } return res; } return F.asList(new VisorLogFile(file)); }
private void writeJsonJobs(ApplicationInfo appInfo, List<CIJob> jobs, String status) throws PhrescoException { try { if (jobs == null) { return; } Gson gson = new Gson(); List<CIJob> existingJobs = getJobs(appInfo); if (CI_CREATE_NEW_JOBS.equals(status) || existingJobs == null) { existingJobs = new ArrayList<CIJob>(); } existingJobs.addAll(jobs); FileWriter writer = null; File ciJobFile = new File(getCIJobPath(appInfo)); String jobJson = gson.toJson(existingJobs); writer = new FileWriter(ciJobFile); writer.write(jobJson); writer.flush(); } catch (Exception e) { throw new PhrescoException(e); } }
/** * A provider has been removed. * * @param provider the ProtocolProviderService that has been unregistered. */ void handleProviderRemoved(ProtocolProviderService provider) { // lets remove the recent messages for this provider, and update // with recent messages for the available providers synchronized (recentMessages) { if (provider != null) { List<ComparableEvtObj> removedItems = new ArrayList<ComparableEvtObj>(); for (ComparableEvtObj msc : recentMessages) { if (msc.getProtocolProviderService().equals(provider)) removedItems.add(msc); } recentMessages.removeAll(removedItems); if (!recentMessages.isEmpty()) oldestRecentMessage = recentMessages.get(recentMessages.size() - 1).getTimestamp(); else oldestRecentMessage = null; if (recentQuery != null) { for (ComparableEvtObj msc : removedItems) { recentQuery.fireContactRemoved(msc); } } } // handleProviderRemoved can be invoked due to stopped // history service, if this is the case we do not want to // update messages if (!this.messageHistoryService.isHistoryLoggingEnabled()) return; // lets do the same as we enable provider // for all registered providers and finally fire events List<ComparableEvtObj> contactsToAdd = new ArrayList<ComparableEvtObj>(); for (ProtocolProviderService pps : messageHistoryService.getCurrentlyAvailableProviders()) { contactsToAdd.addAll(getCachedRecentMessages(pps, true)); } addNewRecentMessages(contactsToAdd); } }
private boolean adaptExistingJobs(ApplicationInfo appInfo) { try { CIJob existJob = getJob(appInfo); S_LOGGER.debug("Going to get existing jobs to relocate!!!!!"); if (existJob != null) { S_LOGGER.debug("Existing job found " + existJob.getName()); boolean deleteExistJob = deleteCIJobFile(appInfo); Gson gson = new Gson(); List<CIJob> existingJobs = new ArrayList<CIJob>(); existingJobs.addAll(Arrays.asList(existJob)); FileWriter writer = null; File ciJobFile = new File(getCIJobPath(appInfo)); String jobJson = gson.toJson(existingJobs); writer = new FileWriter(ciJobFile); writer.write(jobJson); writer.flush(); S_LOGGER.debug("Existing job moved to new type of project!!"); } return true; } catch (Exception e) { S_LOGGER.debug("It is already adapted !!!!! "); } return false; }
// 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; }
/** * Add the ComparableEvtObj, newly added will fire new, for existing fire update and when trimming * the list to desired length fire remove for those that were removed * * @param contactsToAdd */ private void addNewRecentMessages(List<ComparableEvtObj> contactsToAdd) { // now find object to fire new, and object to fire remove // let us find duplicates and fire update List<ComparableEvtObj> duplicates = new ArrayList<ComparableEvtObj>(); for (ComparableEvtObj msgToAdd : contactsToAdd) { if (recentMessages.contains(msgToAdd)) { duplicates.add(msgToAdd); // save update updateRecentMessageToHistory(msgToAdd); } } recentMessages.removeAll(duplicates); // now contacts to add has no duplicates, add them all boolean changed = recentMessages.addAll(contactsToAdd); if (changed) { Collections.sort(recentMessages); if (recentQuery != null) { for (ComparableEvtObj obj : duplicates) recentQuery.updateContact(obj, obj.getEventObject()); } } if (!recentMessages.isEmpty()) oldestRecentMessage = recentMessages.get(recentMessages.size() - 1).getTimestamp(); // trim List<ComparableEvtObj> removedItems = null; if (recentMessages.size() > numberOfMessages) { removedItems = new ArrayList<ComparableEvtObj>( recentMessages.subList(numberOfMessages, recentMessages.size())); recentMessages.removeAll(removedItems); } if (recentQuery != null) { // now fire, removed for all that were in the list // and now are removed after trim if (removedItems != null) { for (ComparableEvtObj msc : removedItems) { if (!contactsToAdd.contains(msc)) recentQuery.fireContactRemoved(msc); } } // fire new for all that were added, and not removed after trim for (ComparableEvtObj msc : contactsToAdd) { if ((removedItems == null || !removedItems.contains(msc)) && !duplicates.contains(msc)) { MessageSourceContact newSourceContact = new MessageSourceContact(msc.getEventObject(), MessageSourceService.this); newSourceContact.initDetails(msc.getEventObject()); recentQuery.addQueryResult(newSourceContact); } } // if recent messages were changed, indexes have change lets // fire event for the last element which will reorder the whole // group if needed. if (changed) recentQuery.fireContactChanged(recentMessages.get(recentMessages.size() - 1)); } }