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:com.hybris.datahub.outbound.adapter.TmallAdapter.java

private List<ErrorData> processItems(final TargetSystemPublication targetSystemPublication,
        final TargetItemMetadata targetItemMetadata) {
    final List<ErrorData> errors = Lists.newArrayList();
    final TransactionTemplate template = new TransactionTemplate(transactionManager);
    Pair<Integer, Long> elementsAndLastId = new ImmutablePair<>(0, 0L);
    do {//  ww w.j a v  a  2s.  c  o  m
        final Long lastProcessedId = elementsAndLastId.getRight();
        elementsAndLastId = template.execute(status -> {
            final List<? extends TargetItem> items = getItems(targetItemMetadata, targetSystemPublication,
                    makePageable(lastProcessedId));
            final Pair<Integer, Long> pageElementsAndLastId;
            if (!CollectionUtils.isEmpty(items)) {
                for (final TargetItem targetItem : items) {
                    errors.addAll(doPublish(targetItem, targetSystemPublication));
                }
                pageElementsAndLastId = new ImmutablePair<>(items.size(),
                        getLastProcessedId(lastProcessedId, items));
            } else {
                pageElementsAndLastId = new ImmutablePair<>(0, 0L);
            }
            return pageElementsAndLastId;
        });
    } while (elementsAndLastId.getRight() > 0);
    return errors;
}

From source file:org.yamj.core.service.artwork.common.TheMovieDbArtworkScanner.java

/**
 * Get the person ID from the person object
 *
 * @param person/*from  ww w  .  j a  va2 s. c o  m*/
 * @return
 */
@Override
public String getPersonId(Person person) {
    String id = person.getPersonId(getScannerName());
    if (StringUtils.isNotBlank(id)) {
        return id;
    }

    if (StringUtils.isBlank(person.getName())) {
        return null;
    }

    try {
        TmdbResultsList<com.omertron.themoviedbapi.model.Person> results = tmdbApi
                .searchPeople(person.getName(), Boolean.FALSE, -1);
        if (CollectionUtils.isEmpty(results.getResults())) {
            return null;
        }

        com.omertron.themoviedbapi.model.Person tmdbPerson = results.getResults().get(0);
        String tmdbId = Integer.toString(tmdbPerson.getId());
        String imdbId = tmdbPerson.getImdbId();
        person.setPersonId(getScannerName(), tmdbId);
        person.setPersonId(ImdbScanner.SCANNER_ID, imdbId);
        LOG.debug("Found IDs for {} - TMDB: '{}', IMDB: '{}'", person.getName(), tmdbId, imdbId);
        return Integer.toString(tmdbPerson.getId());
    } catch (MovieDbException ex) {
        LOG.warn("Failed to get ID for {} from {}, error: {}", person.getName(), getScannerName(),
                ex.getMessage());
        return null;
    }
}

From source file:com.novation.eligibility.rest.spring.web.servlet.handler.DefaultRestErrorResolver.java

/**
 * Returns the config-time 'template' RestError instance configured for the specified Exception, or
 * {@code null} if a match was not found.
 * <p/>//  www  .  j av a 2s  .  c  o m
 * The config-time template is used as the basis for the RestError constructed at runtime.
 * @param ex
 * @return the template to use for the RestError instance to be constructed.
 */
private RestError getRestErrorTemplate(Exception ex) {
    Map<String, RestError> mappings = this.exceptionMappings;
    if (CollectionUtils.isEmpty(mappings)) {
        return null;
    }
    RestError template = null;
    String dominantMapping = null;
    int deepest = Integer.MAX_VALUE;
    for (Map.Entry<String, RestError> entry : mappings.entrySet()) {
        String key = entry.getKey();
        int depth = getDepth(key, ex);
        if (depth >= 0 && depth < deepest) {
            deepest = depth;
            dominantMapping = key;
            template = entry.getValue();
        }
    }
    if (template != null && log.isDebugEnabled()) {
        log.debug("Resolving to RestError template '" + template + "' for exception of type ["
                + ex.getClass().getName() + "], based on exception mapping [" + dominantMapping + "]");
    }
    return template;
}

From source file:org.kuali.student.myplan.plan.controller.PlanController.java

/**
 * plan Access form for student to provide viewing plan access to adviser
 *
 * @param form// w w w .j  a  v  a  2s  . c o  m
 * @param result
 * @param request
 * @param response
 * @return
 */
