Example usage for org.springframework.util CollectionUtils isEmpty

List of usage examples for org.springframework.util CollectionUtils isEmpty

Introduction

In this page you can find the example usage for org.springframework.util CollectionUtils isEmpty.

Prototype

public static boolean isEmpty(@Nullable Map<?, ?> map) 

Source Link

Document

Return true if the supplied Map is null or empty.

Usage

From source file:org.wallride.web.controller.admin.article.ArticleDescribeController.java

@RequestMapping
public String describe(@PathVariable String language, @RequestParam long id, String query, Model model,
        RedirectAttributes redirectAttributes) {
    Article article = articleService.getArticleById(id);
    if (article == null) {
        throw new HttpNotFoundException();
    }/*from   ww  w . ja  v a 2s.c om*/

    if (!article.getLanguage().equals(language)) {
        Article target = articleService.getArticleByCode(article.getCode(), language);
        if (target != null) {
            redirectAttributes.addAttribute("id", target.getId());
            return "redirect:/_admin/{language}/articles/describe?id={id}";
        } else {
            redirectAttributes.addFlashAttribute("original", article);
            redirectAttributes.addAttribute("code", article.getCode());
            return "redirect:/_admin/{language}/articles/create?code={code}";
        }
    }

    MutablePropertyValues mpvs = new MutablePropertyValues(
            UriComponentsBuilder.newInstance().query(query).build().getQueryParams());
    for (Iterator<PropertyValue> i = mpvs.getPropertyValueList().iterator(); i.hasNext();) {
        PropertyValue pv = i.next();
        boolean hasValue = false;
        for (String value : (List<String>) pv.getValue()) {
            if (StringUtils.hasText(value)) {
                hasValue = true;
                break;
            }
        }
        if (!hasValue) {
            i.remove();
        }
    }
    BeanWrapperImpl beanWrapper = new BeanWrapperImpl(new ArticleSearchForm());
    beanWrapper.setConversionService(conversionService);
    beanWrapper.setPropertyValues(mpvs, true, true);
    ArticleSearchForm form = (ArticleSearchForm) beanWrapper.getWrappedInstance();
    List<Long> ids = articleService.getArticleIds(form.toArticleSearchRequest());
    if (!CollectionUtils.isEmpty(ids)) {
        int index = ids.indexOf(article.getId());
        if (index < ids.size() - 1) {
            Long next = ids.get(index + 1);
            model.addAttribute("next", next);
        }
        if (index > 0) {
            Long prev = ids.get(index - 1);
            model.addAttribute("prev", prev);
        }
    }

    model.addAttribute("article", article);
    model.addAttribute("query", query);
    return "article/describe";
}

From source file:com.google.ie.web.view.GsonView.java

/**
 * Filters out undesired attributes from the given model.
 * Removes BindingResult instances and attributes not included in the
 * modelAttributes property./*from  w  w w  . j a v a  2 s.co m*/
 * 
 * @param model the model
 * @return the object to be rendered
 */
private Map<String, Object> filterModel(Map<String, Object> model) {
    Map<String, Object> result = new HashMap<String, Object>(model.size());
    // If renderedAttributes is empty, then use all attributes of the model
    Set<String> modelAttributes = !CollectionUtils.isEmpty(this.modelAttributes) ? this.modelAttributes
            : model.keySet();

    for (Map.Entry<String, Object> entry : model.entrySet()) {
        // Check for instance of BindingResult and check key in set of
        // modelAttributes
        if (!(entry.getValue() instanceof BindingResult) && !(entry.getValue() instanceof User)
                && !(entry.getValue() instanceof RetrievalInfo) && modelAttributes.contains(entry.getKey())) {
            result.put(entry.getKey(), entry.getValue());
        }
    }
    return result;
}

From source file:com.qpark.eip.core.spring.JAXBElementAwarePayloadTypeRouter.java

