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 InputStream extractInputStream(MultipartFile file) { | |
try { | |
return file.getInputStream(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} |
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
@FunctionalInterface | |
interface FunctionWithException<T, R, E extends Exception> { | |
R apply(T t) throws E; | |
} |
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 <T, R, E extends Exception> | |
Function<T, R> wrapper(FunctionWithException<T, R, E> fun) { | |
return arg -> { | |
try { | |
return fun.apply(arg); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
}; | |
} |
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
files.stream() | |
.parallel() | |
.map(wrapper(file->file.getInputStream())) | |
.forEach(inputStream -> carService.saveCars(inputStream)); |
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 interface CarRepository extends JpaRepository<Car, Long> { | |
List<Car> findByManufacturer(String manufacturer, Pageable pageable); | |
List<Car> findByModel(String model, Pageable pageable); | |
List<Car> findByManufacturerAndModel(String manufacturer, String model, Pageable pageable); | |
// other combinations omitted for sanity | |
} |
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.mak.springbootefficientsearchapi.entity; | |
import lombok.AllArgsConstructor; | |
import lombok.Getter; | |
import lombok.NoArgsConstructor; | |
import lombok.Setter; | |
import javax.persistence.Column; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; |
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
@Transactional | |
@GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE) | |
@ResponseStatus(HttpStatus.OK) | |
public ResponseEntity<List<Car>> get( | |
@And({ | |
@Spec(path = "manufacturer", params = "manufacturer", spec = Like.class), | |
@Spec(path = "model", params = "model", spec = Like.class), | |
@Spec(path = "country", params = "country", spec = In.class), | |
@Spec(path = "type", params = "type", spec = Like.class), | |
@Spec(path = "createDate", params = "createDate", spec = Equal.class), |
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
/** | |
* get element using Criteria. | |
* | |
* @param spec * | |
* @param headers pagination data | |
* @param sort sort criteria | |
* @return retrieve elements with pagination | |
*/ | |
public PagingResponse get(Specification<Car> spec, HttpHeaders headers, Sort sort) { | |
if (isRequestPaged(headers)) { |
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>net.kaczmarzyk</groupId> | |
<artifactId>specification-arg-resolver</artifactId> | |
<version>2.1.1</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
package com.mak.springbootefficientsearchapi.configuration; | |
import net.kaczmarzyk.spring.data.jpa.web.SpecificationArgumentResolver; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.transaction.annotation.EnableTransactionManagement; | |
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | |
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |
import java.util.List; |