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