private String findClosestMatch(final Class<?> type, final boolean isArray) {
    int minTypeDiffWeight = Integer.MAX_VALUE;
    List<String> matches = new ArrayList<String>();
    for (String candidate : this.getChannelMappings().keySet()) {
        if (isArray) {
            if (!candidate.endsWith(ARRAY_SUFFIX)) {
                continue;
            }//from ww  w  .  j a  va2  s .  c om
            // trim the suffix
            candidate = candidate.substring(0, candidate.length() - ARRAY_SUFFIX.length());
        } else if (candidate.endsWith(ARRAY_SUFFIX)) {
            continue;
        }
        int typeDiffWeight = this.determineTypeDifferenceWeight(candidate, type, 0);
        if (typeDiffWeight < minTypeDiffWeight) {
            minTypeDiffWeight = typeDiffWeight;
            // new winner, start accumulating matches from scratch
            matches.clear();
            matches.add((isArray) ? candidate + ARRAY_SUFFIX : candidate);
        } else if (typeDiffWeight == minTypeDiffWeight && typeDiffWeight != Integer.MAX_VALUE) {
            // candidate tied with current winner, keep track
            matches.add(candidate);
        }
    }
    if (matches.size() > 1) { // ambiguity
        throw new IllegalStateException("Unresolvable ambiguity while attempting to find closest match for ["
                + type.getName() + "]. Found: " + matches);
    }
    if (CollectionUtils.isEmpty(matches)) { // no match
        return null;
    }
    // we have a winner
    return matches.get(0);
}

From source file:com.frank.search.solr.core.query.result.DelegatingCursor.java

private void process(PartialResult<T> result) {

    if (result == null) {
        this.delegate = Collections.<T>emptyList().iterator();
        this.state = State.FINISHED;
        return;//w ww  . ja v a 2  s  . c om
    }

    if (getCursorMark().equals(result.getNextCursorMark())) {
        this.state = State.FINISHED;
    }

    this.cursorMark = result.getNextCursorMark();

    if (!CollectionUtils.isEmpty(result.getItems())) {
        delegate = result.iterator();
    } else {
        Collections.<T>emptyList().iterator();
    }
}

From source file:org.whitesource.bamboo.plugins.AgentTask.java

private void updateOssInventory(final BuildLogger buildLogger, final TaskResultBuilder taskResultBuilder,
        final ConfigurationMap configurationMap, final BuildContext buildContext, final File buildDirectory,
        Collection<AgentProjectInfo> projectInfos) {
    if (CollectionUtils.isEmpty(projectInfos)) {
        buildLogger.addBuildLogEntry("No open source information found.");
    } else {//from ww w.  j  a  v  a  2 s. c o  m
        WhitesourceService service = WssUtils.createServiceClient();
        try {
            final String apiKey = configurationMap.get(AgentTaskConfigurator.API_KEY);
            final Boolean checkPolicies = configurationMap.getAsBoolean(AgentTaskConfigurator.CHECK_POLICIES);

            if (checkPolicies) {
                buildLogger.addBuildLogEntry("Checking policies ...");
                CheckPoliciesResult result = service.checkPolicies(apiKey, projectInfos);
                reportCheckPoliciesResult(result, buildContext, buildDirectory, buildLogger);
                if (result.hasRejections()) {
                    buildLogger.addErrorLogEntry("... open source rejected by organization policies.");
                    taskResultBuilder.failedWithError();
                } else {
                    buildLogger.addBuildLogEntry("... all dependencies conform with open source policies.");
                    final UpdateInventoryResult updateResult = service.update(apiKey, projectInfos);
                    logUpdateResult(updateResult, buildLogger);
                    buildLogger.addBuildLogEntry("Successfully updated White Source.");
                }
            } else {
                buildLogger.addBuildLogEntry("Ignoring policies ...");
                final UpdateInventoryResult updateResult = service.update(apiKey, projectInfos);
                logUpdateResult(updateResult, buildLogger);
                buildLogger.addBuildLogEntry("Successfully updated White Source.");
            }
        } catch (WssServiceException e) {
            buildLogger.addErrorLogEntry("Communication with White Source failed.", e);
            taskResultBuilder.failedWithError();
        } catch (IOException e) {
            buildLogger.addErrorLogEntry("Generating policy check report failed.", e);
            taskResultBuilder.failedWithError();
        } finally {
            service.shutdown();
        }
    }
}

