Search in sources :

Example 56 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApplicationDeletionWorkflow method completeWorkflow.

public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
    if (application == null) {
        // this is when complete method is executed through workflow rest api
        this.application = applicationDAO.getApplication(getWorkflowReference());
    }
    WorkflowResponse response = workflowExecutor.complete(this);
    setStatus(response.getWorkflowStatus());
    if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Application Deletion workflow complete: Approved");
        }
        applicationDAO.deleteApplication(getWorkflowReference());
        try {
            getApiGateway().deleteApplication(application.getId());
        } catch (GatewayException ex) {
            // This log is not harm to therefore not rethrow
            log.warn("Failed to send the Application Deletion Event ", ex);
        }
    } else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Application Deletion workflow complete: Rejected");
        }
    }
    updateWorkflowEntries(this);
    return response;
}
Also used : GatewayException(org.wso2.carbon.apimgt.core.exception.GatewayException) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse)

Example 57 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class ApplicationUpdateWorkflow method completeWorkflow.

public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
    String appId = getWorkflowReference();
    String name = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_NAME);
    String updatedUser = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_UPDATEDBY);
    String applicationId = getWorkflowReference();
    String tier = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_TIER);
    String policyId = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_POLICY_ID);
    String description = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_DESCRIPTION);
    String permission = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_PERMISSION);
    Application application = new Application(name, updatedUser);
    application.setPolicy(new ApplicationPolicy(policyId, tier));
    application.setDescription(description);
    application.setId(applicationId);
    application.setUpdatedUser(updatedUser);
    application.setPermissionString(permission);
    application.setUpdatedTime(LocalDateTime.now());
    if (existingApplication == null && updatedApplication == null) {
        // this is when complete method is executed through workflow rest api
        existingApplication = applicationDAO.getApplication(appId);
        updatedApplication = application;
    }
    WorkflowResponse response = workflowExecutor.complete(this);
    setStatus(response.getWorkflowStatus());
    if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Application update workflow complete: Approved");
        }
        application.setStatus(APIMgtConstants.ApplicationStatus.APPLICATION_APPROVED);
        applicationDAO.updateApplication(appId, application);
        try {
            getApiGateway().updateApplication(application);
        } catch (GatewayException ex) {
            // This log is not harm to therefore not rethrow
            log.warn("Failed to send the Application Update Event ", ex);
        }
    } else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Application update workflow complete: Rejected");
        }
        String existingAppStatus = getAttribute(WorkflowConstants.ATTRIBUTE_APPLICATION_EXISTIN_APP_STATUS);
        applicationDAO.updateApplicationState(appId, existingAppStatus);
    }
    updateWorkflowEntries(this);
    return response;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) GatewayException(org.wso2.carbon.apimgt.core.exception.GatewayException) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) Application(org.wso2.carbon.apimgt.core.models.Application)

Example 58 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultAPIPolicy.

/**
 * create default api policy
 *
 * @return APIPolicy object is returned
 */
public static APIPolicy createDefaultAPIPolicy() {
    APIPolicy apiPolicy = new APIPolicy(SAMPLE_API_POLICY);
    apiPolicy.setUuid(UUID.randomUUID().toString());
    apiPolicy.setDisplayName(SAMPLE_API_POLICY);
    apiPolicy.setDescription(SAMPLE_API_POLICY_DESCRIPTION);
    apiPolicy.setUserLevel(APIMgtConstants.ThrottlePolicyConstants.API_LEVEL);
    QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
    defaultQuotaPolicy.setType(PolicyConstants.REQUEST_COUNT_TYPE);
    RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 1000, 10000);
    defaultQuotaPolicy.setLimit(requestCountLimit);
    apiPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
    apiPolicy.setPipelines(createDefaultPipelines());
    return apiPolicy;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy)

Example 59 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createUniqueCompositeAPI.

public static CompositeAPI.Builder createUniqueCompositeAPI() {
    Set<String> transport = new HashSet<>();
    transport.add(HTTP);
    HashMap permissionMap = new HashMap();
    permissionMap.put(DEVELOPER_ROLE_ID, 6);
    permissionMap.put(ADMIN_ROLE_ID, 15);
    permissionMap.put(ADMIN_ROLE_ID, 7);
    Application app = createDefaultApplication();
    // generate random name for each time when generating unique composite API
    app.setName(UUID.randomUUID().toString());
    try {
        DAOFactory.getApplicationDAO().addApplication(app);
    } catch (APIMgtDAOException e) {
        log.error("Error adding application", e);
    }
    CompositeAPI.Builder apiBuilder = new CompositeAPI.Builder().id(UUID.randomUUID().toString()).name(UUID.randomUUID().toString()).provider(UUID.randomUUID().toString()).version(API_VERSION).context(UUID.randomUUID().toString()).description("Get Food & Beverage Info").transport(transport).permissionMap(permissionMap).applicationId(app.getId()).createdTime(LocalDateTime.now()).createdBy(API_CREATOR).uriTemplates(Collections.emptyMap()).apiDefinition(apiDefinition).lastUpdatedTime(LocalDateTime.now()).threatProtectionPolicies(threatProtectionPolicies);
    return apiBuilder;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) HashMap(java.util.HashMap) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) Application(org.wso2.carbon.apimgt.core.models.Application) HashSet(java.util.HashSet)

Example 60 with API

use of org.wso2.carbon.apimgt.core.models.API in project carbon-apimgt by wso2.

the class SubscriptionCreationWorkflow method completeWorkflow.

public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
    if (subscription == null) {
        // this is when complete method is executed through workflow rest api
        subscription = apiSubscriptionDAO.getAPISubscription(getWorkflowReference());
    }
    WorkflowResponse response = workflowExecutor.complete(this);
    setStatus(response.getWorkflowStatus());
    APIMgtConstants.SubscriptionStatus subscriptionState = null;
    if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Subscription Creation workflow complete: Approved");
        }
        subscriptionState = APIMgtConstants.SubscriptionStatus.ACTIVE;
    } else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Subscription Creation workflow complete: Rejected");
        }
        subscriptionState = APIMgtConstants.SubscriptionStatus.REJECTED;
    }
    // Add subscription to gateway
    apiSubscriptionDAO.updateSubscriptionStatus(getWorkflowReference(), subscriptionState);
    updateWorkflowEntries(this);
    if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
        if (subscription.getApi() != null && subscription.getApplication() != null) {
            List<SubscriptionValidationData> subscriptionValidationDataList = apiSubscriptionDAO.getAPISubscriptionsOfAPIForValidation(subscription.getApi().getContext(), subscription.getApi().getVersion(), subscription.getApplication().getId());
            if (subscriptionValidationDataList != null && !subscriptionValidationDataList.isEmpty()) {
                apiGateway.addAPISubscription(subscriptionValidationDataList);
                if (log.isDebugEnabled()) {
                    log.debug("Subscription created for API : " + subscription.getApi().getName() + " with " + "application : " + subscription.getApplication().getName() + " has been successfully " + "published to gateway");
                }
            }
        }
    }
    return response;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) APIMgtConstants(org.wso2.carbon.apimgt.core.util.APIMgtConstants)

Aggregations

API (org.wso2.carbon.apimgt.core.models.API)359 Test (org.testng.annotations.Test)320 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)253 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)179 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)154 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)132 HashMap (java.util.HashMap)129 ArrayList (java.util.ArrayList)112 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)106 Test (org.junit.Test)83 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)83 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)82 SQLException (java.sql.SQLException)75 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)75 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)70 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)65 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)61 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)60 Connection (java.sql.Connection)58 Response (javax.ws.rs.core.Response)58