Search in sources :

Example 1 with ArrayUtils.isEmpty

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);
}
Also used : MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) MailParseException(org.springframework.mail.MailParseException) MessagingException(javax.mail.MessagingException) ArrayUtils(org.apache.commons.lang3.ArrayUtils) StringUtils(org.apache.commons.lang3.StringUtils) ByteArrayResource(org.springframework.core.io.ByteArrayResource) PropertiesLoaderUtils(org.springframework.core.io.support.PropertiesLoaderUtils) EncodedResource(org.springframework.core.io.support.EncodedResource) Properties(java.util.Properties) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) IOException(java.io.IOException) MimeMessage(javax.mail.internet.MimeMessage) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) MimeMessagePreparator(org.springframework.mail.javamail.MimeMessagePreparator) JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Configuration(alfio.model.system.Configuration) Log4j2(lombok.extern.log4j.Log4j2) FileTypeMap(javax.activation.FileTypeMap) Session(javax.mail.Session) Optional(java.util.Optional) Event(alfio.model.Event) AllArgsConstructor(lombok.AllArgsConstructor) MailException(org.springframework.mail.MailException) ConfigurationKeys(alfio.model.system.ConfigurationKeys) InputStream(java.io.InputStream) MimeMessagePreparator(org.springframework.mail.javamail.MimeMessagePreparator) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper)

Example 2 with ArrayUtils.isEmpty

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);
    }
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Logger(org.slf4j.Logger) ServletException(javax.servlet.ServletException) JCR_SQL2(javax.jcr.query.Query.JCR_SQL2) Servlet(javax.servlet.Servlet) LoggerFactory(org.slf4j.LoggerFactory) Resource(org.apache.sling.api.resource.Resource) HttpConstants(org.apache.sling.api.servlets.HttpConstants) ArrayUtils(org.apache.commons.lang3.ArrayUtils) IOException(java.io.IOException) SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) StringUtils(org.apache.commons.lang3.StringUtils) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) List(java.util.List) DataSourceBuilder(com.adobe.acs.commons.wcm.datasources.DataSourceBuilder) SlingSafeMethodsServlet(org.apache.sling.api.servlets.SlingSafeMethodsServlet) QueryHelper(com.adobe.acs.commons.util.QueryHelper) DataSourceOption(com.adobe.acs.commons.wcm.datasources.DataSourceOption) Reference(org.osgi.service.component.annotations.Reference) Nonnull(javax.annotation.Nonnull) DataSourceOption(com.adobe.acs.commons.wcm.datasources.DataSourceOption) ValueMap(org.apache.sling.api.resource.ValueMap) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 3 with ArrayUtils.isEmpty

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);
    });
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) Arrays(java.util.Arrays) ApplicationEnvironmentService(alien4cloud.application.ApplicationEnvironmentService) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Subject(alien4cloud.security.Subject) LocationService(alien4cloud.orchestrators.locations.services.LocationService) ResourcePermissionService(alien4cloud.authorization.ResourcePermissionService) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ArrayUtils(org.apache.commons.lang3.ArrayUtils) LocationSecurityService(alien4cloud.orchestrators.locations.services.LocationSecurityService) Location(alien4cloud.model.orchestrators.locations.Location) RequestBody(org.springframework.web.bind.annotation.RequestBody) ApiOperation(io.swagger.annotations.ApiOperation) Audit(alien4cloud.audit.annotation.Audit) RestResponseBuilder(alien4cloud.rest.model.RestResponseBuilder) RestResponse(alien4cloud.rest.model.RestResponse) ILocationResourceService(alien4cloud.orchestrators.locations.services.ILocationResourceService) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) MediaType(org.springframework.http.MediaType) Resource(javax.annotation.Resource) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) SubjectsAuthorizationRequest(alien4cloud.rest.orchestrator.model.SubjectsAuthorizationRequest) List(java.util.List) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate) ApplicationEnvironmentAuthorizationUpdateRequest(alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest) AbstractLocationResourceTemplate(alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)

