List of usage examples for java.util Collection forEach
default void forEach(Consumer<? super T> action)
From source file:com.example.app.model.UserProfileDAO.java
/** * Delete the specified user profiles./*from www .j a va 2 s . c o m*/ * * @param userProfiles the user profiles to delete. */ public void deleteUserProfiles(Collection<? extends UserProfile> userProfiles) { beginTransaction(); boolean success = false; try { final Session session = getSession(); userProfiles.forEach(session::delete); success = true; } finally { if (success) commitTransaction(); else recoverableRollbackTransaction(); } }
From source file:io.kamax.mxisd.invitation.InvitationManager.java
@PostConstruct private void postConstruct() { gson = new Gson(); log.info("Loading saved invites"); Collection<ThreePidInviteIO> ioList = storage.getInvites(); ioList.forEach(io -> { log.info("Processing invite {}", gson.toJson(io)); ThreePidInvite invite = new ThreePidInvite(new MatrixID(io.getSender()), io.getMedium(), io.getAddress(), io.getRoomId(), io.getProperties()); ThreePidInviteReply reply = new ThreePidInviteReply(getId(invite), invite, io.getToken(), ""); invitations.put(reply.getId(), reply); });//ww w . j av a 2 s.c om // FIXME export such madness into matrix-java-sdk with a nice wrapper to talk to a homeserver try { SSLContext sslContext = SSLContextBuilder.create().loadTrustMaterial(new TrustSelfSignedStrategy()) .build(); HostnameVerifier hostnameVerifier = new NoopHostnameVerifier(); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier); client = HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build(); } catch (Exception e) { // FIXME do better... throw new RuntimeException(e); } log.info("Setting up invitation mapping refresh timer"); refreshTimer = new Timer(); refreshTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { lookupMappingsForInvites(); } catch (Throwable t) { log.error("Error when running background mapping refresh", t); } } }, 5000L, TimeUnit.MILLISECONDS.convert(cfg.getResolution().getTimer(), TimeUnit.MINUTES)); }
From source file:org.jboss.tools.openshift.internal.ui.wizard.newapp.fromtemplate.ApplicationSourceFromTemplateModel.java
private Map<String, String> toMap(Collection<IParameter> parameters) { Map<String, String> paramsMap = new HashMap<>(); if (parameters != null) { parameters.forEach(p -> paramsMap.put(p.getName(), p.getValue())); }//w ww . j a v a 2 s . c om return paramsMap; }
From source file:com.haulmont.cuba.core.sys.PersistenceSecurityImpl.java
@Override public void applyConstraints(Collection<Entity> entities) { Set<EntityId> handled = new LinkedHashSet<>(); entities.forEach(entity -> applyConstraints(entity, handled)); }
From source file:com.haulmont.cuba.core.sys.PersistenceSecurityImpl.java
@Override public void calculateFilteredData(Collection<Entity> entities) { Set<EntityId> handled = new LinkedHashSet<>(); entities.forEach(entity -> calculateFilteredData(entity, handled, false)); }
From source file:org.openhab.binding.nest.handler.NestBridgeHandler.java
private void broadcastStructures(Collection<Structure> structures) { structures.forEach(structure -> listeners.forEach(l -> l.onNewNestStructureData(structure))); }
From source file:org.openhab.binding.nest.handler.NestBridgeHandler.java
private void broadcastStructures(NestDeviceDataListener listener, Collection<Structure> structures) { structures.forEach(listener::onNewNestStructureData); }
From source file:co.kuali.rice.kew.notes.service.impl.RiceAttachmentDataToS3ConversionImpl.java
@Override public void execute() { LOG.info("Starting attachment conversion job for file_data to S3"); if (!processRecords()) { return;//from www . j a va 2s. c o m } final Collection<Attachment> attachments = dataObjectService.findMatching(Attachment.class, QueryByCriteria.Builder.fromPredicates(PredicateFactory.isNotNull("fileLoc"))).getResults(); attachments.forEach(attachment -> { try { final File file = new File(attachment.getFileLoc()); if (file.isFile() && file.exists()) { final byte[] fsBytes = FileUtils.readFileToByteArray(file); String fileDataId = attachment.getFileDataId(); final Object s3File; if (StringUtils.isBlank(fileDataId)) { fileDataId = UUID.randomUUID().toString(); s3File = null; } else { 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 + " attachment id " + attachment.getAttachmentId() + " 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 + " attachment id " + attachment.getAttachmentId()); } else { attachment.setFileDataId(fileDataId); if (isDeleteFromFileSystem()) { attachment.setFileLoc(null); } try { dataObjectService.save(attachment, PersistenceOption.FLUSH); } finally { 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.klerch.alexa.state.handler.AlexaSessionStateHandler.java
@Override public void removeValues(final Collection<String> ids) throws AlexaStateException { Validate.notNull(ids, "Collection of ids whose values to be removed must not be null."); ids.forEach(session::removeAttribute); }
From source file:ws.salient.model.Settings.java
private List<Profile> getProfiles(Collection<String> profileIds) { List<Profile> selectedProfiles = new LinkedList(); Optional.ofNullable(activeProfiles).orElse(Collections.EMPTY_LIST).forEach((id) -> { selectedProfiles.add(this.profiles.getOrDefault(id, new Profile())); });/* w w w .ja va 2 s . c o m*/ if (profileIds != null && this.profiles != null) { profileIds.forEach((id) -> { selectedProfiles.add(this.profiles.getOrDefault(id, new Profile())); }); } return selectedProfiles; }