Example usage for org.apache.commons.collections4 CollectionUtils isNotEmpty

List of usage examples for org.apache.commons.collections4 CollectionUtils isNotEmpty

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils isNotEmpty.

Prototype

public static boolean isNotEmpty(final Collection<?> coll) 

Source Link

Document

Null-safe check if the specified collection is not empty.

Usage

From source file:org.apache.nifi.web.server.JettyServer.java

@Override
public void start() {
    try {/*from w w w .  ja v  a 2s.  c o m*/
        // start the server
        server.start();

        // ensure everything started successfully
        for (Handler handler : server.getChildHandlers()) {
            // see if the handler is a web app
            if (handler instanceof WebAppContext) {
                WebAppContext context = (WebAppContext) handler;

                // see if this webapp had any exceptions that would
                // cause it to be unavailable
                if (context.getUnavailableException() != null) {
                    startUpFailure(context.getUnavailableException());
                }
            }
        }

        // ensure the appropriate wars deployed successfully before injecting the NiFi context and security filters
        // this must be done after starting the server (and ensuring there were no start up failures)
        if (webApiContext != null) {
            // give the web api the component ui extensions
            final ServletContext webApiServletContext = webApiContext.getServletHandler().getServletContext();
            webApiServletContext.setAttribute("nifi-ui-extensions", componentUiExtensions);

            // get the application context
            final WebApplicationContext webApplicationContext = WebApplicationContextUtils
                    .getRequiredWebApplicationContext(webApiServletContext);

            // component ui extensions
            if (CollectionUtils.isNotEmpty(componentUiExtensionWebContexts)) {
                final NiFiWebConfigurationContext configurationContext = webApplicationContext
                        .getBean("nifiWebConfigurationContext", NiFiWebConfigurationContext.class);

                for (final WebAppContext customUiContext : componentUiExtensionWebContexts) {
                    // set the NiFi context in each custom ui servlet context
                    final ServletContext customUiServletContext = customUiContext.getServletHandler()
                            .getServletContext();
                    customUiServletContext.setAttribute("nifi-web-configuration-context", configurationContext);

                    // add the security filter to any ui extensions wars
                    final FilterHolder securityFilter = webApiContext.getServletHandler()
                            .getFilter("springSecurityFilterChain");
                    if (securityFilter != null) {
                        customUiContext.addFilter(securityFilter, "/*", EnumSet.allOf(DispatcherType.class));
                    }
                }
            }

            // content viewer extensions
            if (CollectionUtils.isNotEmpty(contentViewerWebContexts)) {
                for (final WebAppContext contentViewerContext : contentViewerWebContexts) {
                    // add the security filter to any content viewer  wars
                    final FilterHolder securityFilter = webApiContext.getServletHandler()
                            .getFilter("springSecurityFilterChain");
                    if (securityFilter != null) {
                        contentViewerContext.addFilter(securityFilter, "/*",
                                EnumSet.allOf(DispatcherType.class));
                    }
                }
            }

            // content viewer controller
            if (webContentViewerContext != null) {
                final ContentAccess contentAccess = webApplicationContext.getBean("contentAccess",
                        ContentAccess.class);

                // add the content access
                final ServletContext webContentViewerServletContext = webContentViewerContext
                        .getServletHandler().getServletContext();
                webContentViewerServletContext.setAttribute("nifi-content-access", contentAccess);

                final FilterHolder securityFilter = webApiContext.getServletHandler()
                        .getFilter("springSecurityFilterChain");
                if (securityFilter != null) {
                    webContentViewerContext.addFilter(securityFilter, "/*",
                            EnumSet.allOf(DispatcherType.class));
                }
            }
        }

        // ensure the web document war was loaded and provide the extension mapping
        if (webDocsContext != null) {
            final ServletContext webDocsServletContext = webDocsContext.getServletHandler().getServletContext();
            webDocsServletContext.setAttribute("nifi-extension-mapping", extensionMapping);
        }

        // if this nifi is a node in a cluster, start the flow service and load the flow - the
        // flow service is loaded here for clustered nodes because the loading of the flow will
        // initialize the connection between the node and the NCM. if the node connects (starts
        // heartbeating, etc), the NCM may issue web requests before the application (wars) have
        // finished loading. this results in the node being disconnected since its unable to
        // successfully respond to the requests. to resolve this, flow loading was moved to here
        // (after the wars have been successfully deployed) when this nifi instance is a node
        // in a cluster
        if (props.isNode()) {

            FlowService flowService = null;
            try {

                logger.info("Loading Flow...");

                ApplicationContext ctx = WebApplicationContextUtils
                        .getWebApplicationContext(webApiContext.getServletContext());
                flowService = ctx.getBean("flowService", FlowService.class);

                // start and load the flow
                flowService.start();
                flowService.load(null);

                logger.info("Flow loaded successfully.");

            } catch (BeansException | LifeCycleStartException | IOException | FlowSerializationException
                    | FlowSynchronizationException | UninheritableFlowException e) {
                // ensure the flow service is terminated
                if (flowService != null && flowService.isRunning()) {
                    flowService.stop(false);
                }
                throw new Exception("Unable to load flow due to: " + e, e);
            }
        }

        // dump the application url after confirming everything started successfully
        dumpUrls();
    } catch (Exception ex) {
        startUpFailure(ex);
    }
}

