getAll endpoint returned and added new getByFilter endpoint
This commit is contained in:
parent
cebd7c2a8c
commit
e3439cacc2
1 changed files with 69 additions and 63 deletions
|
|
@ -5,9 +5,11 @@ import io.swagger.annotations.ApiParam;
|
|||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -65,26 +67,9 @@ public class RegistryController extends AbstractQueueController {
|
|||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll(@RequestParam(name = "designation", required = false) List<String> designations,
|
||||
@RequestParam(name = "status", required = false) String status,
|
||||
@RequestParam(name = "pageSize", required = false) Integer pageSize,
|
||||
@RequestParam(name = "pageIndex", required = false) Integer pageIndex) {
|
||||
if (designations != null && !designations.isEmpty()) {
|
||||
for (String designation : designations) {
|
||||
if (IEnumKey.getEnumByKey(RegistryDesignation.class, designation) == null) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "Unknown registry designation: " + designation);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (status != null && !status.isEmpty() && IEnumKey.getEnumByKey(RegistryStatus.class, status) == null) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "Unknown registry status: " + status);
|
||||
}
|
||||
|
||||
StopWatch sw = new StopWatch("registry-controller-stopwatch");
|
||||
sw.start();
|
||||
ImdgPredicate filter;
|
||||
if (designations == null || designations.isEmpty()) {
|
||||
filter = predicateBuilder.or(
|
||||
public CommonGetAllResponse getAll() {
|
||||
// long t1 = System.currentTimeMillis();
|
||||
ImdgPredicate filter = predicateBuilder.or(
|
||||
predicateBuilder.equals("registryDesignation", RegistryDesignation.A.getKey()),
|
||||
predicateBuilder.equals("registryDesignation", RegistryDesignation.D.getKey()),
|
||||
predicateBuilder.and(
|
||||
|
|
@ -95,26 +80,47 @@ public class RegistryController extends AbstractQueueController {
|
|||
predicateBuilder.greatEqual("settlementDate", LocalDate.now())
|
||||
)
|
||||
);
|
||||
|
||||
if (status != null && !status.isEmpty()) {
|
||||
filter = predicateBuilder.and(filter, predicateBuilder.in("registryStatus", status));
|
||||
}
|
||||
} else if (status == null || status.isEmpty()) {
|
||||
filter = predicateBuilder.in("registryDesignation", designations.toArray(String[]::new));
|
||||
} else {
|
||||
filter = predicateBuilder.and(
|
||||
predicateBuilder.in("registryDesignation", designations.toArray(String[]::new)),
|
||||
predicateBuilder.in("registryStatus", status)
|
||||
);
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_Registry, Registry.class,
|
||||
filter);
|
||||
// long t2 = System.currentTimeMillis();
|
||||
// log.info("Info select and format {} data {}", all.size(), t2 - t1);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
// log.info("Info select and format {} data {}", all.size(), System.currentTimeMillis() - t2);
|
||||
return response;
|
||||
}
|
||||
|
||||
Collection<Map<String, Object>> all;
|
||||
if (pageSize != null && pageIndex != null) {
|
||||
all = stateLoader.getAllMetaTransformWithPagination(IMDGDistributedNames.Map_Registry, Registry.class, filter, pageSize, pageIndex);
|
||||
} else {
|
||||
all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_Registry, Registry.class, filter);
|
||||
@ApiOperation(value = "get registries by filter.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(value = "/filter", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getByFilter(@RequestParam(name = "designation", required = false) Optional<List<String>> designations,
|
||||
@RequestParam(name = "status", required = false) Optional<String> status,
|
||||
@RequestParam(name = "pageSize") Integer pageSize,
|
||||
@RequestParam(name = "pageIndex") Integer pageIndex) {
|
||||
if (designations.isEmpty() && status.isEmpty()) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "Request should have at least one of the parameters: designation, status");
|
||||
}
|
||||
|
||||
StopWatch sw = new StopWatch("registry-controller-stopwatch");
|
||||
sw.start();
|
||||
|
||||
List<ImdgPredicate> filters = new ArrayList<>();
|
||||
designations.ifPresent(ds -> filters.add(predicateBuilder.in("registryDesignation", ds.stream()
|
||||
.map(d -> Optional.ofNullable(IEnumKey.getEnumByKey(RegistryDesignation.class, d))
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "Unknown registry designation: " + d)))
|
||||
.map(RegistryDesignation::getKey)
|
||||
.toArray(String[]::new))));
|
||||
status.ifPresent(s -> filters.add(predicateBuilder.in("registryStatus", Optional.ofNullable(IEnumKey.getEnumByKey(RegistryStatus.class, s))
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "Unknown registry status: " + s))
|
||||
.getKey())));
|
||||
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransformWithPagination(IMDGDistributedNames.Map_Registry,
|
||||
Registry.class,
|
||||
predicateBuilder.and(filters.toArray(ImdgPredicate[]::new)),
|
||||
pageSize,
|
||||
pageIndex);
|
||||
|
||||
sw.stop();
|
||||
log.info("Info select and format {} data took {} ms", all.size(), sw.getLastTaskTimeMillis());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue