use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testResumeWorkflow.
@Test
public void testResumeWorkflow() throws Exception {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
apiConsumer.apiMgtDAO = apiMgtDAO;
WorkflowDTO workflowDTO = new WorkflowDTO();
workflowDTO.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
when(apiMgtDAO.retrieveWorkflow(Mockito.anyString())).thenReturn(workflowDTO);
// Null input case
assertNotNull(apiConsumer.resumeWorkflow(null));
String[] args = { UUID.randomUUID().toString(), WorkflowStatus.CREATED.toString(), UUID.randomUUID().toString() };
assertNotNull(apiConsumer.resumeWorkflow(args));
Mockito.reset(apiMgtDAO);
workflowDTO.setTenantDomain("wso2.com");
when(apiMgtDAO.retrieveWorkflow(Mockito.anyString())).thenReturn(workflowDTO);
JSONObject row = apiConsumer.resumeWorkflow(args);
assertNotNull(row);
Mockito.reset(apiMgtDAO);
when(apiMgtDAO.retrieveWorkflow(Mockito.anyString())).thenThrow(APIManagementException.class);
when(APIUtil.isStringArray(args)).thenReturn(true);
row = apiConsumer.resumeWorkflow(args);
assertEquals("Error while resuming the workflow. null", row.get("message"));
// Workflow DAO null case
Mockito.reset(apiMgtDAO);
when(apiMgtDAO.retrieveWorkflow(Mockito.anyString())).thenReturn(null);
row = apiConsumer.resumeWorkflow(args);
assertNotNull(row);
assertEquals(true, row.get("error"));
assertEquals(500, row.get("statusCode"));
// Invalid status test
args[1] = "Invalid status";
Mockito.reset(apiMgtDAO);
when(apiMgtDAO.retrieveWorkflow(Mockito.anyString())).thenReturn(workflowDTO);
row = apiConsumer.resumeWorkflow(args);
assertEquals("Illegal argument provided. Valid values for status are APPROVED and REJECTED.", row.get("message"));
}
use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.
the class APIConsumerImpl method removeSubscription.
/**
* Removes a subscription specified by SubscribedAPI object
*
* @param subscription SubscribedAPI object
* @param organization Organization
* @throws APIManagementException
*/
@Override
public void removeSubscription(SubscribedAPI subscription, String organization) throws APIManagementException {
String uuid = subscription.getUUID();
if (subscription != null) {
Application application = subscription.getApplication();
Identifier identifier = subscription.getApiId() != null ? subscription.getApiId() : subscription.getProductId();
String userId = application.getSubscriber().getName();
removeSubscription(identifier, userId, application.getId(), organization);
if (log.isDebugEnabled()) {
String appName = application.getName();
String logMessage = "Identifier: " + identifier.toString() + " subscription (uuid : " + uuid + ") removed from app " + appName;
log.debug(logMessage);
}
// get the workflow state once the executor is executed.
WorkflowDTO wfDTO = apiMgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(application.getId()), WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION);
int tenantId = APIUtil.getTenantId(APIUtil.replaceEmailDomainBack(identifier.getProviderName()));
String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(identifier.getProviderName()));
// wfDTO is null when simple wf executor is used because wf state is not stored in the db and is always approved.
if (wfDTO != null) {
if (WorkflowStatus.APPROVED.equals(wfDTO.getStatus())) {
SubscriptionEvent subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_DELETE.name(), tenantId, tenantDomain, subscription.getSubscriptionId(), subscription.getUUID(), identifier.getId(), identifier.getUUID(), application.getId(), application.getUUID(), identifier.getTier(), subscription.getSubStatus());
APIUtil.sendNotification(subscriptionEvent, APIConstants.NotifierType.SUBSCRIPTIONS.name());
}
} else {
SubscriptionEvent subscriptionEvent = new SubscriptionEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.SUBSCRIPTIONS_DELETE.name(), tenantId, tenantDomain, subscription.getSubscriptionId(), subscription.getUUID(), identifier.getId(), identifier.getUUID(), application.getId(), application.getUUID(), identifier.getTier(), subscription.getSubStatus());
APIUtil.sendNotification(subscriptionEvent, APIConstants.NotifierType.SUBSCRIPTIONS.name());
}
} else {
throw new APIManagementException(String.format("Subscription for UUID:%s does not exist.", subscription.getUUID()));
}
}
use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.
the class UserPostSelfRegistrationHandler method executeUserRegistrationWorkflow.
/**
* This method adds new role to the existing user roles
* @param tenantDomain tenant domain extracted from the event
* @param userName username extracted from the event
* @throws org.wso2.carbon.identity.recovery.IdentityRecoveryServerException when unable to retrieve
* userStoreManager instance
*/
private void executeUserRegistrationWorkflow(String tenantDomain, String userName) throws org.wso2.carbon.identity.recovery.IdentityRecoveryServerException {
try {
// Realm service is used for user management tasks
RealmService realmService = ServiceReferenceHolder.getInstance().getRealmService();
UserStoreManager userStoreManager;
try {
userStoreManager = realmService.getTenantUserRealm(IdentityTenantUtil.getTenantId(tenantDomain)).getUserStoreManager();
} catch (UserStoreException e) {
throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED, userName, e);
}
// Start a tenant flow
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
carbonContext.setTenantId(IdentityTenantUtil.getTenantId(tenantDomain));
carbonContext.setTenantDomain(tenantDomain);
if (userStoreManager.isExistingUser(userName)) {
List<String> roleList = asList(userStoreManager.getRoleListOfUser(userName));
// User should have selfSignup role. Checking whether the user is in the new role
if (roleList.contains(SELF_SIGNUP_ROLE) && !roleList.contains(SUBSCRIBER_ROLE)) {
WorkflowExecutor userSignUpWFExecutor = WorkflowExecutorFactory.getInstance().getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_USER_SIGNUP);
// initiate a new signup workflow
WorkflowDTO signUpWFDto = new WorkflowDTO();
signUpWFDto.setWorkflowReference(userName);
signUpWFDto.setStatus(WorkflowStatus.CREATED);
signUpWFDto.setCreatedTime(System.currentTimeMillis());
signUpWFDto.setTenantDomain(tenantDomain);
signUpWFDto.setTenantId(IdentityTenantUtil.getTenantId(tenantDomain));
signUpWFDto.setExternalWorkflowReference(userSignUpWFExecutor.generateUUID());
signUpWFDto.setWorkflowType(WorkflowConstants.WF_TYPE_AM_USER_SIGNUP);
signUpWFDto.setCallbackUrl(userSignUpWFExecutor.getCallbackURL());
userSignUpWFExecutor.execute(signUpWFDto);
}
}
} catch (UserStoreException | WorkflowException e) {
throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_UNEXPECTED, userName, e);
} finally {
Utils.clearArbitraryProperties();
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.
the class SubscriptionCreationSimpleWorkflowExecutorTest method testExecutingSubscriptionCreationWorkFlow.
@Test
public void testExecutingSubscriptionCreationWorkFlow() throws APIManagementException {
WorkflowDTO workflowDTO = new WorkflowDTO();
workflowDTO.setWorkflowReference("1");
try {
PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(1, "UNBLOCKED");
Assert.assertNotNull(subscriptionCreationSimpleWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation simple workflow");
}
}
use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.
the class UserSignUpSimpleWorkflowExecutorTest method testExecutingUserSignUpSimpleWorkflow.
@Test
public void testExecutingUserSignUpSimpleWorkflow() throws APIManagementException, UserStoreException {
Map<String, Boolean> roleMap = new HashMap<String, Boolean>();
roleMap.put(signUpRole, false);
UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
userRegistrationConfigDTO.setAdminUserName("admin");
userRegistrationConfigDTO.setAdminPassword("admin");
userRegistrationConfigDTO.setRoles(roleMap);
PowerMockito.when(SelfSignUpUtil.getSignupConfiguration(tenantDomain)).thenReturn(userRegistrationConfigDTO);
PowerMockito.when(SelfSignUpUtil.getRoleNames(userRegistrationConfigDTO)).thenCallRealMethod();
Mockito.when(userStoreManager.isExistingUser(username)).thenReturn(true);
Mockito.when(userStoreManager.isExistingRole("Internal/" + signUpRole)).thenReturn(true);
Mockito.doNothing().when(userStoreManager).updateRoleListOfUser(username, null, new String[] { "Internal/" + signUpRole });
try {
Assert.assertNotNull(userSignUpSimpleWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException has thrown while executing the user signup simple workflow");
}
}
Aggregations