Search in sources :

Example 1 with PolicyListItem

use of io.gravitee.rest.api.model.PolicyListItem in project gravitee-management-rest-api by gravitee-io.

the class PoliciesResource method convert.

private PolicyListItem convert(PolicyEntity policy) {
    PolicyListItem item = new PolicyListItem();
    item.setId(policy.getId());
    item.setName(policy.getName());
    item.setDescription(policy.getDescription());
    item.setVersion(policy.getVersion());
    item.setType(policy.getType());
    item.setCategory(policy.getCategory());
    PolicyDevelopmentEntity development = policy.getDevelopment();
    if (development != null) {
        item.setOnRequest(development.getOnRequestMethod() != null);
        item.setOnResponse(development.getOnResponseMethod() != null);
    } else {
        item.setOnRequest(false);
        item.setOnResponse(false);
    }
    return item;
}
Also used : PolicyListItem(io.gravitee.rest.api.model.PolicyListItem) PolicyDevelopmentEntity(io.gravitee.rest.api.model.PolicyDevelopmentEntity)

Example 2 with PolicyListItem

use of io.gravitee.rest.api.model.PolicyListItem in project gravitee-management-rest-api by gravitee-io.

the class PoliciesResource method getSwaggerPolicy.

@GET
@Path("swagger")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List policies which are handling Swagger / OAI definition", notes = "These policies are used when importing an OAI to create an API")
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_API, acls = RolePermissionAction.READ) })
public List<PolicyListItem> getSwaggerPolicy() {
    return policyOperationVisitorManager.getPolicyVisitors().stream().filter(operationVisitor -> operationVisitor.display()).map(operationVisitor -> {
        PolicyListItem item = new PolicyListItem();
        item.setId(operationVisitor.getId());
        item.setName(operationVisitor.getName());
        return item;
    }).sorted(Comparator.comparing(PolicyListItem::getName)).collect(Collectors.toList());
}
Also used : RolePermissionAction(io.gravitee.rest.api.model.permissions.RolePermissionAction) Context(javax.ws.rs.core.Context) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PolicyDevelopmentEntity(io.gravitee.rest.api.model.PolicyDevelopmentEntity) Collection(java.util.Collection) Path(javax.ws.rs.Path) PolicyService(io.gravitee.rest.api.service.PolicyService) PolicyOperationVisitorManager(io.gravitee.rest.api.service.impl.swagger.policy.PolicyOperationVisitorManager) Collectors(java.util.stream.Collectors) Permission(io.gravitee.rest.api.management.rest.security.Permission) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) Stream(java.util.stream.Stream) QueryParam(javax.ws.rs.QueryParam) ResourceContext(javax.ws.rs.container.ResourceContext) PolicyEntity(io.gravitee.rest.api.model.PolicyEntity) Api(io.swagger.annotations.Api) Comparator(java.util.Comparator) Permissions(io.gravitee.rest.api.management.rest.security.Permissions) PolicyListItem(io.gravitee.rest.api.model.PolicyListItem) RolePermission(io.gravitee.rest.api.model.permissions.RolePermission) PolicyListItem(io.gravitee.rest.api.model.PolicyListItem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Aggregations

PolicyDevelopmentEntity (io.gravitee.rest.api.model.PolicyDevelopmentEntity)2 PolicyListItem (io.gravitee.rest.api.model.PolicyListItem)2 MediaType (io.gravitee.common.http.MediaType)1 Permission (io.gravitee.rest.api.management.rest.security.Permission)1 Permissions (io.gravitee.rest.api.management.rest.security.Permissions)1 PolicyEntity (io.gravitee.rest.api.model.PolicyEntity)1 RolePermission (io.gravitee.rest.api.model.permissions.RolePermission)1 RolePermissionAction (io.gravitee.rest.api.model.permissions.RolePermissionAction)1 PolicyService (io.gravitee.rest.api.service.PolicyService)1 PolicyOperationVisitorManager (io.gravitee.rest.api.service.impl.swagger.policy.PolicyOperationVisitorManager)1 Api (io.swagger.annotations.Api)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Inject (javax.inject.Inject)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1