use of org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO in project carbon-apimgt by wso2.
the class SubscriptionCreationApprovalWorkflowExecutor method execute.
/**
* Execute the Application Creation workflow approval process.
*
* @param workflowDTO
*/
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Executing Subscription Creation Webservice Workflow.. ");
}
SubscriptionWorkflowDTO subsWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
String message = "Approve API " + subsWorkflowDTO.getApiName() + " - " + subsWorkflowDTO.getApiVersion() + " subscription creation request from subscriber - " + subsWorkflowDTO.getSubscriber() + " for the application - " + subsWorkflowDTO.getApplicationName();
workflowDTO.setWorkflowDescription(message);
workflowDTO.setProperties("apiName", subsWorkflowDTO.getApiName());
workflowDTO.setProperties("apiVersion", subsWorkflowDTO.getApiVersion());
workflowDTO.setProperties("subscriber", subsWorkflowDTO.getSubscriber());
workflowDTO.setProperties("applicationName", subsWorkflowDTO.getApplicationName());
super.execute(workflowDTO);
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO in project carbon-apimgt by wso2.
the class SubscriptionUpdateApprovalWorkflowExecutor method complete.
/**
* Complete the Approval workflow executor for Subscription creation.
*
* @param workflowDTO
*/
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
workflowDTO.setUpdatedTime(System.currentTimeMillis());
super.complete(workflowDTO);
if (log.isDebugEnabled()) {
String logMessage = "Subscription Update [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + " Workflow State : " + workflowDTO.getStatus();
log.debug(logMessage);
}
SubscriptionWorkflowDTO subscriptionWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
if (WorkflowStatus.APPROVED.equals(workflowDTO.getStatus())) {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
try {
apiMgtDAO.updateSubscriptionStatusAndTier(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);
}
} else if (WorkflowStatus.REJECTED.equals(workflowDTO.getStatus())) {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
try {
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.impl.dto.SubscriptionWorkflowDTO in project carbon-apimgt by wso2.
the class SubscriptionUpdateWSWorkflowExecutor method execute.
/**
* This method is used to execute the workflow without giving a workflow response back to the caller to execute
* some other task after completing the workflow
*
* @param workflowDTO - The WorkflowDTO which contains workflow contextual information related to the workflow.
* @throws WorkflowException
*/
@Override
public WorkflowResponse execute(WorkflowDTO workflowDTO) throws WorkflowException {
try {
String action = WorkflowConstants.UPDATE_SUBSCRIPTION_WS_ACTION;
ServiceClient client = getClient(action);
String payload = "<wor:SubscriptionApprovalWorkFlowProcessRequest " + " xmlns:wor=\"http://workflow.subscription.apimgt.carbon.wso2.org\">\n" + " <wor:apiName>$1</wor:apiName>\n" + " <wor:apiVersion>$2</wor:apiVersion>\n" + " <wor:apiContext>$3</wor:apiContext>\n" + " <wor:apiProvider>$4</wor:apiProvider>\n" + " <wor:subscriber>$5</wor:subscriber>\n" + " <wor:applicationName>$6</wor:applicationName>\n" + " <wor:tierName>$7</wor:tierName>\n" + " <wor:workflowExternalRef>$8</wor:workflowExternalRef>\n" + " <wor:callBackURL>$9</wor:callBackURL>\n" + " </wor:SubscriptionApprovalWorkFlowProcessRequest>";
SubscriptionWorkflowDTO subsWorkflowDTO = (SubscriptionWorkflowDTO) workflowDTO;
String callBackURL = subsWorkflowDTO.getCallbackUrl();
payload = payload.replace("$1", subsWorkflowDTO.getApiName());
payload = payload.replace("$2", subsWorkflowDTO.getApiVersion());
payload = payload.replace("$3", subsWorkflowDTO.getApiContext());
payload = payload.replace("$4", subsWorkflowDTO.getApiProvider());
payload = payload.replace("$5", subsWorkflowDTO.getSubscriber());
payload = payload.replace("$6", subsWorkflowDTO.getApplicationName());
payload = payload.replace("$7", subsWorkflowDTO.getTierName());
payload = payload.replace("$8", subsWorkflowDTO.getExternalWorkflowReference());
payload = payload.replace("$9", callBackURL != null ? callBackURL : "?");
client.fireAndForget(AXIOMUtil.stringToOM(payload));
super.execute(workflowDTO);
} catch (AxisFault axisFault) {
log.error("Error sending out message", axisFault);
throw new WorkflowException("Error sending out message", axisFault);
} catch (XMLStreamException e) {
log.error("Error converting String to OMElement", e);
throw new WorkflowException("Error converting String to OMElement", e);
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO in project carbon-apimgt by wso2.
the class WorkflowExecutorFactory method createWorkflowDTO.
/**
* Create a DTO object related to a given workflow type.
* @param wfType Type of the workflow.
*/
public WorkflowDTO createWorkflowDTO(String wfType) {
WorkflowDTO workflowDTO = null;
if (WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION.equals(wfType)) {
workflowDTO = new ApplicationWorkflowDTO();
workflowDTO.setWorkflowType(wfType);
} else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_REGISTRATION_PRODUCTION.equals(wfType)) {
workflowDTO = new ApplicationRegistrationWorkflowDTO();
((ApplicationRegistrationWorkflowDTO) workflowDTO).setKeyType(APIConstants.API_KEY_TYPE_PRODUCTION);
workflowDTO.setWorkflowType(wfType);
} else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_REGISTRATION_SANDBOX.equals(wfType)) {
workflowDTO = new ApplicationRegistrationWorkflowDTO();
((ApplicationRegistrationWorkflowDTO) workflowDTO).setKeyType(APIConstants.API_KEY_TYPE_SANDBOX);
workflowDTO.setWorkflowType(wfType);
} else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION.equals(wfType)) {
workflowDTO = new SubscriptionWorkflowDTO();
workflowDTO.setWorkflowType(wfType);
} else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_UPDATE.equals(wfType)) {
workflowDTO = new SubscriptionWorkflowDTO();
workflowDTO.setWorkflowType(wfType);
} else if (WorkflowConstants.WF_TYPE_AM_USER_SIGNUP.equals(wfType)) {
workflowDTO = new WorkflowDTO();
workflowDTO.setWorkflowType(wfType);
} else if (WorkflowConstants.WF_TYPE_AM_API_STATE.equals(wfType) || WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE.equals(wfType)) {
workflowDTO = new APIStateWorkflowDTO();
workflowDTO.setWorkflowType(wfType);
}
return workflowDTO;
}
use of org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO in project carbon-apimgt by wso2.
the class WorkflowUtils method sendNotificationAfterWFComplete.
public static void sendNotificationAfterWFComplete(WorkflowDTO workflowDTO, String wfType) throws APIManagementException {
if (WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION.equalsIgnoreCase(wfType)) {
String applicationId = workflowDTO.getWorkflowReference();
int appId = Integer.parseInt(applicationId);
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
Application application = apiMgtDAO.getApplicationById(appId);
ApplicationWorkflowDTO appWFDto = (ApplicationWorkflowDTO) workflowDTO;
appWFDto.setApplication(application);
ApplicationEvent applicationEvent = new ApplicationEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.APPLICATION_CREATE.name(), appWFDto.getTenantId(), appWFDto.getTenantDomain(), appWFDto.getApplication().getId(), appWFDto.getApplication().getUUID(), appWFDto.getApplication().getName(), appWFDto.getApplication().getTokenType(), appWFDto.getApplication().getTier(), appWFDto.getApplication().getGroupId(), appWFDto.getApplication().getApplicationAttributes(), application.getSubscriber().getName());
APIUtil.sendNotification(applicationEvent, APIConstants.NotifierType.APPLICATION.name());
} else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION.equalsIgnoreCase(wfType)) {
ApplicationWorkflowDTO appWFDto = (ApplicationWorkflowDTO) workflowDTO;
ApplicationEvent applicationEvent = new ApplicationEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.APPLICATION_DELETE.name(), appWFDto.getTenantId(), appWFDto.getTenantDomain(), appWFDto.getApplication().getId(), appWFDto.getApplication().getUUID(), appWFDto.getApplication().getName(), appWFDto.getApplication().getTokenType(), appWFDto.getApplication().getTier(), appWFDto.getApplication().getGroupId(), appWFDto.getApplication().getApplicationAttributes(), "");
APIUtil.sendNotification(applicationEvent, APIConstants.NotifierType.APPLICATION.name());
} else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION.equalsIgnoreCase(wfType)) {
SubscriptionWorkflowDTO subWFDto = (SubscriptionWorkflowDTO) workflowDTO;
SubscribedAPI sub = ApiMgtDAO.getInstance().getSubscriptionById(Integer.parseInt(subWFDto.getWorkflowReference()));
SubscriptionEvent subscriptionEvent;
if (sub.getApiId() != null) {
subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_CREATE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getIdentifier().getId(), sub.getIdentifier().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
} else {
subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_CREATE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getProductId().getId(), sub.getProductId().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
}
APIUtil.sendNotification(subscriptionEvent, APIConstants.NotifierType.SUBSCRIPTIONS.name());
} else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_UPDATE.equalsIgnoreCase(wfType)) {
SubscriptionWorkflowDTO subWFDto = (SubscriptionWorkflowDTO) workflowDTO;
SubscribedAPI sub = ApiMgtDAO.getInstance().getSubscriptionById(Integer.parseInt(subWFDto.getWorkflowReference()));
SubscriptionEvent subscriptionEvent;
if (sub.getApiId() != null) {
subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_UPDATE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getIdentifier().getId(), sub.getIdentifier().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
} else {
subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_UPDATE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getProductId().getId(), sub.getProductId().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
}
APIUtil.sendNotification(subscriptionEvent, APIConstants.NotifierType.SUBSCRIPTIONS.name());
} else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION.equalsIgnoreCase(wfType)) {
SubscriptionWorkflowDTO subWFDto = (SubscriptionWorkflowDTO) workflowDTO;
SubscribedAPI sub = ApiMgtDAO.getInstance().getSubscriptionById(Integer.parseInt(subWFDto.getWorkflowReference()));
SubscriptionEvent subscriptionEvent;
if (sub.getApiId() != null) {
subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_DELETE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getIdentifier().getId(), sub.getIdentifier().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
} else {
subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_DELETE.name(), subWFDto.getTenantId(), subWFDto.getTenantDomain(), Integer.parseInt(subWFDto.getWorkflowReference()), sub.getUUID(), sub.getProductId().getId(), sub.getProductId().getUUID(), sub.getApplication().getId(), sub.getApplication().getUUID(), sub.getTier().getName(), sub.getSubCreatedStatus());
}
APIUtil.sendNotification(subscriptionEvent, APIConstants.NotifierType.SUBSCRIPTIONS.name());
} else if (WorkflowConstants.WF_TYPE_AM_API_STATE.equalsIgnoreCase(wfType) || WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE.equalsIgnoreCase(wfType)) {
APIStateWorkflowDTO apiStateWFDto = (APIStateWorkflowDTO) workflowDTO;
APIEvent apiEvent = new APIEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.API_LIFECYCLE_CHANGE.name(), apiStateWFDto.getTenantId(), apiStateWFDto.getTenantDomain(), apiStateWFDto.getApiName(), Integer.parseInt(apiStateWFDto.getWorkflowReference()), apiStateWFDto.getApiUUID(), apiStateWFDto.getApiVersion(), apiStateWFDto.getApiType(), apiStateWFDto.getApiContext(), apiStateWFDto.getApiProvider(), apiStateWFDto.getApiLCAction());
APIUtil.sendNotification(apiEvent, APIConstants.NotifierType.API.name());
} else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_REGISTRATION_PRODUCTION.equalsIgnoreCase(wfType)) {
ApplicationRegistrationWorkflowDTO appRegWFDto = (ApplicationRegistrationWorkflowDTO) workflowDTO;
ApplicationRegistrationEvent applicationRegistrationEvent = new ApplicationRegistrationEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.APPLICATION_REGISTRATION_CREATE.name(), appRegWFDto.getTenantId(), appRegWFDto.getTenantDomain(), appRegWFDto.getApplication().getId(), appRegWFDto.getApplication().getUUID(), appRegWFDto.getApplicationInfo().getClientId(), appRegWFDto.getApplication().getTokenType(), appRegWFDto.getKeyManager());
APIUtil.sendNotification(applicationRegistrationEvent, APIConstants.NotifierType.APPLICATION_REGISTRATION.name());
} else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_REGISTRATION_SANDBOX.equalsIgnoreCase(wfType)) {
ApplicationRegistrationWorkflowDTO appRegWFDto = (ApplicationRegistrationWorkflowDTO) workflowDTO;
ApplicationRegistrationEvent applicationRegistrationEvent = new ApplicationRegistrationEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.APPLICATION_REGISTRATION_CREATE.name(), appRegWFDto.getTenantId(), appRegWFDto.getTenantDomain(), appRegWFDto.getApplication().getId(), appRegWFDto.getApplication().getUUID(), appRegWFDto.getApplicationInfo().getClientId(), appRegWFDto.getApplication().getTokenType(), appRegWFDto.getKeyManager());
APIUtil.sendNotification(applicationRegistrationEvent, APIConstants.NotifierType.APPLICATION_REGISTRATION.name());
}
}
Aggregations