All Projects → avrilfanomar → flexiblesearchbuilder

avrilfanomar / flexiblesearchbuilder

Licence: other
Flexible search query builder is SAP Hybris Commerce extension (released as a library) that provides developer-friendly way to build flexible search queries. The aim of this extension is to write().flexibleSearchQueries().easily() in compile-time safe manner without a need to remember the syntax.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to flexiblesearchbuilder

core-next
core-next microservice framework
Stars: ✭ 14 (-6.67%)
Mutual labels:  hybris, hybris-commerce-suite
ccv2-project-template
Opinionated starter template for any CCv2 project
Stars: ✭ 30 (+100%)
Mutual labels:  commerce-cloud, sap-commerce
ydocker
[unofficial PoC] get, build, initialize and run SAP Hybris Commerce Suite inside Docker container
Stars: ✭ 28 (+86.67%)
Mutual labels:  hybris, sap-hybris
sfcc-cli
Command Line Interface for Salesforce Commerce Cloud Sandbox Development
Stars: ✭ 18 (+20%)
Mutual labels:  commerce-cloud
yaas-getting-started-yaasbites
YaaS bites (our getting started series) is a tutorial and sample code set consisting of small, incremental coding exercises to help a developer learn the basics of the YaaS platform. Its goal is to ensure that a Software Developer's initial journies into YaaS are productive and successful.
Stars: ✭ 14 (-6.67%)
Mutual labels:  hybris
securitybuilder
Fluent builders with typesafe API for the JCA
Stars: ✭ 42 (+180%)
Mutual labels:  builder-pattern
java-builder-pattern-tricks
Tricks to use with the java builder pattern
Stars: ✭ 39 (+160%)
Mutual labels:  builder-pattern
rvw developers core
SFCC Developers Core Cartridge. A Salesforce Commerce Cloud (Demandware) Cartridge for Developers.
Stars: ✭ 43 (+186.67%)
Mutual labels:  commerce-cloud
csharp-design-patterns-for-humans-examples
Complete C# Examples Refereed in csharp-design-patterns-for-humans
Stars: ✭ 50 (+233.33%)
Mutual labels:  builder-pattern
Flapi
Flapi is an API generator for Java, which generates 'smart' interfaces for improved fluency in your code.
Stars: ✭ 56 (+273.33%)
Mutual labels:  builder-pattern
design-patterns-php
All Design Patterns Samples in PHP
Stars: ✭ 43 (+186.67%)
Mutual labels:  builder-pattern
cutie-shell
A mobile QtWayland compositor and shell and for smartphones and tablets.
Stars: ✭ 21 (+40%)
Mutual labels:  hybris
BalloonPopup
Forget Android Toast! BalloonPopup displays a round or squared popup and attaches it to a View, like a callout. Uses the Builder pattern for maximum ease. The popup can automatically hide and can persist when the value is updated.
Stars: ✭ 32 (+113.33%)
Mutual labels:  builder-pattern
hybris
hybris gist by winston
Stars: ✭ 65 (+333.33%)
Mutual labels:  hybris
Java-design-patterns
Java Design patterns.
Stars: ✭ 49 (+226.67%)
Mutual labels:  builder-pattern
adyen-hybris
Adyen Payment plugin for Hybris
Stars: ✭ 23 (+53.33%)
Mutual labels:  hybris
manager
The builder (Manager) pattern implementation used by AdonisJs
Stars: ✭ 14 (-6.67%)
Mutual labels:  builder-pattern
SwiftBuilder
SwiftBuilder is a fast way to assign new value to the property of the object.
Stars: ✭ 26 (+73.33%)
Mutual labels:  builder-pattern
csharp-design-patterns-for-humans
Design Patterns for Humans™ - An ultra-simplified explanation - C# Examples
Stars: ✭ 1,086 (+7140%)
Mutual labels:  builder-pattern
annotation-processor-sample
An annotation processor which implements "Builder pattern" for your java classes.
Stars: ✭ 22 (+46.67%)
Mutual labels:  builder-pattern

Flexible search query builder

Flexible search query builder is SAP Hybris Commerce extension (released as a library) that provides developer-friendly way to build flexible search queries. The aim of this extension is to write().flexibleSearchQueries().easily() with the help of IDE in a compile-time safe manner.

Installation

It is released as a Java library. You can find jars at https://bitbucket.org/andriichukandrii/flexiblesearchbuilder/downloads/ It is now also possible to use following Maven dependency:

<dependency>
    <groupId>org.bitbucket.andriichukandrii</groupId>
    <artifactId>flexiblesearchbuilder</artifactId>
    <version>3.2.2</version>
</dependency>

For development purposes it can be added as an extension either to localextensions.xml or to other extension dependencies.

Usage

All the elements of the builder chain are immutable (unless you pass a mutable parameter and then modify it), thus they can be safely reused among different queries.

Here are some examples of using the flexible search query builder (executable in groovy scripting console)

import static de.hybris.platform.core.model.order.AbstractOrderEntryModel.ORDER;
import static de.hybris.platform.core.model.order.AbstractOrderEntryModel.PRODUCT;
import static de.hybris.platform.core.model.order.AbstractOrderModel.USER;

