Example usage for org.apache.commons.lang ArrayUtils isNotEmpty

List of usage examples for org.apache.commons.lang ArrayUtils isNotEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils isNotEmpty.

Prototype

public static boolean isNotEmpty(boolean[] array) 

Source Link

Document

Checks if an array of primitive booleans is not empty or not null.

Usage

From source file:org.kuali.rice.kew.actionlist.web.ActionListForm.java

@Override
public void populate(HttpServletRequest request) {
    setHeaderButtons(getHeaderButtons());

    // take the UserSession from the HttpSession and add it to the request
    request.setAttribute(KRADConstants.USER_SESSION_KEY, GlobalVariables.getUserSession());

    //refactor actionlist.jsp not to be dependent on this
    request.setAttribute("preferences",
            GlobalVariables.getUserSession().retrieveObject(KewApiConstants.PREFERENCES));

    String principalId = GlobalVariables.getUserSession().getPrincipalId();
    final Principal hdalPrinc = (Principal) GlobalVariables.getUserSession()
            .retrieveObject(KewApiConstants.HELP_DESK_ACTION_LIST_PRINCIPAL_ATTR_NAME);
    if (hdalPrinc != null) {
        setHelpDeskActionListUserName(hdalPrinc.getPrincipalName());
    }//from   ww w  .  jav  a 2 s.c o  m
    boolean isHelpDeskAuthorized = KimApiServiceLocator.getPermissionService().isAuthorized(principalId,
            KewApiConstants.KEW_NAMESPACE, KewApiConstants.PermissionNames.VIEW_OTHER_ACTION_LIST,
            new HashMap<String, String>());
    if (isHelpDeskAuthorized) {
        request.setAttribute("helpDeskActionList", "true");
    }

    request.setAttribute("noRefresh", Boolean.valueOf(
            ConfigContext.getCurrentContextConfig().getProperty(KewApiConstants.ACTION_LIST_NO_REFRESH)));

    Boolean routeLogPopup = getParameterService().getParameterValueAsBoolean(KewApiConstants.KEW_NAMESPACE,
            KRADConstants.DetailTypes.ACTION_LIST_DETAIL_TYPE, KewApiConstants.ACTION_LIST_ROUTE_LOG_POPUP_IND,
            false);
    String defaultRouteLogTarget = routeLogPopup ? "_blank" : "_self";

    Boolean documentPopup = getParameterService().getParameterValueAsBoolean(KewApiConstants.KEW_NAMESPACE,
            KRADConstants.DetailTypes.ACTION_LIST_DETAIL_TYPE, KewApiConstants.ACTION_LIST_DOCUMENT_POPUP_IND,
            false);
    String defaultDocumentTarget = documentPopup ? "_blank" : "_self";

    String[] targetSpecs = request.getParameterValues("targetSpec");
    if (ArrayUtils.isNotEmpty(targetSpecs)) {
        String targetSpec = StringUtils.join(targetSpecs, ",");
        setDocumentTargetSpec(targetSpec);
        setRouteLogTargetSpec(targetSpec);
    }
    String[] documentTargetSpecs = request.getParameterValues("documentTargetSpec");
    if (ArrayUtils.isNotEmpty(documentTargetSpecs)) {
        String documentTargetSpec = StringUtils.join(documentTargetSpecs, ",");
        setDocumentTargetSpec(documentTargetSpec);
    }
    String[] routeLogTargetSpecs = request.getParameterValues("routeLogTargetSpec");
    if (ArrayUtils.isNotEmpty(routeLogTargetSpecs)) {
        String routeLogTargetSpec = StringUtils.join(routeLogTargetSpecs, ",");
        setRouteLogTargetSpec(routeLogTargetSpec);
    }

    DocumentTypeWindowTargets targets = new DocumentTypeWindowTargets(getDocumentTargetSpec(),
            getRouteLogTargetSpec(), defaultDocumentTarget, defaultRouteLogTarget,
            KEWServiceLocator.getDocumentTypeService());
    setTargets(targets);

    super.populate(request);
}

From source file:org.kuali.rice.kew.impl.document.search.DocumentSearchCriteriaBoLookupableHelperService.java

/**
 * Cleans up various issues with fieldValues coming from the lookup form (namely, that they don't include
 * multi-valued field values!). Handles these by adding them comma-separated.
 *///  w w w .  ja  v  a2 s.  c  om
