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:be.roots.taconic.pricingguide.service.PricingGuideServiceImpl.java

@Async
@Override/*from  w  w  w . j a  v a  2s  .  c  o  m*/
public void buildPricingGuide(Request request) throws IOException {

    LOGGER.info(request.getId() + " - Received request to create pricing guide for hsID : " + request.getHsId()
            + ", modelList : " + request.getModelList());

    final Contact contact = hubSpotService.getContactFor(request.getHsId());

    if (contact == null) {
        LOGGER.error(request.getId() + " - Unable to find a Contact for hsID : " + request.getHsId()
                + ", will save and retry later");
        saveRequestForRetry(request);
        return;
    }

    try {
        LOGGER.info(request.getId() + " - Report the request in the CSV record ");
        reportService.report(contact, request.getModelList());
    } catch (IOException e) {
        LOGGER.error(request.getId()
                + " - Couldn't report the request in the CSV record, still continuing with creating pricing guide ",
                e);
    }

    final List<Model> models = modelRepository.findFor(request.getModelList());

    if (CollectionUtils.isEmpty(models)) {
        LOGGER.error(request.getId() + " - No models were found, thus no guide can be created.");
        return;
    }

    final byte[] pricingGuide;
    try {
        pricingGuide = pdfService.createPricingGuide(contact, models);
    } catch (DocumentException e) {
        LOGGER.error(request.getId() + " - Could create the pricing guide.", e);
        return;
    }

    if (pricingGuide == null) {
        LOGGER.error(request.getId() + " - Could create the pricing guide.");
        return;
    }

    try {
        mailService.sendMail(contact, pricingGuide);
    } catch (MessagingException e) {
        LOGGER.error(request.getId() + " - Error in sending the pricing guide to " + contact.getEmail(), e);
        return;
    }

    LOGGER.info(request.getId() + " - Pricing guide successfully sent to  " + contact.getEmail());
}

From source file:pe.gob.mef.gescon.service.impl.AsignacionServiceImpl.java

