use of org.wso2.carbon.apimgt.core.exception.WorkflowException in project carbon-apimgt by wso2.
the class APIProviderImpl method cleanUpPendingSubscriptionCreationProcessesByAPI.
/**
* Clean-up pending subscriptions of a given API
*
* @param uuid API uuid
* @throws APIManagementException
*/
private void cleanUpPendingSubscriptionCreationProcessesByAPI(String uuid) throws APIManagementException {
WorkflowExecutor createSubscriptionWFExecutor = getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
Set<Integer> pendingSubscriptions = apiMgtDAO.getPendingSubscriptionsByAPIId(uuid);
String workflowExtRef = null;
for (int subscription : pendingSubscriptions) {
try {
workflowExtRef = apiMgtDAO.getExternalWorkflowReferenceForSubscription(subscription);
createSubscriptionWFExecutor.cleanUpPendingTask(workflowExtRef);
} catch (APIManagementException ex) {
// failed clean-up processes are ignored to prevent failures in API state change flow
log.warn("Failed to retrieve external workflow reference for subscription for subscription ID: " + subscription);
} catch (WorkflowException ex) {
// failed clean-up processes are ignored to prevent failures in API state change flow
log.warn("Failed to clean-up pending subscription approval task for subscription ID: " + subscription);
}
}
}
use of org.wso2.carbon.apimgt.core.exception.WorkflowException 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.core.exception.WorkflowException 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.core.exception.WorkflowException in project carbon-apimgt by wso2.
the class SubscriptionDeletionSimpleWorkflowExecutorTest method testFailureWhileExecutingSubscriptionDeletionWorkFlow.
@Test
public void testFailureWhileExecutingSubscriptionDeletionWorkFlow() throws APIManagementException {
PowerMockito.doThrow(new APIManagementException("Error occurred while removing subscriptions")).when(apiMgtDAO).removeSubscription((APIIdentifier) Mockito.anyObject(), Mockito.anyInt());
try {
subscriptionDeletionSimpleWorkflowExecutor.execute(subscriptionWorkflowDTO);
Assert.fail("Expected WorkflowException is not thrown while executing subscription deletion workflow");
} catch (WorkflowException e) {
Assert.assertTrue(e.getMessage().contains("Could not complete subscription deletion workflow for api: " + subscriptionWorkflowDTO.getApiName()));
}
}
use of org.wso2.carbon.apimgt.core.exception.WorkflowException 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