private Collection<BranchReadable> getBranchesToPurge() throws OseeCoreException { Set<BranchReadable> specifiedBranches = new HashSet<BranchReadable>(); for (Long uuid : branchUuids) { if (uuid <= 0) { console.writeln("UUID listed %s is not a valid UUID", uuid); } else { BranchReadable cached = queryFactory.branchQuery().andUuids(uuid).getResults().getExactlyOne(); if (cached != null) { specifiedBranches.add(cached); } } } Collection<BranchReadable> branchesToPurge = recurse ? getChildBranchesToPurge(specifiedBranches) : specifiedBranches; Iterator<BranchReadable> iter = branchesToPurge.iterator(); while (iter.hasNext()) { if (filterBranch(iter.next())) { iter.remove(); } } return branchesToPurge; }
private Collection<BranchReadable> getChildBranchesToPurge(Iterable<BranchReadable> branches) throws OseeCoreException { BranchQuery branchQuery = queryFactory.branchQuery(); branchQuery.includeArchived(); branchQuery.includeDeleted(); if (includeBaseline) { branchQuery.andIsOfType( BranchType.WORKING, BranchType.MERGE, BranchType.PORT, BranchType.BASELINE); } else { branchQuery.andIsOfType(BranchType.WORKING, BranchType.MERGE, BranchType.PORT); } if (includeUndeleted) { branchQuery.andStateIs( BranchState.CREATED, BranchState.MODIFIED, BranchState.COMMITTED, BranchState.REBASELINED, BranchState.DELETED, BranchState.REBASELINE_IN_PROGRESS, BranchState.COMMIT_IN_PROGRESS, BranchState.CREATION_IN_PROGRESS, BranchState.DELETE_IN_PROGRESS, BranchState.PURGE_IN_PROGRESS, BranchState.PURGED); } else { branchQuery.andStateIs(BranchState.DELETED); } Set<BranchReadable> results = new HashSet<BranchReadable>(); for (BranchReadable parent : branches) { for (BranchReadable branch : branchQuery.andIsChildOf(parent).getResults()) { if (includeUnarchived || branch.getArchiveState() == BranchArchivedState.ARCHIVED) { results.add(branch); } } } if (recurse) { results.addAll(getChildBranchesToPurge(new ArrayList<BranchReadable>(results))); } return results; }