List of usage examples for java.util Collection forEach
default void forEach(Consumer<? super T> action)
From source file:org.apache.jena.fuseki.servlets.Dispatcher.java
/** * Find the ActionProcessor or return null if there can't determine one. This * function does NOT return null; it throws ActionErrorException after sending an * HTTP error response.// w w w . j a va 2 s .c o m * * Returning null indicates an error, and the HTTP response * has been done. */ private static ActionProcessor chooseProcessor(HttpAction action) { // "return null" indicates that processing failed to find a ActionProcessor DataAccessPoint dataAccessPoint = action.getDataAccessPoint(); DataService dataService = action.getDataService(); if (!dataService.isAcceptingRequests()) { ServletOps.error(HttpSC.SERVICE_UNAVAILABLE_503, "Dataset not currently active"); return null; } // ---- Determine Endpoint. String endpointName = mapRequestToOperation(action, dataAccessPoint); Endpoint ep = chooseEndpoint(action, dataService, endpointName); if (ep == null) { if (isEmpty(endpointName)) ServletOps.errorBadRequest("No operation for request: " + action.getActionURI()); else ServletOps.errorNotFound("No endpoint: " + action.getActionURI()); return null; } Operation operation = ep.getOperation(); if (operation == null) { ServletOps.errorNotFound("No operation: " + action.getActionURI()); return null; } action.setEndpoint(ep); // ---- Authorization // -- Server-level authorization. // Checking was carried out by servlet filter AuthFilter. // Need to check Data service and endpoint authorization policies. String user = action.getUser(); // -- Data service level authorization if (dataService.authPolicy() != null) { if (!dataService.authPolicy().isAllowed(user)) ServletOps.errorForbidden(); } // -- Endpoint level authorization // Make sure all contribute authentication. Auth.allow(user, action.getEndpoint().getAuthPolicy(), ServletOps::errorForbidden); if (isEmpty(endpointName) && !ep.isUnnamed()) { // [DISPATCH LEGACY] // If choice was by looking in all named endpoints for a unnamed endpoint // request, ensure all choices allow access. // There may be several endpoints for the operation. // Authorization is the AND of all endpoints. Collection<Endpoint> x = getEndpoints(dataService, operation); if (x.isEmpty()) throw new InternalErrorException("Inconsistent: no endpoints for " + operation); x.forEach(ept -> Auth.allow(user, ept.getAuthPolicy(), ServletOps::errorForbidden)); } // ---- Authorization checking. // ---- Handler. // Decide the code to execute the request. // ActionProcessor handler = target(action, operation); ActionProcessor processor = target(action, operation); if (processor == null) ServletOps.errorBadRequest(format("dataset=%s: op=%s", dataAccessPoint.getName(), operation.getName())); return processor; }
From source file:org.ambraproject.wombat.controller.WombatController.java
/** * If any validation errors from a form are present, set them up to be rendered. * <p>/*from ww w .j av a 2 s .c om*/ * If this method returns {@code true}, it generally means that the calling controller should halt and render a page * displaying the validation messages. * * @param response the response * @param model the model * @param validationErrorNames attribute names for present validation errors * @return {@code true} if a validation error is present */ protected static boolean applyValidation(HttpServletResponse response, Model model, Collection<String> validationErrorNames) { if (validationErrorNames.isEmpty()) return false; /* * Presently, it is assumed that all validation error messages in FreeMarker use a simple presence/absence check * with the '??' operator. The value 'true' is just a placeholder. If any validation error messages require more * specific values, they must be added to the model separately. Refactor this method if that happens too often. */ validationErrorNames.forEach(error -> model.addAttribute(error, true)); response.setStatus(HttpStatus.BAD_REQUEST.value()); return true; }
From source file:org.openecomp.sdc.validation.impl.util.ResourceValidationHeatValidator.java
/** * Handle not empty resource names list. * * @param fileName the file name * @param resourcesNameList the resources name list * @param securityOrServerGroup the security or server group * @param globalContext the global context */// w w w .j a v a 2s. co m public static void handleNotEmptyResourceNamesList(String fileName, Collection<String> resourcesNameList, String securityOrServerGroup, GlobalValidationContext globalContext) { if (CollectionUtils.isNotEmpty(resourcesNameList)) { resourcesNameList.forEach(name -> globalContext.addMessage(fileName, ErrorLevel.WARNING, ErrorMessagesFormatBuilder.getErrorWithParameters( Messages.SERVER_OR_SECURITY_GROUP_NOT_IN_USE.getErrorMessage(), securityOrServerGroup, name))); } }
From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java
public static <T extends Element> Map<String, T> getElementsById(Collection<T> elements) { Map<String, T> result = new LinkedHashMap<>(); elements.forEach(e -> result.put(e.getId(), e)); return result; }
From source file:org.onosproject.netconf.ctl.impl.NetconfSshdTestSubsystem.java
public static String getTestHelloReply(Collection<String> capabilities, Optional<Long> sessionId) { StringBuilder sb = new StringBuilder(); sb.append("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"); sb.append("<capabilities>"); capabilities.forEach(capability -> { sb.append("<capability>").append(capability).append("</capability>"); });/* w w w . java2 s.c o m*/ sb.append("</capabilities>"); if (sessionId.isPresent()) { sb.append("<session-id>"); sb.append(sessionId.get().toString()); sb.append("</session-id>"); } sb.append("</hello>"); return sb.toString(); }
From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java
public static <V extends Node> Graph<V, Edge<V>> createGraph(BetterVisualizationViewer<V, Edge<V>> owner, Collection<V> nodes, Collection<Edge<V>> edges) { Graph<V, Edge<V>> graph = new BetterDirectedSparseMultigraph<>(owner); nodes.forEach(n -> graph.addVertex(n)); edges.forEach(e -> graph.addEdge(e, e.getFrom(), e.getTo())); return graph; }
From source file:javadepchecker.Main.java
/** * Check for orphaned class files not owned by any package in dependencies * * @param pkg Gentoo package name//from w ww . j a va 2 s. c om * @param deps collection of dependencies for the package * @return boolean if the dependency is found or not * @throws IOException */ private static boolean depsFound(Collection<String> pkgs, Collection<String> deps) throws IOException { boolean found = true; Collection<String> jars = new ArrayList<>(); String[] bootClassPathJars = System.getProperty("sun.boot.class.path").split(":"); // Do we need "java-config -r" here? for (String jar : bootClassPathJars) { File jarFile = new File(jar); if (jarFile.exists()) { jars.add(jar); } } pkgs.forEach((String pkg) -> { jars.addAll(getPackageJars(pkg)); }); if (jars.isEmpty()) { return false; } ArrayList<String> jarClasses = new ArrayList<>(); jars.forEach((String jarName) -> { try { JarFile jar = new JarFile(jarName); Collections.list(jar.entries()).forEach((JarEntry entry) -> { jarClasses.add(entry.getName()); }); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }); for (String dep : deps) { if (!jarClasses.contains(dep)) { if (found) { System.out.println("Class files not found via DEPEND in package.env"); } System.out.println("\t" + dep); found = false; } } return found; }
From source file:org.jactr.eclipse.runtime.launching.env.EnvironmentConfigurator.java
@SuppressWarnings("unchecked") static private void setupRuntimeTracers(PrintWriter pw, String credentials, String address, int port, String mode, boolean isIterative, ILaunchConfiguration config) throws CoreException { boolean isDebug = mode.equals(ILaunchManager.DEBUG_MODE); boolean useNetworkSync = config.getAttribute(ACTRLaunchConstants.ATTR_IDE_TRACE, false); boolean useArchivalSync = config.getAttribute(ACTRLaunchConstants.ATTR_RECORD_TRACE, false); /*//from w ww . j a v a 2 s. co m * if iterative run, no sync is permitted - unless it is archival. iterative * normal : only archival, if selected. iterative debug : only archival, if * selected. normal : selected debug : +networked */ if (isIterative) useNetworkSync = false; else useNetworkSync ^= isDebug; // we force it on // not using any? leave if (!useArchivalSync && !useNetworkSync) return; Map<String, Map<String, String>> traceListeners = new TreeMap<String, Map<String, String>>(); Collection<RuntimeTracerDescriptor> selectedTraceListeners = ACTRLaunchConfigurationUtils .getRequiredTracers(config); selectedTraceListeners.forEach((rtd) -> { try { traceListeners.put(rtd.getClassName(), config.getAttribute( ACTRLaunchConstants.ATTR_PARAMETERS + rtd.getClassName(), Collections.EMPTY_MAP)); } catch (Exception e) { LOGGER.error("EnvironmentConfigurator. threw Exception : ", e); } }); if (isDebug && !isIterative) // we must be using network sync.. traceListeners.put(ProceduralModuleTracer.class.getName(), Collections.EMPTY_MAP); if (traceListeners.size() > 0) { /* * now we actually do the writing. If there are */ pw.println("<!-- and this routes events like log and production firing over the network -->"); pw.println(" <attachment class=\"" + RuntimeTracer.class.getName() + "\" attach=\"all\">"); pw.println(" <parameters>"); pw.println(" <parameter name=\"" + RuntimeTracer.EXECUTOR_PARAM + "\" value=\"Background\"/>"); Collection<String> sinks = new ArrayList<String>(); if (useArchivalSync) sinks.add(ArchivalSink.class.getName()); if (useNetworkSync) sinks.add(NetworkedSink.class.getName()); pw.println(" <parameter name=\"" + RuntimeTracer.SINK_CLASS + "\" value=\"" + sinks.stream().collect(Collectors.joining(",")) + "\"/>"); pw.println(" <parameter name=\"" + RuntimeTracer.LISTENERS + "\" value=\"" + traceListeners.keySet().stream().collect(Collectors.joining(",")) + "\"/>"); traceListeners.entrySet().forEach((e) -> { Map<String, String> params = e.getValue(); if (params.size() > 0) { pw.println("<!-- parameters for " + e.getKey() + "-->"); params.entrySet().forEach((pe) -> { pw.println(" <parameter name=\"" + pe.getKey() + "\" value=\"" + pe.getValue() + "\"/>"); }); } }); pw.println(" </parameters>"); pw.println(" </attachment>"); if (useNetworkSync) { /* * auto install the synch manager.. */ pw.println("<!-- since we are connecting to the IDE, we'll auto install the sync tool -->"); pw.println(String.format("<attachment class=\"%s\" />", SynchronizationManager.class.getName())); } } // /* // * the uses of traces is more complex than the above. Tracers are used if // we // * are non-iterative debug (which gives us break point control). Tracers // are // * used there are requested tracers (from the run config), AND at least // one // * sync // */ // // if (useTracer) // { // pw.println("<!-- and this routes events like log and production firing over the network -->"); // pw.println(" <attachment class=\"" + RuntimeTracer.class.getName() // + "\" attach=\"all\">"); // // pw.println(" <parameters>"); // pw.println(" <parameter name=\"" + RuntimeTracer.EXECUTOR_PARAM // + "\" value=\"Background\"/>"); // // /* // * normal runs almost always route to the IDE, but iterative runs never // * do. However, iterative runs are allowed to use the ArchivalSink // */ // StringBuilder sinks = new StringBuilder(); // // if (!isIterative // && config.getAttribute(ACTRLaunchConstants.ATTR_IDE_TRACE, true)) // sinks.append(NetworkedSink.class.getName()).append(","); // // if (config.getAttribute(ACTRLaunchConstants.ATTR_RECORD_TRACE, false)) // sinks.append(ArchivalSink.class.getName()).append(","); // // sinks.delete(sinks.length() - 1, sinks.length()); // // pw.println(" <parameter name=\"" + RuntimeTracer.SINK_CLASS // + "\" value=\"" + sinks.toString() + "\"/>"); // // Collection<RuntimeTracerDescriptor> traceListeners = // ACTRLaunchConfigurationUtils // .getRequiredTracers(config); // StringBuilder listeners = new StringBuilder(); // boolean hasDebug = false; // for (RuntimeTracerDescriptor listener : traceListeners) // { // if (!hasDebug // && listener.getClassName().equals( // ProceduralModuleTracer.class.getName())) hasDebug = true; // // listeners.append(listener.getClassName()).append(","); // // Map<String, String> parameters = config.getAttribute( // ACTRLaunchConstants.ATTR_PARAMETERS + listener.getClassName(), // new TreeMap<String, String>()); // if (parameters.size() > 0) // { // pw.println("<!-- params for " + listener.getClassName() + " -->"); // for (Map.Entry<String, String> parameter : parameters.entrySet()) // pw.println(" <parameter name=\"" + parameter.getKey() // + "\" value=\"" + parameter.getValue() + "\"/>"); // } // } // // // kill ',' // if (listeners.length() != 0) // listeners.delete(listeners.length() - 1, listeners.length()); // // if (mode.equals(ILaunchManager.DEBUG_MODE) && !hasDebug) // { // if (listeners.length() != 0) listeners.append(","); // listeners.append(ProceduralModuleTracer.class.getName()); // } // // pw.println(" <parameter name=\"" + RuntimeTracer.LISTENERS // + "\" value=\"" + listeners + "\"/>"); // // pw.println(" </parameters>"); // // pw.println(" </attachment>"); // } }
From source file:documents.DocumentProvider.java
public void addDocuments(Collection<? extends Document> docs) { docs.forEach(this::addDocument); newDocumentsAvailable();//from www .jav a 2s. c om }
From source file:org.thingsplode.server.bus.executors.EventSyncExecutor.java
@Override public void executeImpl(EventSync sync, MessageHeaders headers, Device device) { Calendar now = Calendar.getInstance(); Collection<Event> evts = sync.getEvents(); evts.forEach(e -> { if (sync.getComponentName().equalsIgnoreCase(device.getIdentification())) { e.setComponent(device);//from w w w .j a v a 2 s . c o m } else { e.setComponent(device.getComponentByName(sync.getComponentName())); } if (e.getReceiveDate() == null) { e.setReceiveDate(now); } if (e.getEventDate() == null) { e.setEventDate(now); } }); eventRepo.save(evts); }