public boolean isServiceInstanceVariableDefinedInAllConfigs(GlobalVariable variable) { return configs.entrySet().stream(). map(v -> getServices(v.getKey().getA(), v.getKey().getB()). stream().map(s -> T.V(v.getKey().getA(),v.getKey().getB(),s)) ). flatMap(v -> v). map(v -> getInstances(v.getA(), v.getB(), v.getC()). stream().map(instance -> getInstanceConfig(v.getA(), v.getB(), v.getC(), instance).get())). flatMap(n -> n). filter(checkServiceInstanceVariableInConfig(variable)). count() == 0; }
public void updateFile(Path outputPath, List<T.V3<String, byte[], ZipEntry>> files) { try (ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(outputPath.toFile()))) { for (V3<String, byte[], ZipEntry> v : files) { ZipEntry zipEntry = (ZipEntry)v.getC().clone(); zipEntry.setCompressedSize(-1); zipEntry.setSize(v.getB().length); zipFile.putNextEntry(zipEntry); zipFile.write(v.getB()); } } catch (IOException e) { throw new RuntimeException("Cannot store zip file ("+outputPath+")" + e.getMessage(), e); } } public static Comparator<? super V2<String, byte[]>> fileListComparator() {
public Set<String> getDuplicateVariables() { Map<V3<String, String, String>, List<V2<V2<Environment, Archive>, String>>> collect = configs. entrySet().stream(). map(v -> v.getValue().searchFirstByName("NVPairs").search(true, "name").map(nn -> T.V(v.getKey(), nn.getTextContent()))). // search all name elements from NVPairs flatMap(n -> n). collect(Collectors.groupingBy(s -> (V3<String, String, String>)T.V(s.getA().getA().getValue(), s.getA().getB().getValue(), s.getB()))); return collect. entrySet(). stream(). filter(v -> v.getValue().size() > 1). map(v -> v.getKey().getC()). collect(Collectors.toSet()); } public Set<String> getDuplicateServiceVariables() {
collect(Collectors.groupingBy(s -> (V4<String, String, String, String>)T.V(s.getA().getA().getValue(), s.getA().getB().getValue(), s.getB(), s.getC()))); return collect.
public static void main(String[] args) { ArgumentParser argParser = ArgumentParsers.newArgumentParser("EAR Version Updater", true, "-") .description("Updates version in ear files in given directory."); argParser.addArgument("-directory").type(String.class).required(true).help("Path to directory with ears"); argParser.addArgument("-version").type(String.class).required(true).help("Version that will be written in Tibco.xml"); Namespace res = argParser.parseArgsOrFail(args); String directory = res.get("directory"); String version = res.getString("version"); new FileSearcher().searchFiles(Paths.get(directory), "glob:**/*.ear", false). stream().parallel(). map(p -> T.V(p, new LoadZipFile().load(p))). map(v -> T.V(v.getA(), getVersion(v), v.getB())). filter(v -> v.getB().isPresent()). map(v -> T.V(v.getA(), new XmlBuilderFactory().parseDocument(new ByteArrayInputStream(v.getB().get().getB())), v.getB(), v.getC())). forEach(v -> { v.getB().search("version").forEach(vnode -> { System.out.println(v.getA() + " " + vnode.getTextContent() + " -> " + version); vnode.setTextContent(version); }); byte[] bytes = v.getB().toString().getBytes(); V3<String, byte[], ZipEntry> zipFileEntry = v.getC().get(); zipFileEntry.setB(bytes); new LoadZipFile().updateFile(v.getA(), v.getD()); }); }
public FullConfigsModel(Repository repo, SDKPropertiesLoader loader) { this.repo = repo; this.bwPropertiesNames = loader.getBwPropertiesNames(); this.adaptersPropertiesNames = loader.getAdaptersPropertiesNames(); this.availableAdapters = loader.getAvailableAdapters(); Path configPath = repo.getPath().getParent().resolve("_config"); availableArchives = repo.findAll(i -> i.getItemType() == ItemType.Archive).stream().map(i -> new Archive(i)).collect(Collectors.toList()); availableEnvironemnts = new FileSearcher().searchFiles(configPath, "glob:**/*", false).stream().filter(p -> p.toFile().isDirectory()).map(p -> new Environment(p)).collect(Collectors.toList()); availableArchives.forEach(archive -> { availableEnvironemnts.stream(). map(e -> T.V(e,archive, getConfigPath(archive, e))). filter(fc -> fc.getC().toFile().exists()). map(fc -> T.V(fc.getA(), fc.getB(), new XmlBuilderFactory().loadFromFile(fc.getC()))). forEach(fc -> { configs.put(T.V(fc.getA(), fc.getB()), fc.getC()); origConfigs.put(T.V(fc.getA(), fc.getB()), fc.getC().copy()); }); ; }); }
public void removeDuplicateProcesses(Archive archive) { Set<String> duplicated = getDuplicateProcesses(archive); Map<V2<String, String>, List<V3<V2<Environment, Archive>, String, NodeBuilder>>> toRemove = configs. entrySet().stream().filter(v -> v.getKey().getB().equals(archive)). map(v -> v.getValue().search(true, "bwprocess").map(nn -> T.V(v.getKey(), nn.getAttribute("name"), nn))). flatMap(n -> n). filter(v -> duplicated.contains(v.getB())). collect(Collectors.groupingBy(t -> (V2<String, String>)T.V(t.getA().getA().getValue(), t.getB()))); toRemove. entrySet().stream(). forEach(v -> { v.getValue().stream().skip(1).forEach(n -> n.getC().getParent().removeChild(n.getC())); }); }
private Stream<V2<Service, NodeBuilder>> loadServicesStream(Archive archive) { return archive.getArchive().loadAsXml(). search(true, n -> ARCHIVES_ELEMENT_NAMES.contains(n.getName())). map(n -> T.V(SERVICE_TYPES.get(n.getName()), n.getAttribute("name"), n)). map(v -> T.V(new Service(v.getB(), v.getA()), v.getC())); }
public void removeDuplicateVariables() { Set<String> duplicated = getDuplicateVariables(); Map<V3<String, String, String>, List<V3<V2<Environment, Archive>, String, NodeBuilder>>> toRemove = configs. entrySet().stream(). map(v -> v.getValue().searchFirstByName("NVPairs").search(true, "name").map(nn -> T.V(v.getKey(), nn.getTextContent(), nn.getParent()))). // search all name elements from NVPairs //map(v -> v.getValue().search(true, "bwprocess").map(nn -> T.V(v.getKey(), nn.getAttribute("name"), nn))). flatMap(n -> n). filter(v -> duplicated.contains(v.getB())). collect(Collectors.groupingBy(t -> (V3<String, String, String>)T.V(t.getA().getA().getValue(), t.getA().getB().getValue(), t.getB()))); toRemove. entrySet().stream(). forEach(v -> { v.getValue().stream().skip(1).forEach(n -> n.getC().getParent().removeChild(n.getC())); }); }
public static <A, B, C, D> V4<A, B, C, D> copyAndAdd(V3<A, B, C> v, D d) { return new V4<A, B, C, D>(v.getA(), v.getB(), v.getC(), d); } public static <A, B, C, D, E> V5<A, B, C, D, E> copyAndAdd(V4<A, B, C, D> v, E e) {