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:uk.ac.kcl.iop.brc.core.pipeline.dncpipeline.data.DNCWorkUnitDao.java

private Object getObjectFromCoordinate(DNCWorkCoordinate coordinate) {
    SessionWrapper sessionWrapper = getCurrentSourceSession();
    try {//from  ww  w.jav a 2 s  .  c  o m
        Query coordinateQuery = sessionWrapper.getNamedQuery("getObjectFromCoordinate");
        String queryString = coordinateQuery.getQueryString();
        queryString = queryString.replace(":sourceTable", coordinate.getSourceTable())
                .replace(":sourceColumn", coordinate.getSourceColumn())
                .replace(":pkColumnName", coordinate.getPkColumnName())
                .replace(":id", Long.toString(coordinate.getIdInSourceTable()));

        List result = getSQLResultFromSource(queryString);

        if (CollectionUtils.isEmpty(result)) {
            throw new WorkCoordinateNotFound("Coordinate is invalid. No data found at " + coordinate);
        }

        return result.get(0);
    } finally {
        sessionWrapper.closeSession();
    }
}

From source file:nl.surfnet.coin.teams.control.HomeController.java

@RequestMapping("/home.shtml")
public String start(ModelMap modelMap, HttpServletRequest request,
        @RequestParam(required = false, defaultValue = "my") String teams,
        @RequestParam(required = false) String teamSearch,
        @RequestParam(required = false) Long groupProviderId) {

    Person person = (Person) request.getSession().getAttribute(LoginInterceptor.PERSON_SESSION_KEY);
    String display = teams;//  w  w w  .j  a  v  a  2  s  .  co m
    String query = teamSearch;
    modelMap.addAttribute("groupProviderId", groupProviderId);

    if ("externalGroups".equals(display)) {
        modelMap.addAttribute("display", display);
    } else {
        addTeams(query, person.getId(), display, modelMap, request);
    }

    String email = getFirstEmail(person);
    if (StringUtils.hasText(email)) {
        List<Invitation> invitations = teamInviteService.findPendingInvitationsByEmail(email);
        modelMap.addAttribute("myinvitations", !CollectionUtils.isEmpty(invitations));
    }

    List<GroupProvider> allGroupProviders = processor.getAllGroupProviders();

    List<GroupProvider> groupProviders = processor.getGroupProvidersForUser(person.getId(), allGroupProviders);

    if (groupProviderId != null) {
        addExternalGroupsToModelMap(modelMap, getOffset(request), groupProviderId, person, allGroupProviders);
    }

    // Add the external group providers to the ModelMap for the navigation
    modelMap.addAttribute("groupProviders", groupProviders);

    modelMap.addAttribute("appversion", environment.getVersion());
    ViewUtil.addViewToModelMap(request, modelMap);

    return "home";
}

From source file:com.frank.search.solr.repository.query.SolrQueryMethod.java

/**
 * @return true if {@link com.frank.search.solr.repository.Query#fields()} is not empty
 *///  w  w w.jav  a  2  s. co  m
public boolean hasProjectionFields() {
    if (hasQueryAnnotation()) {
        return !CollectionUtils.isEmpty(getProjectionFields());
    }
    return false;
}

From source file:nc.noumea.mairie.organigramme.viewmodel.TreeViewModel.java

/**
 * Cre l'arbre et l'ajoute au {@link Vlayout} client
 * /*  w  w  w  .ja  v  a2s . c  o  m*/
 * @param entiteDtoRoot
 *            : l'ancien arbre
 */
