List of usage examples for java.util Collection forEach
default void forEach(Consumer<? super T> action)
From source file:com.linagora.james.mailets.GuessClassificationMailet.java
private URI serviceUrlWithQueryParameters(Collection<MailAddress> recipients) throws URISyntaxException { URIBuilder uriBuilder = new URIBuilder(serviceUrl); recipients.forEach(address -> uriBuilder.addParameter("recipients", address.asString())); return uriBuilder.build(); }
From source file:com.holonplatform.auth.jwt.internal.DefaultJwtTokenParser.java
@Override public Builder parseJwt(JwtConfiguration configuration, String jwt) throws InvalidJwtConfigurationException, AuthenticationException { ObjectUtils.argumentNotNull(configuration, "JwtConfiguration must be not null"); ObjectUtils.argumentNotNull(jwt, "JWT token must be not null"); // decode and get claims Claims claims = null;/*w w w. j a v a 2 s .co m*/ try { JwtParser parser = Jwts.parser(); if (configuration.getSignatureAlgorithm() != JwtSignatureAlgorithm.NONE) { // Token expected to be signed (JWS) if (configuration.getSignatureAlgorithm().isSymmetric()) { parser = parser.setSigningKey(configuration.getSharedKey() .orElseThrow(() -> new UnexpectedAuthenticationException( "JWT authenticator not correctly configured: missing shared key for symmetric signature algorithm [" + configuration.getSignatureAlgorithm().getDescription() + "] - JWT configuration: [" + configuration + "]"))); } else { parser = parser.setSigningKey(configuration.getPublicKey() .orElseThrow(() -> new UnexpectedAuthenticationException( "JWT authenticator not correctly configured: missing public key for asymmetric signature algorithm [" + configuration.getSignatureAlgorithm().getDescription() + "] - JWT configuration: [" + configuration + "]"))); } claims = parser.parseClaimsJws(jwt).getBody(); } else { // not signed (JWT) claims = parser.parseClaimsJwt(jwt).getBody(); } } catch (@SuppressWarnings("unused") ExpiredJwtException eje) { throw new ExpiredCredentialsException("Expired JWT token"); } catch (@SuppressWarnings("unused") MalformedJwtException | UnsupportedJwtException mje) { throw new InvalidTokenException("Malformed or unsupported JWT token"); } catch (@SuppressWarnings("unused") SignatureException sje) { throw new InvalidTokenException("Invalid JWT token signature"); } catch (Exception e) { throw new UnexpectedAuthenticationException(ExceptionUtils.getRootCauseMessage(e), e); } // check claims if (claims == null) { throw new UnexpectedAuthenticationException("No valid claims found in JWT token"); } String principalName = claims.getSubject(); if (principalName == null) { throw new UnknownAccountException("No principal id (subject) found in JWT token"); } // build Authentication Authentication.Builder auth = Authentication.builder(principalName).scheme("Bearer").root(false); // process claims claims.forEach((n, v) -> { if (AuthenticationClaims.CLAIM_NAME_PERMISSIONS.equals(n)) { if (configuration.isIncludePermissions()) { @SuppressWarnings("unchecked") Collection<String> permissions = (Collection<String>) v; if (permissions != null) { permissions.forEach(p -> auth.withPermission(Permission.create(p))); } } } else { if (configuration.isIncludeDetails()) { auth.withParameter(n, v); } } }); return auth; }
From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.PhotoInspectorImpl.java
private void updateMap(Collection<Photo> photos) { mapScene.clear();// w ww .ja va 2s .c o m photos.forEach((photo) -> mapScene .addMarker(new LatLong(photo.getData().getLatitude(), photo.getData().getLongitude()))); mapScene.fitToMarkers(); }
From source file:org.kie.workbench.common.stunner.backend.service.DiagramServiceImpl.java
@PostConstruct public void init() { // Initialize caches. super.initialize(); // Initialize the application's VFS. initFileSystem();//from ww w. j a v a 2s .c om // Register packaged diagrams into VFS. registerAppDefinitions(); // Load vfs diagrams and put into the parent registry. final Collection<Diagram<Graph, Metadata>> diagrams = getAllDiagrams(); if (null != diagrams) { diagrams.forEach(diagram -> getRegistry().register(diagram)); } }
From source file:co.kuali.rice.krad.service.impl.RiceAttachmentDataToS3ConversionImpl.java
@Override public void execute() { LOG.info("Starting attachment conversion job for file_data to S3"); if (!processRecords()) { return;//from w w w . j av a2 s. co m } final Collection<Attachment> attachments = dataObjectService.findAll(Attachment.class).getResults(); attachments.forEach(attachment -> { try { final File file = new File(getDocumentDirectory(attachment.getNote().getRemoteObjectIdentifier()) + File.separator + attachment.getAttachmentIdentifier()); if (file.isFile() && file.exists()) { final byte[] fsBytes = FileUtils.readFileToByteArray(file); String fileDataId = attachment.getAttachmentIdentifier(); final Object s3File = riceS3FileService.retrieveFile(fileDataId); final byte[] s3Bytes; if (s3File == null) { final Class<?> s3FileClass = Class.forName(RiceAttachmentDataS3Constants.S3_FILE_CLASS); final Object newS3File = s3FileClass.newInstance(); final Method setId = s3FileClass.getMethod(RiceAttachmentDataS3Constants.SET_ID_METHOD, String.class); setId.invoke(newS3File, fileDataId); final Method setFileContents = s3FileClass.getMethod( RiceAttachmentDataS3Constants.SET_FILE_CONTENTS_METHOD, InputStream.class); try (InputStream stream = new BufferedInputStream(new ByteArrayInputStream(fsBytes))) { setFileContents.invoke(newS3File, stream); riceS3FileService.createFile(newS3File); } s3Bytes = getBytesFromS3File(riceS3FileService.retrieveFile(fileDataId)); } else { if (LOG.isDebugEnabled()) { final Method getFileMetaData = s3File.getClass() .getMethod(RiceAttachmentDataS3Constants.GET_FILE_META_DATA_METHOD); LOG.debug("data found in S3, existing id: " + fileDataId + " note id " + attachment.getNoteIdentifier() + " metadata: " + getFileMetaData.invoke(s3File)); } s3Bytes = getBytesFromS3File(s3File); } if (s3Bytes != null && fsBytes != null) { final String s3MD5 = DigestUtils.md5Hex(s3Bytes); final String dbMD5 = DigestUtils.md5Hex(fsBytes); if (!Objects.equals(s3MD5, dbMD5)) { LOG.error("S3 data MD5: " + s3MD5 + " does not equal DB data MD5: " + dbMD5 + " for id: " + fileDataId + " note id " + attachment.getNoteIdentifier()); } else { if (isDeleteFromFileSystem()) { file.delete(); } } } } } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | IOException | ClassNotFoundException | InstantiationException e) { throw new RuntimeException(e); } }); LOG.info("Finishing attachment conversion job for file_data to S3"); }
From source file:io.apicurio.hub.api.bitbucket.BitbucketSourceConnectorTest.java
@Test @Ignore/* w w w . j a va 2 s . co m*/ public void testGetRepositories() throws SourceConnectorException, BitbucketException { String team = "apicurio"; Collection<BitbucketRepository> repos = service.getRepositories(team); Assert.assertNotNull(repos); Assert.assertFalse(repos.isEmpty()); repos.forEach(repo -> { System.out.println("Found repository: " + repo.getName() + " -- " + repo.getSlug()); }); }
From source file:net.dv8tion.jda.core.managers.fields.PermissionField.java
/** * Sets the permissions for this PermissionField. * <br>Convenience method to provide multiple permissions with a single * method./*w ww. j av a2s . c o m*/ * * @param permissions * The {@link net.dv8tion.jda.core.Permission Permissions} to use * * @throws IllegalArgumentException * If the provided permission collection or any of the permissions within * it are null * @throws net.dv8tion.jda.core.exceptions.PermissionException * If the permissions provided require other permissions * to be available * * @return The {@link net.dv8tion.jda.core.managers.RoleManagerUpdatable RoleManagerUpdatable} instance * for this PermissionField for chaining convenience */ public RoleManagerUpdatable setPermissions(Collection<Permission> permissions) { Args.notNull(permissions, "permissions Collection"); permissions.forEach(p -> { Args.notNull(p, "Permission in the Collection"); }); return setValue(Permission.getRaw(permissions)); }
From source file:org.obiba.agate.web.rest.notification.NotificationsResource.java
/** * Lookup active users belonging to one the groups and verify its access to the application requesting the notification. * * @param groups/*from ww w . ja va2 s .co m*/ * @param emails */ private void appendRecipientsFromGroup(Collection<String> groups, Collection<User> recipients) { if (groups == null || groups.isEmpty()) return; // find all users in each group and having access to the application groups.forEach(group -> userService.findActiveUsersByApplicationAndGroup(getApplicationName(), group) .forEach(recipients::add)); }
From source file:net.dv8tion.jda.core.managers.fields.PermissionField.java
/** * Adds the specified permissions to the result value * <br>If any of the specified permissions is present in the revoked permissions it will be removed! * <br><b>This does not apply immediately - it is applied in the value returned by {@link #getValue()}</b> * * @param permissions/*from w w w . ja v a 2 s. c om*/ * Permissions that should be granted * * @throws IllegalArgumentException * If any of the provided Permissions is {@code null} * * @return The {@link net.dv8tion.jda.core.managers.RoleManagerUpdatable RoleManagerUpdatable} instance * for this PermissionField for chaining convenience */ public RoleManagerUpdatable givePermissions(Collection<Permission> permissions) { Args.notNull(permissions, "Permission Collection"); permissions.forEach(p -> { Args.notNull(p, "Permission in the Collection"); checkPermission(p); }); permsGiven.addAll(permissions); permsRevoked.removeAll(permissions); set = true; return manager; }
From source file:net.dv8tion.jda.core.managers.fields.PermissionField.java
/** * Adds the specified permissions to the result value * <br>These will override permissions that are given through {@link #givePermissions(Collection)} and {@link #givePermissions(Permission...)}! * <br><b>This does not apply immediately - it is applied in the value returned by {@link #getValue()}</b> * * @param permissions/*w w w . j av a2 s . c o m*/ * Permissions that should be revoked * * @throws IllegalArgumentException * If any of the provided Permissions is {@code null} * * @return The {@link net.dv8tion.jda.core.managers.RoleManagerUpdatable RoleManagerUpdatable} instance * for this PermissionField for chaining convenience */ public RoleManagerUpdatable revokePermissions(Collection<Permission> permissions) { Args.notNull(permissions, "Permission Collection"); permissions.forEach(p -> { Args.notNull(p, "Permission in the Collection"); checkPermission(p); }); permsRevoked.addAll(permissions); permsGiven.removeAll(permissions); set = true; return manager; }