private void deleteJsonJobs(ApplicationInfo appInfo, List<CIJob> selectedJobs) throws PhrescoException { try { if (CollectionUtils.isEmpty(selectedJobs)) { return; } Gson gson = new Gson(); List<CIJob> jobs = getJobs(appInfo); if (CollectionUtils.isEmpty(jobs)) { return; } // all values Iterator<CIJob> iterator = jobs.iterator(); // deletable values for (CIJob selectedInfo : selectedJobs) { while (iterator.hasNext()) { CIJob itrCiJob = iterator.next(); if (itrCiJob.getName().equals(selectedInfo.getName())) { iterator.remove(); break; } } } writeJsonJobs(appInfo, jobs, CI_CREATE_NEW_JOBS); } catch (Exception e) { throw new PhrescoException(e); } }
public static int traverse(Iterator iterator) { int count = 0; while (iterator.hasNext()) { iterator.next(); count++; } return count; }
public static Map shiftLevelsDown(Map vertexLevelMap, Digraph digraph) { for (Iterator i = digraph.vertexIterator(); i.hasNext(); ) { Object rootCandidate = i.next(); if (digraph.incomingSize(rootCandidate) == 0) shiftLevelsDown(vertexLevelMap, digraph, rootCandidate); } return vertexLevelMap; }
public static Map computeLevels(Map vertexLevelMap, Digraph digraph, boolean longest) { if (vertexLevelMap == null) vertexLevelMap = new HashMap(digraph.order()); for (Iterator i = digraph.vertexIterator(); i.hasNext(); ) { Object rootCandidate = i.next(); if (digraph.incomingSize(rootCandidate) == 0) computeLevels(vertexLevelMap, digraph, rootCandidate, longest); } return vertexLevelMap; }
public static Digraph merge(Digraph destination, DigraphIteration graphToMerge) { for (Iterator i = graphToMerge.vertexIterator(); i.hasNext(); ) { destination.addVertex(i.next()); } for (ArcIterator i = graphToMerge.arcIterator(); i.hasNext(); ) { Object arc = i.next(); Object origin = i.getOrigin(); Object dst = i.getDestination(); destination.putArc(origin, dst, arc); } return destination; }
/** Concatenate params for URL string */ String concatParams(Properties props) { if (props == null) { return null; } java.util.List list = new ArrayList(); for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) { String key = (String) iter.next(); String val = props.getProperty(key); if (!StringUtil.isNullString(val)) { list.add(key + "=" + urlEncode(val)); } } return StringUtil.separatedString(list, "&"); }
public static List findCycles(DigraphIteration graph) { ArrayStack stack = new ArrayStack(); ArrayStack path = new ArrayStack(); Set seen = new HashSet(); List cycles = new ArrayList(); Iterator vertexIterator = graph.vertexIterator(); while (vertexIterator.hasNext()) { while (vertexIterator.hasNext()) { Object vertex = vertexIterator.next(); if (seen.add(vertex)) { stack.push(graph.outgoingIterator(vertex)); path.push(vertex); break; } } while (!stack.isEmpty()) { ArcIterator i = (ArcIterator) stack.peek(); Object origin = i.getOrigin(); boolean subtreeIsTraversed = true; while (i.hasNext()) { i.next(); Object dst = i.getDestination(); int index = path.indexOf(dst); if (index < 0) { seen.add(dst); stack.push(graph.outgoingIterator(dst)); path.push(dst); subtreeIsTraversed = false; break; } else { cycles.add(new ArrayList(path.subList(index, path.size()))); } } if (subtreeIsTraversed) { stack.pop(); path.pop(); } } } return cycles; }
public static Digraph transform( Digraph result, DigraphIteration source, Transformer vertexTransform, Transformer arcTransform) { for (Iterator i = new TransformIterator(source.vertexIterator(), vertexTransform); i.hasNext(); ) { result.addVertex(i.next()); } for (ArcIterator i = new TransformArcIterator(source.arcIterator(), vertexTransform, arcTransform); i.hasNext(); ) { Object arc = i.next(); Object origin = i.getOrigin(); Object dst = i.getDestination(); result.putArc(origin, dst, arc); } return result; }
public static boolean isAcyclic(Digraph digraph) { int order = digraph.order(); if (order == 0) return true; Set spanned = new HashSet(order); DepthFirstStampSearch dfs = new DepthFirstStampSearch(digraph, digraph.vertexIterator().next()); for (Iterator i = digraph.vertexIterator(); i.hasNext(); ) { Object dfsRoot = i.next(); if (spanned.contains(dfsRoot)) continue; dfs.reset(dfsRoot); Map dfsOrders = dfs.traverse(new HashMap(digraph.order())); for (Iterator j = dfsOrders.entrySet().iterator(); j.hasNext(); ) { Map.Entry entry = (Map.Entry) j.next(); Object origin = entry.getKey(); DepthFirstStampSearch.OrderPair orgOrders = (DepthFirstStampSearch.OrderPair) entry.getValue(); spanned.add(origin); for (ArcIterator k = digraph.outgoingIterator(origin); k.hasNext(); ) { k.next(); Object dst = k.getDestination(); DepthFirstStampSearch.OrderPair dstOrders = (DepthFirstStampSearch.OrderPair) dfsOrders.get(dst); if (dstOrders.getPostOrder() > orgOrders.getPostOrder()) return false; } } if (dfsOrders.size() == order) break; } return true; }
public static boolean isTree(Digraph digraph) { Object root = null; for (Iterator i = digraph.vertexIterator(); i.hasNext(); ) { Object vertex = i.next(); int inSize = digraph.incomingSize(vertex); if (inSize == 0) { root = vertex; break; } } // not a tree - no vertex with 0 in-degree if (root == null) return false; // try to reach all vertices from the root candidate BreadthFirstSearch traversal = new BreadthFirstSearch(digraph, root); while (traversal.isValidTree() && traversal.hasNext()) traversal.next(); // not a tree - one of vertices has been seen more than once by the BFS if (!traversal.isValidTree()) return false; // has every vertex been reached? Set seenVertices = traversal.getSeenVertices(); for (Iterator i = digraph.vertexIterator(); i.hasNext(); ) if (!seenVertices.contains(i.next())) return false; // all tests are passed - good! return true; }
public CIJobStatus deleteBuilds(ApplicationInfo appInfo, Map<String, List<String>> builds) throws PhrescoException { S_LOGGER.debug("Entering Method ProjectAdministratorImpl.deleteCI()"); try { CIJobStatus deleteCI = null; Iterator iterator = builds.keySet().iterator(); while (iterator.hasNext()) { String jobName = iterator.next().toString(); List<String> deleteBuilds = builds.get(jobName); S_LOGGER.debug("jobName " + jobName + " builds " + deleteBuilds); CIJob ciJob = getJob(appInfo, jobName); // job and build numbers deleteCI = deleteCI(ciJob, deleteBuilds); } return deleteCI; } catch (ClientHandlerException ex) { S_LOGGER.error( "Entered into catch block of ProjectAdministratorImpl.deleteCI()" + ex.getLocalizedMessage()); throw new PhrescoException(ex); } }
public static Digraph randomizeTree( Digraph digraph, int maxChildren, int maxLevels, Random randomizer) { int vertexIndex = 1; Object root = new Integer(vertexIndex); List level = Collections.singletonList(root); digraph.addVertex(root); for (int i = 1; i < maxLevels; i++) { List childLevel = new ArrayList(level.size() * maxChildren); for (Iterator j = level.iterator(); j.hasNext(); ) { Object parent = j.next(); int childCount = randomizer.nextInt(maxChildren + 1); for (int k = 0; k < childCount; k++) { Object child = new Integer(++vertexIndex); digraph.addVertex(child); digraph.putArc(parent, child, Boolean.TRUE); childLevel.add(child); } } if (childLevel.isEmpty()) break; level = childLevel; } return digraph; }
/** Sherpa romeo submission support */ public void make_sherpaRomeo_submission(Item item, Division divIn) throws WingException { if (ConfigurationManager.getBooleanProperty( "webui.submission.sherparomeo-policy-enabled", true)) { SHERPASubmitService sherpaSubmitService = new DSpace().getSingletonService(SHERPASubmitService.class); if (sherpaSubmitService.hasISSNs(context, item)) { List div = divIn.addList("submit-upload-new", List.TYPE_FORM); div.setHead(T_sherpa_title); // Since sherpa web service doesn't work reliable with more than 1 issn, perform the service // for each issn Set<String> issns = sherpaSubmitService.getISSNs(context, item); Iterator<String> issnsIterator = issns.iterator(); int i = 0; while (issnsIterator.hasNext()) { SHERPAResponse shresp = sherpaSubmitService.searchRelatedJournalsByISSN(issnsIterator.next()); java.util.List<SHERPAJournal> journals = shresp.getJournals(); java.util.List<SHERPAPublisher> publishers = shresp.getPublishers(); if (CollectionUtils.isNotEmpty(journals)) { for (SHERPAJournal journ : journals) { SHERPAPublisher pub = publishers.get(0); List sherpaList = div.addList("sherpaList" + (i + 1), "simple", "sherpaList"); sherpaList .addItem() .addFigure( contextPath + "/static/images/" + (i == 0 ? "romeosmall" : "clear") + ".gif", "http://www.sherpa.ac.uk/romeo/", "sherpaLogo"); sherpaList.addItem().addHighlight("sherpaBold").addContent(T_sherpa_journal); sherpaList.addItem(journ.getTitle() + " (" + journ.getIssn() + ")"); sherpaList.addItem().addHighlight("sherpaBold").addContent(T_sherpa_publisher); sherpaList.addItemXref(pub.getHomeurl(), pub.getName()); sherpaList.addItem().addHighlight("sherpaBold").addContent(T_sherpa_colour); sherpaList .addItem() .addHighlight("sherpaStyle " + pub.getRomeocolour()) .addContent(message("xmlui.aspect.sherpa.submission." + pub.getRomeocolour())); sherpaList .addItem() .addXref( "http://www.sherpa.ac.uk/romeo/search.php?issn=" + journ.getIssn(), T_sherpa_more, "sherpaMoreInfo"); i = i + 1; } } } List sherpaList = div.addList("sherpaListEnd", "simple", "sherpaList"); sherpaList.addItem(T_sherpa_consult); } } }