protected static Map<String, String> cleanupFieldValues(Map<String, String> fieldValues,
        Map<String, String[]> parameters) {
    Map<String, String> cleanedUpFieldValues = new HashMap<String, String>(fieldValues);
    if (ArrayUtils
            .isNotEmpty(parameters.get(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_STATUS_CODE))) {
        cleanedUpFieldValues.put(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_STATUS_CODE, StringUtils
                .join(parameters.get(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_STATUS_CODE), ","));
    }
    if (ArrayUtils
            .isNotEmpty(parameters.get(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOC_STATUS))) {
        cleanedUpFieldValues.put(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOC_STATUS, StringUtils
                .join(parameters.get(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOC_STATUS), ","));
    }
    Map<String, String> documentAttributeFieldValues = new HashMap<String, String>();
    for (String parameterName : parameters.keySet()) {
        if (parameterName.contains(KewApiConstants.DOCUMENT_ATTRIBUTE_FIELD_PREFIX)) {
            String[] value = parameters.get(parameterName);
            if (ArrayUtils.isNotEmpty(value)) {
                if (parameters.containsKey(parameterName + KRADConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION)) {
                    documentAttributeFieldValues.put(parameterName, "Y");
                } else {
                    documentAttributeFieldValues.put(parameterName,
                            StringUtils.join(value, " " + SearchOperator.OR.op() + " "));
                }
            }
        }
    }
    // if any of the document attributes are range values, process them
    documentAttributeFieldValues.putAll(LookupUtils.preProcessRangeFields(documentAttributeFieldValues));
    cleanedUpFieldValues.putAll(documentAttributeFieldValues);

    replaceCurrentUserInFields(cleanedUpFieldValues);

    return cleanedUpFieldValues;
}

From source file:org.kuali.rice.kew.impl.document.search.DocumentSearchCriteriaBoLookupableHelperService.java

/**
 * Loads a saved search//from   w ww.  ja  v a2s  .c  o  m
 * @return returns true on success to run the loaded search, false on error.
 */