From source file:com.alibaba.otter.manager.biz.monitor.impl.ProcessTimeoutRuleMonitor.java

private String checkTimeout(AlarmRule rule, Map<Long, Long> processTime) {
    if (!inPeriod(rule)) {
        return StringUtils.EMPTY;
    }//from w  w w . j  a va 2s .  c o  m

    String matchValue = rule.getMatchValue();
    matchValue = StringUtils.substringBeforeLast(matchValue, "@");
    Long maxSpentTime = Long.parseLong(StringUtils.trim(matchValue));
    List<Long> timeoutProcessIds = new LinkedList<Long>();
    Collections.sort(timeoutProcessIds);
    long maxSpent = 0;
    for (Entry<Long, Long> entry : processTime.entrySet()) {
        // maxSpentTime processTimevalue
        if (entry.getValue() >= (maxSpentTime * 1000)) {
            timeoutProcessIds.add(entry.getKey());
            maxSpent = maxSpent > entry.getValue() ? maxSpent : entry.getValue();
        }
    }

    if (CollectionUtils.isEmpty(timeoutProcessIds)) {
        return StringUtils.EMPTY;
    }

    String processIds = StringUtils.join(timeoutProcessIds, ",");
    String message = String.format(TIME_OUT_MESSAGE, rule.getPipelineId(), processIds, (maxSpent / 1000));
    sendAlarm(rule, message);
    return message;
}

From source file:org.wallride.web.controller.guest.page.PageDescribeController.java

protected ModelAndView createModelAndView(Page page) {
    ModelAndView modelAndView = new ModelAndView();

    List<Long> ids = pageService.getPageIds(new PageSearchRequest().withStatus(Post.Status.PUBLISHED));
    if (!CollectionUtils.isEmpty(ids)) {
        int index = ids.indexOf(page.getId());
        if (index < ids.size() - 1) {
            Page next = pageService.getPageById(ids.get(index + 1));
            modelAndView.addObject("next", next);
        }/*from   ww  w . j av a 2 s. co  m*/
        if (index > 0) {
            Page prev = pageService.getPageById(ids.get(index - 1));
            modelAndView.addObject("prev", prev);
        }
    }
    modelAndView.addObject("page", page);
    modelAndView.setViewName("page/describe");
    return modelAndView;
}

From source file:nl.surfnet.coin.api.GroupProviderConfigurationImpl.java

private boolean isAclConfiguredForGroupProvider(GroupProvider groupProvider, String spEntityId,
        Service service) {// www  .j  a  va2 s.c  o  m
    if (groupProvider == null) {
        return false;
    }
    List<ServiceProviderGroupAcl> acls = groupProvider.getServiceProviderGroupAcls();
    if (CollectionUtils.isEmpty(acls)) {
        return false;
    }
    for (ServiceProviderGroupAcl acl : acls) {
        if (acl.getSpEntityId().equals(spEntityId)) {
            switch (service) {
            case People:
                return acl.isAllowMembers();
            case Group:
                return acl.isAllowGroups();
            }
        }
    }
    return false;
}

From source file:com.nortal.petit.orm.statement.BeansStatement.java

/**
 * Returns statements sql with parameter values
 * /*from w w w . j av a  2 s. c o  m*/
 * @return
 */
@Override
public String getSqlWithParams() {
    prepare();

    StringBuilder sb = new StringBuilder();
    MappingParamFunction<B> function = new MappingParamFunction<B>(getMapping());
    if (!CollectionUtils.isEmpty(getBeans())) {
        for (B bean : getBeans()) {
            function.setBean(bean);
            sb.append(super.getSqlWithParams(function)).append("\n");
        }
    } else {
        sb.append(super.getSqlWithParams(function)).append("\n");
    }
    return sb.toString();
}

