List of usage examples for org.apache.commons.collections4 CollectionUtils isEmpty
public static boolean isEmpty(final Collection<?> coll)
From source file:org.blocks4j.reconf.client.setup.Environment.java
private static void validate(PropertiesConfiguration configuration) { if (configuration == null) { throw new ReConfInitializationError(msg.get("error.internal")); }/* ww w . j a v a 2 s . c o m*/ Set<String> violations = PropertiesConfigurationValidator.validate(configuration); if (CollectionUtils.isEmpty(violations)) { return; } List<String> errors = new ArrayList<String>(); int i = 1; for (String violation : violations) { errors.add(i++ + " - " + violation); } if (configuration.isDebug()) { LoggerHolder.getLog().error(msg.format("error.config", LineSeparator.value(), StringUtils.join(errors, LineSeparator.value()))); } else { throw new ReConfInitializationError(msg.format("error.config", LineSeparator.value(), StringUtils.join(errors, LineSeparator.value()))); } }
From source file:org.broadleafcommerce.openadmin.server.security.service.AdminSecurityServiceImpl.java
@Override @Transactional("blTransactionManager") public GenericResponse sendForgotUsernameNotification(String emailAddress) { GenericResponse response = new GenericResponse(); List<AdminUser> users = null; if (emailAddress != null) { users = adminUserDao.readAdminUserByEmail(emailAddress); }// ww w. ja v a 2 s . c om if (CollectionUtils.isEmpty(users)) { response.addErrorCode("notFound"); } else { List<String> activeUsernames = new ArrayList<String>(); for (AdminUser user : users) { if (user.getActiveStatusFlag()) { activeUsernames.add(user.getLogin()); } } if (activeUsernames.size() > 0) { HashMap<String, Object> vars = new HashMap<String, Object>(); vars.put("accountNames", activeUsernames); emailService.sendTemplateEmail(emailAddress, getSendUsernameEmailInfo(), vars); } else { // send inactive username found email. response.addErrorCode("inactiveUser"); } } return response; }
From source file:org.broadleafcommerce.profile.core.dao.CustomerDaoImpl.java
@Override public Customer readCustomerByUsername(String username, Boolean cacheable) { List<Customer> customers = readCustomersByUsername(username, cacheable); return CollectionUtils.isEmpty(customers) ? null : customers.get(0); }
From source file:org.broadleafcommerce.profile.core.dao.CustomerDaoImpl.java
@Override public Customer readCustomerByEmail(String emailAddress) { List<Customer> customers = readCustomersByEmail(emailAddress); return CollectionUtils.isEmpty(customers) ? null : customers.get(0); }
From source file:org.broadleafcommerce.profile.core.service.CustomerServiceImpl.java
@Override @Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER) public GenericResponse sendForgotUsernameNotification(String emailAddress) { GenericResponse response = new GenericResponse(); List<Customer> customers = null; if (emailAddress != null) { customers = customerDao.readCustomersByEmail(emailAddress); }/*from w w w . java 2 s. c o m*/ if (CollectionUtils.isEmpty(customers)) { response.addErrorCode("notFound"); } else { List<String> activeUsernames = new ArrayList<String>(); for (Customer customer : customers) { if (!customer.isDeactivated()) { activeUsernames.add(customer.getUsername()); } } if (activeUsernames.size() > 0) { HashMap<String, Object> vars = new HashMap<String, Object>(); vars.put("userNames", activeUsernames); emailService.sendTemplateEmail(emailAddress, getForgotUsernameEmailInfo(), vars); } else { // send inactive username found email. response.addErrorCode("inactiveUser"); } } return response; }
From source file:org.cleverbus.api.asynch.AsynchRouteBuilder.java
/** * Builds new route definition for processing incoming asynchronous messages. * * @param route current route builder/*from ww w. j a v a 2s . c o m*/ * @return route definition */ public final RouteDefinition build(RouteBuilder route) { Assert.notNull(route, "the route must not be null"); // check guaranteed order - funnel value must be filled if (guaranteedOrder && CollectionUtils.isEmpty(funnelValues)) { throw new IllegalStateException("There is no funnel value for guaranteed order."); } String finalRouteId = routeId; if (finalRouteId == null) { finalRouteId = AbstractBasicRoute.getInRouteId(serviceType, operation); } RouteDefinition routeDefinition = route.from(inUri).routeId(finalRouteId); if (validators != null) { for (Processor validator : validators) { routeDefinition.process(validator); } } if (policyRef != null) { routeDefinition.policy(policyRef); } if (objectIdExpr != null) { routeDefinition.setHeader(AsynchConstants.OBJECT_ID_HEADER, objectIdExpr); } if (!CollectionUtils.isEmpty(funnelValues)) { routeDefinition.setHeader(AsynchConstants.FUNNEL_VALUES_HEADER, new MultiValueExpression(funnelValues, false)); } if (guaranteedOrder) { routeDefinition.setHeader(AsynchConstants.GUARANTEED_ORDER_HEADER, constant(true)); } if (excludeFailedState) { routeDefinition.setHeader(AsynchConstants.EXCLUDE_FAILED_HEADER, constant(true)); } // header values routeDefinition.setHeader(AsynchConstants.SERVICE_HEADER, route.constant(serviceType)); routeDefinition.setHeader(AsynchConstants.OPERATION_HEADER, route.constant(operation)); // route the request to asynchronous processing routeDefinition.to(AsynchConstants.URI_ASYNCH_IN_MSG); // create response if (responseProcessor != null) { routeDefinition.process(responseProcessor); } else { // use default response, general for all asynch. requests routeDefinition.process(new AsynchResponseProcessor() { @Override protected Object setCallbackResponse(CallbackResponse callbackResponse) { AsynchResponse asynchResponse = new AsynchResponse(); asynchResponse.setConfirmAsynchRequest(callbackResponse); return asynchResponse; } }); } // response -> XML if (responseMarshalling != null) { routeDefinition.marshal(responseMarshalling); } else { routeDefinition.marshal(jaxb(AsynchResponse.class)); } return routeDefinition; }
From source file:org.cleverbus.component.funnel.MsgFunnelProducer.java
@Override public void process(Exchange exchange) throws Exception { Message msg = exchange.getIn().getHeader(AsynchConstants.MSG_HEADER, Message.class); Assert.notNull(msg, "message must be defined, msg-funnel component is for asynchronous messages only"); MsgFunnelEndpoint endpoint = (MsgFunnelEndpoint) getEndpoint(); Collection<String> funnelValues = getFunnelValues(msg, endpoint); if (CollectionUtils.isEmpty(funnelValues)) { Log.debug("Message " + msg.toHumanString() + " doesn't have funnel value => won't be filtered"); } else {/* w w w .j a va 2 s . c om*/ // set ID to message String funnelCompId = getFunnelCompId(msg, exchange, endpoint); //is equal funnel values on endpoint and on message boolean equalFunnelValues = CollectionUtils.isEqualCollection(funnelValues, msg.getFunnelValues()); //set funnel value if not equals and funnel id if (!equalFunnelValues || !funnelCompId.equals(msg.getFunnelComponentId())) { //add funnel value into message if is not equal and save it if (!equalFunnelValues) { endpoint.getMessageService().setFunnelComponentIdAndValue(msg, funnelCompId, funnelValues); } else { //funnel component id is not same, than we save it endpoint.getMessageService().setFunnelComponentId(msg, funnelCompId); } } if (endpoint.isGuaranteedOrder()) { // By default classic funnel works with running messages (PROCESSING, WAITING, WAITING_FOR_RES) only // and if it's necessary to guarantee processing order then also PARTLY_FAILED, POSTPONED [and FAILED] // messages should be involved List<Message> messages = endpoint.getMessageService().getMessagesForGuaranteedOrderForFunnel( funnelValues, endpoint.getIdleInterval(), endpoint.isExcludeFailedState(), funnelCompId); if (messages.size() == 1) { Log.debug("There is only one processing message with funnel values: " + funnelValues + " => no filtering"); // is specified message first one for processing? } else if (messages.get(0).equals(msg)) { Log.debug("Processing message (msg_id = {}, funnel values = '{}') is the first one" + " => no filtering", msg.getMsgId(), funnelValues); } else { Log.debug( "There is at least one processing message with funnel values '{}'" + " before current message (msg_id = {}); message {} will be postponed.", funnelValues, msg.getMsgId(), msg.toHumanString()); postponeMessage(exchange, msg, endpoint); } } else { // is there processing message with same funnel value? int count = endpoint.getMessageService().getCountProcessingMessagesForFunnel(funnelValues, endpoint.getIdleInterval(), funnelCompId); if (count > 1) { // note: one processing message is this message Log.debug("There are more processing messages with funnel values '" + funnelValues + "', message " + msg.toHumanString() + " will be postponed."); postponeMessage(exchange, msg, endpoint); } else { Log.debug("There is only one processing message with funnel values: " + funnelValues + " => no filtering"); } } } }
From source file:org.cleverbus.core.common.asynch.msg.MessageTransformer.java
/** * Creates message entity.//from ww w . j a va2s.c o m * * @param exchange the exchange * @param traceHeader the trace header * @param payload the message payload * @param service the source service * @param operationName the source operation name * @param objectId the object ID * @param entityType the entity type * @param funnelValue the funnel value * @return new message */ @Handler public Message createMessage(Exchange exchange, @Header(value = TraceHeaderProcessor.TRACE_HEADER) TraceHeader traceHeader, @Body String payload, @Header(value = AsynchConstants.SERVICE_HEADER) ServiceExtEnum service, @Header(value = AsynchConstants.OPERATION_HEADER) String operationName, @Header(value = AsynchConstants.OBJECT_ID_HEADER) @Nullable String objectId, @Header(value = AsynchConstants.ENTITY_TYPE_HEADER) @Nullable EntityTypeExtEnum entityType, @Header(value = AsynchConstants.FUNNEL_VALUE_HEADER) @Nullable String funnelValue, @Header(value = AsynchConstants.FUNNEL_VALUES_HEADER) @Nullable List<String> funnelValues, @Header(value = AsynchConstants.GUARANTEED_ORDER_HEADER) @Nullable Boolean guaranteedOrder, @Header(value = AsynchConstants.EXCLUDE_FAILED_HEADER) @Nullable Boolean excludeFailedState) { // validate input params (trace header is validated in TraceHeaderProcessor) Assert.notNull(exchange, "the exchange must not be null"); Assert.notNull(traceHeader, "the traceHeader must not be null"); Assert.notNull(payload, "the payload must not be null"); Assert.notNull(service, "the service must not be null"); Assert.notNull(operationName, "the operationName must not be null"); Date currDate = new Date(); Message msg = new Message(); msg.setState(MsgStateEnum.PROCESSING); msg.setStartProcessTimestamp(currDate); // params from trace header final TraceIdentifier traceId = traceHeader.getTraceIdentifier(); msg.setMsgTimestamp(traceId.getTimestamp().toDate()); msg.setReceiveTimestamp(currDate); msg.setSourceSystem(new ExternalSystemExtEnum() { @Override public String getSystemName() { return StringUtils.upperCase(traceId.getApplicationID()); } }); msg.setCorrelationId(traceId.getCorrelationID()); msg.setProcessId(traceId.getProcessID()); msg.setService(service); msg.setOperationName(operationName); msg.setObjectId(objectId); msg.setEntityType(entityType); //setting funnel value information List<String> funnels = new ArrayList<String>(); if (!StringUtils.isBlank(funnelValue)) { funnels.add(funnelValue); } //settings funnel values if (!CollectionUtils.isEmpty(funnelValues)) { for (String fnlValue : funnelValues) { if (!StringUtils.isBlank(fnlValue)) { funnels.add(fnlValue); } } } if (!funnels.isEmpty()) { msg.setFunnelValues(funnels); } msg.setGuaranteedOrder(BooleanUtils.isTrue(guaranteedOrder)); msg.setExcludeFailedState(BooleanUtils.isTrue(excludeFailedState)); msg.setPayload(payload); msg.setEnvelope(getSOAPEnvelope(exchange)); msg.setLastUpdateTimestamp(currDate); return msg; }
From source file:org.codice.alliance.transformer.nitf.NitfAttributeConverters.java
/** * Gets the alpha3 country code for a fips country code by delegating to the {@link * CountryCodeConverter} service.//from w w w . ja va 2 s . c o m * * @param fipsCode FIPS 10-4 country code to convert * @return a ISO 3166 Alpha3 country code * @throws NitfAttributeTransformException when the fipsCode maps to multiple ISO 3166-1 Alpha3 * values */ @Nullable public static String fipsToStandardCountryCode(@Nullable String fipsCode) throws NitfAttributeTransformException { List<String> countryCodes = countryCodeConverter.convertFipsToIso3(fipsCode); if (countryCodes.size() > 1) { throw new NitfAttributeTransformException( String.format("Found %s while converting %s, but expected only 1 conversion value.", countryCodes, fipsCode), fipsCode); } if (CollectionUtils.isEmpty(countryCodes)) { return null; } return countryCodes.get(0); }
From source file:org.codice.ddf.catalog.ui.forms.filter.TransformVisitor.java
@Override public void visitLiteralType(VisitableElement<List<Serializable>> visitable) { super.visitLiteralType(visitable); List<Serializable> values = visitable.getValue(); if (CollectionUtils.isEmpty(values)) { LOGGER.debug("No values found on literal type"); return;//from ww w. j av a 2 s. c o m } // Assumption: we only support one literal value builder.setValue(values.get(0).toString()); }