From source file:org.apache.nifi.web.StandardNiFiServiceFacade.java

/**
 * Utility method for extracting component counts from the specified group status.
 *//*from w  w  w.j a v  a2s  . co m*/
private ProcessGroupCounts extractProcessGroupCounts(ProcessGroupStatus groupStatus) {
    int running = 0;
    int stopped = 0;
    int invalid = 0;
    int disabled = 0;
    int activeRemotePorts = 0;
    int inactiveRemotePorts = 0;

    for (final ProcessorStatus processorStatus : groupStatus.getProcessorStatus()) {
        switch (processorStatus.getRunStatus()) {
        case Disabled:
            disabled++;
            break;
        case Running:
            running++;
            break;
        case Invalid:
            invalid++;
            break;
        default:
            stopped++;
            break;
        }
    }

    for (final PortStatus portStatus : groupStatus.getInputPortStatus()) {
        switch (portStatus.getRunStatus()) {
        case Disabled:
            disabled++;
            break;
        case Running:
            running++;
            break;
        case Invalid:
            invalid++;
            break;
        default:
            stopped++;
            break;
        }
    }

    for (final PortStatus portStatus : groupStatus.getOutputPortStatus()) {
        switch (portStatus.getRunStatus()) {
        case Disabled:
            disabled++;
            break;
        case Running:
            running++;
            break;
        case Invalid:
            invalid++;
            break;
        default:
            stopped++;
            break;
        }
    }

    for (final RemoteProcessGroupStatus remoteStatus : groupStatus.getRemoteProcessGroupStatus()) {
        if (remoteStatus.getActiveRemotePortCount() != null) {
            activeRemotePorts += remoteStatus.getActiveRemotePortCount();
        }
        if (remoteStatus.getInactiveRemotePortCount() != null) {
            inactiveRemotePorts += remoteStatus.getInactiveRemotePortCount();
        }
        if (CollectionUtils.isNotEmpty(remoteStatus.getAuthorizationIssues())) {
            invalid++;
        }
    }

    for (final ProcessGroupStatus childGroupStatus : groupStatus.getProcessGroupStatus()) {
        final ProcessGroupCounts childCounts = extractProcessGroupCounts(childGroupStatus);
        running += childCounts.getRunningCount();
        stopped += childCounts.getStoppedCount();
        invalid += childCounts.getInvalidCount();
        disabled += childCounts.getDisabledCount();
        activeRemotePorts += childCounts.getActiveRemotePortCount();
        inactiveRemotePorts += childCounts.getInactiveRemotePortCount();
    }

    return new ProcessGroupCounts(0, 0, running, stopped, invalid, disabled, activeRemotePorts,
            inactiveRemotePorts);
}

From source file:org.apache.syncope.client.console.bulk.BulkContent.java