From source file:com.sinet.gage.dlap.utils.XMLUtils.java

public static List<DomainResponse> transferObject(Domains domains) {

    List<DomainResponse> domainsResponseList = new ArrayList<DomainResponse>();
    try {//from w  ww .  jav  a  2 s.co  m
        if (domains != null && !CollectionUtils.isEmpty(domains.getDomain())) {
            for (Domain domain : domains.getDomain()) {
                EdivateLearn edivateLearn = null;
                if (domain.getData() != null && domain.getData().getCustomization() != null
                        && domain.getData().getCustomization().getEdivatelearn() != null) {
                    edivateLearn = new EdivateLearn(
                            domain.getData().getCustomization().getEdivatelearn().getDomaintype() != null
                                    ? domain.getData().getCustomization().getEdivatelearn().getDomaintype()
                                    : "",
                            domain.getData().getCustomization().getEdivatelearn().getLicensetype() != null
                                    ? domain.getData().getCustomization().getEdivatelearn().getLicensetype()
                                    : "",
                            domain.getData().getCustomization().getEdivatelearn().getNooflicense() != null
                                    ? domain.getData().getCustomization().getEdivatelearn().getNooflicense()
                                    : "",
                            domain.getData().getCustomization().getEdivatelearn().getPooltype() != null
                                    ? domain.getData().getCustomization().getEdivatelearn().getPooltype()
                                    : "",
                            domain.getData().getCustomization().getEdivatelearn().isPilot(),
                            domain.getData().getCustomization().getEdivatelearn().getPilotstartdate() != null
                                    ? domain.getData().getCustomization().getEdivatelearn().getPilotstartdate()
                                    : "",
                            domain.getData().getCustomization().getEdivatelearn().getPilotenddate() != null
                                    ? domain.getData().getCustomization().getEdivatelearn().getPilotenddate()
                                    : "",
                            domain.getData().getCustomization().getEdivatelearn().isFullsubscription(),
                            domain.getData().getCustomization().getEdivatelearn()
                                    .getSubscriptionstartdate() != null
                                            ? domain.getData().getCustomization().getEdivatelearn()
                                                    .getSubscriptionstartdate()
                                            : "",
                            domain.getData().getCustomization().getEdivatelearn()
                                    .getSubscriptionenddate() != null
                                            ? domain.getData().getCustomization().getEdivatelearn()
                                                    .getSubscriptionenddate()
                                            : "");
                } else {
                    edivateLearn = new EdivateLearn("", "", "", "", Boolean.FALSE, "", "", Boolean.FALSE, "",
                            "");
                }
                List<Securehash> securehashList = new ArrayList<Securehash>();
                if (domain.getData() != null && domain.getData().getCustomization() != null
                        && domain.getData().getCustomization().getSecurehash() != null) {
                    for (com.sinet.gage.dlap.entities.Domains.Domain.Data.Customization.Securehash securehash : domain
                            .getData().getCustomization().getSecurehash()) {
                        List<Secretkey> secretkeyList = new ArrayList<>();
                        if (!CollectionUtils.isEmpty(securehash.getSecretkey())) {
                            for (com.sinet.gage.dlap.entities.Domains.Domain.Data.Customization.Securehash.Secretkey secretkey : securehash
                                    .getSecretkey()) {
                                Secretkey secretkeyTemp = new Secretkey(secretkey.getName(),
                                        secretkey.get$value());

                                secretkeyList.add(secretkeyTemp);
                            }
                        }

                        List<EncryptedData> encryptedDataList = new ArrayList<>();
                        if (!CollectionUtils.isEmpty(securehash.getEncryptedData())) {
                            for (com.sinet.gage.dlap.entities.Domains.Domain.Data.Customization.Securehash.EncryptedData encryptedData : securehash
                                    .getEncryptedData()) {
                                CipherValue cipherValue = new CipherValue(
                                        encryptedData.getCipherData().getCipherValue().get$value());
                                CipherData cipherData = new CipherData(cipherValue);
                                EncryptionMethod encryptionMethod = new EncryptionMethod(
                                        encryptedData.getEncryptionMethod().getAlgorithm());
                                EncryptedData encryptedDataTemp = new EncryptedData(encryptedData.getXmlns(),
                                        cipherData, encryptionMethod);

                                encryptedDataList.add(encryptedDataTemp);
                            }
                        }
                        Securehash securehashTemp = new Securehash(secretkeyList, encryptedDataList);

                        securehashList.add(securehashTemp);
                    }
                }

                Files files = null;
                if (domain.getData() != null && domain.getData().getCustomization() != null
                        && domain.getData().getCustomization().getFiles() != null
                        && !CollectionUtils.isEmpty(domain.getData().getCustomization().getFiles().getFile())) {
                    List<File> fileList = new ArrayList<>();
                    for (com.sinet.gage.dlap.entities.Domains.Domain.Data.Customization.Files.File file : domain
                            .getData().getCustomization().getFiles().getFile()) {
                        File fileTemp = new File(file.getType(), file.getPath());
                        fileList.add(fileTemp);
                    }
                    files = new Files(fileList);
                }

                ResourceBase resourceBase = null;
                if (domain.getData() != null && domain.getData().getCustomization() != null
                        && domain.getData().getCustomization().getResourcebase() != null) {
                    resourceBase = new ResourceBase(
                            domain.getData().getCustomization().getResourcebase().get$value());
                }
                AllowViewInGpeerCompletion allowViewInGpeerCompletion = null;
                if (domain.getData() != null && domain.getData().getCustomization() != null
                        && domain.getData().getCustomization().getAllowviewingpeercompletion() != null) {
                    allowViewInGpeerCompletion = new AllowViewInGpeerCompletion(
                            domain.getData().getCustomization().getAllowviewingpeercompletion().get$value());
                }

                LearningObjectives learningObjectives = null;
                if (domain.getData() != null && domain.getData().getCustomization() != null
                        && domain.getData().getCustomization().getLearningobjectives() != null) {
                    learningObjectives = new LearningObjectives(
                            domain.getData().getCustomization().getLearningobjectives().getSetowner(),
                            domain.getData().getCustomization().getLearningobjectives().getLowgrade(),
                            domain.getData().getCustomization().getLearningobjectives().getHighgrade());
                }

                MenuItems menuItems = null;
                if (domain.getData() != null && domain.getData().getCustomization() != null
                        && domain.getData().getCustomization().getMenuitems() != null && !CollectionUtils
                                .isEmpty(domain.getData().getCustomization().getMenuitems().getMenuitem())) {
                    List<MenuItem> menuItemList = new ArrayList<>();
                    for (com.sinet.gage.dlap.entities.Domains.Domain.Data.Customization.MenuItems.MenuItem menuItem : domain
                            .getData().getCustomization().getMenuitems().getMenuitem()) {
                        MenuItem menuItemTemp = new MenuItem(menuItem.getType(), menuItem.getText(),
                                menuItem.getUrl());
                        menuItemList.add(menuItemTemp);
                    }
                    menuItems = new MenuItems(menuItemList);
                }

                Strings strings = null;
                if (domain.getData() != null && domain.getData().getCustomization() != null
                        && domain.getData().getCustomization().getStrings() != null
                        && domain.getData().getCustomization().getStrings().getString() != null) {
                    com.sinet.gage.dlap.entities.Customization.Strings.String string = new com.sinet.gage.dlap.entities.Customization.Strings.String(
                            domain.getData().getCustomization().getStrings().getString().getName(),
                            domain.getData().getCustomization().getStrings().getString().get$value());
                    strings = new Strings(string);
                }

                ItemMetadata itemMetadata = null;
                if (domain.getData() != null && domain.getData().getCustomization() != null
                        && domain.getData().getCustomization().getItemMetadata() != null) {
                    Choice choice = new Choice(
                            domain.getData().getCustomization().getItemMetadata().getValue().getChoice()
                                    .getValue(),
                            domain.getData().getCustomization().getItemMetadata().getValue().getChoice()
                                    .getDisplay());
                    Value value = new Value(
                            domain.getData().getCustomization().getItemMetadata().getValue().getId(),
                            domain.getData().getCustomization().getItemMetadata().getValue().getDisplay(),
                            domain.getData().getCustomization().getItemMetadata().getValue().getInputtype(),
                            domain.getData().getCustomization().getItemMetadata().getValue().getSearchtype(),
                            domain.getData().getCustomization().getItemMetadata().getValue().getItemtype(),
                            domain.getData().getCustomization().getItemMetadata().getValue()
                                    .isAllowgroupoverride(),
                            domain.getData().getCustomization().getItemMetadata().getValue().getDefaultvalue(),
                            domain.getData().getCustomization().getItemMetadata().getValue().getMinvalue(),
                            domain.getData().getCustomization().getItemMetadata().getValue().getMaxvalue(),
                            choice);
                    itemMetadata = new ItemMetadata(value);
                }

                Authentication authentication = null;
                if (domain.getData() != null && domain.getData().getCustomization() != null
                        && domain.getData().getCustomization().getAuthentication() != null) {
                    if (domain.getData().getCustomization().getAuthentication().getProvider() != null
                            && !CollectionUtils.isEmpty(
                                    domain.getData().getCustomization().getAuthentication().getProvider())) {
                        List<Provider> providerList = new ArrayList<>();
                        for (com.sinet.gage.dlap.entities.Domains.Domain.Data.Customization.Authentication.Provider provider : domain
                                .getData().getCustomization().getAuthentication().getProvider()) {
                            ApplicationId applicationid = null;
                            if (provider.getApplicationid() != null) {
                                applicationid = new ApplicationId(provider.getApplicationid().get$value());
                            }
                            EncryptedData encryptedDataTemp = null;
                            if (provider.getEncryptedData() != null) {
                                CipherValue cipherValue = new CipherValue(provider.getEncryptedData()
                                        .getCipherData().getCipherValue().get$value());
                                CipherData cipherData = new CipherData(cipherValue);
                                EncryptionMethod encryptionMethod = new EncryptionMethod(
                                        provider.getEncryptedData().getEncryptionMethod().getAlgorithm());
                                encryptedDataTemp = new EncryptedData(provider.getEncryptedData().getXmlns(),
                                        cipherData, encryptionMethod);
                            }

                            Server server = null;
                            if (provider.getServer() != null) {
                                server = new Server(provider.getServer().get$value());
                            }
                            Logout logout = null;
                            if (provider.getLogout() != null) {
                                logout = new Logout(provider.getLogout().get$value());
                            }
                            Provider providerTemp = new Provider(provider.getType(), applicationid,
                                    encryptedDataTemp, server, logout);
                            providerList.add(providerTemp);
                        }
                        authentication = new Authentication(
                                domain.getData().getCustomization().getAuthentication().getLoginprefix(),
                                providerList);
                    }
                }

                Customization customization = new Customization(edivateLearn, securehashList, files,
                        resourceBase, allowViewInGpeerCompletion, learningObjectives, menuItems, strings,
                        itemMetadata, authentication);
                Data data = new Data(customization);
                DomainResponse domainResponse = new DomainResponse(domain.getId(), domain.getName(),
                        domain.getUserspace(), domain.getParentid(), domain.getReference(), domain.getGuid(),
                        domain.getFlags(), domain.getCreationdate(), domain.getCreationby(),
                        domain.getModifieddate(), domain.getModifiedby(), domain.getVersion(), data);
                domainsResponseList.add(domainResponse);
            }
        }
    } catch (Exception e) {
        LOGGER.error("Exception in tranferring from object: ", e);
    }

    return domainsResponseList;
}