protected boolean loadSavedSearch(boolean ignoreErrors) {
    Map<String, String[]> fieldValues = new HashMap<String, String[]>();

    String savedSearchName = getSavedSearchName();
    if (StringUtils.isEmpty(savedSearchName) || "*ignore*".equals(savedSearchName)) {
        if (!ignoreErrors) {
            GlobalVariables.getMessageMap().putError(SAVED_SEARCH_NAME_PARAM, RiceKeyConstants.ERROR_CUSTOM,
                    "You must select a saved search");
        } else {
            //if we're ignoring errors and we got an error just return, no reason to continue.  Also set false to indicate not to perform lookup
            return false;
        }
        getFormFields().setFieldValue(SAVED_SEARCH_NAME_PARAM, "");
    }
    if (!GlobalVariables.getMessageMap().hasNoErrors()) {
        throw new ValidationException("errors in search criteria");
    }

    DocumentSearchCriteria criteria = KEWServiceLocator.getDocumentSearchService()
            .getSavedSearchCriteria(GlobalVariables.getUserSession().getPrincipalId(), savedSearchName);

    // get the document type
    String docTypeName = criteria.getDocumentTypeName();

    // update the parameters to include whether or not this is an advanced search
    if (this.getParameters().containsKey(KRADConstants.ADVANCED_SEARCH_FIELD)) {
        Map<String, String[]> parameters = this.getParameters();
        String[] params = (String[]) parameters.get(KRADConstants.ADVANCED_SEARCH_FIELD);
        if (ArrayUtils.isNotEmpty(params)) {
            params[0] = criteria.getIsAdvancedSearch();
            this.setParameters(parameters);
        }
    }

    // and set the rows based on doc type
    setRows(docTypeName);

    // clear the name of the search in the form
    //fieldValues.put(SAVED_SEARCH_NAME_PARAM, new String[0]);

    // set the custom document attribute values on the search form
    for (Map.Entry<String, List<String>> entry : criteria.getDocumentAttributeValues().entrySet()) {
        fieldValues.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
    }

    // sets the field values on the form, trying criteria object properties if a field value is not present in the map
    for (Field field : getFormFields().getFields()) {
        if (field.getPropertyName() != null && !field.getPropertyName().equals("")) {
            // UI Fields know whether they are single or multiple value
            // just set both so they can make the determination and render appropriately
            String[] values = null;
            if (fieldValues.get(field.getPropertyName()) != null) {
                values = fieldValues.get(field.getPropertyName());
            } else {
                //may be on the root of the criteria object, try looking there:
                try {
                    if (field.isRanged() && field.isDatePicker()) {
                        if (field.getPropertyName()
                                .startsWith(KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) {
                            String lowerBoundName = field.getPropertyName().replace(
                                    KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX, "") + "From";
                            Object lowerBoundDate = PropertyUtils.getProperty(criteria, lowerBoundName);
                            if (lowerBoundDate != null) {
                                values = new String[] { CoreApiServiceLocator.getDateTimeService()
                                        .toDateTimeString(((org.joda.time.DateTime) lowerBoundDate).toDate()) };
                            }
                        } else {
                            // the upper bound prefix may or may not be on the propertyName.  Using "replace" just in case.
                            String upperBoundName = field.getPropertyName()
                                    .replace(KRADConstants.LOOKUP_RANGE_UPPER_BOUND_PROPERTY_PREFIX, "") + "To";
                            Object upperBoundDate = PropertyUtils.getProperty(criteria, upperBoundName);
                            if (upperBoundDate != null) {
                                values = new String[] { CoreApiServiceLocator.getDateTimeService()
                                        .toDateTimeString(((org.joda.time.DateTime) upperBoundDate).toDate()) };
                            }
                        }
                    } else {
                        values = new String[] { ObjectUtils
                                .toString(PropertyUtils.getProperty(criteria, field.getPropertyName())) };
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                } catch (NoSuchMethodException e) {
                    // e.printStackTrace();
                    //hmm what to do here, we should be able to find everything either in the search atts or at the base as far as I know.
                }
            }
            if (values != null) {
                getFormFields().setFieldValue(field, values);
            }
        }
    }

    return true;
}

From source file:org.kuali.rice.kew.impl.document.search.DocumentSearchCriteriaBoLookupableHelperService.java

/**
 * Parses a boolean request parameter/*  w w w.  j  a v  a2 s  .  c  om*/
 */
protected boolean isFlagSet(String flagName) {
    if (this.getParameters().containsKey(flagName)) {
        String[] params = (String[]) this.getParameters().get(flagName);
        if (ArrayUtils.isNotEmpty(params)) {
            return "YES".equalsIgnoreCase(params[0]);
        }
    }
    return false;
}

From source file:org.kuali.rice.kew.impl.document.search.FormFields.java

/**
 * Overrides Row Field values with Map values
 * @param values the fieldvalues//w w w .  ja v  a 2  s .c  o m
 */
void setFieldValues(Map<String, String[]> values) {
    for (Field field : getFields()) {
        if (StringUtils.isNotBlank(field.getPropertyName())) {
            String[] value = values.get(field.getPropertyName());
            if (ArrayUtils.isNotEmpty(value)) {
                setFieldValue(field, value);
            }
        }
    }
}

From source file:org.nebula.console.facade.AdminDomainFacade.java

public String selectNebulaServer(String domainName) throws Exception {

    DomainSummary domainSummary = getDomainSummary(domainName);

    if (domainSummary != null && ArrayUtils.isNotEmpty(domainSummary.getServers())) {
        return domainSummary.getServers()[0];
    }//from   w  w  w . ja v  a2s  .  c  om

    return null;
}

From source file:org.nuxeo.ecm.platform.query.api.AbstractPageProvider.java

/**
 * Send a search event so that PageProvider calls can be tracked by Audit or other statistic gathering process
 *
 * @param principal//from ww w  .  ja  v a  2  s . co m
 * @param query
 * @param entries
 * @since 7.4
 */
protected void fireSearchEvent(Principal principal, String query, List<T> entries, Long executionTimeMs) {

    if (!isTrackingEnabled()) {
        return;
    }

    Map<String, Serializable> props = new HashMap<String, Serializable>();

    props.put("pageProviderName", getDefinition().getName());

    props.put("effectiveQuery", query);
    props.put("searchPattern", getDefinition().getPattern());
    props.put("queryParams", getDefinition().getQueryParameters());
    props.put("params", getParameters());
    WhereClauseDefinition wc = getDefinition().getWhereClause();
    if (wc != null) {
        props.put("whereClause_fixedPart", wc.getFixedPart());
        props.put("whereClause_select", wc.getSelectStatement());
    }

    DocumentModel searchDocumentModel = getSearchDocumentModel();
    if (searchDocumentModel != null && !(searchDocumentModel instanceof SimpleDocumentModel)) {
        RenderingContext rCtx = RenderingContext.CtxBuilder.properties("*").get();
        try {
            // the SearchDocumentModel is not a Document bound to the repository
            // - it may not survive the Event Stacking (ShallowDocumentModel)
            // - it may take too much space in memory
            // => let's use JSON
            String searchDocumentModelAsJson = MarshallerHelper.objectToJson(DocumentModel.class,
                    searchDocumentModel, rCtx);
            props.put("searchDocumentModelAsJson", searchDocumentModelAsJson);
        } catch (IOException e) {
            log.error("Unable to Marshall SearchDocumentModel as JSON", e);
        }

        ArrayList<String> searchFields = new ArrayList<String>();
        // searchFields collects the non- null fields inside the SearchDocumentModel
        // some schemas are skipped because they contains ContentView related info
        for (String schema : searchDocumentModel.getSchemas()) {
            for (Property prop : searchDocumentModel.getPropertyObjects(schema)) {
                if (prop.getValue() != null
                        && !SKIPPED_SCHEMAS_FOR_SEARCHFIELD.contains(prop.getSchema().getNamespace().prefix)) {
                    if (prop.isList()) {
                        if (ArrayUtils.isNotEmpty(prop.getValue(Object[].class))) {
                            searchFields.add(prop.getPath());
                        }
                    } else {
                        searchFields.add(prop.getPath());
                    }
                }
            }
        }
        props.put("searchFields", searchFields);
    }

    if (entries != null) {
        props.put("resultsCountInPage", entries.size());
    }
    props.put("resultsCount", getResultsCount());
    props.put("pageSize", getPageSize());
    props.put("pageIndex", getCurrentPageIndex());
    props.put("principal", principal.getName());

    if (executionTimeMs != null) {
        props.put("executionTimeMs", executionTimeMs);
    }

    incorporateAggregates(props);

    EventService es = Framework.getService(EventService.class);
    EventContext ctx = new UnboundEventContext(principal, props);
    es.fireEvent(ctx.newEvent("search"));
}

From source file:org.nuxeo.launcher.connect.ConnectBroker.java

private void appendIfNotEmpty(StringBuilder sb, String label, Object[] array) {
    if (ArrayUtils.isNotEmpty(array)) {
        sb.append(label + ArrayUtils.toString(array));
    }//from w w  w . ja  v  a  2 s . c o  m
}

From source file:org.onehippo.forge.camel.component.hippo.HippoEventConsumer.java

@Override
protected void doStart() throws Exception {
    super.doStart();

    final boolean persistedEventConsumer = BooleanUtils.toBoolean((String) endpoint.getProperty("_persisted"));

    if (persistedEventConsumer) {
        LOG.info("Registering a persisted event consumer because the _persisted parameter set to true.");

        HippoPersistedEventListener listener = new HippoPersistedEventListener();

        final String channelName = (String) endpoint.getProperty("_channelName");

        if (StringUtils.isEmpty(channelName)) {
            throw new RuntimeCamelException(
                    "Channel name must be specified for a persisted event consumer with '_channelName' parameter!");
        }/*from   w  w  w.j  av  a 2 s. c om*/

        listener.setChannelName(channelName);

        final String[] eventCategories = StringUtils.split((String) endpoint.getProperty("category"), ",");

        if (ArrayUtils.isNotEmpty(eventCategories) && StringUtils.isNotEmpty(eventCategories[0])) {
            listener.setEventCategory(eventCategories[0]);
        }

        if (endpoint.hasProperty("_onlyNewEvents")) {
            listener.setOnlyNewEvents(BooleanUtils.toBoolean((String) endpoint.getProperty("_onlyNewEvents")));
        }

        HippoServiceRegistry.registerService(listener, HippoEventBus.class);

        persistedEventListener = listener;

    } else {
        LOG.info(
                "Registering a local event consumer because the _persisted parameter unspecified or set to false.");

        HippoLocalEventListener listener = new HippoLocalEventListener();
        HippoServiceRegistry.registerService(listener, HippoEventBus.class);
        localEventListener = listener;

    }
}

From source file:org.onehippo.forge.camel.component.hippo.HippoEventConsumer.java

protected boolean isConsumable(final HippoEvent<?> event, final JSONObject messageBody) {
    String[] availableValues;//from  w  w  w. j  a  va  2  s  .com
    String value;

    for (String propName : endpoint.getPropertyNameSet()) {
        availableValues = StringUtils.split((String) endpoint.getProperty(propName), ",");
        value = null;

        if (messageBody.has(propName)) {
            value = messageBody.getString(propName);
        }

        if (value == null && ArrayUtils.isNotEmpty(availableValues)) {
            return false;
        }

        if (!ArrayUtils.contains(availableValues, value)) {
            return false;
        }
    }

    return true;
}