use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.
the class DefaultWorkflowExecutor method execute.
/**
* {@inheritDoc}
*/
@Override
public WorkflowResponse execute(Workflow workFlow) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Executing execute() in Workflow for " + workFlow.getWorkflowType());
}
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
// set the state to approved
workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
return workflowResponse;
}
use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.
the class SubscriptionDeletionWorkflow method completeWorkflow.
public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
if (subscription == null) {
// this is when complete method is executed through workflow rest api
this.subscription = apiSubscriptionDAO.getAPISubscription(getWorkflowReference());
}
WorkflowResponse response = workflowExecutor.complete(this);
setStatus(response.getWorkflowStatus());
List<SubscriptionValidationData> subscriptionValidationDataList = null;
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Subscription deletion workflow complete: Approved");
}
if (subscription.getApi() != null && subscription.getApplication() != null) {
subscriptionValidationDataList = apiSubscriptionDAO.getAPISubscriptionsOfAPIForValidation(subscription.getApi().getContext(), subscription.getApi().getVersion(), subscription.getApplication().getId());
}
apiSubscriptionDAO.deleteAPISubscription(getWorkflowReference());
} else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Subscription deletion workflow complete: Rejected");
}
}
updateWorkflowEntries(this);
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (subscriptionValidationDataList != null && !subscriptionValidationDataList.isEmpty()) {
apiGateway.deleteAPISubscription(subscriptionValidationDataList);
if (log.isDebugEnabled()) {
log.debug("Subscription for API : " + subscription.getApi().getName() + " with " + "application : " + subscription.getApplication().getName() + " has been successfully " + "removed from gateway");
}
}
}
return response;
}
use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.
the class WorkflowExecutorFactory method createWorkflow.
/**
* Create a DTO object related to a given workflow type.
*
* @param workflowType Type of the workflow.
* @return WorkFlow instance
*/
public Workflow createWorkflow(String workflowType) throws APIMgtDAOException {
Workflow workflow = null;
if (WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION.equals(workflowType)) {
workflow = new ApplicationCreationWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
workflow.setWorkflowType(workflowType);
} else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION.equals(workflowType)) {
workflow = new ApplicationDeletionWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
workflow.setWorkflowType(workflowType);
} else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION.equals(workflowType)) {
workflow = new SubscriptionCreationWorkflow(DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
workflow.setWorkflowType(workflowType);
} else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION.equals(workflowType)) {
workflow = new SubscriptionDeletionWorkflow(DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
workflow.setWorkflowType(workflowType);
} else if (WorkflowConstants.WF_TYPE_AM_API_STATE.equals(workflowType)) {
workflow = new APIStateChangeWorkflow(DAOFactory.getApiDAO(), DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().geApiLifecycleManager(), APIManagerFactory.getInstance().getApiGateway(), DAOFactory.getLabelDAO());
workflow.setWorkflowType(workflowType);
} else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_UPDATE.equals(workflowType)) {
workflow = new ApplicationUpdateWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
workflow.setWorkflowType(workflowType);
} else {
throw new APIMgtDAOException("Invalid workflow type: " + workflowType + " specified", ExceptionCodes.WORKFLOW_INVALID_WFTYPE);
}
return workflow;
}
use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testTemovePendingLifecycleWorkflowTaskForAPIForAPIWithoutPendingLCState.
@Test(description = "Exception when removing api pending lc status change request for an api", expectedExceptions = APIManagementException.class)
public void testTemovePendingLifecycleWorkflowTaskForAPIForAPIWithoutPendingLCState() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiLifecycleManager, apiDAO, workflowDAO, gateway);
APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
builder.workflowStatus(APILCWorkflowStatus.PENDING.toString());
API api = builder.build();
String uuid = api.getId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
/*
Mockito.doThrow(new APIMgtDAOException("Error while executing sql query")).when(workflowDAO)
.getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE);
*/
Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE)).thenThrow(new APIMgtDAOException("Error occurred while changing api lifecycle workflow status"));
apiPublisher.removePendingLifecycleWorkflowTaskForAPI(uuid);
Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE);
}
use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testUpdateAPIWorkflowStatus.
@Test(description = "Update API Status when its workflow status is pending", expectedExceptions = APIManagementException.class)
public void testUpdateAPIWorkflowStatus() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiLifecycleManager, apiDAO, workflowDAO, gateway);
API api = SampleTestObjectCreator.createDefaultAPI().workflowStatus(APIMgtConstants.APILCWorkflowStatus.PENDING.toString()).build();
String uuid = api.getId();
String lcState = api.getLifeCycleStatus();
String lifecycleId = api.getLifecycleInstanceId();
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
LifecycleState lifecycleState = SampleTestObjectCreator.getMockLifecycleStateObject(lifecycleId);
Mockito.when(apiLifecycleManager.getLifecycleDataForState(lifecycleId, lcState)).thenReturn(lifecycleState);
Mockito.when(apiLifecycleManager.executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api)).thenReturn(lifecycleState);
API.APIBuilder apiBuilder = new API.APIBuilder(api);
apiBuilder.lifecycleState(lifecycleState);
apiBuilder.updatedBy(USER);
api = apiBuilder.build();
lifecycleState.setState(APIStatus.PUBLISHED.getStatus());
apiPublisher.updateAPIStatus(uuid, APIStatus.PUBLISHED.getStatus(), new HashMap<>());
Mockito.verify(apiLifecycleManager, Mockito.times(1)).executeLifecycleEvent(APIStatus.CREATED.getStatus(), APIStatus.PUBLISHED.getStatus(), lifecycleId, USER, api);
}
Aggregations