Search in sources :

Example 56 with WorkflowResponse

use of org.wso2.carbon.apimgt.api.WorkflowResponse in project carbon-apimgt by wso2.

the class APIStoreImpl method deleteAPISubscription.

/**
 * @see APIStore#deleteAPISubscription(String)
 */
@Override
public WorkflowResponse deleteAPISubscription(String subscriptionId) throws APIManagementException {
    try {
        WorkflowExecutor removeSubscriptionWFExecutor = WorkflowExecutorFactory.getInstance().getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION);
        // check for pending subscription creation
        if (subscriptionId == null) {
            String errorMsg = "Subscription Id is not provided";
            log.error(errorMsg);
            throw new APIManagementException(errorMsg, ExceptionCodes.PARAMETER_NOT_PROVIDED);
        }
        Subscription subscription = getApiSubscriptionDAO().getAPISubscription(subscriptionId);
        if (subscription == null) {
            String errorMsg = "Subscription not found for the id - " + subscriptionId;
            log.error(errorMsg);
            throw new APIManagementException(errorMsg, ExceptionCodes.SUBSCRIPTION_NOT_FOUND);
        } else {
            // remove pending tasks for subscription creation first
            cleanupPendingTaskForSubscriptionDeletion(subscription);
            SubscriptionDeletionWorkflow workflow = new SubscriptionDeletionWorkflow(getApiSubscriptionDAO(), getWorkflowDAO(), getApiGateway());
            workflow.setWorkflowReference(subscriptionId);
            workflow.setSubscription(subscription);
            workflow.setWorkflowType(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION);
            workflow.setStatus(WorkflowStatus.CREATED);
            workflow.setCreatedTime(LocalDateTime.now());
            workflow.setExternalWorkflowReference(UUID.randomUUID().toString());
            workflow.setSubscriber(getUsername());
            String workflowDescription = "API [ " + subscription.getApi().getName() + " - " + subscription.getApi().getVersion() + " ] subscription deletion request from subscriber - " + getUsername() + "  for the application - " + subscription.getApplication().getName() + "";
            workflow.setWorkflowDescription(workflowDescription);
            WorkflowResponse response = removeSubscriptionWFExecutor.execute(workflow);
            workflow.setStatus(response.getWorkflowStatus());
            if (WorkflowStatus.CREATED != response.getWorkflowStatus()) {
                completeWorkflow(removeSubscriptionWFExecutor, workflow);
            } else {
                // add entry to workflow table if it is only in pending state
                // haven't changed the subscription's state to allow to use it till approval
                addWorkflowEntries(workflow);
            }
            return response;
        }
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while deleting api subscription - " + subscriptionId;
        log.error(errorMsg, e);
        throw new APIManagementException(errorMsg, e, e.getErrorHandler());
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) WorkflowExecutor(org.wso2.carbon.apimgt.core.api.WorkflowExecutor) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) SubscriptionDeletionWorkflow(org.wso2.carbon.apimgt.core.workflow.SubscriptionDeletionWorkflow)

Example 57 with WorkflowResponse

use of org.wso2.carbon.apimgt.api.WorkflowResponse in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method testApisChangeLifecyclePostException.

@Test
public void testApisChangeLifecyclePostException() throws Exception {
    printTestMethodName();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
    String action = "CheckListItemChange";
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
    Map<String, Boolean> lifecycleChecklistMap = new HashMap<>();
    PowerMockito.mockStatic(RestAPIPublisherUtil.class);
    PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
    String apiId = UUID.randomUUID().toString();
    Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.API_TYPE_INVALID)).when(apiPublisher).updateCheckListItem(apiId, action, lifecycleChecklistMap);
    Response response = apisApiService.apisChangeLifecyclePost(action, apiId, null, null, null, getRequest());
    assertEquals(response.getStatus(), 400);
    assertTrue(response.getEntity().toString().contains("API Type specified is invalid"));
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 58 with WorkflowResponse

use of org.wso2.carbon.apimgt.api.WorkflowResponse in project carbon-apimgt by wso2.

the class TestMappingUtilTestCase method testWorkflowResponseToWorkflowResponseDTOMapping.

