Search in sources :

Example 1 with ApplicationWorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationDeletionSimpleWorkflowExecutor method complete.

@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
    ApplicationWorkflowDTO applicationWorkflowDTO = (ApplicationWorkflowDTO) workflowDTO;
    Application application = applicationWorkflowDTO.getApplication();
    String errorMsg = null;
    try {
        apiMgtDAO.deleteApplication(application);
    } catch (APIManagementException e) {
        if (e.getMessage() == null) {
            errorMsg = "Couldn't complete simple application deletion workflow for application: " + application.getName();
        } else {
            errorMsg = e.getMessage();
        }
        throw new WorkflowException(errorMsg, e);
    }
    return new GeneralWorkflowResponse();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 2 with ApplicationWorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO 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;
}
Also used : WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)

Example 3 with ApplicationWorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO 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());
    }
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionEvent) ApplicationRegistrationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO) ApplicationEvent(org.wso2.carbon.apimgt.impl.notifier.events.ApplicationEvent) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) ApplicationRegistrationEvent(org.wso2.carbon.apimgt.impl.notifier.events.ApplicationRegistrationEvent) APIEvent(org.wso2.carbon.apimgt.impl.notifier.events.APIEvent) ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) SubscriptionWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 4 with ApplicationWorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationCreationSimpleWorkflowExecutorTest method init.

@Before
public void init() {
    applicationCreationSimpleWorkflowExecutor = new ApplicationCreationSimpleWorkflowExecutor();
    PowerMockito.mockStatic(ApiMgtDAO.class);
    apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    workflowDTO = new ApplicationWorkflowDTO();
    workflowDTO.setWorkflowReference("1");
}
Also used : ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Before(org.junit.Before)

Example 5 with ApplicationWorkflowDTO

use of org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO in project carbon-apimgt by wso2.

the class ApplicationDeletionSimpleWorkflowExecutorTest method init.

@Before
public void init() {
    applicationDeletionSimpleWorkflowExecutor = new ApplicationDeletionSimpleWorkflowExecutor();
    PowerMockito.mockStatic(ApiMgtDAO.class);
    apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
    PowerMockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
    workflowDTO = new ApplicationWorkflowDTO();
    workflowDTO.setWorkflowReference("1");
    application = new Application("test", new Subscriber("testUser"));
    workflowDTO.setApplication(application);
}
Also used : ApplicationWorkflowDTO(org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO) Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Application(org.wso2.carbon.apimgt.api.model.Application) Before(org.junit.Before)

Aggregations

ApplicationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO)15 Application (org.wso2.carbon.apimgt.api.model.Application)11 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)7 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ServiceReferenceHolderMockCreator (org.wso2.carbon.apimgt.impl.ServiceReferenceHolderMockCreator)6 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)4 ApplicationRegistrationWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.ApplicationRegistrationWorkflowDTO)4 SubscriptionWorkflowDTO (org.wso2.carbon.apimgt.impl.dto.SubscriptionWorkflowDTO)4 WorkflowDTO (org.wso2.carbon.apimgt.impl.dto.WorkflowDTO)3 ApplicationEvent (org.wso2.carbon.apimgt.impl.notifier.events.ApplicationEvent)3 XMLStreamException (javax.xml.stream.XMLStreamException)2 JSONObject (org.json.simple.JSONObject)2 Before (org.junit.Before)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 ApplicationRegistrationEvent (org.wso2.carbon.apimgt.impl.notifier.events.ApplicationRegistrationEvent)2 RecommenderDetailsExtractor (org.wso2.carbon.apimgt.impl.recommendationmgt.RecommenderDetailsExtractor)2 RecommenderEventPublisher (org.wso2.carbon.apimgt.impl.recommendationmgt.RecommenderEventPublisher)2 WorkflowException (org.wso2.carbon.apimgt.impl.workflow.WorkflowException)2 WorkflowExecutor (org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor)2