public void creeArbre(EntiteDto entiteDtoRoot) {

    // On renseigne deux map<idTypeEntite, couleur> qui permettront de
    // setter chaque couleur de chaque EntiteDto de l'arbre
    Map<Long, String> mapIdTypeEntiteCouleurEntite = new HashMap<Long, String>();
    Map<Long, String> mapIdTypeEntiteCouleurTexte = new HashMap<Long, String>();
    List<CouleurTypeEntite> listeCouleurTypeEntite = organigrammeViewModel.couleurTypeEntiteService.findAll();
    for (CouleurTypeEntite couleurTypeEntite : listeCouleurTypeEntite) {
        mapIdTypeEntiteCouleurEntite.put(new Long(couleurTypeEntite.getIdTypeEntite()),
                couleurTypeEntite.getCouleurEntite());
        mapIdTypeEntiteCouleurTexte.put(new Long(couleurTypeEntite.getIdTypeEntite()),
                couleurTypeEntite.getCouleurTexte());
    }

    Vlayout vlayout = organigrammeViewModel.vlayout;
    Component arbre = genereArbre(organigrammeViewModel.entiteDtoRoot, mapIdTypeEntiteCouleurEntite,
            mapIdTypeEntiteCouleurTexte);
    if (!CollectionUtils.isEmpty(vlayout.getChildren())) {
        vlayout.removeChild(vlayout.getChildren().get(0));
    }
    if (arbre == null) {
        return;
    }
    vlayout.appendChild(arbre);
}

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

