Search in sources :

Example 26 with Application

use of org.wso2.carbon.apimgt.core.models.Application 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 27 with Application

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

the class ApprovalWorkflowExecutor method complete.

/**
 * Complete the external process status
 * Based on the workflow status we will update the status column of the
 * Application table
 *
 * @param workFlow - Workflow
 */
public WorkflowResponse complete(Workflow workFlow) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("Executing complete() in Workflow for " + workFlow.getWorkflowType());
    }
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(workFlow.getStatus());
    return workflowResponse;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse)

Example 28 with Application

use of org.wso2.carbon.apimgt.core.models.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 29 with Application

use of org.wso2.carbon.apimgt.core.models.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 30 with Application

use of org.wso2.carbon.apimgt.core.models.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)

Aggregations

Application (org.wso2.carbon.apimgt.core.models.Application)121 Test (org.testng.annotations.Test)91 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)61 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 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)40 ArrayList (java.util.ArrayList)35 SQLException (java.sql.SQLException)33 API (org.wso2.carbon.apimgt.core.models.API)33 Test (org.junit.Test)29 BeforeTest (org.testng.annotations.BeforeTest)29 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)29 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)27 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)27 Connection (java.sql.Connection)26 PreparedStatement (java.sql.PreparedStatement)26 HashMap (java.util.HashMap)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)25