Search in sources :

Example 1 with SubscriptionValidationDAO

use of org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImpl method subscriptionsGet.

@Override
public Response subscriptionsGet(String xWSO2Tenant, Integer apiId, Integer appId, String apiUUID, String applicationUUID, MessageContext messageContext) throws APIManagementException {
    Response result;
    SubscriptionValidationDAO subscriptionValidationDAO = new SubscriptionValidationDAO();
    List<Subscription> subscriptionList = new ArrayList<>();
    xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
    if (StringUtils.isNotEmpty(applicationUUID) && StringUtils.isNotEmpty(apiUUID)) {
        Subscription subscription = subscriptionValidationDAO.getSubscription(apiUUID, applicationUUID);
        if (subscription != null) {
            subscriptionList.add(subscription);
        }
        result = Response.ok().entity(SubscriptionValidationDataUtil.fromSubscriptionToSubscriptionListDTO(subscriptionList)).build();
    } else if (apiId != null && appId != null) {
        Subscription subscription = subscriptionValidationDAO.getSubscription(apiId, appId);
        if (subscription != null) {
            subscriptionList.add(subscription);
        }
        result = Response.ok().entity(SubscriptionValidationDataUtil.fromSubscriptionToSubscriptionListDTO(subscriptionList)).build();
    } else if (StringUtils.isNotEmpty(xWSO2Tenant)) {
        result = Response.ok().entity(SubscriptionValidationDataUtil.fromSubscriptionToSubscriptionListDTO(subscriptionValidationDAO.getAllSubscriptions(xWSO2Tenant))).build();
    } else {
        result = Response.ok().entity(SubscriptionValidationDataUtil.fromSubscriptionToSubscriptionListDTO(subscriptionValidationDAO.getAllSubscriptions())).build();
    }
    return result;
}
Also used : Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) Subscription(org.wso2.carbon.apimgt.api.model.subscription.Subscription) SubscriptionValidationDAO(org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO)

Example 2 with SubscriptionValidationDAO

use of org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO in project carbon-apimgt by wso2.

the class ApplicationPoliciesApiServiceImpl method applicationPoliciesGet.

@Override
public Response applicationPoliciesGet(String xWSO2Tenant, String policyName, MessageContext messageContext) {
    SubscriptionValidationDAO subscriptionValidationDAO = new SubscriptionValidationDAO();
    xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
    if (StringUtils.isNotEmpty(xWSO2Tenant)) {
        if (APIConstants.CHAR_ASTERIX.equals(xWSO2Tenant)) {
            return Response.ok().entity(SubscriptionValidationDataUtil.fromApplicationPolicyToApplicationPolicyListDTO(subscriptionValidationDAO.getAllApplicationPolicies())).build();
        } else if (StringUtils.isNotEmpty(policyName)) {
            List<ApplicationPolicy> model = new ArrayList<>();
            ApplicationPolicy applicationPolicy = subscriptionValidationDAO.getApplicationPolicyByNameForTenant(policyName, xWSO2Tenant);
            if (applicationPolicy != null) {
                model.add(applicationPolicy);
            }
            return Response.ok().entity(SubscriptionValidationDataUtil.fromApplicationPolicyToApplicationPolicyListDTO(model)).build();
        } else {
            return Response.ok().entity(SubscriptionValidationDataUtil.fromApplicationPolicyToApplicationPolicyListDTO(subscriptionValidationDAO.getAllApplicationPolicies(xWSO2Tenant))).build();
        }
    } else {
        if (StringUtils.isNotEmpty(policyName)) {
            return Response.status(Response.Status.BAD_REQUEST.getStatusCode(), "X-WSo2-Tenant header is missing.").build();
        }
    }
    return Response.ok().entity(SubscriptionValidationDataUtil.fromApplicationPolicyToApplicationPolicyListDTO(subscriptionValidationDAO.getAllApplicationPolicies())).build();
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.api.model.subscription.ApplicationPolicy) List(java.util.List) ArrayList(java.util.ArrayList) SubscriptionValidationDAO(org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO)