@Test(description = "Workflow response to Workflow response DTO mapping ")
void testWorkflowResponseToWorkflowResponseDTOMapping() {
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
    WorkflowResponseDTO workflowResponseDTO = MappingUtil.toWorkflowResponseDTO(workflowResponse);
    assertEquals(workflowResponse.getWorkflowStatus().name(), workflowResponseDTO.getWorkflowStatus().name());
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.WorkflowResponseDTO) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Test(org.testng.annotations.Test)

Example 59 with WorkflowResponse

use of org.wso2.carbon.apimgt.api.WorkflowResponse in project carbon-apimgt by wso2.

the class SampleWorkFlowExecutor method execute.

@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    WorkflowResponse workflowResponse = complete(workflowDTO);
    if (workflowDTO instanceof ApplicationRegistrationWorkflowDTO) {
        OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo();
        AccessTokenInfo accessTokenInfo = new AccessTokenInfo();
        ((ApplicationRegistrationWorkflowDTO) workflowDTO).setApplicationInfo(oAuthApplicationInfo);
        ((ApplicationRegistrationWorkflowDTO) workflowDTO).setAccessTokenInfo(accessTokenInfo);
    }
    return workflowResponse;
}
Also used : AccessTokenInfo(org.wso2.carbon.apimgt.api.model.AccessTokenInfo) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) OAuthApplicationInfo(org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo) WorkflowResponse(org.wso2.carbon.apimgt.api.WorkflowResponse)

Example 60 with WorkflowResponse

use of org.wso2.carbon.apimgt.api.WorkflowResponse in project carbon-apimgt by wso2.

the class APIProviderImpl method executeStateChangeWorkflow.

/**
 * Execute state change workflow
 *
 * @param currentStatus     Current Status of the API or API Product
 * @param action            LC state change action
 * @param apiName           Name of API or API Product
 * @param apiContext        Context of API or API Product
 * @param apiType           API Type
 * @param apiVersion        Version of API or API Product
 * @param providerName      Provider of API or API Product
 * @param apiOrApiProductId Unique ID API or API Product
 * @param uuid              UUID of the API or API Product
 * @param gatewayVendor     Gateway vendor
 * @param workflowType      Workflow Type
 * @return  APIStateChangeResponse
 * @throws APIManagementException Error when executing the state change workflow
 */
private APIStateChangeResponse executeStateChangeWorkflow(String currentStatus, String action, String apiName, String apiContext, String apiType, String apiVersion, String providerName, int apiOrApiProductId, String uuid, String gatewayVendor, String workflowType) throws APIManagementException {
    APIStateChangeResponse response = new APIStateChangeResponse();
    try {
        WorkflowExecutor apiStateWFExecutor = WorkflowExecutorFactory.getInstance().getWorkflowExecutor(workflowType);
        APIStateWorkflowDTO apiStateWorkflow = setAPIStateWorkflowDTOParameters(currentStatus, action, apiName, apiContext, apiType, apiVersion, providerName, apiOrApiProductId, uuid, gatewayVendor, workflowType, apiStateWFExecutor);
        WorkflowResponse workflowResponse = apiStateWFExecutor.execute(apiStateWorkflow);
        response.setWorkflowResponse(workflowResponse);
    } catch (WorkflowException e) {
        handleException("Failed to execute workflow for life cycle status change : " + e.getMessage(), e);
    }
    return response;
}
Also used : APIStateChangeResponse(org.wso2.carbon.apimgt.api.model.APIStateChangeResponse) WorkflowException(org.wso2.carbon.apimgt.impl.workflow.WorkflowException) APIStateWorkflowDTO(org.wso2.carbon.apimgt.impl.workflow.APIStateWorkflowDTO) WorkflowResponse(org.wso2.carbon.apimgt.api.WorkflowResponse) WorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)

Aggregations

WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)37 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)20 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)15 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)14 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)14 Application (org.wso2.carbon.apimgt.core.models.Application)13 HashMap (java.util.HashMap)11 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)11 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 WorkflowResponse (org.wso2.carbon.apimgt.api.WorkflowResponse)10 WorkflowExecutor (org.wso2.carbon.apimgt.core.api.WorkflowExecutor)9 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)9 Response (javax.ws.rs.core.Response)8 Test (org.testng.annotations.Test)8 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)8 Application (org.wso2.carbon.apimgt.api.model.Application)7 URI (java.net.URI)6 Map (java.util.Map)6 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)6