List of usage examples for java.util Set stream
default Stream<E> stream()
From source file:nu.yona.server.analysis.service.ActivityService.java
private Set<GoalDto> getActiveGoals(Set<GoalDto> relevantGoals, ZonedDateTime dateAtStartOfInterval, ChronoUnit timeUnit) {//w w w . java 2 s . c o m return relevantGoals.stream().filter(g -> g.wasActiveAtInterval(dateAtStartOfInterval, timeUnit)) .collect(Collectors.toSet()); }
From source file:io.swagger.api.impl.ToolsApiServiceImpl.java
/** * @param registryId registry id// w w w .j a v a2s . co m * @param versionId git reference * @param type type of file * @param relativePath if null, return the primary descriptor, if not null, return a specific file * @param unwrap unwrap the file and present the descriptor sans wrapper model * @return a specific file wrapped in a response */ private Response getFileByToolVersionID(String registryId, String versionId, SourceFile.FileType type, String relativePath, boolean unwrap) { // if a version is provided, get that version, otherwise return the newest ParsedRegistryID parsedID = new ParsedRegistryID(registryId); try { versionId = URLDecoder.decode(versionId, StandardCharsets.UTF_8.displayName()); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } Entry entry = getEntry(parsedID); // check whether this is registered if (!entry.getIsPublished()) { return Response.status(Response.Status.UNAUTHORIZED).build(); } final Pair<io.swagger.model.Tool, Table<String, SourceFile.FileType, Object>> toolTablePair = convertContainer2Tool( entry); String finalVersionId = versionId; if (toolTablePair == null || toolTablePair.getKey().getVersions() == null) { return Response.status(Response.Status.NOT_FOUND).build(); } io.swagger.model.Tool convertedTool = toolTablePair.getKey(); final Optional<ToolVersion> first = convertedTool.getVersions().stream() .filter(toolVersion -> toolVersion.getName().equalsIgnoreCase(finalVersionId)).findFirst(); Optional<? extends Version> oldFirst; if (entry instanceof Tool) { Tool toolEntry = (Tool) entry; oldFirst = toolEntry.getVersions().stream() .filter(toolVersion -> toolVersion.getName().equalsIgnoreCase(finalVersionId)).findFirst(); } else { Workflow workflowEntry = (Workflow) entry; oldFirst = workflowEntry.getVersions().stream() .filter(toolVersion -> toolVersion.getName().equalsIgnoreCase(finalVersionId)).findFirst(); } final Table<String, SourceFile.FileType, Object> table = toolTablePair.getValue(); if (first.isPresent() && oldFirst.isPresent()) { final ToolVersion toolVersion = first.get(); final String toolVersionName = toolVersion.getName(); if (type == DOCKERFILE) { final ToolDockerfile dockerfile = (ToolDockerfile) table.get(toolVersionName, SourceFile.FileType.DOCKERFILE); return Response.status(Response.Status.OK) .type(unwrap ? MediaType.TEXT_PLAIN : MediaType.APPLICATION_JSON) .entity(unwrap ? dockerfile.getDockerfile() : dockerfile).build(); } else { if (relativePath == null) { if ((type == DOCKSTORE_WDL) && (((ToolDescriptor) table.get(toolVersionName, SourceFile.FileType.DOCKSTORE_WDL)) .getType() == ToolDescriptor.TypeEnum.WDL)) { final ToolDescriptor descriptor = (ToolDescriptor) table.get(toolVersionName, SourceFile.FileType.DOCKSTORE_WDL); return Response.status(Response.Status.OK) .entity(unwrap ? descriptor.getDescriptor() : descriptor).build(); } else if (type == DOCKSTORE_CWL && (((ToolDescriptor) table.get(toolVersionName, SourceFile.FileType.DOCKSTORE_CWL)) .getType() == ToolDescriptor.TypeEnum.CWL)) { final ToolDescriptor descriptor = (ToolDescriptor) table.get(toolVersionName, SourceFile.FileType.DOCKSTORE_CWL); return Response.status(Response.Status.OK) .type(unwrap ? MediaType.TEXT_PLAIN : MediaType.APPLICATION_JSON) .entity(unwrap ? descriptor.getDescriptor() : descriptor).build(); } return Response.status(Response.Status.NOT_FOUND).build(); } else { final Set<SourceFile> sourceFiles = oldFirst.get().getSourceFiles(); final Optional<SourceFile> first1 = sourceFiles.stream() .filter(file -> file.getPath().equalsIgnoreCase(relativePath)).findFirst(); if (first1.isPresent()) { final SourceFile entity = first1.get(); return Response.status(Response.Status.OK) .type(unwrap ? MediaType.TEXT_PLAIN : MediaType.APPLICATION_JSON) .entity(unwrap ? entity.getContent() : entity).build(); } } } } return Response.status(Response.Status.NOT_FOUND).build(); }
From source file:act.installer.reachablesexplorer.FreemarkerRenderer.java
private String renderSetOfProteinDesignMetadata(Set<ProteinInformation> proteinInformationSet) { List<String> listOfProteinMetaData = proteinInformationSet.stream().filter(Objects::nonNull) .map(this::renderProteinMetadata).collect(Collectors.toList()); String concatenatedListOfProteinMetaData = StringUtils.join(listOfProteinMetaData, ", "); return StringUtils.capitalize(concatenatedListOfProteinMetaData); }
From source file:nu.yona.server.analysis.service.ActivityService.java
private void createInactivityEntities(Set<IntervalInactivityDto> missingInactivities) { Map<UUID, Set<IntervalInactivityDto>> activitiesByUserAnonymizedId = missingInactivities.stream() .collect(Collectors.groupingBy(mia -> mia.getUserAnonymizedId().get(), Collectors.toSet())); activitiesByUserAnonymizedId/*from w w w . j ava 2s . c o m*/ .forEach((u, mias) -> analysisEngineProxyService.createInactivityEntities(u, mias)); }
From source file:com.thinkbiganalytics.feedmgr.rest.controller.FeedCategoryRestController.java
@GET @Path("{categoryId}/actions/change") @Produces(MediaType.APPLICATION_JSON)//w w w . java 2s . c o m @ApiOperation("Constructs and returns a permission change request for a set of users/groups containing the actions that the requester may permit or revoke.") @ApiResponses({ @ApiResponse(code = 200, message = "Returns the change request that may be modified by the client and re-posted.", response = PermissionsChange.class), @ApiResponse(code = 400, message = "The type is not valid.", response = RestResponseStatus.class), @ApiResponse(code = 404, message = "No category exists with the specified ID.", response = RestResponseStatus.class) }) public Response getAllowedPermissionsChange(@PathParam("categoryId") String categoryIdStr, @QueryParam("type") String changeType, @QueryParam("user") Set<String> userNames, @QueryParam("group") Set<String> groupNames) { if (StringUtils.isBlank(changeType)) { throw new WebApplicationException("The query parameter \"type\" is required", Status.BAD_REQUEST); } Set<? extends Principal> users = Arrays.stream(this.securityTransform.asUserPrincipals(userNames)) .collect(Collectors.toSet()); Set<? extends Principal> groups = Arrays.stream(this.securityTransform.asGroupPrincipals(groupNames)) .collect(Collectors.toSet()); return this.securityService .createCategoryPermissionChange(categoryIdStr, ChangeType.valueOf(changeType.toUpperCase()), Stream.concat(users.stream(), groups.stream()).collect(Collectors.toSet())) .map(p -> Response.ok(p).build()).orElseThrow(() -> new WebApplicationException( "A category with the given ID does not exist: " + categoryIdStr, Status.NOT_FOUND)); }
From source file:com.ggvaidya.scinames.ui.DatasetDiffController.java
private void regenerateByUniques() { byUniques.clear();//from w w w .ja v a 2s .c o m addUniqueMaps(byUniques); // Get columns from both datasets Set<DatasetColumn> cols = new HashSet<>( dataset1ComboBox.getSelectionModel().getSelectedItem().getColumns()); cols.retainAll(dataset2ComboBox.getSelectionModel().getSelectedItem().getColumns()); byUniques.addAll(cols.stream().sorted().collect(Collectors.toList())); }
From source file:org.graylog2.indexer.indices.Indices.java
public Optional<String> aliasTarget(String alias) throws TooManyAliasesException { final GetAliases request = new GetAliases.Builder().build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't collect indices for alias " + alias); // The ES return value of this has an awkward format: The first key of the hash is the target index. Thanks. final ImmutableSet.Builder<String> indicesBuilder = ImmutableSet.builder(); for (Map.Entry<String, JsonElement> entry : jestResult.getJsonObject().entrySet()) { final String indexName = entry.getKey(); Optional.of(entry.getValue()).map(GsonUtils::asJsonObject) .map(json -> asJsonObject(json.get("aliases"))).map(JsonObject::entrySet) .filter(aliases -> !aliases.isEmpty()) .filter(aliases -> aliases.stream().anyMatch(aliasEntry -> aliasEntry.getKey().equals(alias))) .ifPresent(x -> indicesBuilder.add(indexName)); }//from w w w .j a va2s.c o m final Set<String> indices = indicesBuilder.build(); if (indices.size() > 1) { throw new TooManyAliasesException(indices); } return indices.stream().findFirst(); }
From source file:nu.yona.server.analysis.service.ActivityService.java
private Map<ZonedDateTime, Set<DayActivityDto>> getDayActivitiesForUserAnonymizedIdsInInterval( Set<UUID> userAnonymizedIds, Set<UUID> relevantActivityCategoryIds, Interval interval, Set<IntervalInactivityDto> mia) { return userAnonymizedIds.stream() .map(id -> getDayActivitiesForCategories(userAnonymizedService.getUserAnonymized(id), relevantActivityCategoryIds, interval, mia)) .map(Map::entrySet).flatMap(Collection::stream) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> { Set<DayActivityDto> allActivities = new HashSet<>(a); allActivities.addAll(b); return allActivities; }));/*from www.jav a2s . c om*/ }
From source file:nu.yona.server.analysis.service.ActivityService.java
private Map<LocalDate, Set<WeekActivity>> getWeekActivitiesGroupedByDate(UUID userAnonymizedId, Interval interval) {/* w w w .jav a2s .c o m*/ Set<WeekActivity> weekActivityEntities = weekActivityRepository.findAll(userAnonymizedId, interval.startDate, interval.endDate); return weekActivityEntities.stream() .collect(Collectors.groupingBy(IntervalActivity::getStartDate, Collectors.toSet())); }
From source file:com.thinkbiganalytics.feedmgr.rest.controller.NifiIntegrationRestController.java
/** * Finds controller services of the specified type. * * @param processGroupId the process group id * @param type the type to match * @return the list of matching controller services *///from w ww . j a va 2 s . co m @GET @Path("/controller-services/process-group/{processGroupId}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation("Finds controller services of the specified type.") @ApiResponses({ @ApiResponse(code = 200, message = "Returns the matching controller services.", response = ControllerServiceDTO.class, responseContainer = "Set"), @ApiResponse(code = 400, message = "The type cannot be empty.", response = RestResponseStatus.class), @ApiResponse(code = 404, message = "The process group cannot be found.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "The process group is unavailable.", response = RestResponseStatus.class) }) public Response getControllerServices(@Nonnull @PathParam("processGroupId") final String processGroupId, @Nullable @QueryParam("type") final String type) { // Verify parameters if (StringUtils.isBlank(processGroupId)) { throw new NotFoundException(STRINGS.getString("getControllerServices.missingProcessGroup")); } if (StringUtils.isBlank(type)) { throw new BadRequestException(STRINGS.getString("getControllerServices.missingType")); } // Determine allowed service types final Stream<String> subTypes = nifiRestClient.controllerServices().getTypes(type).stream() .map(DocumentedTypeDTO::getType); final Set<String> allowedTypes = Stream.concat(Stream.of(type), subTypes).collect(Collectors.toSet()); // Filter controller services final Set<ControllerServiceDTO> controllerServices = ("all".equalsIgnoreCase(processGroupId) || "root".equalsIgnoreCase(processGroupId)) ? nifiRestClient.processGroups().getControllerServices("root") : nifiRestClient.processGroups().getControllerServices(processGroupId); final Set<ControllerServiceDTO> matchingControllerServices = controllerServices.stream() .filter(controllerService -> allowedTypes.contains(controllerService.getType())) .filter(datasourceService.getControllerServiceAccessControlFilter()).collect(Collectors.toSet()); return Response.ok(matchingControllerServices).build(); }