public BulkContent(final String id, final BaseModal<?> modal, final Collection<T> items,
        final List<IColumn<T, S>> columns, final Collection<ActionLink.ActionType> actions,
        final RestClient bulkActionExecutor, final String keyFieldName) {

    super(id);/*from  w w  w. j  av a  2 s. co  m*/

    final WebMarkupContainer container = new WebMarkupContainer("container");
    container.setOutputMarkupId(true);
    add(container);

    final SortableDataProvider<T, S> dataProvider = new SortableDataProvider<T, S>() {

        private static final long serialVersionUID = 5291903859908641954L;

        @Override
        public Iterator<? extends T> iterator(final long first, final long count) {
            return items.iterator();
        }

        @Override
        public long size() {
            return items.size();
        }

        @Override
        public IModel<T> model(final T object) {
            return new CompoundPropertyModel<>(object);
        }
    };

    container
            .add(new AjaxFallbackDefaultDataTable<>("selectedObjects", columns, dataProvider, Integer.MAX_VALUE)
                    .setMarkupId("selectedObjects").setVisible(items != null && !items.isEmpty()));

    final ActionLinksPanel<Serializable> actionPanel = ActionLinksPanel.builder().build("actions");
    container.add(actionPanel);

    for (ActionLink.ActionType action : actions) {
        final ActionType actionToBeAddresed = action;

        actionPanel.add(new ActionLink<Serializable>() {

            private static final long serialVersionUID = -3722207913631435501L;

            @Override
            protected boolean statusCondition(final Serializable modelObject) {
                return CollectionUtils.isNotEmpty(items);
            }

            @Override
            public void onClick(final AjaxRequestTarget target, final Serializable ignore) {
                try {
                    if (CollectionUtils.isEmpty(items)) {
                        throw new IllegalArgumentException("Invalid items");
                    }

                    String fieldName = keyFieldName;

                    BulkActionResult res = null;
                    try {
                        if (items.iterator().next() instanceof StatusBean) {
                            throw new IllegalArgumentException("Invalid items");
                        }

                        final BulkAction bulkAction = new BulkAction();
                        bulkAction.setType(BulkAction.Type.valueOf(actionToBeAddresed.name()));
                        for (T item : items) {
                            try {
                                bulkAction.getTargets().add(getTargetId(item, keyFieldName).toString());
                            } catch (IllegalAccessException | InvocationTargetException e) {
                                LOG.error("Error retrieving item id {}", keyFieldName, e);
                            }
                        }
                        res = BulkActionResult.class
                                .cast(bulkActionExecutor.getClass().getMethod("bulkAction", BulkAction.class)
                                        .invoke(bulkActionExecutor, bulkAction));
                    } catch (IllegalArgumentException biae) {
                        if (!(items.iterator().next() instanceof StatusBean)) {
                            throw new IllegalArgumentException("Invalid items");
                        }

                        if (!(bulkActionExecutor instanceof AbstractAnyRestClient)) {
                            throw new IllegalArgumentException("Invalid bulk action executor");
                        }

                        final AbstractAnyRestClient<?, ?> anyRestClient = AbstractAnyRestClient.class
                                .cast(bulkActionExecutor);

                        // Group bean information by anyKey
                        final Map<String, List<StatusBean>> beans = new HashMap<>();
                        for (T bean : items) {
                            final StatusBean sb = StatusBean.class.cast(bean);
                            final List<StatusBean> sblist;
                            if (beans.containsKey(sb.getAnyKey())) {
                                sblist = beans.get(sb.getAnyKey());
                            } else {
                                sblist = new ArrayList<>();
                                beans.put(sb.getAnyKey(), sblist);
                            }
                            sblist.add(sb);
                        }

                        for (Map.Entry<String, List<StatusBean>> entry : beans.entrySet()) {
                            final String etag = anyRestClient.read(entry.getKey()).getETagValue();
                            switch (actionToBeAddresed.name()) {
                            case "DEPROVISION":
                                res = anyRestClient.deprovision(etag, entry.getKey(), entry.getValue());
                                break;
                            case "UNASSIGN":
                                res = anyRestClient.unassign(etag, entry.getKey(), entry.getValue());
                                break;
                            case "UNLINK":
                                res = anyRestClient.unlink(etag, entry.getKey(), entry.getValue());
                                break;
                            case "ASSIGN":
                                res = anyRestClient.assign(etag, entry.getKey(), entry.getValue());
                                break;
                            case "LINK":
                                res = anyRestClient.link(etag, entry.getKey(), entry.getValue());
                                break;
                            case "PROVISION":
                                res = anyRestClient.provision(etag, entry.getKey(), entry.getValue());
                                break;
                            case "REACTIVATE":
                                res = ((UserRestClient) anyRestClient).reactivate(etag, entry.getKey(),
                                        entry.getValue());
                                fieldName = "resourceName";
                                break;
                            case "SUSPEND":
                                res = ((UserRestClient) anyRestClient).suspend(etag, entry.getKey(),
                                        entry.getValue());
                                fieldName = "resourceName";
                                break;
                            default:
                                break;
                            }
                        }
                    }

                    if (modal != null) {
                        modal.changeCloseButtonLabel(getString("close", null, "Close"), target);
                    }

                    final List<IColumn<T, S>> newColumnList = new ArrayList<>(columns);
                    newColumnList.add(newColumnList.size(), new BulkActionResultColumn<T, S>(res, fieldName));

                    container.addOrReplace(new AjaxFallbackDefaultDataTable<>("selectedObjects", newColumnList,
                            dataProvider, Integer.MAX_VALUE).setVisible(!items.isEmpty()));

                    actionPanel.setEnabled(false);
                    actionPanel.setVisible(false);
                    target.add(container);
                    target.add(actionPanel);

                    SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED));
                } catch (Exception e) {
                    LOG.error("Bulk action failure", e);
                    SyncopeConsoleSession.get()
                            .error("Operation " + actionToBeAddresed.getActionId() + " not supported");
                }
                ((BasePage) getPage()).getNotificationPanel().refresh(target);
            }
        }, action, StandardEntitlement.CONFIGURATION_LIST, !items.isEmpty());
    }
}

