This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>mysql</groupId> | |
<artifactId>mysql-connector-java</artifactId> | |
<scope>runtime</scope> | |
</dependency> | |
<!-- Query DSL --> | |
<dependency> | |
<groupId>com.querydsl</groupId> | |
<artifactId>querydsl-apt</artifactId> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.abhicodes.querydsldynamicquery.utils; | |
import lombok.Builder; | |
import lombok.Getter; | |
import lombok.ToString; | |
@Getter | |
@ToString | |
@Builder | |
public class SearchCriteria { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private BooleanExpression getPredicate(String key, String operator, String value, PathBuilder<?> entityPath, | |
Class<?> classType) { | |
boolean isMultiValue = value.contains(","); | |
Class<?> propertyType = getPropertyType(classType, key); | |
switch (propertyType.getSimpleName()) { | |
case "Integer": | |
if (isMultiValue) { | |
NumberPath<Integer> path = entityPath.getNumber(key, Integer.class); | |
Integer[] numValue = Stream.of(value.split(",")).map(Integer::parseInt).toArray(Integer[]::new); | |
return getNumberPredicate(path, operator, numValue); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Format search criteria. | |
* | |
* @param filter the filter | |
* @return the list | |
*/ | |
public List<SearchCriteria> formatSearchCriteria(String[] filter) { | |
List<SearchCriteria> criterias = new ArrayList<>(); | |
if (null != filter) { | |
Collection<SearchCriteria> collect = Arrays.asList(filter).parallelStream().map(this::validateFilterPattern) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.abhicodes.querydsldynamicquery.repository; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import org.springframework.data.querydsl.QuerydslPredicateExecutor; | |
import org.springframework.stereotype.Repository; | |
import com.abhicodes.querydsldynamicquery.entity.Post; | |
@Repository | |
public interface PostRepository extends JpaRepository<Post, Integer>, QuerydslPredicateExecutor<Post> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Operator | Meaning | Applicable for Data Type | |
---|---|---|---|
: | In | Integer,Long,Double,Date | |
> | Greater than | Integer,Long,Double,Date | |
>= | Greater than equal to | Integer,Long,Double,Date | |
< | Less than | Integer,Long,Double,Date | |
<= | Less than equal to | Integer,Long,Double,Date | |
: | Equals Ignore Case | String | |
% | Starts With Ignore Case | String | |
- | Contains Ignore Case | String | |
() | Inclusive Range | Date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>io.springfox</groupId> | |
<artifactId>springfox-boot-starter</artifactId> | |
<version>3.0.0</version> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public Docket api() { | |
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()) | |
.securityContexts(Arrays.asList(securityContext())).securitySchemes(Arrays.asList(apiKey())).select() | |
.apis(RequestHandlerSelectors.basePackage("com.abhicodes.springfoxswagger3.controller")) | |
.paths(PathSelectors.ant("/api/**")).build() | |
.globalRequestParameters(Arrays.asList( | |
new RequestParameterBuilder().name("x-global-header-1").description("Remote User") | |
.in(ParameterType.HEADER).required(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("/api") | |
@Api(value = "Demo APIs") | |
public class DemoController { | |
@GetMapping("/hello-world") | |
@ApiOperation("Hello peeps") | |
public ResponseEntity<String> helloWorld() { | |
return ResponseEntity.ok("Hello Medium"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String getAccessTokenByClientCredentialGrant() { | |
String accessToken = null; | |
String clientId = imapClientId; | |
String secret = imapSecret; | |
String authority = "https://login.microsoftonline.com/" + imapTenantId + "/oauth2/v2.0/token"; | |
String scope = "https://outlook.office365.com/.default"; | |
log.info("Client ID : " + clientId); | |
log.info("Client Secret : " + secret); | |
log.info("Auth Server: " + authority); |
OlderNewer