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());
}
}
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"));
}
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());
}
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;
}
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;
}
Aggregations