From source file:org.apache.syncope.client.console.tasks.PushTaskWrapper.java

public Map<String, String> getFilters() {
    Map<String, String> filters = new HashMap<>();

    for (Map.Entry<String, List<SearchClause>> entry : getFilterClauses().entrySet()) {
        if (CollectionUtils.isNotEmpty(entry.getValue())) {
            AbstractFiqlSearchConditionBuilder bld;
            switch (entry.getKey()) {
            case "USER":
                bld = SyncopeClient.getUserSearchConditionBuilder();
                break;

            case "GROUP":
                bld = SyncopeClient.getGroupSearchConditionBuilder();
                break;

            default:
                bld = SyncopeClient.getAnyObjectSearchConditionBuilder(entry.getKey());
            }/*from  w  w w.  j a  v a 2  s  . c o  m*/

            filters.put(entry.getKey(), SearchUtils.buildFIQL(entry.getValue(), bld));
        }
    }

    return filters;
}

From source file:org.apache.syncope.client.console.wizards.any.AbstractAttrs.java

@Override
public boolean evaluate() {
    this.attrTOs.setObject(loadAttrTOs());
    this.membershipTOs.setObject(loadMembershipAttrTOs());
    return CollectionUtils.isNotEmpty(attrTOs.getObject())
            || CollectionUtils.isNotEmpty(membershipTOs.getObject());
}

From source file:org.apache.syncope.client.console.wizards.any.ConnObjectPanel.java

public ConnObjectPanel(final String id, final Pair<ConnObjectTO, ConnObjectTO> connObjectTOs,
        final boolean view) {
    super(id);/*from  ww w  .jav  a  2s  . c o  m*/

    final IModel<List<String>> formProps = new LoadableDetachableModel<List<String>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override
        protected List<String> load() {
            List<AttrTO> right = new ArrayList<>(
                    connObjectTOs == null || connObjectTOs.getRight() == null ? Collections.<AttrTO>emptyList()
                            : connObjectTOs.getRight().getAttrs());

            List<AttrTO> left = new ArrayList<>(
                    connObjectTOs == null || connObjectTOs.getLeft() == null ? Collections.<AttrTO>emptyList()
                            : connObjectTOs.getLeft().getAttrs());

            final List<String> schemas = ListUtils.sum(
                    right.stream().map(AttrTO::getSchema).collect(Collectors.toList()),
                    left.stream().map(AttrTO::getSchema).collect(Collectors.toList()));

            Collections.sort(schemas);

            return schemas;
        }
    };

    final Map<String, AttrTO> beforeProfile = connObjectTOs == null || connObjectTOs.getLeft() == null ? null
            : EntityTOUtils.buildAttrMap(connObjectTOs.getLeft().getAttrs());
    final Map<String, AttrTO> afterProfile = connObjectTOs == null || connObjectTOs.getRight() == null ? null
            : EntityTOUtils.buildAttrMap(connObjectTOs.getRight().getAttrs());

    final ListView<String> propView = new ListView<String>("propView", formProps) {

        private static final long serialVersionUID = 3109256773218160485L;

        @Override
        protected void populateItem(final ListItem<String> item) {
            final String prop = item.getModelObject();

            final Fragment valueFragment;
            final AttrTO before = beforeProfile == null ? null : beforeProfile.get(prop);
            final AttrTO after = afterProfile == null ? null : afterProfile.get(prop);

            valueFragment = new Fragment("value", "doubleValue", ConnObjectPanel.this);

            Panel oldAttribute = getValuePanel("oldAttribute", prop, before);
            oldAttribute.setOutputMarkupPlaceholderTag(true);
            oldAttribute.setVisible(!view);
            valueFragment.add(oldAttribute);

            valueFragment.add(getValuePanel("newAttribute", prop, after));

            if (before == null || after == null
                    || (CollectionUtils.isNotEmpty(after.getValues())
                            && CollectionUtils.isEmpty(before.getValues()))
                    || (CollectionUtils.isEmpty(after.getValues())
                            && CollectionUtils.isNotEmpty(before.getValues()))
                    || (CollectionUtils.isNotEmpty(after.getValues())
                            && CollectionUtils.isNotEmpty(before.getValues())
                            && after.getValues().size() != before.getValues().size())
                    || (CollectionUtils.isNotEmpty(after.getValues())
                            && CollectionUtils.isNotEmpty(before.getValues())
                            && !after.getValues().equals(before.getValues()))) {

                valueFragment.add(new Behavior() {

                    private static final long serialVersionUID = 3109256773218160485L;

                    @Override
                    public void onComponentTag(final Component component, final ComponentTag tag) {
                        tag.put("class", "highlight");
                    }
                });
            }
            item.add(valueFragment);
        }
    };
    add(propView);
}

