public NodeBuilder getConfig(Environment env, Archive archive) { return configs.get(T.V(env, archive)); } public NodeBuilder getConfig(T.V2<Environment, Archive> archiveEnv) {
public boolean isConfigAvailable(Environment env, Archive archive) { return configs.get(T.V(env, archive)) != null; } public boolean isConfigAvailable(T.V2<Environment, Archive> archiveEnv) {
public synchronized void insertPath(Path path) { queue.add(T.V(path, null)); FileStreamIterator.this.notifyAll(); } public synchronized void insertThrowable(Throwable throwable) {
public synchronized void insertThrowable(Throwable throwable) { setError(true); queue.add(T.V(null, throwable)); FileStreamIterator.this.notifyAll(); } public boolean isFinished() {
public NodeBuilder getGlobalVariables(Environment env, Archive archive) { return configs.get(T.V(env, archive)).searchFirstByName("NVPairs"); } public NodeBuilder getConfig(Environment env, Archive archive) {
public List<T.V3<String, byte[], ZipEntry>> load(Path path) { try (ZipFile zipFile = new ZipFile(path.toFile())) { List<T.V3<String, byte[], ZipEntry>> entries = Collections.list(zipFile.entries()).stream().map(z -> (ZipEntry)z).map(e -> T.V("" + /*path.getFileName() +*/ "!/" + e.getName(), retrieveFileData(path, zipFile, e), e)).sorted(fileListComparator()).collect(Collectors.toList()); return entries; } catch (ZipException zip) { try (InputStream is = new FileInputStream(path.toString())) { ArrayList<T.V3<String, byte[], ZipEntry>> list = new ArrayList<>(); list.add(T.V("SingleFile", IOUtils.toByteArray(is), new ZipEntry("SingleFile"))); return list; } catch (FileNotFoundException e) { throw new RuntimeException("File not found ("+path+")", e); } catch (IOException e) { throw new RuntimeException("File read failed ("+path+")", e); } } catch (IOException e) { throw new RuntimeException("Cannot read file ("+path+")", e); } } public List<T.V3<String, byte[], ZipEntry>> load(String path, byte[] array) {
public List<T.V3<String, byte[], ZipEntry>> load(String path, byte[] array) { try (ZipInputStream zipFile = new ZipInputStream(new ByteArrayInputStream(array))) { List<T.V3<String, byte[], ZipEntry>> entries = new ArrayList<>();// Collections.list(zipFile.entries()).stream().map(z -> (ZipEntry)z).map(e -> T.V(e.getName(), retrieveFileData(path, zipFile, e))).collect(Collectors.toList()); ZipEntry entry; while((entry = zipFile.getNextEntry())!=null) { try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { int len = 0; byte[] buffer = new byte[4096]; while ((len = zipFile.read(buffer)) > 0) { output.write(buffer, 0, len); } entries.add(T.V(path + "!/" + entry.getName(), output.toByteArray(), entry)); } } entries.sort(LoadZipFile.fileListComparator()); return entries; } catch (IOException e) { throw new RuntimeException("Cannot read library file ("+path+")", e); } }
private Set<ReferenceInfo> getAttributes( Map<String, Map<String, String>> prefixedAttributes) { return prefixedAttributes.keySet().stream(). map(prefix -> prefixedAttributes.get(prefix).entrySet().stream().map(v -> T.V(prefix, v))). flatMap(m -> m). map(m -> new ReferenceInfoImpl(getNamespace(m.getA()), m.getB().getKey() + ( m.getB().getValue() != null ? "=" + m.getB().getValue() : ""))). //map(i -> i.createQualifiedName(this)). collect(Collectors.toSet()); } @Override
private Stream<T.V2<StreamSource, NodeBuilder>> loadSchemasFromWSDL(Path p) { List<NodeBuilder> schemasInWSDL = new XmlBuilderFactory().loadFromFile(p).search(true, n -> "schema".equals(n.getName())).collect(Collectors.toList()); Map<String, String> mapNamespaceToLocation = new HashMap<>(); for (int i = 0; i < schemasInWSDL.size(); i++) { mapNamespaceToLocation.put(schemasInWSDL.get(i).getAttribute("targetNamespace"), p.toUri().toString()+"#"+i+".xsd"); } List<T.V2<StreamSource, NodeBuilder>> streamSorucesFromSchemas = new ArrayList<>(); for (int i = 0; i < schemasInWSDL.size(); i++) { NodeBuilder schemaXml = mergeNamespaces(schemasInWSDL.get(i), mapNamespaceToLocation); streamSorucesFromSchemas.add(T.V(new StreamSource( new StringReader(schemaXml.toString()), p.toUri().toString()+"#"+i+".xsd"), schemaXml)); } return streamSorucesFromSchemas.stream(); }
private Map<String, Set<V2<String, String>>> getPropertiesNamesAndValues( Map<String, NodeBuilder> adapterProperties) { return adapterProperties.entrySet().stream().map(p -> T.V(p.getKey(), p.getValue().search(true, "option").map(n -> T.V(n.getTextContent(), n.getParent().searchFirstByName("default").getTextContent())).collect(Collectors.toSet()))).collect(Collectors.toMap(v -> v.getA(), v -> v.getB())); }
public Set<String> getDuplicateProcesses(Archive archive) { Map<V2<String, String>, List<V2<V2<Environment, Archive>, String>>> collect = 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")))). // search all name elements from NVPairs flatMap(n -> n). collect(Collectors.groupingBy(s -> (V2<String, String>)T.V(s.getA().getA().getValue(), s.getB()))); return collect. entrySet(). stream(). filter(v -> v.getValue().size() > 1). map(v -> v.getKey().getB()). collect(Collectors.toSet()); } public Set<String> getDuplicateVariables() {
@Override public List<GlobalVariables> getChildVariables() { if (childVariables == null) { childVariables = parentItem. getChildren(). stream(). filter(i -> ItemType.Folder == i.getItemType()). map(parent -> T.V(parent, parent.getChildren().stream().filter(c -> ItemType.GlobalVariable == c.getItemType()).findAny().orElse(null))). //filter(i -> i != null). map(tupple -> new GlobalVariablesImpl(this, tupple.getB(), tupple.getA(), repository)). collect(Collectors.toList()); } return childVariables; }
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() {
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())); }); }
public void normalizeBWSDKVariables(NodeBuilder bw, String version) { Set<V2<String, String>> availableSDKVariables = loader.getBwPropertiesNames().get(version); if (availableSDKVariables == null) { throw new IllegalArgumentException("Cannot find BW SDK Properties for version " + version + " at " + loader.getTibcoBWPath()); } List<NodeBuilder> variableWithDefaultValue = bw.search(true, "name"). map(n -> T.V(n, availableSDKVariables.stream().filter(v -> v.getA().equals(n.getTextContent())).findFirst())). filter(v -> v.getB().isPresent()). filter(v -> sdkVariableHasSameValue(v)). map(v -> v.getA().getParent()). collect(Collectors.toList()); variableWithDefaultValue.forEach(v -> v.getParent().removeChild(v)); }
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 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 V2<Path, String> getVersionFromEAR(Path p) { Optional<V3<String, byte[], ZipEntry>> v = getVersion(T.V(p, new LoadZipFile().load(p))); NodeBuilder node = new XmlBuilderFactory().parseDocument(new ByteArrayInputStream(v.get().getB())); String version = node.searchFirst(true, n -> "version".equals(n.getName())).getTextContent(); return T.V(p, version); }
stream(). map(p -> p.getFileName().toString()). map(n -> T.V(n, n.replaceFirst("ad", ""))). collect(Collectors.toMap(v -> v.getB(), v -> v.getA())); map(s -> T.V(s, new FileSearcher().searchFiles(tibcoAdaptersPath.resolve(s), "glob:**/*", false).stream().sorted((a,b) -> b.toString().compareTo(a.toString())).findFirst().get())). map(adPath -> new FileSearcher().searchFiles(adPath.getB().resolve("lib"), "glob:**/*.jar", true). stream(). .filter(v -> filterXmlPropertyFile(adPath, v) ) .map(v -> new XmlBuilderFactory().parseDocument(new String(v.getB())))). flatMap(s ->s).map(s-> T.V(adPath.getA(),s))) //filter(s -> s.size() > 0) .flatMap(s -> s) Map<String, NodeBuilder> bwProperties = BWPaths. stream(). map(BWPath -> T.V(BWPath.getFileName().toString(), new XmlBuilderFactory().loadFromFile(BWPath.resolve("lib/com/tibco/deployment/bwengine.xml")))). collect(Collectors.toMap(v -> v.getA(), v -> v.getB()));
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())); }