Example usage for org.springframework.util Assert notEmpty

List of usage examples for org.springframework.util Assert notEmpty

Introduction

In this page you can find the example usage for org.springframework.util Assert notEmpty.

Prototype

@Deprecated
public static void notEmpty(@Nullable Map<?, ?> map) 

Source Link

Document

Assert that a Map contains entries; that is, it must not be null and must contain at least one entry.

Usage

From source file:de.hybris.platform.acceleratorservices.dataimport.batch.FileOrderComparator.java

@Override
public void afterPropertiesSet() {
    Assert.notEmpty(prefixPriority);
}

From source file:de.hybris.platform.acceleratorservices.dataimport.batch.FileOrderComparator.java

/**
 * @param prefixPriority//from   w w  w .  j  a  v a 2  s .  c  om
 *           the prefixPriority to set
 */
public void setPrefixPriority(final Map<String, Integer> prefixPriority) {
    Assert.notEmpty(prefixPriority);
    this.prefixPriority = prefixPriority;
}

From source file:gov.guilin.service.impl.OrderServiceImpl.java

@Transactional(readOnly = true)
public Order build(Cart cart, Receiver receiver, PaymentMethod paymentMethod, ShippingMethod shippingMethod,
        CouponCode couponCode, boolean isInvoice, String invoiceTitle, boolean useBalance, String memo) {
    Assert.notNull(cart);/*  w  w w. j  av a2  s . c  o  m*/
    Assert.notNull(cart.getMember());
    Assert.notEmpty(cart.getCartItems());

    Order order = new Order();
    order.setShippingStatus(ShippingStatus.unshipped);
    order.setFee(new BigDecimal(0));
    order.setPromotionDiscount(cart.getDiscount());
    order.setCouponDiscount(new BigDecimal(0));
    order.setOffsetAmount(new BigDecimal(0));
    order.setPoint(cart.getEffectivePoint());
    order.setMemo(memo);
    order.setMember(cart.getMember());
    Supplier supplier = cart.getCartItems().iterator().next().getProduct().getSupplier();
    Assert.notNull(supplier);
    order.setSupplier(supplier);

    if (receiver != null) {
        order.setConsignee(receiver.getConsignee());
        order.setAreaName(receiver.getAreaName());
        order.setAddress(receiver.getAddress());
        order.setZipCode(receiver.getZipCode());
        order.setPhone(receiver.getPhone());
        order.setArea(receiver.getArea());
    }

    if (!cart.getPromotions().isEmpty()) {
        StringBuffer promotionName = new StringBuffer();
        for (Promotion promotion : cart.getPromotions()) {
            if (promotion != null && promotion.getName() != null) {
                promotionName.append(" " + promotion.getName());
            }
        }
        if (promotionName.length() > 0) {
            promotionName.deleteCharAt(0);
        }
        order.setPromotion(promotionName.toString());
    }

    order.setPaymentMethod(paymentMethod);

    if (shippingMethod != null && paymentMethod != null
            && paymentMethod.getShippingMethods().contains(shippingMethod)) {
        BigDecimal freight = shippingMethod.calculateFreight(cart.getWeight());
        for (Promotion promotion : cart.getPromotions()) {
            if (promotion.getIsFreeShipping()) {
                freight = new BigDecimal(0);
                break;
            }
        }
        order.setFreight(freight);
        order.setShippingMethod(shippingMethod);
    } else {
        order.setFreight(new BigDecimal(0));
    }

    if (couponCode != null && cart.isCouponAllowed()) {
        couponCodeDao.lock(couponCode, LockModeType.PESSIMISTIC_WRITE);
        if (!couponCode.getIsUsed() && couponCode.getCoupon() != null && cart.isValid(couponCode.getCoupon())) {
            BigDecimal couponDiscount = cart.getEffectivePrice().subtract(
                    couponCode.getCoupon().calculatePrice(cart.getQuantity(), cart.getEffectivePrice()));
            couponDiscount = couponDiscount.compareTo(new BigDecimal(0)) > 0 ? couponDiscount
                    : new BigDecimal(0);
            order.setCouponDiscount(couponDiscount);
            order.setCouponCode(couponCode);
        }
    }

    List<OrderItem> orderItems = order.getOrderItems();
    for (CartItem cartItem : cart.getCartItems()) {
        if (cartItem != null && cartItem.getProduct() != null) {
            Product product = cartItem.getProduct();
            OrderItem orderItem = new OrderItem();
            orderItem.setSn(product.getSn());
            orderItem.setName(product.getName());
            orderItem.setFullName(product.getFullName());
            orderItem.setPrice(cartItem.getPrice());
            orderItem.setWeight(product.getWeight());
            orderItem.setThumbnail(product.getThumbnail());
            orderItem.setIsGift(false);
            orderItem.setQuantity(cartItem.getQuantity());
            orderItem.setShippedQuantity(0);
            orderItem.setReturnQuantity(0);
            orderItem.setProduct(product);
            orderItem.setOrder(order);
            orderItems.add(orderItem);
        }
    }

    for (GiftItem giftItem : cart.getGiftItems()) {
        if (giftItem != null && giftItem.getGift() != null) {
            Product gift = giftItem.getGift();
            OrderItem orderItem = new OrderItem();
            orderItem.setSn(gift.getSn());
            orderItem.setName(gift.getName());
            orderItem.setFullName(gift.getFullName());
            orderItem.setPrice(new BigDecimal(0));
            orderItem.setWeight(gift.getWeight());
            orderItem.setThumbnail(gift.getThumbnail());
            orderItem.setIsGift(true);
            orderItem.setQuantity(giftItem.getQuantity());
            orderItem.setShippedQuantity(0);
            orderItem.setReturnQuantity(0);
            orderItem.setProduct(gift);
            orderItem.setOrder(order);
            orderItems.add(orderItem);
        }
    }

    Setting setting = SettingUtils.get();
    if (setting.getIsInvoiceEnabled() && isInvoice && StringUtils.isNotEmpty(invoiceTitle)) {
        order.setIsInvoice(true);
        order.setInvoiceTitle(invoiceTitle);
        order.setTax(order.calculateTax());
    } else {
        order.setIsInvoice(false);
        order.setTax(new BigDecimal(0));
    }

    if (useBalance) {
        Member member = cart.getMember();
        if (member.getBalance().compareTo(order.getAmount()) >= 0) {
            order.setAmountPaid(order.getAmount());
        } else {
            order.setAmountPaid(member.getBalance());
        }
    } else {
        order.setAmountPaid(new BigDecimal(0));
    }

    if (order.getAmountPayable().compareTo(new BigDecimal(0)) == 0) {
        order.setOrderStatus(OrderStatus.confirmed);
        order.setPaymentStatus(PaymentStatus.paid);
    } else if (order.getAmountPayable().compareTo(new BigDecimal(0)) > 0
            && order.getAmountPaid().compareTo(new BigDecimal(0)) > 0) {
        order.setOrderStatus(OrderStatus.confirmed);
        order.setPaymentStatus(PaymentStatus.partialPayment);
    } else {
        order.setOrderStatus(OrderStatus.unconfirmed);
        order.setPaymentStatus(PaymentStatus.unpaid);
    }

    if (paymentMethod != null && paymentMethod.getTimeout() != null
            && order.getPaymentStatus() == PaymentStatus.unpaid) {
        order.setExpire(DateUtils.addMinutes(new Date(), paymentMethod.getTimeout()));
    }

    return order;
}

