use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.
the class SubscriptionUpdateWSWorkflowExecutor method complete.
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
workflowDTO.setUpdatedTime(System.currentTimeMillis());
super.complete(workflowDTO);
log.info("Subscription Update [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + "Workflow State : " + workflowDTO.getStatus());
if (WorkflowStatus.APPROVED.equals(workflowDTO.getStatus())) {
ApiMgtDAO apiMgtDAO = ApiMgtDAO.getInstance();
try {
apiMgtDAO.updateSubscriptionStatus(Integer.parseInt(workflowDTO.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(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
} 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.WorkflowDTO in project carbon-apimgt by wso2.
the class ApiMgtDAO method populateAppRegistrationWorkflowDTO.
public void populateAppRegistrationWorkflowDTO(ApplicationRegistrationWorkflowDTO workflowDTO) throws APIManagementException {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Application application = null;
Subscriber subscriber = null;
String registrationEntry = SQLConstants.GET_APPLICATION_REGISTRATION_ENTRY_BY_SUBSCRIBER_SQL;
try {
conn = APIMgtDBUtil.getConnection();
ps = conn.prepareStatement(registrationEntry);
ps.setString(1, workflowDTO.getExternalWorkflowReference());
rs = ps.executeQuery();
while (rs.next()) {
subscriber = new Subscriber(rs.getString("USER_ID"));
subscriber.setId(rs.getInt("SUBSCRIBER_ID"));
application = new Application(rs.getString("NAME"), subscriber);
application.setId(rs.getInt("APPLICATION_ID"));
application.setUUID(rs.getString("UUID"));
application.setTokenType(rs.getString("APP_TYPE"));
application.setApplicationWorkFlowStatus(rs.getString("APPLICATION_STATUS"));
application.setCallbackUrl(rs.getString("CALLBACK_URL"));
application.setDescription(rs.getString("DESCRIPTION"));
application.setTier(rs.getString("APPLICATION_TIER"));
workflowDTO.setApplication(application);
workflowDTO.setKeyType(rs.getString("TOKEN_TYPE"));
workflowDTO.setUserName(subscriber.getName());
workflowDTO.setDomainList(rs.getString("ALLOWED_DOMAINS"));
workflowDTO.setValidityTime(rs.getLong("VALIDITY_PERIOD"));
String tenantDomain = MultitenantUtils.getTenantDomain(subscriber.getName());
String keyManagerUUID = rs.getString("KEY_MANAGER");
workflowDTO.setKeyManager(keyManagerUUID);
KeyManagerConfigurationDTO keyManagerConfigurationByUUID = getKeyManagerConfigurationByUUID(conn, keyManagerUUID);
if (keyManagerConfigurationByUUID != null) {
OAuthAppRequest request = ApplicationUtils.createOauthAppRequest(application.getName(), null, application.getCallbackUrl(), rs.getString("TOKEN_SCOPE"), rs.getString("INPUTS"), application.getTokenType(), keyManagerConfigurationByUUID.getOrganization(), keyManagerConfigurationByUUID.getName());
request.setMappingId(workflowDTO.getWorkflowReference());
request.getOAuthApplicationInfo().setApplicationUUID(application.getUUID());
workflowDTO.setAppInfoDTO(request);
} else {
throw new APIManagementException("Error occured while finding the KeyManager from uuid " + keyManagerUUID + ".", ExceptionCodes.KEY_MANAGER_NOT_REGISTERED);
}
}
} catch (SQLException | IOException e) {
handleException("Error occurred while retrieving an " + "Application Registration Entry for Workflow : " + workflowDTO.getExternalWorkflowReference(), e);
} finally {
APIMgtDBUtil.closeAllConnections(ps, conn, rs);
}
}
use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.
the class ApiMgtDAO method retrieveWorkflowFromInternalReference.
/**
* Returns a workflow object for a given internal workflow reference and the workflow type.
*
* @param workflowReference
* @param workflowType
* @return
* @throws APIManagementException
*/
public WorkflowDTO retrieveWorkflowFromInternalReference(String workflowReference, String workflowType) throws APIManagementException {
Connection connection = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
WorkflowDTO workflowDTO = null;
String query = SQLConstants.GET_ALL_WORKFLOW_ENTRY_FROM_INTERNAL_REF_SQL;
try {
connection = APIMgtDBUtil.getConnection();
prepStmt = connection.prepareStatement(query);
prepStmt.setString(1, workflowReference);
prepStmt.setString(2, workflowType);
rs = prepStmt.executeQuery();
while (rs.next()) {
workflowDTO = WorkflowExecutorFactory.getInstance().createWorkflowDTO(rs.getString("WF_TYPE"));
workflowDTO.setStatus(WorkflowStatus.valueOf(rs.getString("WF_STATUS")));
workflowDTO.setExternalWorkflowReference(rs.getString("WF_EXTERNAL_REFERENCE"));
workflowDTO.setCreatedTime(rs.getTimestamp("WF_CREATED_TIME").getTime());
workflowDTO.setWorkflowReference(rs.getString("WF_REFERENCE"));
workflowDTO.setTenantDomain(rs.getString("TENANT_DOMAIN"));
workflowDTO.setTenantId(rs.getInt("TENANT_ID"));
workflowDTO.setWorkflowDescription(rs.getString("WF_STATUS_DESC"));
}
} catch (SQLException e) {
handleException("Error while retrieving workflow details for " + workflowReference, e);
} finally {
APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
}
return workflowDTO;
}
use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO in project carbon-apimgt by wso2.
the class UserSignUpWSWorkflowExecutor method complete.
@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
// workflowDTO.setStatus(workflowDTO.getStatus());
workflowDTO.setUpdatedTime(System.currentTimeMillis());
if (log.isDebugEnabled()) {
log.debug("User Sign Up [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + "Workflow State : " + workflowDTO.getStatus());
}
super.complete(workflowDTO);
String tenantDomain = workflowDTO.getTenantDomain();
try {
UserRegistrationConfigDTO signupConfig = SelfSignUpUtil.getSignupConfiguration(tenantDomain);
String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(workflowDTO.getWorkflowReference());
if (WorkflowStatus.APPROVED.equals(workflowDTO.getStatus())) {
try {
updateRolesOfUser(tenantAwareUserName, SelfSignUpUtil.getRoleNames(signupConfig), tenantDomain);
} catch (Exception e) {
// updateRolesOfUser throws generic Exception. Therefore generic Exception is caught
throw new WorkflowException("Error while assigning role to user", e);
}
} else {
try {
/* Remove created user */
deleteUser(tenantDomain, tenantAwareUserName);
} catch (Exception e) {
throw new WorkflowException("Error while deleting the user", e);
}
}
} catch (APIManagementException e1) {
throw new WorkflowException("Error while accessing signup configuration", e1);
}
return new GeneralWorkflowResponse();
}
use of org.wso2.carbon.apimgt.impl.dto.WorkflowDTO 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;
}
Aggregations