class AssetListController {

    @ApiOperation(httpMethod = "POST", value = "Get the complete details assets")
    @PostMapping(value = "/v1/listing/assets")
    public ResponseEntity<Object> getAssetLists(@RequestBody(required = true) Request request) {

        String assetGroup = request.getAg();
        if (Strings.isNullOrEmpty(assetGroup)) {
            return ResponseUtils.buildFailureResponse(new Exception(Constants.ASSET_MANDATORY));
        }

        String resourceType = null;
        Map<String, String> filter = request.getFilter();
        if (filter != null && MapUtils.isNotEmpty(filter)) {
            resourceType = filter.get(AssetConstants.FILTER_RES_TYPE);
        }
        
        if (Strings.isNullOrEmpty(resourceType)) {
            return ResponseUtils.buildFailureResponse(new Exception("Resource Type is Mandatory"));
        }

        int from = request.getFrom();
        int size = request.getSize();
        if (from < 0) {
            return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FROM_NEGATIVE));

        }

        String searchText = request.getSearchtext();

        List<String> acceptedFilterKeys = Arrays.asList(AssetConstants.FILTER_APPLICATION,
                AssetConstants.FILTER_ENVIRONMENT, AssetConstants.FILTER_RES_TYPE);
        for (Map.Entry<String, String> entry : filter.entrySet()) {
            if (!acceptedFilterKeys.contains(entry.getKey())) {
                return ResponseUtils.buildFailureResponse(new Exception(AssetConstants.ERROR_FILTER_ACCEPTS
                        + StringUtils.join(acceptedFilterKeys, ", ")));
            }
        }

        ResponseWithEditableFields response;
        try {
            Long totalDocCount = assetService.getTotalCountForListingAsset(assetGroup, resourceType);
            if (size <= 0) {
                size = Constants.TEN_THOUSAND;
            }

            List<Map<String, Object>> masterDetailList = assetService.getAssetLists(assetGroup, filter, from, size,
                    searchText);
            Map<String, Object> identifier = new HashMap<>();
            identifier.put("key", "_resourceid");
            response = new ResponseWithEditableFields(masterDetailList, totalDocCount,
                    assetService.getDataTypeInfoByTargetType(resourceType), identifier);
        } catch (Exception e) {
            LOGGER.error("Error in getAssetLists",e);
            return ResponseUtils.buildFailureResponse(e);
        }
        return ResponseUtils.buildSucessResponse(response);
    }

}