@Override
public List<Consulta> getNotificationsAssignedPanelByUser(User user) {
    List<Consulta> lista = new ArrayList<Consulta>();
    try {/*from w w  w . ja  v a  2 s  .  co  m*/
        Mtuser mtuser = new Mtuser();
        BeanUtils.copyProperties(mtuser, user);
        AsignacionDao asignacionDao = (AsignacionDao) ServiceFinder.findBean("AsignacionDao");
        List<HashMap> consulta = asignacionDao.getNotificationsAssignedPanelByMtuser(mtuser);
        if (!CollectionUtils.isEmpty(consulta)) {
            for (HashMap map : consulta) {
                Consulta c = new Consulta();
                c.setIdconocimiento((BigDecimal) map.get("ID"));
                c.setCodigo((String) map.get("NUMERO"));
                c.setNombre((String) map.get("NOMBRE"));
                c.setSumilla((String) map.get("SUMILLA"));
                c.setFechaPublicacion((Date) map.get("FECHA"));
                c.setIdCategoria((BigDecimal) map.get("IDCATEGORIA"));
                c.setCategoria((String) map.get("CATEGORIA"));
                c.setIdTipoConocimiento((BigDecimal) map.get("IDTIPOCONOCIMIENTO"));
                c.setTipoConocimiento((String) map.get("TIPOCONOCIMIENTO"));
                c.setIdEstado((BigDecimal) map.get("IDESTADO"));
                c.setEstado((String) map.get("ESTADO"));
                c.setFechaAsignacion((Date) map.get("FECHAASIG"));
                c.setSemaforo((BigDecimal) map.get("SEMAFORO"));
                lista.add(c);
            }
        }
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
    return lista;
}

From source file:com.jim.im.topic.rpc.TopicRpcServiceImpl.java

@Override
public Map<TopicType, TopicInfo> getTopicInfo(TopicRequest request) throws TopicRpcException {
    List<String> topicNames = topicService.invalidTopicNames(request.getOperatorId(), request.getAppId(),
            request.getTenantId(), request.getTopicOwnerType(), request.getTopicTypes());
    if (CollectionUtils.isEmpty(topicNames))
        throw new TopicRpcException("The set of topic name can be not empty.");

    List<TopicInfo> infoList = topicService.getTopicInfo(topicNames);
    Map<TopicType, TopicInfo> topicMap = Maps.newHashMap();
    for (TopicInfo topicInfo : infoList)
        topicMap.put(topicInfo.getTopicType(), topicInfo);
    return topicMap;
}

From source file:com.phoenixnap.oss.ramlapisync.naming.RamlHelper.java

/**
 * Gets the successful response from an action (200 or 201)
 * /*w w w.j  a  v  a 2  s.  co m*/
 * @param action The action to parse
 * @return The Successful response or null if not found
 */
public static RamlResponse getSuccessfulResponse(RamlAction action) {
    String[] successfulResponses = new String[] { "200", "201" };
    for (String code : successfulResponses) {
        if (action != null && !CollectionUtils.isEmpty(action.getResponses())
                && action.getResponses().containsKey(code)) {
            return action.getResponses().get(code);
        }
    }
    return null;
}

From source file:cn.loveapple.service.cool.service.impl.SiteContentsServiceImpl.java

/**
 * /*from   ww  w .  j a  va  2 s.  co m*/
 * {@inheritDoc}
 */
@Override
public List<SiteContentsCategoryModel> findSiteContentsCategory(Long siteId, Long creatorId, String creatorMail,
        String lang, int start, int size) {
    if (!isSupportedLanguage(lang)) {
        throw new RuntimeException("not be supported language. " + lang);
    }
    List<SiteContentsCategoryModel> tmp = findSiteContentsCategory(siteId, creatorId, creatorMail, lang);

    if (CollectionUtils.isEmpty(tmp) || tmp.size() < start) {
        return null;
    }
    int startSize = tmp.size() - start;
    int realSize = (tmp.size() - startSize) < size ? (tmp.size() - startSize) : size;
    List<SiteContentsCategoryModel> result = new ArrayList<SiteContentsCategoryModel>(realSize);
    for (int i = startSize; i < realSize; i++) {
        result.add(tmp.get(i));
    }
    return result;
}

From source file:com.iana.dver.dao.impl.DverDetailsDaoImpl.java

@Override
public List<DverDetail> findAllRejectedDvers(final int start, final int end) throws DataAccessException {

    logger.info("Find All Rejected Dvers....");
    List rejectedDvers = getHibernateTemplate().executeFind(new HibernateCallback<List<DverDetail>>() {
        @Override//ww w .ja  v  a  2 s. co  m
        public List<DverDetail> doInHibernate(Session session) throws HibernateException, SQLException {
            org.hibernate.Query q = session.createQuery(FIND_REJECTED_DVERS);
            q.setFirstResult(start);
            q.setMaxResults(end);
            return q.list();
        }
    });

    return (!CollectionUtils.isEmpty(rejectedDvers)) ? rejectedDvers : new ArrayList<DverDetail>();
}

From source file:com.hs.mail.imap.message.MessageHeader.java

public Mailbox getReplyTo() {
    MailboxList mailboxList = getMailboxList(FieldName.REPLY_TO);
    if (CollectionUtils.isEmpty(mailboxList)) {
        return null;
    } else {/*  ww  w.ja  va2  s. co  m*/
        return mailboxList.get(0);
    }
}

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

@RequestMapping
public String describe(@PathVariable String language, @RequestParam long id, String query, Model model,
        RedirectAttributes redirectAttributes) {
    Page page = pageService.getPageById(id);
    if (page == null) {
        throw new HttpNotFoundException();
    }//from ww w  . j  ava  2 s . co  m

    if (!page.getLanguage().equals(language)) {
        Page target = pageService.getPageByCode(page.getCode(), language);
        if (target != null) {
            redirectAttributes.addAttribute("id", target.getId());
            return "redirect:/_admin/{language}/pages/describe?id={id}";
        } else {
            redirectAttributes.addFlashAttribute("original", page);
            redirectAttributes.addAttribute("code", page.getCode());
            return "redirect:/_admin/{language}/pages/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 PageSearchForm());
    beanWrapper.setConversionService(conversionService);
    beanWrapper.setPropertyValues(mpvs, true, true);
    PageSearchForm form = (PageSearchForm) beanWrapper.getWrappedInstance();
    List<Long> ids = pageService.getPageIds(form.toPageSearchRequest());
    if (!CollectionUtils.isEmpty(ids)) {
        int index = ids.indexOf(page.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("page", page);
    model.addAttribute("query", query);
    return "page/describe";
}

From source file:be.roots.taconic.pricingguide.domain.Model.java

@JsonIgnore
public List<Pricing> validPricings(Contact contact) {
    final List<Pricing> validPricing = new ArrayList<>();

    if (!CollectionUtils.isEmpty(pricing)) {

        final Set<String> categoryCodes = new LinkedHashSet<>();
        final Map<String, Pricing> nonProfitPricing = new HashMap<>();
        final Map<String, Pricing> profitPricing = new HashMap<>();

        // loop trough all pricings and note all the available
        for (Pricing p : pricing) {
            if (p.getCurrency().getIsoCode().equals(contact.getCurrency().getIsoCode())) {
                categoryCodes.add(p.getCategoryCode());
                if (p.isProfit()) {
                    profitPricing.put(p.getCategoryCode(), p);
                } else {
                    nonProfitPricing.put(p.getCategoryCode(), p);
                }/*from ww w . j  av  a2 s  .  c o  m*/
            }
        }

        // for each code; look for the correct pricing
        for (String categoryCode : categoryCodes) {

            if (contact.getCurrency().isNonProfit()) {
                if (nonProfitPricing.containsKey(categoryCode)) {
                    validPricing.add(nonProfitPricing.get(categoryCode));
                } else {
                    validPricing.add(profitPricing.get(categoryCode));
                }

            } else {
                validPricing.add(profitPricing.get(categoryCode));
            }

        }

    }
    return validPricing;
}