This commit is contained in:
parent
08243c6964
commit
54ed129de6
1 changed files with 14 additions and 12 deletions
|
|
@ -95,11 +95,11 @@ public class RegistryController extends AbstractQueueController {
|
||||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||||
@RequestMapping(value = "/filter", method = RequestMethod.GET)
|
@RequestMapping(value = "/filter", method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public CommonGetAllResponse getByFilter(@RequestParam(name = "designation", required = false) Optional<List<String>> designations,
|
public CommonGetAllResponse getByFilter(@RequestParam(name = "registryCode", required = false) Optional<String> registryCode,
|
||||||
@RequestParam(name = "status", required = false) Optional<String> status,
|
@RequestParam(name = "status", required = false) Optional<List<String>> status,
|
||||||
@RequestParam(name = "pageSize", required = false) Optional<Integer> pageSize,
|
@RequestParam(name = "pageSize", required = false) Optional<Integer> pageSize,
|
||||||
@RequestParam(name = "pageIndex", required = false) Optional<Integer> pageIndex) {
|
@RequestParam(name = "pageIndex", required = false) Optional<Integer> pageIndex) {
|
||||||
if (designations.isEmpty() && status.isEmpty()) {
|
if (registryCode.isEmpty() && status.isEmpty()) {
|
||||||
throw new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "Request should have at least one of the parameters: designation, status");
|
throw new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "Request should have at least one of the parameters: designation, status");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,20 +107,22 @@ public class RegistryController extends AbstractQueueController {
|
||||||
sw.start();
|
sw.start();
|
||||||
|
|
||||||
List<ImdgPredicate> filters = new ArrayList<>();
|
List<ImdgPredicate> filters = new ArrayList<>();
|
||||||
designations.ifPresent(ds -> filters.add(predicateBuilder.in("registryDesignation", ds.stream()
|
registryCode.ifPresent(regex -> filters.add(predicateBuilder.regex("registryCode", regex)));
|
||||||
.map(d -> Optional.ofNullable(IEnumKey.getEnumByKey(RegistryDesignation.class, d))
|
|
||||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "Unknown registry designation: " + d)))
|
status.ifPresent(collection -> {
|
||||||
.map(RegistryDesignation::getKey)
|
String[] values = collection.stream()
|
||||||
.toArray(String[]::new))));
|
.map(val -> Optional.ofNullable(IEnumKey.getEnumByKey(RegistryStatus.class, val))
|
||||||
status.ifPresent(s -> filters.add(predicateBuilder.in("registryStatus", Optional.ofNullable(IEnumKey.getEnumByKey(RegistryStatus.class, s))
|
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "Unknown registry status: " + val)))
|
||||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "Unknown registry status: " + s))
|
.map(RegistryStatus::getKey)
|
||||||
.getKey())));
|
.toArray(String[]::new);
|
||||||
|
filters.add(predicateBuilder.in("registryStatus", values));
|
||||||
|
});
|
||||||
|
|
||||||
AtomicReference<Collection<Map<String, Object>>> all = new AtomicReference<>();
|
AtomicReference<Collection<Map<String, Object>>> all = new AtomicReference<>();
|
||||||
pageIndex.ifPresentOrElse(index -> {
|
pageIndex.ifPresentOrElse(index -> {
|
||||||
ImdgPredicate filter = predicateBuilder.and(filters.toArray(ImdgPredicate[]::new));
|
ImdgPredicate filter = predicateBuilder.and(filters.toArray(ImdgPredicate[]::new));
|
||||||
all.set(stateLoader.getAllMetaTransformWithPagination(IMDGDistributedNames.Map_Registry, Registry.class, filter,
|
all.set(stateLoader.getAllMetaTransformWithPagination(IMDGDistributedNames.Map_Registry, Registry.class, filter,
|
||||||
index, pageSize.orElse(100)));
|
pageSize.orElse(10_000), index));
|
||||||
},
|
},
|
||||||
() -> {
|
() -> {
|
||||||
ImdgPredicate filter = predicateBuilder.and(filters.toArray(ImdgPredicate[]::new));
|
ImdgPredicate filter = predicateBuilder.and(filters.toArray(ImdgPredicate[]::new));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue