use of com.redhat.cloud.policies.app.model.pager.Pager in project policies-ui-backend by RedHatInsights.
the class PolicyCrudService method getPoliciesForCustomer.
@Operation(summary = "Return all policies for a given account")
@GET
@Path("/")
@Parameters({ @Parameter(name = "offset", in = ParameterIn.QUERY, description = "Page number, starts 0, if not specified uses 0.", schema = @Schema(type = SchemaType.INTEGER)), @Parameter(name = "limit", in = ParameterIn.QUERY, description = "Number of items per page, if not specified uses 50. " + Pager.NO_LIMIT + " can be used to specify an unlimited page, when specified it ignores the offset", schema = @Schema(type = SchemaType.INTEGER)), @Parameter(name = "sortColumn", in = ParameterIn.QUERY, description = "Column to sort the results by", schema = @Schema(type = SchemaType.STRING, enumeration = { "name", "description", "is_enabled", "mtime" })), @Parameter(name = "sortDirection", in = ParameterIn.QUERY, description = "Sort direction used", schema = @Schema(type = SchemaType.STRING, enumeration = { "asc", "desc" })), @Parameter(name = "filter[name]", in = ParameterIn.QUERY, description = "Filtering policies by the name depending on the Filter operator used.", schema = @Schema(type = SchemaType.STRING)), @Parameter(name = "filter:op[name]", in = ParameterIn.QUERY, description = "Operations used with the filter", schema = @Schema(type = SchemaType.STRING, enumeration = { "equal", "like", "ilike", "not_equal" }, defaultValue = "equal")), @Parameter(name = "filter[description]", in = ParameterIn.QUERY, description = "Filtering policies by the description depending on the Filter operator used.", schema = @Schema(type = SchemaType.STRING)), @Parameter(name = "filter:op[description]", in = ParameterIn.QUERY, description = "Operations used with the filter", schema = @Schema(type = SchemaType.STRING, enumeration = { "equal", "like", "ilike", "not_equal" }, defaultValue = "equal")), @Parameter(name = "filter[is_enabled]", in = ParameterIn.QUERY, description = "Filtering policies by the is_enabled field." + "Defaults to true if no operand is given.", schema = @Schema(type = SchemaType.STRING, defaultValue = "true", enumeration = { "true", "false" })) })
@APIResponse(responseCode = "400", description = "Bad parameter for sorting was passed")
@APIResponse(responseCode = "404", description = "No policies found for customer")
@APIResponse(responseCode = "403", description = "Individual permissions missing to complete action")
@APIResponse(responseCode = "200", description = "Policies found", content = @Content(schema = @Schema(implementation = PagedResponseOfPolicy.class)), headers = @Header(name = "TotalCount", description = "Total number of items found", schema = @Schema(type = SchemaType.INTEGER)))
public Response getPoliciesForCustomer() {
if (!user.canReadPolicies()) {
return Response.status(Response.Status.FORBIDDEN).entity(new Msg(MISSING_PERMISSIONS_TO_RETRIEVE_POLICIES)).build();
}
Page<Policy> page;
try {
Pager pager = PagingUtils.extractPager(uriInfo);
page = Policy.pagePoliciesForCustomer(entityManager, user.getAccount(), pager);
for (Policy policy : page) {
Long lastTriggerTime = policiesHistoryRepository.getLastTriggerTime(user.getAccount(), policy.id);
if (lastTriggerTime != null) {
policy.setLastTriggered(lastTriggerTime);
}
}
} catch (IllegalArgumentException iae) {
return Response.status(400, iae.getLocalizedMessage()).build();
}
return PagingUtils.responseBuilder(page).build();
}
use of com.redhat.cloud.policies.app.model.pager.Pager in project policies-ui-backend by RedHatInsights.
the class PolicyCrudService method getPolicyIdsForCustomer.
@Operation(summary = "Return all policy ids for a given account after applying the filters")
@GET
@Path("/ids")
@Parameters({ @Parameter(name = "filter[name]", in = ParameterIn.QUERY, description = "Filtering policies by the name depending on the Filter operator used.", schema = @Schema(type = SchemaType.STRING)), @Parameter(name = "filter:op[name]", in = ParameterIn.QUERY, description = "Operations used with the filter", schema = @Schema(type = SchemaType.STRING, enumeration = { "equal", "like", "ilike", "not_equal" }, defaultValue = "equal")), @Parameter(name = "filter[description]", in = ParameterIn.QUERY, description = "Filtering policies by the description depending on the Filter operator used.", schema = @Schema(type = SchemaType.STRING)), @Parameter(name = "filter:op[description]", in = ParameterIn.QUERY, description = "Operations used with the filter", schema = @Schema(type = SchemaType.STRING, enumeration = { "equal", "like", "ilike", "not_equal" }, defaultValue = "equal")), @Parameter(name = "filter[is_enabled]", in = ParameterIn.QUERY, description = "Filtering policies by the is_enabled field." + "Defaults to true if no operand is given.", schema = @Schema(type = SchemaType.STRING, defaultValue = "true", enumeration = { "true", "false" })) })
@APIResponse(responseCode = "400", description = "Bad parameter for sorting was passed")
@APIResponse(responseCode = "404", description = "No policies found for customer")
@APIResponse(responseCode = "403", description = "Individual permissions missing to complete action")
@APIResponse(responseCode = "200", description = "PolicyIds found", content = @Content(schema = @Schema(type = SchemaType.ARRAY, implementation = UUID.class)))
public Response getPolicyIdsForCustomer() {
if (!user.canReadPolicies()) {
return Response.status(Response.Status.FORBIDDEN).entity(new Msg(MISSING_PERMISSIONS_TO_RETRIEVE_POLICIES)).build();
}
List<UUID> uuids;
try {
Pager pager = PagingUtils.extractPager(uriInfo);
uuids = Policy.getPolicyIdsForCustomer(entityManager, user.getAccount(), pager);
} catch (IllegalArgumentException iae) {
return Response.status(400, iae.getLocalizedMessage()).build();
}
return Response.ok(uuids).build();
}
use of com.redhat.cloud.policies.app.model.pager.Pager in project policies-ui-backend by RedHatInsights.
the class TagsFilterTest method filter3.
@Test
void filter3() throws URISyntaxException {
UriInfo info = new ResteasyUriInfo(new URI("https://foo?filter[name]=VM&filter:op[name]=like"));
Pager pager = PagingUtils.extractPager(info);
String query = PolicyHistoryTagFilterHelper.getTagsFilterFromPager(pager);
assertEquals("tags.display_name MATCHES '*vm*'", query);
}
use of com.redhat.cloud.policies.app.model.pager.Pager in project policies-ui-backend by RedHatInsights.
the class TagsFilterTest method filter1.
@Test
void filter1() throws URISyntaxException {
UriInfo info = new ResteasyUriInfo(new URI("https://foo?filter[name]=VM"));
Pager pager = PagingUtils.extractPager(info);
String query = PolicyHistoryTagFilterHelper.getTagsFilterFromPager(pager);
assertEquals("tags.display_name = 'vm'", query);
}
use of com.redhat.cloud.policies.app.model.pager.Pager in project policies-ui-backend by RedHatInsights.
the class TagsFilterTest method filter6.
@Test
void filter6() throws URISyntaxException {
UriInfo info = new ResteasyUriInfo(new URI("https://foo?filter[name]=VM&filter:op[id]=not_equal"));
Pager pager = PagingUtils.extractPager(info);
String query = PolicyHistoryTagFilterHelper.getTagsFilterFromPager(pager);
assertEquals("tags.display_name = 'vm'", query);
}
Aggregations