use of org.apache.commons.lang3.StringUtils.substringAfter in project kylo by Teradata.
the class DebugController method queryJcr.
/**
* Prints the nodes of the JCR path given, for debugging.
*
* @param query the jcr query
* @return a printout of the JCR tree
*/
@GET
@Path("jcr-sql")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
public JcrQueryResult queryJcr(@QueryParam("query") final String query) {
return metadata.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ADMIN_METADATA);
List<List<String>> rows = new ArrayList<>();
Long startTime = System.currentTimeMillis();
JcrQueryResult jcrQueryResult = new JcrQueryResult();
try {
Session session = JcrMetadataAccess.getActiveSession();
Workspace workspace = (Workspace) session.getWorkspace();
String explainPlain = JcrQueryUtil.explainPlain(session, query);
// start the timer now:
startTime = System.currentTimeMillis();
QueryResult result = JcrQueryUtil.query(session, query);
jcrQueryResult.setExplainPlan(explainPlain);
RowIterator rowItr = result.getRows();
List<JcrQueryResultColumn> columns = new ArrayList<>();
String colsStr = StringUtils.substringAfter(query.toLowerCase(), "select");
colsStr = StringUtils.substringBefore(colsStr, "from");
if (StringUtils.isNotBlank(colsStr)) {
colsStr = colsStr.trim();
columns = Arrays.asList(colsStr.split(",")).stream().map(c -> {
String columnName = c;
if (c.contains("as ")) {
columnName = StringUtils.substringAfter(c, "as ");
} else if (c.contains(" ")) {
columnName = StringUtils.substringAfter(c, " ");
}
return new JcrQueryResultColumn(columnName);
}).collect(Collectors.toList());
}
jcrQueryResult.setColumns(columns);
while (rowItr.hasNext()) {
Row row = rowItr.nextRow();
Value[] rowValues = row.getValues();
if (rowValues != null) {
if (rowValues.length != columns.size()) {
columns = IntStream.range(0, rowValues.length).mapToObj(i -> new JcrQueryResultColumn("Column " + i)).collect(Collectors.toList());
jcrQueryResult.setColumns(columns);
}
JcrQueryResultRow jcrQueryResultRow = new JcrQueryResultRow();
jcrQueryResult.addRow(jcrQueryResultRow);
List<JcrQueryResultColumnValue> jcrQueryResultColumnValues = Arrays.asList(rowValues).stream().map(v -> {
try {
String value = v.getString();
return new JcrQueryResultColumnValue(value);
} catch (Exception e) {
return new JcrQueryResultColumnValue("ERROR: " + e.getMessage());
}
}).collect(Collectors.toList());
jcrQueryResultRow.setColumnValues(jcrQueryResultColumnValues);
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
long totalTime = System.currentTimeMillis() - startTime;
jcrQueryResult.setQueryTime(totalTime);
return jcrQueryResult;
});
}
use of org.apache.commons.lang3.StringUtils.substringAfter in project openEHR_SDK by ehrbase.
the class DvCodedTextRMUnmarshaller method handle.
/**
* {@inheritDoc}
*/
@Override
public void handle(String currentTerm, DvCodedText rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
setValue(currentTerm, "value", currentValues, rmObject::setValue, String.class, consumedPaths);
rmObject.setDefiningCode(new CodePhrase());
setValue(currentTerm, "code", currentValues, c -> rmObject.getDefiningCode().setCodeString(c), String.class, consumedPaths);
rmObject.getDefiningCode().setTerminologyId(new TerminologyId());
setValue(currentTerm, "terminology", currentValues, t -> rmObject.getDefiningCode().getTerminologyId().setValue(t), String.class, consumedPaths);
if (rmObject.getDefiningCode().getCodeString() == null && rmObject.getValue() == null) {
setValue(currentTerm, null, currentValues, c -> {
if (c != null) {
// try to interpret as code
setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), c));
if (rmObject.getValue() == null) {
// try to interpret as value
setFromNode(rmObject, context, v -> Objects.equals(v.getLabel(), c));
}
}
}, String.class, consumedPaths);
} else if (rmObject.getDefiningCode().getCodeString() == null) {
setValue(currentTerm, null, currentValues, // It is the code
c -> rmObject.getDefiningCode().setCodeString(c), String.class, consumedPaths);
}
// Set terminology from Node
Optional.of(context.getNodeDeque().peek().getInputs()).stream().flatMap(List::stream).filter(i -> "code".equals(i.getSuffix())).findAny().map(WebTemplateInput::getTerminology).ifPresent(t -> rmObject.getDefiningCode().getTerminologyId().setValue(t));
// Set value from Node
setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), rmObject.getDefiningCode().getCodeString()));
// set code from value if not set
if (rmObject.getDefiningCode().getCodeString() == null && rmObject.getValue() != null) {
setFromNode(rmObject, context, v -> Objects.equals(v.getLabel(), rmObject.getValue()));
}
setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), rmObject.getDefiningCode().getCodeString()));
// consume strange legacy paths
if (rmObject.getDefiningCode() != null && rmObject.getDefiningCode().getCodeString() != null) {
currentValues.keySet().stream().map(FlatPathDto::format).filter(k -> StringUtils.substringAfter(k, "|").equals(rmObject.getDefiningCode().getCodeString())).forEach(consumedPaths::add);
}
setValue(currentTerm, "formatting", currentValues, rmObject::setFormatting, String.class, consumedPaths);
}
use of org.apache.commons.lang3.StringUtils.substringAfter in project tumo-boot by Tumo-Team.
the class AuthUtil method getRoleNames.
/**
* 获取用户角色Alias集合
*/
public static List<String> getRoleNames() {
List<String> roleNames = new ArrayList<>();
Authentication authentication = getAuthentication();
if (authentication == null) {
return roleNames;
}
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
authorities.stream().filter(granted -> StringUtils.startsWith(granted.getAuthority(), AuthConstant.ROLE_PREFIX)).forEach(granted -> {
String name = StringUtils.substringAfter(granted.getAuthority(), AuthConstant.ROLE_SUFFIX);
roleNames.add(name);
});
return roleNames;
}
use of org.apache.commons.lang3.StringUtils.substringAfter in project kylo by Teradata.
the class RefreshableDataSourceTest method testCreateDataSourceAndGetProperties.
private Map<String, String> testCreateDataSourceAndGetProperties() throws Exception {
DataSource ds = Whitebox.invokeMethod(hiveDs, "create", true, principal);
Map<String, String> props = Arrays.stream(ds.toString().split("; ")).collect(Collectors.toMap(s -> StringUtils.substringBefore(s, "="), s -> StringUtils.substringAfter(s, "=")));
return props;
}
use of org.apache.commons.lang3.StringUtils.substringAfter in project Piped-Backend by TeamPiped.
the class DownloaderImpl method executeRequest.
/**
* Executes a request with HTTP/2.
*/
public Response executeRequest(Request request) throws IOException, ReCaptchaException {
// TODO: HTTP/3 aka QUIC
var bytes = request.dataToSend();
RequestBody body = null;
if (bytes != null)
body = RequestBody.create(bytes);
var builder = new okhttp3.Request.Builder().url(request.url()).method(request.httpMethod(), body).header("User-Agent", Constants.USER_AGENT);
if (saved_cookie != null && !saved_cookie.hasExpired())
builder.header("Cookie", saved_cookie.getName() + "=" + saved_cookie.getValue());
request.headers().forEach((name, values) -> values.forEach(value -> builder.header(name, value)));
var resp = Constants.h2client.newCall(builder.build()).execute();
if (resp.code() == 429) {
synchronized (cookie_lock) {
if (saved_cookie != null && saved_cookie.hasExpired() || (System.currentTimeMillis() - cookie_received > TimeUnit.MINUTES.toMillis(30)))
saved_cookie = null;
String redir_url = String.valueOf(resp.request().url());
if (saved_cookie == null && redir_url.startsWith("https://www.google.com/sorry")) {
var formBuilder = new FormBody.Builder();
String sitekey = null, data_s = null;
for (Element el : Jsoup.parse(resp.body().string()).selectFirst("form").children()) {
String name;
if (!(name = el.tagName()).equals("script")) {
if (name.equals("input"))
formBuilder.add(el.attr("name"), el.attr("value"));
else if (name.equals("div") && el.attr("id").equals("recaptcha")) {
sitekey = el.attr("data-sitekey");
data_s = el.attr("data-s");
}
}
}
if (StringUtils.isEmpty(sitekey) || StringUtils.isEmpty(data_s))
throw new ReCaptchaException("Could not get recaptcha", redir_url);
SolvedCaptcha solved = null;
try {
solved = CaptchaSolver.solve(redir_url, sitekey, data_s);
} catch (JsonParserException | InterruptedException e) {
e.printStackTrace();
}
formBuilder.add("g-recaptcha-response", solved.getRecaptchaResponse());
var formReqBuilder = new okhttp3.Request.Builder().url("https://www.google.com/sorry/index").header("User-Agent", Constants.USER_AGENT).post(formBuilder.build());
var formResponse = Constants.h2_no_redir_client.newCall(formReqBuilder.build()).execute();
saved_cookie = HttpCookie.parse(URLUtils.silentDecode(StringUtils.substringAfter(formResponse.headers().get("Location"), "google_abuse="))).get(0);
cookie_received = System.currentTimeMillis();
}
if (// call again as captcha has been solved or cookie has not expired.
saved_cookie != null)
execute(request);
}
}
var response = new Response(resp.code(), resp.message(), resp.headers().toMultimap(), resp.body().string(), String.valueOf(resp.request().url()));
resp.close();
return response;
}
Aggregations