From source file:net.shopxx.service.impl.SmsServiceImpl.java

private void send(String[] mobiles, String content, Date sendTime) {
    Assert.notEmpty(mobiles);
    Assert.hasText(content);/*w w  w  .  j  a v  a 2 s .  c om*/

    Setting setting = SystemUtils.getSetting();
    String smsSn = setting.getSmsSn();
    String smsKey = setting.getSmsKey();
    if (StringUtils.isEmpty(smsSn) || StringUtils.isEmpty(smsKey)) {
        return;
    }
    try {
        Client client = new Client(smsSn, smsKey);
        if (sendTime != null) {
            client.sendScheduledSMS(mobiles, content, DateFormatUtils.format(sendTime, "yyyyMMddhhmmss"));
        } else {
            client.sendSMS(mobiles, content, 5);
        }
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:net.shopxx.service.impl.SmsServiceImpl.java

public void send(String[] mobiles, String content, Date sendTime, boolean async) {
    Assert.notEmpty(mobiles);
    Assert.hasText(content);/*  w ww . ja  va 2s.c  o m*/

    if (async) {
        addSendTask(mobiles, content, sendTime);
    } else {
        send(mobiles, content, sendTime);
    }
}

From source file:net.shopxx.service.impl.SmsServiceImpl.java

public void send(String[] mobiles, String templatePath, Map<String, Object> model, Date sendTime,
        boolean async) {
    Assert.notEmpty(mobiles);
    Assert.hasText(templatePath);//from  w w w  .j a v  a  2s .com

    try {
        Configuration configuration = freeMarkerConfigurer.getConfiguration();
        Template template = configuration.getTemplate(templatePath);
        String content = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
        send(mobiles, content, sendTime, async);
    } catch (TemplateException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:ome.security.basic.BasicSecuritySystem.java

/**
 * //w ww  . j a  v a2s .c o  m
 * It would be better to catch the
 * {@link SecureAction#updateObject(IObject)} method in a try/finally block,
 * but since flush can be so poorly controlled that's not possible. instead,
 * we use the one time token which is removed this Object is checked for
 * {@link #hasPrivilegedToken(IObject) privileges}.
 * 
 * @param obj
 *            A managed (non-detached) entity. Not null.
 * @param action
 *            A code-block that will be given the entity argument with a
 *            {@link #hasPrivilegedToken(IObject)} privileged token}.
 */
public <T extends IObject> T doAction(SecureAction action, T... objs) {
    Assert.notNull(objs);
    Assert.notEmpty(objs);
    Assert.notNull(action);

    final LocalQuery query = (LocalQuery) sf.getQueryService();
    final List<GraphHolder> ghs = new ArrayList<GraphHolder>();

    for (T obj : objs) {

        // TODO inject
        if (obj.getId() != null && !query.contains(obj)) {
            throw new SecurityViolation(
                    "Services are not allowed to call " + "doAction() on non-Session-managed entities.");
        }

        // ticket:1794 - use of IQuery.get along with doAction() creates
        // two objects (outer proxy and inner target) and only the outer
        // proxy has its graph holder modified without this block, leading
        // to security violations on flush since no token is present.
        if (obj instanceof HibernateProxy) {
            HibernateProxy hp = (HibernateProxy) obj;
            IObject obj2 = (IObject) hp.getHibernateLazyInitializer().getImplementation();
            ghs.add(obj2.getGraphHolder());
        }

        // FIXME
        // Token oneTimeToken = new Token();
        // oneTimeTokens.put(oneTimeToken);
        ghs.add(obj.getGraphHolder());

    }

    // Holding onto the graph holders since they protect the access
    // to their tokens
    for (GraphHolder graphHolder : ghs) {
        tokenHolder.setToken(graphHolder); // oneTimeToken
    }

    T retVal;
    try {
        retVal = action.updateObject(objs);
    } finally {
        for (GraphHolder graphHolder : ghs) {
            tokenHolder.clearToken(graphHolder);
        }
    }
    return retVal;
}

From source file:org.alfresco.bm.dataload.rm.records.ScheduleInPlaceRecordLoaders.java

@Override
public void afterPropertiesSet() throws Exception {
    Assert.notNull(maxActiveLoaders);/*from   ww w.j a  v  a2 s  .c o  m*/
    Assert.notNull(collabSiteId);
    Assert.notEmpty(collabSitePaths);
    Assert.notNull(username);
    Assert.notNull(password);
    Assert.notNull(getEventNameDeclareInPlaceRecord());
    Assert.notNull(getEventNameComplete());
    Assert.notNull(getEventNameRescheduleSelf());
    Assert.notNull(recordDeclarationLimit);
}

From source file:org.eclipse.gemini.blueprint.config.internal.adapter.CustomListenerAdapterUtils.java

/**
 * Specialised reflection utility that determines all methods that accept two parameters such:
 * /* w w w .java 2s.  c o m*/
 * <pre> methodName(Type serviceType, Type1 arg)
 * 
 * methodName(Type serviceType, Type2 arg)
 * 
 * methodName(AnotherType serviceType, Type1 arg)
 * 
 * methodName(Type serviceType) </pre>
 * 
 * It will return a map which has the serviceType (first argument) as type and contains as list the variants of
 * methods using the second argument. This method is normally used by listeners when determining custom methods.
 * 
 * @param target
 * @param methodName
 * @param possibleArgumentTypes
 * @param modifier
 * @return
 */
static Map<Class<?>, List<Method>> determineCustomMethods(final Class<?> target, final String methodName,
        final Class<?>[] possibleArgumentTypes, final boolean onlyPublic) {

    if (!StringUtils.hasText(methodName)) {
        return Collections.emptyMap();
    }

    Assert.notEmpty(possibleArgumentTypes);

    if (System.getSecurityManager() != null) {
        return AccessController.doPrivileged(new PrivilegedAction<Map<Class<?>, List<Method>>>() {
            public Map<Class<?>, List<Method>> run() {
                return doDetermineCustomMethods(target, methodName, possibleArgumentTypes, onlyPublic);
            }
        });
    } else {
        return doDetermineCustomMethods(target, methodName, possibleArgumentTypes, onlyPublic);
    }
}

From source file:org.lexevs.dao.database.operation.root.DefaultRootBuilder.java

private String getAssociationPredicateName(List<String> associations) {
    Assert.notEmpty(associations);

    if (associations.size() > 1) {
        return MULTI_ASSN_ROOT_PREDICATE_NAME;
    } else {/*from   www  .  j  a  va2 s  .  c om*/
        return associations.get(0);
    }
}