use of org.codelibs.core.lang.StringUtil in project fess by codelibs.
the class NotificationHelper method sendToSlack.
protected void sendToSlack(final CardView cardView, final SMailPostingDiscloser discloser) {
// https://api.slack.com/messaging/webhooks#posting_with_webhooks
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String slackWebhookUrls = fessConfig.getSlackWebhookUrls();
if (StringUtil.isBlank(slackWebhookUrls)) {
return;
}
final String body = toSlackMessage(discloser);
StreamUtil.split(slackWebhookUrls, "[,\\s]").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(url -> {
try (CurlResponse response = Curl.post(url).header("Content-Type", "application/json").body(body).execute()) {
if (response.getHttpStatusCode() == 200) {
if (logger.isDebugEnabled()) {
logger.debug("Sent {} to {}.", body, url);
}
} else {
logger.warn("Failed to send {} to {}. HTTP Status is {}. {}", body, url, response.getHttpStatusCode(), response.getContentAsString());
}
} catch (final IOException e) {
logger.warn("Failed to send {} to {}.", body, url, e);
}
}));
}
use of org.codelibs.core.lang.StringUtil in project fess by codelibs.
the class SamlCredential method getDefaultGroupsAsArray.
protected String[] getDefaultGroupsAsArray() {
final List<String> list = new ArrayList<>();
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String key = fessConfig.getSystemProperty("saml.attribute.group.name", "memberOf");
if (StringUtil.isNotBlank(key)) {
final List<String> nameList = attributes.get(key);
if (nameList != null) {
list.addAll(nameList);
}
}
final String value = fessConfig.getSystemProperty("saml.default.groups");
if (StringUtil.isNotBlank(value)) {
split(value, ",").of(stream -> stream.forEach(list::add));
}
return list.stream().filter(StringUtil::isNotBlank).map(String::trim).toArray(n -> new String[n]);
}
use of org.codelibs.core.lang.StringUtil in project fess by codelibs.
the class ApiAdminWebconfigAction method createEditBody.
protected EditBody createEditBody(final WebConfig entity) {
final EditBody body = new EditBody();
copyBeanToBean(entity, body, copyOp -> {
copyOp.excludeNull();
copyOp.exclude(Constants.PERMISSIONS, Constants.VIRTUAL_HOSTS);
});
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
body.permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
body.virtualHosts = stream(entity.getVirtualHosts()).get(stream -> stream.filter(StringUtil::isNotBlank).distinct().map(String::trim).collect(Collectors.joining("\n")));
return body;
}
use of org.codelibs.core.lang.StringUtil in project fess by codelibs.
the class AdminDataconfigAction method createnew.
// ===================================================================================
// Edit Execute
// ============
// -----------------------------------------------------
// Entry Page
// ----------
@Execute
@Secured({ ROLE })
public HtmlResponse createnew() {
saveToken();
return asEditHtml().useForm(CreateForm.class, op -> {
op.setup(form -> {
form.initialize();
ComponentUtil.getCrawlingConfigHelper().getDefaultConfig(ConfigType.DATA).ifPresent(entity -> {
copyBeanToBean(entity, form, copyOp -> {
copyOp.excludeNull();
copyOp.exclude(Stream.concat(Stream.of(Constants.COMMON_CONVERSION_RULE), Stream.of(Constants.PERMISSIONS, Constants.VIRTUAL_HOSTS)).toArray(n -> new String[n]));
});
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
form.permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining("\n")));
form.virtualHosts = stream(entity.getVirtualHosts()).get(stream -> stream.filter(StringUtil::isNotBlank).map(String::trim).collect(Collectors.joining("\n")));
form.name = null;
});
form.crudMode = CrudMode.CREATE;
});
});
}
use of org.codelibs.core.lang.StringUtil in project fess by codelibs.
the class AdminDataconfigAction method getDataConfig.
public static OptionalEntity<DataConfig> getDataConfig(final CreateForm form) {
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final String username = systemHelper.getUsername();
final long currentTime = systemHelper.getCurrentTimeAsLong();
return getEntity(form, username, currentTime).map(entity -> {
entity.setUpdatedBy(username);
entity.setUpdatedTime(currentTime);
copyBeanToBean(form, entity, op -> op.exclude(Stream.concat(Stream.of(Constants.COMMON_CONVERSION_RULE), Stream.of(Constants.PERMISSIONS, Constants.VIRTUAL_HOSTS)).toArray(n -> new String[n])));
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
entity.setPermissions(split(form.permissions, "\n").get(stream -> stream.map(s -> permissionHelper.encode(s)).filter(StringUtil::isNotBlank).distinct().toArray(n -> new String[n])));
entity.setVirtualHosts(split(form.virtualHosts, "\n").get(stream -> stream.filter(StringUtil::isNotBlank).distinct().map(String::trim).toArray(n -> new String[n])));
return entity;
});
}
Aggregations