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:nl.surfnet.coin.eb.EngineBlockImpl.java

@Override
public String getUserUUID(String identifier) {
    Assert.hasText(identifier, "Not allowed to provide a null or empty identifier");
    String sql = "SELECT user_uuid FROM saml_persistent_id WHERE persistent_id =  ?";
    LOG.debug("Executing query with identifier {}: {}", identifier, sql);
    List<String> results = ebJdbcTemplate.query(sql, new String[] { identifier }, new RowMapper<String>() {
        @Override/* w w  w.  j  a v  a  2s.  c  o m*/
        public String mapRow(ResultSet rs, int rowNum) throws SQLException {
            return rs.getString(1);
        }
    });
    if (CollectionUtils.isEmpty(results)) {
        throw new RuntimeException("No persistent_id found for user_uuid(" + identifier + ")");
    }
    LOG.debug("Numer of results from query: {}", results.size());
    return results.get(0);
}

From source file:com.inspiresoftware.lib.dto.geda.interceptor.GeDAInterceptor.java

/** {@inheritDoc} */
public Object invoke(final MethodInvocation invocation) throws Throwable {

    final Method method = invocation.getMethod();
    final Class<?> targetClass = (invocation.getThis() != null ? invocation.getThis().getClass() : null);

    final Map<Occurrence, AdviceConfig> cfg = this.resolver.resolve(method, targetClass);
    if (CollectionUtils.isEmpty(cfg)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("skipping method {} because it is not advised", invocation.getMethod());
        }//from  w w w  .  j a va 2 s.com
        return invocation.proceed(); // unadvised
    }

    final Object[] args = invocation.getArguments();

    if (cfg.containsKey(Occurrence.BEFORE_METHOD_INVOCATION)) {
        final AdviceConfig configuration = cfg.get(Occurrence.BEFORE_METHOD_INVOCATION);
        if (LOG.isDebugEnabled()) {
            LOG.debug("performing transfer in mode {} before invocation of {} ",
                    configuration.getDtoSupportMode().name(), invocation.getMethod());
        }
        this.invokeTransferBefore(args, configuration);
    }

    final Object result = invocation.proceed();

    if (cfg.containsKey(Occurrence.AFTER_METHOD_INVOCATION)) {
        final AdviceConfig configuration = cfg.get(Occurrence.AFTER_METHOD_INVOCATION);
        if (LOG.isDebugEnabled()) {
            LOG.debug("performing transfer in mode {} after invocation of {}",
                    configuration.getDtoSupportMode().name(), invocation.getMethod());
        }
        return this.invokeTransferAfter(args, result, configuration);
    }

    return result;
}

From source file:com.streamreduce.core.service.OutboundStorageServiceImpl.java

@Override
public int sendRawMessage(JSONObject jsonObject, Connection connection) throws OutboundStorageException {
    if (MapUtils.isEmpty(jsonObject) || CollectionUtils.isEmpty(connection.getOutboundConfigurations())) {
        return 0;
    }/*from w ww  .  j  av  a2 s. co  m*/
    int numberOfMessagesRoutedOutbound = 0;
    for (OutboundConfiguration outboundConfiguration : connection.getOutboundConfigurations()) {
        if (outboundConfiguration.getDataTypes().contains(OutboundDataType.RAW)) {
            try {
                routePayloadOutbound(outboundConfiguration, jsonObject.toString(), OutboundDataType.RAW);
                numberOfMessagesRoutedOutbound++;
            } catch (Exception e) {
                logger.error("Unable to route message outbound", e);
            }
        }
    }
    return numberOfMessagesRoutedOutbound;
}

From source file:nl.surfnet.coin.teams.service.impl.TeamInviteServiceHibernateImpl.java

/**
 * {@inheritDoc}// w  ww  .j  ava2s  . com
 */
@Override
public Invitation findOpenInvitation(String email, Team team) {
    List<Invitation> invitations = findByCriteria(Restrictions.eq("email", email),
            Restrictions.eq("teamId", team.getId()), Restrictions.eq("accepted", false),
            Restrictions.eq("declined", false));
    return CollectionUtils.isEmpty(invitations) ? null : invitations.get(0);
}

From source file:nl.surfnet.coin.selfservice.provisioner.SAMLProvisioner.java

@Override
public UserDetails provisionUser(Assertion assertion) {

    CoinUser coinUser = new CoinUser();

    final String idpId = getAuthenticatingAuthority(assertion);

    List<InstitutionIdentityProvider> institutionIdentityProviders = csa.getInstitutionIdentityProviders(idpId);

    if (CollectionUtils.isEmpty(institutionIdentityProviders)) {
        //duhh, fail fast, big problems
        throw new IllegalArgumentException(
                "Csa#getInstitutionIdentityProviders('" + idpId + "') returned zero result");
    }/*from  w ww.  j  a  va2s  .  c o m*/
    if (institutionIdentityProviders.size() == 1) {
        //most common case
        InstitutionIdentityProvider idp = institutionIdentityProviders.get(0);
        coinUser.setIdp(idp);
        coinUser.addInstitutionIdp(idp);
    } else {
        coinUser.setIdp(getCurrentIdp(idpId, institutionIdentityProviders));
        coinUser.getInstitutionIdps().addAll(institutionIdentityProviders);
        Collections.sort(coinUser.getInstitutionIdps(), new Comparator<InstitutionIdentityProvider>() {
            @Override
            public int compare(final InstitutionIdentityProvider lh, final InstitutionIdentityProvider rh) {
                return lh.getName().compareTo(rh.getName());
            }
        });
    }

    coinUser.setUid(getValueFromAttributeStatements(assertion, uuidAttribute));
    coinUser.setDisplayName(getValueFromAttributeStatements(assertion, DISPLAY_NAME));
    coinUser.setEmail(getValueFromAttributeStatements(assertion, EMAIL));
    coinUser.setSchacHomeOrganization(getValueFromAttributeStatements(assertion, SCHAC_HOME));

    coinUser.setAttributeMap(PersonAttributeUtil.getAttributesAsMap(assertion));

    return coinUser;
}