@RequestMapping(params = "methodToCall=startPlanAccessForm")
public ModelAndView startPlanAccessForm(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
        HttpServletRequest request, HttpServletResponse response) {
    super.start(form, result, request, response);

    /**
     * Initializing
     */
    PlanForm planForm = (PlanForm) form;
    List<LearningPlanInfo> plan = null;

    /**
     * Loading Bookmark Plan Items count and adviser sharing flag
     */
    try {

        plan = getAcademicPlanService().getLearningPlansForStudentByType(getUserSessionHelper().getStudentId(),
                PlanConstants.LEARNING_PLAN_TYPE_PLAN, PlanConstants.CONTEXT_INFO);

        if (!CollectionUtils.isEmpty(plan)) {

            //A student should have only one learning plan associated to his Id
            LearningPlan learningPlan = plan.get(0);

            planForm.setEnableAdviserView(learningPlan.getShared().toString());

            List<PlanItemInfo> planItems = getAcademicPlanService().getPlanItemsInPlanByType(
                    learningPlan.getId(), PlanConstants.LEARNING_PLAN_ITEM_TYPE_WISHLIST,
                    PlanConstants.CONTEXT_INFO);

            if (!CollectionUtils.isEmpty(planItems)) {
                planForm.setBookmarkedCount(planItems.size());
            }

        }

    } catch (Exception e) {

        return doOperationFailedError(planForm, "Could not load the plan items", e);

    }

    /**
     * Loading the messages count
     */
    List<MessageDataObject> messages = null;

    try {
        CommentQueryHelper commentQueryHelper = new CommentQueryHelper();
        messages = commentQueryHelper.getMessages(getUserSessionHelper().getStudentId());
    } catch (Exception e) {
        throw new RuntimeException("Could not retrieve messages.", e);
    }

    if (!CollectionUtils.isEmpty(messages)) {
        planForm.setMessagesCount(messages.size());
    }

    return getUIFModelAndView(planForm);
}

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

@Override
public DverConfig findDverConfigByUserId(Integer userId) throws DataAccessException {
    logger.info("find DverConfig By UserId ");
    List result = getHibernateTemplate().findByNamedParam(FIND_DVER_CONFIG_BY_USER_ID, "dverUserId", userId);
    return CollectionUtils.isEmpty(result) ? null : (DverConfig) result.get(0);
}

From source file:com.deloitte.smt.service.SignalDetectionService.java

/**
 * @param signalDetection/*www .  ja va  2  s  .com*/
 * @param ingredient
 */
private void saveProduct(SignalDetection signalDetection, List<Ingredient> ingredients) {
    List<Product> products = null;
    if (!CollectionUtils.isEmpty(ingredients)) {
        for (Ingredient ingredient : ingredients) {
            products = ingredient.getProducts();
            if (!CollectionUtils.isEmpty(products)) {
                for (Product singleProduct : products) {
                    singleProduct.setIngredientId(ingredient.getId());
                    singleProduct.setDetectionId(signalDetection.getId());
                    //productRepository.deleteByIngredientId(ingredient.getId());
                }
                productRepository.save(products);
            }
        }
    }
}

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

@Override
public List<Consulta> getConcimientosDisponibles(HashMap filters) {
    List<Consulta> lista = new ArrayList<Consulta>();
    try {/*www .  j  a v  a2 s  . co  m*/
        PreguntaDao preguntaDao = (PreguntaDao) ServiceFinder.findBean("PreguntaDao");
        List<HashMap> consulta = preguntaDao.getConcimientosDisponibles(filters);
        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"));
                lista.add(c);
            }
        }
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
    return lista;
}

From source file:com.alibaba.otter.shared.arbitrate.impl.setl.rpc.RpcStageController.java

/**
 * ???processIds?reply queue?processIds/*  ww w . jav  a  2 s  .  co m*/
 */
private synchronized void compareReply(List<Long> processIds, ReplyProcessQueue replyProcessIds) {
    Object[] replyIds = replyProcessIds.toArray();
    for (Object replyId : replyIds) {
        if (processIds.contains((Long) replyId) == false) { // reply id??processId
            // ?Listener???processprocessIdreply
            // ?processIds??process??
            if (CollectionUtils.isEmpty(processIds) == false) {
                Long processId = processIds.get(0);
                if (processId > (Long) replyId) { // ??processIdreplyId, processId
                    logger.info("## {} remove reply id [{}]", ClassUtils.getShortClassName(this.getClass()),
                            (Long) replyId);
                    replyProcessIds.remove((Long) replyId);
                    progress.remove((Long) replyId);
                }
            }
        }
    }
}

From source file:eu.openanalytics.rsb.security.ApplicationPermissionEvaluator.java

private boolean isAuthenticationAuthorized(final Authentication authentication,
        final Set<String> authorizedPrincipals, final Set<String> authorizedRoles) {
    final String userName = getUserName(authentication);

    if ((StringUtils.isNotBlank(userName)) && (!CollectionUtils.isEmpty(authorizedPrincipals))
            && (authorizedPrincipals.contains(userName))) {
        return true;
    }//from   w  w  w . ja va  2s. c o m

    final Set<String> roles = new HashSet<String>();
    for (final GrantedAuthority authority : authentication.getAuthorities()) {
        roles.add(authority.getAuthority());
    }

    return CollectionUtils.containsAny(authorizedRoles, roles);
}

From source file:com.formkiq.core.form.service.FormValidatorServiceImpl.java

/**
 * Validate Variable.// w  ww  . jav  a  2 s .  c  om
 * @param archive {@link ArchiveDTO}
 * @param form {@link FormJSON}
 * @param field {@link FormJSONField}
 * @param value {@link String}
 * @param errors {@link Map}
 */
private void validateFieldVariable(final ArchiveDTO archive, final FormJSON form, final FormJSONField field,
        final String value, final Map<String, String> errors) {

    String variable = field.getVariable();

    if (StringUtils.hasText(variable)) {

        List<FormJSONValidator> validators = new ArrayList<>(
                form.getValidators().getOrDefault(variable, Collections.emptyList()));

        validators.addAll(getSourceFieldValidators(archive, field));

        if (!CollectionUtils.isEmpty(validators)) {

            for (FormJSONValidator validator : validators) {
                validate(validator, field, value, errors);
            }
        }
    }
}