From source file:org.apache.syncope.client.console.wizards.any.GroupHandler.java

public Map<String, String> getADynMembershipConds() {
    if (this.aDynClauses == null || this.aDynClauses.isEmpty()) {
        return this.anyTO.getADynMembershipConds();
    } else {/* w  w w.ja  v  a2  s  . c om*/
        final Map<String, String> res = new HashMap<>();

        for (Map.Entry<String, List<SearchClause>> entry : this.aDynClauses.entrySet()) {
            if (CollectionUtils.isNotEmpty(entry.getValue())) {
                res.put(entry.getKey(), getFIQLString(entry.getValue(),
                        SyncopeClient.getAnyObjectSearchConditionBuilder(entry.getKey())));
            }
        }

        return res;
    }
}

From source file:org.apache.syncope.client.console.wizards.any.GroupWrapper.java

public Map<String, String> getADynMembershipConds() {
    final Map<String, String> res = new HashMap<>();
    if (this.aDynClauses != null && !this.aDynClauses.isEmpty()) {
        for (Map.Entry<String, List<SearchClause>> entry : this.aDynClauses.entrySet()) {
            if (CollectionUtils.isNotEmpty(entry.getValue())) {
                final String fiql = SearchUtils.buildFIQL(entry.getValue(),
                        SyncopeClient.getAnyObjectSearchConditionBuilder(entry.getKey()));
                if (fiql != null) {
                    res.put(entry.getKey(), fiql);
                }//from   ww w  .  j ava 2  s.c  om
            }
        }
    }

    return res;
}

From source file:org.apache.syncope.client.console.wizards.any.Roles.java

@Override
public final boolean evaluate() {
    return CollectionUtils.isNotEmpty(allRoles) && SyncopeConsoleApplication.get().getSecuritySettings()
            .getAuthorizationStrategy().isActionAuthorized(this, RENDER);
}

From source file:org.apache.syncope.client.console.wizards.DynRealmWrapper.java

public Map<String, String> getDynMembershipConds() {
    final Map<String, String> res = new HashMap<>();
    if (this.dynClauses != null && !this.dynClauses.isEmpty()) {
        this.dynClauses.entrySet().stream().filter(entry -> (CollectionUtils.isNotEmpty(entry.getValue())))
                .forEachOrdered(entry -> {
                    AbstractFiqlSearchConditionBuilder builder = AnyTypeKind.USER.name().equals(entry.getKey())
                            ? SyncopeClient.getUserSearchConditionBuilder()
                            : AnyTypeKind.GROUP.name().equals(entry.getKey())
                                    ? SyncopeClient.getGroupSearchConditionBuilder()
                                    : SyncopeClient.getAnyObjectSearchConditionBuilder(entry.getKey());
                    String fiql = SearchUtils.buildFIQL(entry.getValue(), builder);
                    if (fiql != null) {
                        res.put(entry.getKey(), fiql);
                    }//ww w . j a  va2 s  .com
                });
    }

    return res;
}