Search in sources :

Example 26 with Application

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application 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 27 with Application

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application 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)

Example 28 with Application

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application in project carbon-apimgt by wso2.

the class WorkflowConfigHolder method load.

public void load() throws WorkflowException {
    workflowExecutorMap = new ConcurrentHashMap<>();
    try {
        WorkflowConfig config = WorkflowExtensionsConfigBuilder.getWorkflowConfig();
        // Load application creation workflow configurations
        loadWorkflowConfigurations(config.getApplicationCreation(), WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
        // Load application deletion workflow configurations
        loadWorkflowConfigurations(config.getApplicationDeletion(), WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION);
        // Load subscription creation workflow configurations
        loadWorkflowConfigurations(config.getSubscriptionCreation(), WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
        // Load subscription deletion workflow configurations
        loadWorkflowConfigurations(config.getSubscriptionDeletion(), WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION);
        // Load api state change workflow configurations
        loadWorkflowConfigurations(config.getApiStateChange(), WorkflowConstants.WF_TYPE_AM_API_STATE);
        // Load application update workflow configurations
        loadWorkflowConfigurations(config.getApplicationUpdate(), WorkflowConstants.WF_TYPE_AM_APPLICATION_UPDATE);
    } catch (ClassNotFoundException e) {
        handleException("Unable to find class", e);
    } catch (InstantiationException e) {
        handleException("Unable to instantiate class", e);
    } catch (IllegalAccessException e) {
        handleException("Illegal attempt to invoke class methods", e);
    } catch (WorkflowException e) {
        handleException("Unable to load workflow executor class", e);
    }
}
Also used : WorkflowConfig(org.wso2.carbon.apimgt.core.models.WorkflowConfig) WorkflowException(org.wso2.carbon.apimgt.core.exception.WorkflowException)

Example 29 with Application

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultApplication.

public static Application createDefaultApplication() {
    // created by admin
    Application application = new Application(TEST_APP_1, ADMIN);
    application.setId(UUID.randomUUID().toString());
    application.setDescription("This is a test application");
    application.setStatus(APIMgtConstants.ApplicationStatus.APPLICATION_CREATED);
    application.setPolicy(fiftyPerMinApplicationPolicy);
    application.setCreatedTime(LocalDateTime.now());
    application.setUpdatedUser(ADMIN);
    application.setUpdatedTime(LocalDateTime.now());
    return application;
}
Also used : Application(org.wso2.carbon.apimgt.core.models.Application)

Example 30 with Application

use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultBlockCondition.

public static BlockConditions createDefaultBlockCondition(String conditionType) {
    BlockConditions blockConditions = new BlockConditions();
    blockConditions.setConditionType(conditionType);
    blockConditions.setEnabled(true);
    if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_IP)) {
        blockConditions.setConditionValue(SAMPLE_IP_1);
    } else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE)) {
        blockConditions.setStartingIP(SAMPLE_IP_1);
        blockConditions.setEndingIP(SAMPLE_IP_2);
    } else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_API)) {
        try {
            API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
            API api = apiBuilder.build();
            DAOFactory.getApiDAO().addAPI(api);
            blockConditions.setConditionValue(api.getContext());
        } catch (APIMgtDAOException e) {
            log.error("Error while adding default api in default block condition", e);
        }
    } else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_APPLICATION)) {
        try {
            Application app = createDefaultApplication();
            DAOFactory.getApplicationDAO().addApplication(app);
            blockConditions.setConditionValue(app.getId() + ":" + app.getName());
        } catch (APIMgtDAOException e) {
            log.error("Error while adding default app in default block condition", e);
        }
    } else if (conditionType.equals(APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_USER)) {
        blockConditions.setConditionValue(ADMIN);
    }
    return blockConditions;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) Application(org.wso2.carbon.apimgt.core.models.Application)

Aggregations

Test (org.testng.annotations.Test)156 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)143 Application (org.wso2.carbon.apimgt.api.model.Application)130 Application (org.wso2.carbon.apimgt.core.models.Application)121 Test (org.junit.Test)102 ArrayList (java.util.ArrayList)98 SQLException (java.sql.SQLException)94 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)94 PreparedStatement (java.sql.PreparedStatement)88 Connection (java.sql.Connection)83 ResultSet (java.sql.ResultSet)73 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)71 HashMap (java.util.HashMap)70 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)63 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)63 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)61 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)60 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)59 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)58 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)57