use of org.wso2.carbon.apimgt.core.api.WorkflowResponse in project carbon-apimgt by wso2.
the class SubscriptionUpdateSimpleWorkflowExecutor method complete.
/**
* This method completes subscription update 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
*/
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
SubscriptionWorkflowDTO subscriptionWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
try {
if (subscriptionWorkflowDTO.getStatus() == WorkflowStatus.APPROVED) {
apiMgtDAO.updateSubscriptionStatusAndTier(Integer.parseInt(subscriptionWorkflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
} else if (subscriptionWorkflowDTO.getStatus() == WorkflowStatus.CREATED || subscriptionWorkflowDTO.getStatus() == WorkflowStatus.REGISTERED) {
apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(subscriptionWorkflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.TIER_UPDATE_PENDING);
} else if (subscriptionWorkflowDTO.getStatus() == WorkflowStatus.REJECTED) {
apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(subscriptionWorkflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.UNBLOCKED);
}
} catch (APIManagementException e) {
log.error("Could not complete subscription update workflow", e);
throw new WorkflowException("Could not complete subscription update workflow", e);
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.core.api.WorkflowResponse in project carbon-apimgt by wso2.
the class SubscriptionUpdateSimpleWorkflowExecutor method execute.
/**
* This method executes subscription update 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;
}
use of org.wso2.carbon.apimgt.core.api.WorkflowResponse in project carbon-apimgt by wso2.
the class UserSignUpSimpleWorkflowExecutor method complete.
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("User Sign Up [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + "Workflow State : " + workflowDTO.getStatus());
}
String tenantDomain = workflowDTO.getTenantDomain();
try {
UserRegistrationConfigDTO signupConfig = SelfSignUpUtil.getSignupConfiguration(tenantDomain);
String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(workflowDTO.getWorkflowReference());
updateRolesOfUser(tenantAwareUserName, SelfSignUpUtil.getRoleNames(signupConfig), tenantDomain);
} catch (APIManagementException e) {
throw new WorkflowException("Error while accessing signup configuration", e);
} catch (Exception e) {
throw new WorkflowException("Error while assigning role to user", e);
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.core.api.WorkflowResponse in project carbon-apimgt by wso2.
the class APIStateChangeWSWorkflowExecutor method execute.
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Executing API State change Workflow.");
log.debug("Execute workflowDTO " + workflowDTO.toString());
}
if (stateList != null) {
Map<String, List<String>> stateActionMap = getSelectedStatesToApprove();
APIStateWorkflowDTO apiStateWorkFlowDTO = (APIStateWorkflowDTO) workflowDTO;
if (stateActionMap.containsKey(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()) && stateActionMap.get(apiStateWorkFlowDTO.getApiCurrentState().toUpperCase()).contains(apiStateWorkFlowDTO.getApiLCAction())) {
// set the auth application related info. This will be used to call the callback service
setOAuthApplicationInfo(apiStateWorkFlowDTO);
// build request payload
String jsonPayload = buildPayloadForBPMNProcess(apiStateWorkFlowDTO);
if (log.isDebugEnabled()) {
log.debug("APIStateChange payload: " + jsonPayload);
}
if (serviceEndpoint == null) {
// set the bps endpoint from the global configurations
WorkflowProperties workflowProperties = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration().getWorkflowProperties();
serviceEndpoint = workflowProperties.getServerUrl();
}
URL serviceEndpointURL = new URL(serviceEndpoint);
HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
HttpPost httpPost = new HttpPost(serviceEndpoint + RUNTIME_INSTANCE_RESOURCE_PATH);
// Generate the basic auth header using provided user credentials
String authHeader = getBasicAuthHeader();
httpPost.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
StringEntity requestEntity = new StringEntity(jsonPayload, ContentType.APPLICATION_JSON);
httpPost.setEntity(requestEntity);
try {
HttpResponse response = httpClient.execute(httpPost);
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
String error = "Error while starting the process: " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase();
log.error(error);
throw new WorkflowException(error);
}
} catch (ClientProtocolException e) {
String errorMsg = "Error while creating the http client";
log.error(errorMsg, e);
throw new WorkflowException(errorMsg, e);
} catch (IOException e) {
String errorMsg = "Error while connecting to the BPMN process server from the WorkflowExecutor.";
log.error(errorMsg, e);
throw new WorkflowException(errorMsg, e);
} finally {
httpPost.reset();
}
super.execute(workflowDTO);
} else {
// For any other states, act as simpleworkflow executor.
workflowDTO.setStatus(WorkflowStatus.APPROVED);
// calling super.complete() instead of complete() to act as the simpleworkflow executor
super.complete(workflowDTO);
}
} else {
String msg = "State change list is not provided. Please check <stateList> element in ";
log.error(msg);
throw new WorkflowException(msg);
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.core.api.WorkflowResponse in project carbon-apimgt by wso2.
the class AbstractApplicationRegistrationWorkflowExecutor method complete.
public WorkflowResponse complete(WorkflowDTO workFlowDTO) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Completing AbstractApplicationRegistrationWorkflowExecutor...");
}
super.complete(workFlowDTO);
ApiMgtDAO dao = ApiMgtDAO.getInstance();
try {
String status = null;
if ("CREATED".equals(workFlowDTO.getStatus().toString())) {
status = APIConstants.AppRegistrationStatus.REGISTRATION_CREATED;
} else if ("REJECTED".equals(workFlowDTO.getStatus().toString())) {
status = APIConstants.AppRegistrationStatus.REGISTRATION_REJECTED;
} else if ("APPROVED".equals(workFlowDTO.getStatus().toString())) {
status = APIConstants.AppRegistrationStatus.REGISTRATION_APPROVED;
}
ApplicationRegistrationWorkflowDTO regWorkFlowDTO;
if (workFlowDTO instanceof ApplicationRegistrationWorkflowDTO) {
regWorkFlowDTO = (ApplicationRegistrationWorkflowDTO) workFlowDTO;
} else {
String message = "Invalid workflow type found";
log.error(message);
throw new WorkflowException(message);
}
dao.populateAppRegistrationWorkflowDTO(regWorkFlowDTO);
dao.updateApplicationRegistration(status, regWorkFlowDTO.getKeyType(), regWorkFlowDTO.getApplication().getId(), regWorkFlowDTO.getKeyManager());
} catch (APIManagementException e) {
log.error("Error while completing Application Registration entry.", e);
throw new WorkflowException("Error while completing Application Registration entry.", e);
}
return new GeneralWorkflowResponse();
}
Aggregations