Search in sources :

Example 56 with WorkflowResponse

use of org.wso2.carbon.apimgt.core.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.core.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.core.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.core.api.WorkflowResponse in project carbon-apimgt by wso2.

the class SubscriptionCreationSimpleWorkflowExecutor method execute.

/**
 * This method executes subscription creation simple workflow and return workflow response back to the caller
 *
 * @param workflowDTO The WorkflowDTO which contains workflow contextual information related to the workflow
 * @return workflow response back to the caller
 * @throws WorkflowException Thrown when the workflow execution was not fully performed
 */
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
    workflowDTO.setStatus(WorkflowStatus.APPROVED);
    WorkflowResponse workflowResponse = complete(workflowDTO);
    return workflowResponse;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.api.WorkflowResponse)

Example 60 with WorkflowResponse

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

the class SubscriptionDeletionSimpleWorkflowExecutor method complete.

@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
    SubscriptionWorkflowDTO subWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
    String errorMsg = null;
    try {
        APIIdentifier identifier = new APIIdentifier(subWorkflowDTO.getApiProvider(), subWorkflowDTO.getApiName(), subWorkflowDTO.getApiVersion());
        identifier.setId(Integer.parseInt(subWorkflowDTO.getMetadata(WorkflowConstants.PayloadConstants.API_ID)));
        apiMgtDAO.removeSubscription(identifier, ((SubscriptionWorkflowDTO) workflowDTO).getApplicationId());
    } catch (APIManagementException e) {
        errorMsg = "Could not complete subscription deletion workflow for api: " + subWorkflowDTO.getApiName();
        throw new WorkflowException(errorMsg, e);
    }
    return new GeneralWorkflowResponse();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier)

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