Example 3 with SubscriptionValidationDAO

use of org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO in project carbon-apimgt by wso2.

the class SubscriptionPoliciesApiServiceImpl method subscriptionPoliciesGet.

@Override
public Response subscriptionPoliciesGet(String xWSO2Tenant, String policyName, MessageContext messageContext) {
    SubscriptionValidationDAO subscriptionValidationDAO = new SubscriptionValidationDAO();
    xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
    if (StringUtils.isNotEmpty(xWSO2Tenant)) {
        if (APIConstants.CHAR_ASTERIX.equals(xWSO2Tenant)) {
            return Response.ok().entity(SubscriptionValidationDataUtil.fromSubscriptionPolicyToSubscriptionPolicyListDTO(subscriptionValidationDAO.getAllSubscriptionPolicies())).build();
        } else if (StringUtils.isNotEmpty(policyName)) {
            List<SubscriptionPolicy> model = new ArrayList<>();
            SubscriptionPolicy subscriptionPolicy = subscriptionValidationDAO.getSubscriptionPolicyByNameForTenant(policyName, xWSO2Tenant);
            if (subscriptionPolicy != null) {
                model.add(subscriptionPolicy);
            }
            return Response.ok().entity(SubscriptionValidationDataUtil.fromSubscriptionPolicyToSubscriptionPolicyListDTO(model)).build();
        } else {
            return Response.ok().entity(SubscriptionValidationDataUtil.fromSubscriptionPolicyToSubscriptionPolicyListDTO(subscriptionValidationDAO.getAllSubscriptionPolicies(xWSO2Tenant))).build();
        }
    } else {
        if (StringUtils.isNotEmpty(policyName)) {
            return Response.status(Response.Status.BAD_REQUEST.getStatusCode(), "X-WSo2-Tenant header is missing.").build();
        }
    }
    return Response.ok().entity(SubscriptionValidationDataUtil.fromSubscriptionPolicyToSubscriptionPolicyListDTO(subscriptionValidationDAO.getAllSubscriptionPolicies())).build();
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.api.model.subscription.SubscriptionPolicy) List(java.util.List) ArrayList(java.util.ArrayList) SubscriptionValidationDAO(org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO)

Example 4 with SubscriptionValidationDAO

use of org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO in project carbon-apimgt by wso2.

the class ApiPoliciesApiServiceImpl method apiPoliciesGet.

public Response apiPoliciesGet(String xWSO2Tenant, String policyName, MessageContext messageContext) {
    SubscriptionValidationDAO subscriptionValidationDAO = new SubscriptionValidationDAO();
    xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
    if (StringUtils.isNotEmpty(xWSO2Tenant)) {
        if (APIConstants.CHAR_ASTERIX.equals(xWSO2Tenant)) {
            return Response.ok().entity(SubscriptionValidationDataUtil.fromApiPolicyToApiPolicyListDTO(subscriptionValidationDAO.getAllApiPolicies())).build();
        } else if (StringUtils.isNotEmpty(policyName)) {
            List<APIPolicy> model = new ArrayList<>();
            APIPolicy apiPolicy = subscriptionValidationDAO.getApiPolicyByNameForTenant(policyName, xWSO2Tenant);
            if (apiPolicy != null) {
                model.add(apiPolicy);
            }
            return Response.ok().entity(SubscriptionValidationDataUtil.fromApiPolicyToApiPolicyListDTO(model)).build();
        } else {
            return Response.ok().entity(SubscriptionValidationDataUtil.fromApiPolicyToApiPolicyListDTO(subscriptionValidationDAO.getAllApiPolicies(xWSO2Tenant))).build();
        }
    } else {
        if (StringUtils.isNotEmpty(policyName)) {
            return Response.status(Response.Status.BAD_REQUEST.getStatusCode(), "X-WSo2-Tenant header is missing.").build();
        }
    }
    return Response.ok().entity(SubscriptionValidationDataUtil.fromApiPolicyToApiPolicyListDTO(subscriptionValidationDAO.getAllApiPolicies())).build();
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) APIPolicy(org.wso2.carbon.apimgt.api.model.subscription.APIPolicy) SubscriptionValidationDAO(org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO)

