use of java.util.Objects in project cxf by apache.
the class OpenApiParseUtils method getUserApplicationFromJson.
public static UserApplication getUserApplicationFromJson(String json, ParseConfiguration cfg) {
JsonMapObjectReaderWriter reader = new JsonMapObjectReaderWriter();
Map<String, Object> map = reader.fromJson(json);
UserApplication app = new UserApplication();
app.setBasePath("/");
List<Map<String, Object>> servers = CastUtils.cast((List<?>) map.get("servers"));
if (servers != null && !servers.isEmpty()) {
final String url = (String) servers.get(0).get("url");
if (url != null) {
app.setBasePath(url);
}
}
Map<String, List<UserOperation>> userOpsMap = new LinkedHashMap<String, List<UserOperation>>();
Set<String> tags = new HashSet<>();
List<Map<String, Object>> tagsProp = CastUtils.cast((List<?>) map.get("tags"));
if (tagsProp != null) {
for (Map<String, Object> tagProp : tagsProp) {
tags.add((String) tagProp.get("name"));
}
} else {
tags.add("");
}
for (String tag : tags) {
userOpsMap.put(tag, new LinkedList<UserOperation>());
}
Map<String, Map<String, Object>> paths = CastUtils.cast((Map<?, ?>) map.get("paths"));
for (Map.Entry<String, Map<String, Object>> pathEntry : paths.entrySet()) {
String operPath = pathEntry.getKey();
Map<String, Object> operations = pathEntry.getValue();
for (Map.Entry<String, Object> operEntry : operations.entrySet()) {
UserOperation userOp = new UserOperation();
userOp.setVerb(operEntry.getKey().toUpperCase());
Map<String, Object> oper = CastUtils.cast((Map<?, ?>) operEntry.getValue());
userOp.setPath(operPath);
userOp.setName((String) oper.get("operationId"));
Map<String, Object> responses = CastUtils.cast((Map<?, ?>) oper.get("responses"));
if (responses != null) {
userOp.setProduces(listToString(responses.entrySet().stream().map(entry -> CastUtils.cast((Map<?, ?>) entry.getValue())).map(value -> CastUtils.cast((Map<?, ?>) value.get("content"))).filter(Objects::nonNull).flatMap(content -> content.keySet().stream().map(type -> (String) type)).collect(Collectors.toList())));
}
Map<String, Object> payloads = CastUtils.cast((Map<?, ?>) oper.get("requestBody"));
if (payloads != null) {
userOp.setConsumes(listToString(payloads.entrySet().stream().map(entry -> CastUtils.cast((Map<?, ?>) entry.getValue())).map(value -> CastUtils.cast((Map<?, ?>) value.get("content"))).filter(Objects::nonNull).flatMap(content -> content.keySet().stream().map(type -> (String) type)).collect(Collectors.toList())));
}
List<Parameter> userOpParams = new LinkedList<Parameter>();
List<Map<String, Object>> params = CastUtils.cast((List<?>) oper.get("parameters"));
if (params != null) {
for (Map<String, Object> param : params) {
String name = (String) param.get("name");
// "query", "header", "path" or "cookie".
String paramType = (String) param.get("in");
ParameterType pType = null;
if ("query".equals(paramType)) {
pType = ParameterType.QUERY;
} else if ("header".equals(paramType)) {
pType = ParameterType.HEADER;
} else if ("path".equals(paramType)) {
pType = ParameterType.PATH;
} else if ("cookie".equals(paramType)) {
pType = ParameterType.COOKIE;
} else {
pType = ParameterType.REQUEST_BODY;
}
Parameter userParam = new Parameter(pType, name);
setJavaType(userParam, (String) param.get("type"));
userOpParams.add(userParam);
}
}
if (!userOpParams.isEmpty()) {
userOp.setParameters(userOpParams);
}
List<String> opTags = CastUtils.cast((List<?>) oper.get("tags"));
if (opTags == null) {
opTags = Collections.singletonList("");
}
for (String opTag : opTags) {
userOpsMap.get(opTag).add(userOp);
}
}
}
List<UserResource> resources = new LinkedList<UserResource>();
for (Map.Entry<String, List<UserOperation>> entry : userOpsMap.entrySet()) {
UserResource ur = new UserResource();
ur.setPath("/");
ur.setOperations(entry.getValue());
ur.setName(entry.getKey());
resources.add(ur);
}
app.setResources(resources);
return app;
}
use of java.util.Objects in project winery by eclipse.
the class Showcases method convert.
public MultiException convert(String path, String namespace, Stream<String> files) throws Exception {
MultiException exception = new MultiException();
files.map(name -> {
try {
return new LinkedHashMap.SimpleEntry<>(name, readServiceTemplate(path + File.separator + name));
} catch (Exception e) {
exception.add(e);
}
return null;
}).filter(Objects::nonNull).map(entry -> new LinkedHashMap.SimpleEntry<>(entry.getKey(), convert(entry.getValue(), entry.getKey(), namespace))).forEach(entry -> WriterUtils.saveDefinitions(entry.getValue(), outPath, namespace, entry.getKey()));
if (exception.hasException()) {
throw exception.getException();
}
return exception;
}
use of java.util.Objects in project pravega by pravega.
the class AsyncStorageWrapper method supplyAsync.
/**
* Executes the given Callable asynchronously and returns a CompletableFuture that will be completed with the result.
* @param operation The Callable to execute.
* @param segmentNames The names of the Segments involved in this operation (for sequencing purposes).
*/
private <R> CompletableFuture<R> supplyAsync(Callable<R> operation, String... segmentNames) {
Exceptions.checkNotClosed(this.closed.get(), this);
CompletableFuture<R> result;
synchronized (this.lastTasks) {
// Collect all futures this is dependent on.
val futures = Arrays.stream(segmentNames).map(this.lastTasks::get).filter(Objects::nonNull).map(t -> t.task).toArray(CompletableFuture[]::new);
int taskId = this.currentTaskId++;
if (futures.length == 0) {
// Nothing to depend on - free to execute now.
result = CompletableFuture.supplyAsync(() -> execute(operation, taskId, segmentNames), this.executor);
} else {
// We need to wait on these futures to complete before executing ours.
result = CompletableFuture.allOf(futures).handleAsync((r, ex) -> execute(operation, taskId, segmentNames), this.executor);
}
// Update the last task for each involved segment to be this so that future tasks can be properly sequenced.
RunningTask t = new RunningTask(taskId, result);
for (String s : segmentNames) {
this.lastTasks.put(s, t);
}
}
return result;
}
use of java.util.Objects in project drools by kiegroup.
the class DroolsObjectInputStream method bindAllExtractors.
public void bindAllExtractors(InternalKnowledgeBase kbase) {
extractorBinders.forEach((k, l) -> {
ClassFieldReader extractor = kbase.getPackagesMap().values().stream().map(pkg -> pkg.getClassFieldAccessorStore().getReader(k)).filter(Objects::nonNull).findFirst().orElseThrow(() -> new RuntimeException("Unknown extractor for " + k));
l.forEach(binder -> binder.accept(extractor));
});
}
use of java.util.Objects in project grakn by graknlabs.
the class ReasonerQueryImpl method getSubstitution.
/**
* @return substitution obtained from all id predicates (including internal) in the query
*/
public Answer getSubstitution() {
if (substitution == null) {
Set<Var> varNames = getVarNames();
Set<IdPredicate> predicates = getAtoms(IsaAtomBase.class).map(IsaAtomBase::getTypePredicate).filter(Objects::nonNull).filter(p -> varNames.contains(p.getVarName())).collect(Collectors.toSet());
getAtoms(IdPredicate.class).forEach(predicates::add);
HashMap<Var, Concept> answerMap = new HashMap<>();
predicates.forEach(p -> {
Concept concept = tx().getConcept(p.getPredicate());
if (concept == null)
throw GraqlQueryException.idNotFound(p.getPredicate());
answerMap.put(p.getVarName(), concept);
});
substitution = new QueryAnswer(answerMap);
}
return substitution;
}
Aggregations