From source file:org.sakuli.services.receiver.database.DatabaseResultServiceImpl.java

@Override
public void saveAllResults() {
    logger.info("try to save all results to the database");
    try {//from   w w  w.  j a  va2s  .co m
        daoTestSuite.saveTestSuiteResult();
        daoTestSuite.saveTestSuiteToSahiJobs();

        if (!CollectionUtils.isEmpty(testSuite.getTestCases())) {
            for (TestCase tc : testSuite.getTestCases().values()) {
                //write testcase and steps to DB
                daoTestCase.saveTestCaseResult(tc);

                logger.info("... try to save all STEPS for test case '" + tc.getId() + "'!");
                if (!CollectionUtils.isEmpty(tc.getSteps())) {
                    daoTestCaseStep.saveTestCaseSteps(tc.getSteps(), tc.getDbPrimaryKey());
                    logger.info("all STEPS for '" + tc.getId() + "' saved!");
                } else {
                    logger.info("no STEPS for '\" + tc.getId() +\"'found => no STEPS saved in DB!");
                }
            }
        }
    } catch (Throwable e) {
        exceptionHandler.handleException(new SakuliReceiverException(e,
                String.format("error by saving the results to the database [%s]", testSuite.toString())), true);
    }
}

From source file:org.swarmcom.jsynapse.service.room.RoomAliasServiceImpl.java

public RoomAlias.AliasServers findByAlias(String alias) {
    List<RoomAlias> roomAliases = roomAliasRepository.findByAlias(alias);
    String roomId = StringUtils.EMPTY;
    if (!CollectionUtils.isEmpty(roomAliases)) {
        roomId = roomAliases.get(0).getRoomId();
    }/*from   www . j ava2  s.  c o  m*/

    return new RoomAlias.AliasServers(roomId, roomAliases);
}

From source file:at.porscheinformatik.common.spring.web.extended.template.chunk.ChunkTemplateFactory.java

@PostConstruct
public void buildTheme() {
    theme = new Theme();

    if (expressionHandlers == null) {
        return;/*w  w w.  j  ava2 s .  c  o m*/
    }

    Collection<String> expressionHandlerNames = expressionHandlers.getHandlerNames();

    if (CollectionUtils.isEmpty(expressionHandlerNames)) {
        return;
    }

    for (String handlerName : expressionHandlerNames) {
        ExpressionHandler handler = expressionHandlers.getHandler(handlerName);

        theme.addProtocol(new ExpressionHandlerContentSource(handlerName, handler));
    }
}

From source file:ua.com.manometer.jasperreports.AbstractJasperReportsSingleFormatView.java

/**
 * Perform rendering for a single Jasper Reports exporter, that is,
 * for a pre-defined output format./* ww  w.  ja va2s.  com*/
 */
@Override
protected void renderReport(JasperPrint populatedReport, Map<String, Object> model,
        HttpServletResponse response) throws Exception {

    JRExporter exporter = createExporter();

    Map mergedExporterParameters = getConvertedExporterParameters();
    if (!CollectionUtils.isEmpty(mergedExporterParameters)) {
        exporter.setParameters(mergedExporterParameters);
    }

    if (useWriter()) {
        renderReportUsingWriter(exporter, populatedReport, response);
    } else {
        renderReportUsingOutputStream(exporter, populatedReport, response);
    }
}

From source file:com.devicehive.handler.notification.NotificationSubscribeRequestHandler.java

@Override
public Response handle(Request request) {
    NotificationSubscribeRequest body = (NotificationSubscribeRequest) request.getBody();
    validate(body);/*from   www  .j a  v  a2  s.c o  m*/

    Subscriber subscriber = new Subscriber(body.getSubscriptionId(), request.getReplyTo(),
            request.getCorrelationId());

    Set<Subscription> subscriptions = new HashSet<>();
    if (CollectionUtils.isEmpty(body.getNames())) {
        Subscription subscription = new Subscription(Action.NOTIFICATION_EVENT.name(), body.getDevice());
        subscriptions.add(subscription);
    } else {
        for (String name : body.getNames()) {
            Subscription subscription = new Subscription(Action.NOTIFICATION_EVENT.name(), body.getDevice(),
                    name);
            subscriptions.add(subscription);
        }
    }

    subscriptions.forEach(subscription -> eventBus.subscribe(subscriber, subscription));

    Collection<DeviceNotification> notifications = findNotifications(body.getDevice(), body.getNames(),
            body.getTimestamp());
    NotificationSubscribeResponse subscribeResponse = new NotificationSubscribeResponse(
            body.getSubscriptionId(), notifications);

    return Response.newBuilder().withBody(subscribeResponse).withLast(false)
            .withCorrelationId(request.getCorrelationId()).buildSuccess();
}