Example 5 with SubscriptionValidationDAO

use of org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method apisGet.

@Override
public Response apisGet(String xWSO2Tenant, String apiId, String context, String version, String gatewayLabel, String accept, MessageContext messageContext) throws APIManagementException {
    SubscriptionValidationDAO subscriptionValidationDAO = new SubscriptionValidationDAO();
    xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
    APIListDTO apiListDTO;
    if (StringUtils.isNotEmpty(gatewayLabel)) {
        if (StringUtils.isNotEmpty(apiId)) {
            API api = subscriptionValidationDAO.getApiByUUID(apiId, gatewayLabel, xWSO2Tenant);
            apiListDTO = SubscriptionValidationDataUtil.fromAPIToAPIListDTO(api);
        } else if (StringUtils.isNotEmpty(context) && StringUtils.isNotEmpty(version)) {
            if (!context.startsWith("/t/" + xWSO2Tenant.toLowerCase())) {
                apiListDTO = new APIListDTO();
            }
            API api = subscriptionValidationDAO.getAPIByContextAndVersion(context, version, gatewayLabel);
            apiListDTO = SubscriptionValidationDataUtil.fromAPIToAPIListDTO(api);
        } else {
            // Retrieve API Detail according to Gateway label.
            apiListDTO = SubscriptionValidationDataUtil.fromAPIListToAPIListDTO(subscriptionValidationDAO.getAllApis(xWSO2Tenant, gatewayLabel));
        }
    } else {
        apiListDTO = SubscriptionValidationDataUtil.fromAPIListToAPIListDTO(subscriptionValidationDAO.getAllApis(xWSO2Tenant));
    }
    if (APIConstants.APPLICATION_GZIP.equals(accept)) {
        try {
            File zippedResponse = GZIPUtils.constructZippedResponse(apiListDTO);
            return Response.ok().entity(zippedResponse).header("Content-Disposition", "attachment").header("Content-Encoding", "gzip").build();
        } catch (APIManagementException e) {
            RestApiUtil.handleInternalServerError(e.getMessage(), e, log);
        }
    } else {
        return Response.ok().entity(apiListDTO).build();
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIListDTO(org.wso2.carbon.apimgt.internal.service.dto.APIListDTO) API(org.wso2.carbon.apimgt.api.model.subscription.API) File(java.io.File) SubscriptionValidationDAO(org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO)

Aggregations

SubscriptionValidationDAO (org.wso2.carbon.apimgt.impl.dao.SubscriptionValidationDAO)8 ArrayList (java.util.ArrayList)6 List (java.util.List)4 File (java.io.File)1 Response (javax.ws.rs.core.Response)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 API (org.wso2.carbon.apimgt.api.model.subscription.API)1 APIPolicy (org.wso2.carbon.apimgt.api.model.subscription.APIPolicy)1 Application (org.wso2.carbon.apimgt.api.model.subscription.Application)1 ApplicationKeyMapping (org.wso2.carbon.apimgt.api.model.subscription.ApplicationKeyMapping)1 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.subscription.ApplicationPolicy)1 GlobalPolicy (org.wso2.carbon.apimgt.api.model.subscription.GlobalPolicy)1 Subscription (org.wso2.carbon.apimgt.api.model.subscription.Subscription)1 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.subscription.SubscriptionPolicy)1 APIListDTO (org.wso2.carbon.apimgt.internal.service.dto.APIListDTO)1