List of usage examples for java.util SortedSet stream
default Stream<E> stream()
From source file:ambroafb.general.StagesContainer.java
private static List<String> getFirstLevelChildrenFor(String ownerPath) { List<String> children = new ArrayList<>(); SortedSet<Object> sortedKeys = new TreeSet<>(bidmap.keySet()); sortedKeys.stream().forEach((key) -> { String path = (String) key; String pathAfterFirstSlash = StringUtils.substringAfter(path, ownerPath + pathDelimiter); if (!path.equals(ownerPath) && path.startsWith(ownerPath) && !pathAfterFirstSlash.contains(pathDelimiter) && ((Stage) bidmap.get(path)).isShowing()) { children.add(path);// w ww .ja va 2 s. c o m } }); return children; }
From source file:org.sakuli.services.forwarder.AbstractOutputBuilder.java
static String generateStepInformation(SortedSet<TestCaseStep> steps) { StringBuilder sb = new StringBuilder(); steps.stream().filter(step -> step.getState().isWarning() || step.getState().isError()).forEach(step -> { sb.append(", step \"").append(step.getName()).append("\" "); if (step.getState().isError()) { sb.append("EXCEPTION: ").append(step.getExceptionMessages(true)); } else {/* w ww .j a v a 2s. c om*/ sb.append("over runtime (").append(NagiosFormatter.formatToSec(step.getDuration())) .append("/warn at ").append(NagiosFormatter.formatToSec(step.getWarningTime())).append(")"); } }); return sb.toString(); }
From source file:org.sakuli.services.forwarder.AbstractOutputBuilder.java
static String generateCaseInformation(SortedSet<TestCase> cases) { StringBuilder sb = new StringBuilder(); cases.stream().filter(c -> c.getState().isWarning() || c.getState().isCritical() || c.getState().isError()) .forEach(c -> {//from ww w . ja v a2s. co m sb.append(", case \"").append(c.getName()).append("\" "); if (c.getState().isError()) { sb.append("EXCEPTION: ").append(c.getExceptionMessages(true)); } else { sb.append("over runtime (").append(NagiosFormatter.formatToSec(c.getDuration())); if (c.getState().isCritical()) { sb.append("/crit at ").append(NagiosFormatter.formatToSec(c.getCriticalTime())); } else { sb.append("/warn at ").append(NagiosFormatter.formatToSec(c.getWarningTime())); } sb.append(")"); } }); return sb.toString(); }
From source file:org.obiba.mica.web.model.StudySummaryDtos.java
private void addDataSources(Mica.StudySummaryDto.Builder builder, SortedSet<Population> populations) { //needed for retro-compatibility (and search functionality) populations.stream().filter(population -> population.getAllDataSources() != null) .map(Population::getAllDataSources).flatMap(Collection::stream).distinct() .forEach(builder::addDataSources); }
From source file:org.apache.storm.daemon.logviewer.handler.LogviewerLogPageHandler.java
/** * Provides a worker log file to view./*from w w w. j av a 2 s. c o m*/ * * @param fileName file to view * @param start start offset, can be null * @param length length to read in this page, can be null * @param grep search string if request is a result of the search, can be null * @param user username * @return HTML view page of worker log */ public Response logPage(String fileName, Integer start, Integer length, String grep, String user) throws IOException, InvalidRequestException { String rootDir = logRoot; if (resourceAuthorizer.isUserAllowedToAccessFile(user, fileName)) { workerLogs.setLogFilePermission(fileName); File file = new File(rootDir, fileName).getCanonicalFile(); String path = file.getCanonicalPath(); boolean isZipFile = path.endsWith(".gz"); File topoDir = file.getParentFile().getParentFile(); if (file.exists() && new File(rootDir).getCanonicalFile().equals(topoDir.getParentFile())) { SortedSet<File> logFiles; try { logFiles = Arrays.stream(topoDir.listFiles()) .flatMap(Unchecked .function(portDir -> DirectoryCleaner.getFilesForDir(portDir).stream())) .filter(File::isFile).collect(toCollection(TreeSet::new)); } catch (UncheckedIOException e) { throw e.getCause(); } List<String> filesStrWithoutFileParam = logFiles.stream().map(WorkerLogs::getTopologyPortWorkerLog) .filter(fileStr -> !StringUtils.equals(fileName, fileStr)).collect(toList()); List<String> reorderedFilesStr = new ArrayList<>(); reorderedFilesStr.addAll(filesStrWithoutFileParam); reorderedFilesStr.add(fileName); length = length != null ? Math.min(10485760, length) : LogviewerConstant.DEFAULT_BYTES_PER_PAGE; String logString; if (isTxtFile(fileName)) { logString = escapeHtml(start != null ? pageFile(path, start, length) : pageFile(path, length)); } else { logString = escapeHtml( "This is a binary file and cannot display! You may download the full file."); } long fileLength = isZipFile ? ServerUtils.zipFileSize(file) : file.length(); start = start != null ? start : Long.valueOf(fileLength - length).intValue(); List<DomContent> bodyContents = new ArrayList<>(); if (StringUtils.isNotEmpty(grep)) { String matchedString = String.join("\n", Arrays.stream(logString.split("\n")) .filter(str -> str.contains(grep)).collect(toList())); bodyContents.add(pre(matchedString).withId("logContent")); } else { DomContent pagerData = null; if (isTxtFile(fileName)) { pagerData = pagerLinks(fileName, start, length, Long.valueOf(fileLength).intValue(), "log"); } bodyContents.add(searchFileForm(fileName, "no")); // list all files for this topology bodyContents.add(logFileSelectionForm(reorderedFilesStr, fileName, "log")); if (pagerData != null) { bodyContents.add(pagerData); } bodyContents.add(downloadLink(fileName)); bodyContents.add(pre(logString).withClass("logContent")); if (pagerData != null) { bodyContents.add(pagerData); } } String content = logTemplate(bodyContents, fileName, user).render(); return LogviewerResponseBuilder.buildSuccessHtmlResponse(content); } else { return LogviewerResponseBuilder.buildResponsePageNotFound(); } } else { if (resourceAuthorizer.getLogUserGroupWhitelist(fileName) != null) { return LogviewerResponseBuilder.buildResponsePageNotFound(); } else { return LogviewerResponseBuilder.buildResponseUnautohrizedUser(user); } } }
From source file:org.apache.storm.daemon.logviewer.utils.LogCleaner.java
/** * Delete old log dirs for which the workers are no longer alive. *//* w w w. j a v a 2 s . com*/ @Override public void run() { try { int nowSecs = Time.currentTimeSecs(); Set<File> oldLogDirs = selectDirsForCleanup(nowSecs * 1000); SortedSet<File> deadWorkerDirs = getDeadWorkerDirs(nowSecs, oldLogDirs); LOG.debug("log cleanup: now={} old log dirs {} dead worker dirs {}", nowSecs, oldLogDirs.stream().map(File::getName).collect(joining(",")), deadWorkerDirs.stream().map(File::getName).collect(joining(","))); deadWorkerDirs.forEach(Unchecked.consumer(dir -> { String path = dir.getCanonicalPath(); LOG.info("Cleaning up: Removing {}", path); try { Utils.forceDelete(path); cleanupEmptyTopoDirectory(dir); } catch (Exception ex) { LOG.error(ex.getMessage(), ex); } })); perWorkerDirCleanup(maxPerWorkerLogsSizeMb * 1024 * 1024); globalLogCleanup(maxSumWorkerLogsSizeMb * 1024 * 1024); } catch (Exception ex) { LOG.error("Exception while cleaning up old log.", ex); } }
From source file:org.eclipse.winery.repository.rest.resources.AbstractComponentsResource.java
/** * Used by org.eclipse.winery.repository.repository.client and by the artifactcreationdialog.tag. Especially the * "name" field is used there at the UI//from w w w . j a va 2 s. com * * @param grouped if given, the JSON output is grouped by namespace * @return A list of all ids of all instances of this component type. <br /> Format: <code>[({"namespace": * "[namespace]", "id": "[id]"},)* ]</code>. <br /><br /> If grouped is set, the list will be grouped by namespace. * <br /> <code>[{"id": "[namsepace encoded]", "test": "[namespace decoded]", "children":[{"id": "[qName]", "text": * "[id]"}]}]</code> */ @GET @Produces(MediaType.APPLICATION_JSON) public String getListOfAllIds(@QueryParam("grouped") String grouped) { Class<? extends TOSCAComponentId> idClass = RestUtils .getComponentIdClassForComponentContainer(this.getClass()); boolean supportsNameAttribute = Util.instanceSupportsNameAttribute(idClass); SortedSet<? extends TOSCAComponentId> allTOSCAcomponentIds = RepositoryFactory.getRepository() .getAllTOSCAComponentIds(idClass); JsonFactory jsonFactory = new JsonFactory(); StringWriter sw = new StringWriter(); try { JsonGenerator jg = jsonFactory.createGenerator(sw); // We produce org.eclipse.winery.repository.client.WineryRepositoryClient.NamespaceAndId by hand here // Refactoring could move this class to common and fill it here if (grouped == null) { jg.writeStartArray(); for (TOSCAComponentId id : allTOSCAcomponentIds) { jg.writeStartObject(); jg.writeStringField("namespace", id.getNamespace().getDecoded()); jg.writeStringField("id", id.getXmlId().getDecoded()); if (supportsNameAttribute) { AbstractComponentInstanceResource componentInstaceResource = AbstractComponentsResource .getComponentInstaceResource(id); String name = ((IHasName) componentInstaceResource).getName(); jg.writeStringField("name", name); } else { // used for winery-qNameSelector to avoid an if there jg.writeStringField("name", id.getXmlId().getDecoded()); } jg.writeStringField("qName", id.getQName().toString()); jg.writeEndObject(); } jg.writeEndArray(); } else { jg.writeStartArray(); Map<Namespace, ? extends List<? extends TOSCAComponentId>> groupedIds = allTOSCAcomponentIds .stream().collect(Collectors.groupingBy(id -> id.getNamespace())); groupedIds.keySet().stream().sorted().forEach(namespace -> { try { jg.writeStartObject(); jg.writeStringField("id", namespace.getEncoded()); jg.writeStringField("text", namespace.getDecoded()); jg.writeFieldName("children"); jg.writeStartArray(); groupedIds.get(namespace).forEach(id -> { try { jg.writeStartObject(); String text; if (supportsNameAttribute) { AbstractComponentInstanceResource componentInstaceResource = AbstractComponentsResource .getComponentInstaceResource(id); text = ((IHasName) componentInstaceResource).getName(); } else { text = id.getXmlId().getDecoded(); } jg.writeStringField("id", id.getQName().toString()); jg.writeStringField("text", text); jg.writeEndObject(); } catch (IOException e) { AbstractComponentsResource.LOGGER.error("Could not create JSON", e); } }); jg.writeEndArray(); jg.writeEndObject(); } catch (IOException e) { AbstractComponentsResource.LOGGER.error("Could not create JSON", e); } }); jg.writeEndArray(); } jg.close(); } catch (Exception e) { AbstractComponentsResource.LOGGER.error(e.getMessage(), e); return "[]"; } return sw.toString(); }
From source file:org.eclipse.winery.repository.rest.resources._support.AbstractComponentsResource.java
private List<NamespaceAndDefinedLocalNamesForAngular> getGroupedListOfIds( SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds, String full, String includeVersions) { Map<Namespace, ? extends List<? extends DefinitionsChildId>> groupedIds = allDefinitionsChildIds.stream() .collect(Collectors.groupingBy(DefinitionsChildId::getNamespace)); return groupedIds.keySet().stream().sorted().map(namespace -> { List<LocalNameForAngular> names = groupedIds.get(namespace).stream().map(definition -> { Definitions fullDefinition = null; if (Objects.nonNull(full)) { fullDefinition = getFullComponentData(definition); }/*www. j a v a 2 s .com*/ String qName = definition.getQName().toString(); String id = definition.getXmlId().toString(); if ("componentVersionOnly".equals(includeVersions)) { qName = VersionUtils.getQNameWithComponentVersionOnly(definition); id = qName.split("}")[1]; } return new LocalNameForAngular(qName, id, fullDefinition); }).distinct().collect(Collectors.toList()); return new NamespaceAndDefinedLocalNamesForAngular(namespace, names); }).collect(Collectors.toList()); }
From source file:org.eclipse.winery.repository.rest.resources._support.AbstractComponentsResource.java
private List<ComponentId> getListOfIds(SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds, boolean supportsNameAttribute, String full, String includeVersions) { return allDefinitionsChildIds.stream().sorted().map(id -> { String name = id.getXmlId().getDecoded(); Definitions definitions = null;/*from ww w . j a v a 2 s . c o m*/ WineryVersion version = null; if (supportsNameAttribute) { AbstractComponentInstanceResource componentInstanceResource = AbstractComponentsResource .getComponentInstanceResource(id); name = ((IHasName) componentInstanceResource).getName(); } if (Objects.nonNull(full)) { definitions = getFullComponentData(id); } if (Objects.nonNull(includeVersions)) { version = VersionUtils.getVersion(id.getXmlId().getDecoded()); } return new ComponentId(id.getXmlId().getDecoded(), name, id.getNamespace().getDecoded(), id.getQName(), definitions, version); }).collect(Collectors.toList()); }