Search in sources :

Example 1 with CustomerImpl

use of org.broadleafcommerce.profile.core.domain.CustomerImpl in project BroadleafCommerce by BroadleafCommerce.

the class CustomerDaoImpl method readCustomersByIds.

@Override
public List<Customer> readCustomersByIds(List<Long> ids) {
    if (ids == null || ids.size() == 0) {
        return null;
    }
    if (ids.size() > 100) {
        LOG.warn("Not recommended to use the readCustomersByIds method for long lists of customerIds, since " + "Hibernate is required to transform the distinct results. The list of requested" + "customer ids was (" + ids.size() + ") in length.");
    }
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Customer> criteria = builder.createQuery(Customer.class);
    Root<CustomerImpl> customer = criteria.from(CustomerImpl.class);
    criteria.select(customer);
    // We only want results that match the customer IDs
    criteria.where(customer.get("id").as(Long.class).in(ids));
    TypedQuery<Customer> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Order");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerImpl(org.broadleafcommerce.profile.core.domain.CustomerImpl)

Example 2 with CustomerImpl

use of org.broadleafcommerce.profile.core.domain.CustomerImpl in project BroadleafCommerce by BroadleafCommerce.

the class CustomerDaoImpl method readBatchCustomers.

@Override
public List<Customer> readBatchCustomers(int start, int pageSize) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Customer> criteria = builder.createQuery(Customer.class);
    Root<CustomerImpl> customer = criteria.from(CustomerImpl.class);
    criteria.select(customer);
    TypedQuery<Customer> query = em.createQuery(criteria);
    query.setFirstResult(start);
    query.setMaxResults(pageSize);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Customer");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerImpl(org.broadleafcommerce.profile.core.domain.CustomerImpl)

Example 3 with CustomerImpl

use of org.broadleafcommerce.profile.core.domain.CustomerImpl in project BroadleafCommerce by BroadleafCommerce.

the class ResourcePurgeDaoImpl method buildCustomerQuery.

protected <T> TypedQuery<T> buildCustomerQuery(Date dateCreatedMinThreshold, Boolean registered, Boolean deactivated, Boolean isPreview, Class<T> returnType, List<Long> excludedIds) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<T> criteria = builder.createQuery(returnType);
    Root<CustomerImpl> root = criteria.from(CustomerImpl.class);
    if (Long.class.equals(returnType)) {
        criteria.select((Selection<? extends T>) builder.count(root));
    } else {
        criteria.select((Selection<? extends T>) root);
    }
    // find only customers that do not have any orders, otherwise a purge would fail because of referential integrity
    Subquery<Long> subquery = criteria.subquery(Long.class);
    Root orderRoot = subquery.from(OrderImpl.class);
    subquery.select(builder.count(orderRoot));
    subquery.where(builder.equal(orderRoot.get("customer"), root));
    List<Predicate> restrictions = new ArrayList<Predicate>();
    restrictions.add(builder.equal(subquery, 0L));
    if (registered != null) {
        if (registered) {
            restrictions.add(builder.isTrue(root.get("registered").as(Boolean.class)));
        } else {
            restrictions.add(builder.or(builder.isNull(root.get("registered")), builder.isFalse(root.get("registered").as(Boolean.class))));
        }
    }
    if (deactivated != null) {
        if (deactivated) {
            restrictions.add(builder.isTrue(root.get("deactivated").as(Boolean.class)));
        } else {
            restrictions.add(builder.or(builder.isNull(root.get("deactivated")), builder.isFalse(root.get("deactivated").as(Boolean.class))));
        }
    }
    if (dateCreatedMinThreshold != null) {
        restrictions.add(builder.lessThan(root.get("auditable").get("dateCreated").as(Date.class), dateCreatedMinThreshold));
    }
    if (isPreview != null) {
        if (isPreview) {
            restrictions.add(builder.isTrue(root.get("previewable").get("isPreview").as(Boolean.class)));
        } else {
            restrictions.add(builder.or(builder.isNull(root.get("previewable").get("isPreview")), builder.isFalse(root.get("previewable").get("isPreview").as(Boolean.class))));
        }
    }
    if (excludedIds != null && excludedIds.size() > 0) {
        applyLimitedInClause(excludedIds, builder, root, restrictions);
    }
    criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
    return em.createQuery(criteria);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Root(javax.persistence.criteria.Root) ArrayList(java.util.ArrayList) CustomerImpl(org.broadleafcommerce.profile.core.domain.CustomerImpl) Predicate(javax.persistence.criteria.Predicate)

Example 4 with CustomerImpl

use of org.broadleafcommerce.profile.core.domain.CustomerImpl in project BroadleafCommerce by BroadleafCommerce.

the class RegisterCustomerDataProvider method createCustomer.

@DataProvider(name = "setupCustomerControllerData")
public static Object[][] createCustomer() {
    Customer customer = new CustomerImpl();
    customer.setEmailAddress("testCase@test.com");
    customer.setFirstName("TestFirstName");
    customer.setLastName("TestLastName");
    customer.setUsername("TestCase");
    ChallengeQuestion question = new ChallengeQuestionImpl();
    question.setId(1L);
    customer.setChallengeQuestion(question);
    customer.setChallengeAnswer("Challenge CandidateItemOfferAnswer");
    RegisterCustomerForm registerCustomer = new RegisterCustomerForm();
    registerCustomer.setCustomer(customer);
    registerCustomer.setPassword("TestPassword");
    registerCustomer.setPasswordConfirm("TestPassword");
    return new Object[][] { new Object[] { registerCustomer } };
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) ChallengeQuestionImpl(org.broadleafcommerce.profile.core.domain.ChallengeQuestionImpl) RegisterCustomerForm(org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm) CustomerImpl(org.broadleafcommerce.profile.core.domain.CustomerImpl) ChallengeQuestion(org.broadleafcommerce.profile.core.domain.ChallengeQuestion) DataProvider(org.testng.annotations.DataProvider)

Example 5 with CustomerImpl

use of org.broadleafcommerce.profile.core.domain.CustomerImpl in project BroadleafCommerce by BroadleafCommerce.

the class CustomerDataProvider method createCustomers.

@DataProvider(name = "setupCustomers")
public static Object[][] createCustomers() {
    Customer customer1 = new CustomerImpl();
    customer1.setPassword("customer1Password");
    customer1.setUsername("customer1");
    Customer customer2 = new CustomerImpl();
    customer2.setPassword("customer2Password");
    customer2.setUsername("customer2");
    return new Object[][] { new Object[] { customer1 }, new Object[] { customer2 } };
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerImpl(org.broadleafcommerce.profile.core.domain.CustomerImpl) DataProvider(org.testng.annotations.DataProvider)

Aggregations

CustomerImpl (org.broadleafcommerce.profile.core.domain.CustomerImpl)7 Customer (org.broadleafcommerce.profile.core.domain.Customer)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)2 ISOCountryImpl (org.broadleafcommerce.common.i18n.domain.ISOCountryImpl)2 Money (org.broadleafcommerce.common.money.Money)2 Category (org.broadleafcommerce.core.catalog.domain.Category)2 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)2 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)2 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)2 Product (org.broadleafcommerce.core.catalog.domain.Product)2 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)2 Sku (org.broadleafcommerce.core.catalog.domain.Sku)2 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)2 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)2 PromotableOrderImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl)2 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)2 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)2 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)2 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)2