Example 4 with ArrayUtils.isEmpty

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);
}
Also used : Arrays(java.util.Arrays) AllIcons(com.intellij.icons.AllIcons) AzureSdkCategoryService(com.microsoft.azure.toolkit.intellij.azuresdk.service.AzureSdkCategoryService) Presentation(com.intellij.openapi.actionSystem.Presentation) StringUtils(org.apache.commons.lang3.StringUtils) Map(java.util.Map) CommonActionsManager(com.intellij.ide.CommonActionsManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreePath(javax.swing.tree.TreePath) TailingDebouncer(com.microsoft.azure.toolkit.lib.common.utils.TailingDebouncer) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Collectors(java.util.stream.Collectors) DefaultTreeExpander(com.intellij.ide.DefaultTreeExpander) MutableTreeNode(javax.swing.tree.MutableTreeNode) JBScrollPane(com.intellij.ui.components.JBScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Objects(java.util.Objects) IdeBundle(com.intellij.ide.IdeBundle) RelativeFont(com.intellij.ui.RelativeFont) List(java.util.List) SimpleTree(com.intellij.ui.treeStructure.SimpleTree) ActionPlaces(com.intellij.openapi.actionSystem.ActionPlaces) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Optional(java.util.Optional) TextDocumentListenerAdapter(com.microsoft.azure.toolkit.intellij.common.TextDocumentListenerAdapter) NotNull(org.jetbrains.annotations.NotNull) AzureTaskManager(com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager) Setter(lombok.Setter) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Getter(lombok.Getter) ActionToolbarImpl(com.intellij.openapi.actionSystem.impl.ActionToolbarImpl) SearchTextField(com.intellij.ui.SearchTextField) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) CollectionUtils(org.apache.commons.collections4.CollectionUtils) AzureSdkLibraryService(com.microsoft.azure.toolkit.intellij.azuresdk.service.AzureSdkLibraryService) ActivityTracker(com.intellij.ide.ActivityTracker) Tree(com.intellij.ui.treeStructure.Tree) TreeUtil(com.intellij.util.ui.tree.TreeUtil) AnimatedIcon(com.intellij.ui.AnimatedIcon) AzureSdkCategoryEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity) IOException(java.io.IOException) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) RenderingUtil(com.intellij.ui.render.RenderingUtil) Consumer(java.util.function.Consumer) AzureSdkFeatureEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkFeatureEntity) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) Comparator(java.util.Comparator) javax.swing(javax.swing) AzureSdkCategoryEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) StringUtils(org.apache.commons.lang3.StringUtils) AzureSdkServiceEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity) MutableTreeNode(javax.swing.tree.MutableTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 5 with ArrayUtils.isEmpty

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);
}
Also used : MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) java.util(java.util) MailParseException(org.springframework.mail.MailParseException) MessagingException(javax.mail.MessagingException) ArrayUtils(org.apache.commons.lang3.ArrayUtils) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) IOException(java.io.IOException) MimeMessage(javax.mail.internet.MimeMessage) StringUtils(org.apache.commons.lang3.StringUtils) ByteArrayResource(org.springframework.core.io.ByteArrayResource) StandardCharsets(java.nio.charset.StandardCharsets) PropertiesLoaderUtils(org.springframework.core.io.support.PropertiesLoaderUtils) MimeMessagePreparator(org.springframework.mail.javamail.MimeMessagePreparator) EncodedResource(org.springframework.core.io.support.EncodedResource) JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) Log4j2(lombok.extern.log4j.Log4j2) FileTypeMap(javax.activation.FileTypeMap) Session(javax.mail.Session) Configurable(alfio.model.Configurable) AllArgsConstructor(lombok.AllArgsConstructor) ConfigurationKeys(alfio.model.system.ConfigurationKeys) InputStream(java.io.InputStream) MimeMessagePreparator(org.springframework.mail.javamail.MimeMessagePreparator) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper)

Aggregations

ArrayUtils (org.apache.commons.lang3.ArrayUtils)8 List (java.util.List)6 Arrays (java.util.Arrays)5 Collectors (java.util.stream.Collectors)5 IOException (java.io.IOException)4 StringUtils (org.apache.commons.lang3.StringUtils)4 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)3 Audit (alien4cloud.audit.annotation.Audit)3 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)3 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 AbstractLocationResourceTemplate (alien4cloud.model.orchestrators.locations.AbstractLocationResourceTemplate)3 Location (alien4cloud.model.orchestrators.locations.Location)3 ILocationResourceService (alien4cloud.orchestrators.locations.services.ILocationResourceService)3 LocationSecurityService (alien4cloud.orchestrators.locations.services.LocationSecurityService)3 LocationService (alien4cloud.orchestrators.locations.services.LocationService)3 RestResponse (alien4cloud.rest.model.RestResponse)3 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)3 ApplicationEnvironmentAuthorizationUpdateRequest (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest)3 SubjectsAuthorizationRequest (alien4cloud.rest.orchestrator.model.SubjectsAuthorizationRequest)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3