use of org.apache.commons.lang3.ArrayUtils.isEmpty in project alf.io by alfio-event.
the class SmtpMailer method send.
@Override
public void send(Event event, String to, List<String> cc, String subject, String text, Optional<String> html, Attachment... attachments) {
MimeMessagePreparator preparator = (mimeMessage) -> {
MimeMessageHelper message = html.isPresent() || !ArrayUtils.isEmpty(attachments) ? new MimeMessageHelper(mimeMessage, true, "UTF-8") : new MimeMessageHelper(mimeMessage, "UTF-8");
message.setSubject(subject);
message.setFrom(configurationManager.getRequiredValue(Configuration.from(event.getOrganizationId(), event.getId(), SMTP_FROM_EMAIL)), event.getDisplayName());
String replyTo = configurationManager.getStringConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), MAIL_REPLY_TO), "");
if (StringUtils.isNotBlank(replyTo)) {
message.setReplyTo(replyTo);
}
message.setTo(to);
if (cc != null && !cc.isEmpty()) {
message.setCc(cc.toArray(new String[cc.size()]));
}
if (html.isPresent()) {
message.setText(text, html.get());
} else {
message.setText(text, false);
}
if (attachments != null) {
for (Attachment a : attachments) {
message.addAttachment(a.getFilename(), new ByteArrayResource(a.getSource()), a.getContentType());
}
}
message.getMimeMessage().saveChanges();
message.getMimeMessage().removeHeader("Message-ID");
};
toMailSender(event).send(preparator);
}
use of org.apache.commons.lang3.ArrayUtils.isEmpty in project acs-aem-commons by Adobe-Consulting-Services.
the class DynamicSelectDataSource method doGet.
@Override
protected void doGet(@Nonnull SlingHttpServletRequest request, @Nonnull SlingHttpServletResponse response) throws ServletException, IOException {
final ResourceResolver resolver = request.getResourceResolver();
final ValueMap properties = request.getResource().getValueMap();
final List<DataSourceOption> options = new ArrayList<>();
try {
// The query language property
final String queryLanguage = properties.get(PN_DROP_DOWN_QUERY_LANGUAGE, JCR_SQL2);
// The query statement (this must match the queryLanguage else the query will fail)
final String queryStatement = properties.get(PN_DROP_DOWN_QUERY, String.class);
// The property names to extract; these are specified as a String[] property
final String[] allowedPropertyNames = properties.get(PN_ALLOW_PROPERTY_NAMES, new String[0]);
if (StringUtils.isNotBlank(queryStatement)) {
// perform the query
final List<Resource> results = queryHelper.findResources(resolver, queryLanguage, queryStatement, StringUtils.EMPTY);
final List<String> distinctOptionValues = new ArrayList<>();
for (final Resource resource : results) {
// For each result...
// - ensure the property value is a String
// - ensure either no properties have been specified (which means ALL properties are eligible) OR the property is in the list of enumerated propertyNames
// - ensure this property value has not already been processed
// -- if the above criteria is satisfied, add to the options
resource.getValueMap().entrySet().stream().filter(entry -> entry.getValue() instanceof String).filter(entry -> ArrayUtils.isEmpty(allowedPropertyNames) || ArrayUtils.contains(allowedPropertyNames, entry.getKey())).filter(entry -> !distinctOptionValues.contains(entry.getValue().toString())).forEach(entry -> {
String value = entry.getValue().toString();
distinctOptionValues.add(value);
options.add(new DataSourceOption(value, value));
});
}
}
// Create a datasource from the collected options, even if there are 0 options.
dataSourceBuilder.addDataSource(request, options);
} catch (Exception e) {
log.error("Unable to collect the information to populate the ACS Commons Report Builder dynamic-select drop-down.", e);
response.sendError(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
}
use of org.apache.commons.lang3.ArrayUtils.isEmpty in project alien4cloud by alien4cloud.
the class AbstractLocationResourcesBatchSecurityController method processRevokeForSubjectType.
private void processRevokeForSubjectType(Subject subjectType, String[] resources, String[] subjects) {
if (ArrayUtils.isEmpty(resources)) {
return;
}
Arrays.stream(resources).forEach(resourceId -> {
AbstractLocationResourceTemplate resourceTemplate = locationResourceService.getOrFail(resourceId);
resourcePermissionService.revokePermission(resourceTemplate, (resource -> locationResourceService.saveResource((AbstractLocationResourceTemplate) resource)), subjectType, subjects);
});
}
use of org.apache.commons.lang3.ArrayUtils.isEmpty in project azure-tools-for-java by Microsoft.
the class AzureSdkTreePanel method loadData.
private void loadData(final Map<String, List<AzureSdkCategoryEntity>> categoryToServiceMap, final List<? extends AzureSdkServiceEntity> services, String... filters) {
final DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.model.getRoot();
root.removeAllChildren();
final Map<String, AzureSdkServiceEntity> serviceMap = services.stream().collect(Collectors.toMap(e -> getServiceKeyByName(e.getName()), e -> e));
final List<String> categories = categoryToServiceMap.keySet().stream().filter(StringUtils::isNotBlank).sorted((s1, s2) -> StringUtils.contains(s1, "Others") ? 1 : StringUtils.contains(s2, "Others") ? -1 : s1.compareTo(s2)).collect(Collectors.toList());
for (final String category : categories) {
// no feature found for current category
if (CollectionUtils.isEmpty(categoryToServiceMap.get(category)) || categoryToServiceMap.get(category).stream().allMatch(e -> Objects.isNull(serviceMap.get(getServiceKeyByName(e.getServiceName()))) || CollectionUtils.isEmpty(serviceMap.get(getServiceKeyByName(e.getServiceName())).getContent()))) {
continue;
}
// add features for current category
final MutableTreeNode categoryNode = new DefaultMutableTreeNode(category);
final boolean categoryMatched = this.isMatchedFilters(category, filters);
categoryToServiceMap.get(category).stream().sorted(Comparator.comparing(AzureSdkCategoryEntity::getServiceName)).forEach(categoryService -> {
final AzureSdkServiceEntity service = serviceMap.get(getServiceKeyByName(categoryService.getServiceName()));
this.loadServiceData(service, categoryService, categoryNode, filters);
});
if (ArrayUtils.isEmpty(filters) || categoryMatched || categoryNode.getChildCount() > 0) {
this.model.insertNodeInto(categoryNode, root, root.getChildCount());
}
}
this.model.reload();
if (ArrayUtils.isNotEmpty(filters)) {
TreeUtil.expandAll(this.tree);
}
TreeUtil.promiseSelectFirstLeaf(this.tree);
}
use of org.apache.commons.lang3.ArrayUtils.isEmpty in project alf.io by alfio-event.
the class SmtpMailer method send.
@Override
public void send(Configurable configurable, String fromName, String to, List<String> cc, String subject, String text, Optional<String> html, Attachment... attachments) {
var conf = configurationManager.getFor(Set.of(SMTP_FROM_EMAIL, MAIL_REPLY_TO, SMTP_HOST, SMTP_PORT, SMTP_PROTOCOL, SMTP_USERNAME, SMTP_PASSWORD, SMTP_PROPERTIES), configurable.getConfigurationLevel());
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper message = html.isPresent() || !ArrayUtils.isEmpty(attachments) ? new MimeMessageHelper(mimeMessage, true, "UTF-8") : new MimeMessageHelper(mimeMessage, "UTF-8");
message.setSubject(subject);
message.setFrom(conf.get(SMTP_FROM_EMAIL).getRequiredValue(), fromName);
String replyTo = conf.get(MAIL_REPLY_TO).getValueOrDefault("");
if (StringUtils.isNotBlank(replyTo)) {
message.setReplyTo(replyTo);
}
message.setTo(to);
if (cc != null && !cc.isEmpty()) {
message.setCc(cc.toArray(new String[0]));
}
if (html.isPresent()) {
message.setText(text, html.get());
} else {
message.setText(text, false);
}
if (attachments != null) {
for (Attachment a : attachments) {
message.addAttachment(a.getFilename(), new ByteArrayResource(a.getSource()), a.getContentType());
}
}
message.getMimeMessage().saveChanges();
message.getMimeMessage().removeHeader("Message-ID");
};
toMailSender(conf).send(preparator);
}
Aggregations