@Override
public List<Consulta> getConcimientosVinculadosByHistorial(HashMap filters) throws Exception {
    List<Consulta> lista = new ArrayList<Consulta>();
    try {/* ww w  . jav a2s. c o  m*/
        VinculoHistDao vinculoHistDao = (VinculoHistDao) ServiceFinder.findBean("VinculoHistDao");
        List<HashMap> consulta = vinculoHistDao.getConcimientosVinculadosByHistorial(filters);
        if (!CollectionUtils.isEmpty(consulta)) {
            for (HashMap map : consulta) {
                Consulta c = new Consulta();
                c.setId((BigDecimal) map.get("ID"));
                c.setIdconocimiento((BigDecimal) map.get("IDCONOCIMIENTO"));
                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();
    }
    return lista;
}

From source file:com.embedler.moon.graphql.boot.sample.test.GenericTodoSchemaParserTest.java

@Test
public void restViewerByIdTest() throws IOException {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON_UTF8);

    GraphQLServerRequest qlQuery = new GraphQLServerRequest("{viewer{ id }}");

    HttpEntity<GraphQLServerRequest> httpEntity = new HttpEntity<>(qlQuery, headers);
    ResponseEntity<GraphQLServerResult> responseEntity = restTemplate.exchange(
            "http://localhost:" + port + "/graphql", HttpMethod.POST, httpEntity, GraphQLServerResult.class);

    GraphQLServerResult result = responseEntity.getBody();
    Assert.assertTrue(CollectionUtils.isEmpty(result.getErrors()));
    Assert.assertFalse(CollectionUtils.isEmpty(result.getData()));
    LOGGER.info(objectMapper.writeValueAsString(result.getData()));
}

From source file:io.cloudslang.engine.queue.services.assigner.ExecutionAssignerServiceImpl.java

@Override
@Transactional/*ww w  .ja  v a  2s . c  o m*/
public List<ExecutionMessage> assignWorkers(List<ExecutionMessage> messages) {
    if (logger.isDebugEnabled())
        logger.debug("Assigner iteration started");
    if (CollectionUtils.isEmpty(messages)) {
        if (logger.isDebugEnabled())
            logger.debug("Assigner iteration finished");
        return messages;

    }
    List<ExecutionMessage> assignMessages = new ArrayList<>(messages.size());
    Multimap<String, String> groupWorkersMap = null;
    Random randIntGenerator = new Random(System.currentTimeMillis());

    for (ExecutionMessage msg : messages) {

        if (msg.getWorkerId().equals(ExecutionMessage.EMPTY_WORKER) && msg.getStatus() == ExecStatus.PENDING) {
            if (groupWorkersMap == null) {
                String engineVersionId = engineVersionService.getEngineVersionId();
                //We allow to assign to workers who's version is equal to the engine version
                groupWorkersMap = workerNodeService
                        .readGroupWorkersMapActiveAndRunningAndVersion(engineVersionId);
            }
            String workerId = chooseWorker(msg.getWorkerGroup(), groupWorkersMap, randIntGenerator);
            if (workerId == null) {
                // error on assigning worker, no available worker
                logger.warn("Can't assign worker for group name: " + msg.getWorkerGroup()
                        + " , because there are no available workers for that group.");

                //We need to extract the payload in case of FAILED
                fillPayload(msg);

                // send step finish event
                ExecutionMessage stepFinishMessage = (ExecutionMessage) msg.clone();
                stepFinishMessage.setStatus(ExecStatus.FINISHED);
                stepFinishMessage.incMsgSeqId();
                assignMessages.add(stepFinishMessage);

                // send step finish event
                ExecutionMessage flowFailedMessage = (ExecutionMessage) stepFinishMessage.clone();
                flowFailedMessage.setStatus(ExecStatus.FAILED);
                addErrorMessage(flowFailedMessage);
                flowFailedMessage.incMsgSeqId();
                assignMessages.add(flowFailedMessage);
            } else {
                // assign worker
                assignMessages.add(msg);
                msg.setStatus(ExecStatus.ASSIGNED);
                msg.incMsgSeqId();
                msg.setWorkerId(workerId);
            }
        } else {
            // msg that was already assigned or non pending status
            assignMessages.add(msg);
        }
    } // end for

    if (logger.isDebugEnabled())
        logger.debug("Assigner iteration finished");
    return assignMessages;
}

From source file:com.alibaba.otter.manager.biz.config.datacolumnpair.impl.DataColumnPairGroupServiceImpl.java

@Override
public Map<Long, List<ColumnGroup>> listByDataMediaPairIds(Long... dataMediaPairIds) {
    Assert.assertNotNull(dataMediaPairIds);
    Map<Long, List<ColumnGroup>> dataColumnGroups = new HashMap<Long, List<ColumnGroup>>();
    try {//from  w ww.ja  v a2  s .  c o  m
        List<DataColumnPairGroupDO> dataColumnPairGroupDos = dataColumnPairGroupDao
                .ListByDataMediaPairIds(dataMediaPairIds);
        if (CollectionUtils.isEmpty(dataColumnPairGroupDos)) {
            logger.debug(
                    "DEBUG ## couldn't query any dataColumnPairGroup, maybe hasn't create any dataColumnPairGroup.");
            return dataColumnGroups;
        }

        for (DataColumnPairGroupDO dataColumnPairGroupDo : dataColumnPairGroupDos) {
            List<ColumnGroup> columnGroups = dataColumnGroups.get(dataColumnPairGroupDo.getDataMediaPairId());
            if (columnGroups != null) {
                if (!columnGroups.contains(doToModel(dataColumnPairGroupDo))) {
                    columnGroups.add(doToModel(dataColumnPairGroupDo));
                }
            } else {
                columnGroups = new ArrayList<ColumnGroup>();
                columnGroups.add(doToModel(dataColumnPairGroupDo));
                dataColumnGroups.put(dataColumnPairGroupDo.getDataMediaPairId(), columnGroups);
            }
        }
    } catch (Exception e) {
        logger.error(
                "ERROR ## query dataColumnPairGroup by dataMediaId:" + dataMediaPairIds + " has an exception!");
        throw new ManagerException(e);
    }

    return dataColumnGroups;
}

From source file:edu.wisc.wisccal.caldav2Exchange.impl.caldav.datagenerator.ICal4jTestDataGenerator.java

public int getComponentCount(Calendar calendar) {
    int compCount = 0;
    ComponentList components = calendar.getComponents();
    if (!CollectionUtils.isEmpty(components)) {
        compCount = components.size();/*from w ww.jav a2 s .  co m*/
    }
    return compCount;
}

From source file:nc.noumea.mairie.appock.core.utility.MessageErreurUtil.java

/**
 * Mthode pratique, pour construire une liste de message d'erreur sur une liste d'entit
 * //  w  ww.  j a va  2s.co m
 * @param collectionEntity liste des entits concernes, si null, la mthode retourne une liste vide
 * @return une liste (jamais null) de messages d'erreur concernant la liste des entits
 */
public static List<MessageErreur> construitListeMessageErreurCollection(
        Collection<? extends AbstractEntity> collectionEntity) {
    List<MessageErreur> result = new ArrayList<MessageErreur>();
    if (CollectionUtils.isEmpty(collectionEntity)) {
        return result; // liste vide
    }
    for (AbstractEntity entity : collectionEntity) {
        if (entity == null) {
            continue;
        }
        result.addAll(entity.construitListeMessageErreur());
    }
    return result;
}