import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.Conditions.braces;
import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.Conditions.condition;
import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.FlexibleSearchQueryBuilder.select;
import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.FlexibleSearchQueryBuilder.selectFrom;
import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.FromClauseElements.table;
import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.ParameterlessConditionType.IS_NOT_NULL;
import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.ParameterlessConditionType.IS_NULL;
import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.TwoParameterConditionType.BETWEEN;
import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.RegularParameterConditionType.IS_EQUAL_TO;
import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.RegularParameterConditionType.IS_GREATER_THAN;
import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.RegularParameterConditionType.LIKE;
import static org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.SqlFunctions.count;

import de.hybris.platform.catalog.model.CatalogUnawareMediaModel;
import de.hybris.platform.catalog.model.ProductReferenceModel;
import de.hybris.platform.category.constants.CategoryConstants;
import de.hybris.platform.category.model.CategoryModel;
import de.hybris.platform.core.model.order.OrderEntryModel;
import de.hybris.platform.core.model.order.OrderModel;
import de.hybris.platform.core.model.product.ProductModel;
import de.hybris.platform.core.model.user.UserModel;
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
import de.hybris.platform.variants.model.VariantProductModel;

import org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.AbstractFieldCondition;
import org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.Alias;
import org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.FieldWithType;
import org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.FunctionWithType;
import org.bitbucket.andriichukandrii.hybris.flexiblesearchbuilder.JoinOnElement;


final FlexibleSearchQuery query1 = 
    selectFrom(CatalogUnawareMediaModel.class)
    .where(
        condition(CatalogUnawareMediaModel.CODE, IS_EQUAL_TO, "someLogoCode"))
    .build();

final AbstractFieldCondition nameAndDescriptionNonNull = 
    condition(ProductModel.NAME, IS_NOT_NULL)
    .and()
    .condition(ProductModel.DESCRIPTION, IS_NOT_NULL);

final FlexibleSearchQuery query2 =
    selectFrom(ProductModel.class)
    .where(
        condition(ProductModel.CODE, LIKE, "p%")
        .and()
        .condition(nameAndDescriptionNonNull)
    )
    .orderByAsc(ProductModel.NAME)
    .build();

final Alias p = new Alias("p");
final Alias v = new Alias("v");
final FlexibleSearchQuery query3 =
    select(p)
    .from(
        table(ProductModel.class).as(p)
        join(VariantProductModel.class).as(v)
            .on(p.pk(), IS_EQUAL_TO, v.field(VariantProductModel.BASEPRODUCT))
    )
    .where(
        condition(v.field(VariantProductModel.OFFLINEDATE), IS_GREATER_THAN, timeService.getCurrentTime())
    )
    .build();

final FlexibleSearchQuery query4 =
    select(
        FieldWithType.of(ProductModel.NAME, String.class),
        FieldWithType.of(ProductModel.DESCRIPTION, String.class),
        FieldWithType.of(ProductModel.PK, Long.class)
    )
    .from(
        table(ProductModel.class)
    )
    .where(
        braces(
            condition(ProductModel.SUMMARY, IS_NULL)
            .or()
            .condition(ProductModel.NAME, IS_NOT_NULL)
        )
        .and()
        .condition(ProductModel.PK, BETWEEN, 8796093054977L, 8796193054977L)
    )
    .build();

final UserModel user = userService.getAnonymousUser();
final CategoryModel category = new CategoryModel();//just for demonstration purposes

final Alias r = new Alias("r");
final Alias e = new Alias("e");
final Alias o = new Alias("o");
final Alias c2p = new Alias("c2p");
final Alias c = new Alias("c");

final JoinOnElement joinTables =
    table(ProductModel.class).as(p)
    .leftJoin(ProductReferenceModel.class).as(r)
        .on(p.pk(), r.target())
    .leftJoin(OrderEntryModel.class).as(e)
        .on(r.source(), e.field(PRODUCT))
    .leftJoin(OrderModel.class).as(o)
        .on(o.pk(), e.field(ORDER))
    .leftJoin(CategoryConstants.Relations.CATEGORYPRODUCTRELATION).as(c2p)
        .on(r.source(), c2p.target())
    .leftJoin(CategoryModel.class).as(c)
        .on(c.pk(), c2p.source());

final FlexibleSearchQuery query5 =
    select(p)
    .from(joinTables)
    .where(
        condition(o.field(USER), IS_EQUAL_TO, user)
        .and()
        .condition(c.pk(), IS_EQUAL_TO, category)
    )
    .orderByAsc(p.field(ProductModel.CODE))
    .build();

final FlexibleSearchQuery query6 = 
    select(
        FunctionWithType.of(count(o.field(OrderModel.CODE)), Long.class),
        FieldWithType.of(p.field(ProductModel.CODE), String.class)
    )
    .from(
        table(ProductModel.class).as(p)
        .join(OrderEntryModel.class).as(e)
            .on(p.pk(), e.field(OrderEntryModel.PRODUCT))
        .join(OrderModel.class).as(o)
            .on(o.pk(), e.field(OrderEntryModel.ORDER))
    )
    .groupBy(p.field(ProductModel.CODE))
    .orderByDesc(count(o.field(OrderModel.CODE)))
    .build();

Contributing

Pull requests are welcome. If you're planning to contribute, drop me a mail as currently the process is not formal yet.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].