use of org.wso2.carbon.humantask.core.db.Database in project carbon-apimgt by wso2.
the class APIStoreImpl method generateApplicationKeys.
@Override
public OAuthApplicationInfo generateApplicationKeys(String applicationId, String keyType, String callbackUrl, List<String> grantTypes) throws APIManagementException {
if (log.isDebugEnabled()) {
log.debug("Generating application keys for application: " + applicationId);
}
Application application = getApplicationByUuid(applicationId);
OAuthAppRequest oauthAppRequest = new OAuthAppRequest(application.getName(), callbackUrl, keyType, grantTypes);
OAuthApplicationInfo oauthAppInfo = getKeyManager().createApplication(oauthAppRequest);
if (log.isDebugEnabled()) {
log.debug("Application key generation was successful for application: " + application.getName() + " Client Id: " + oauthAppInfo.getClientId());
}
try {
getApplicationDAO().addApplicationKeys(applicationId, keyType, oauthAppInfo.getClientId());
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while saving key data for application: " + application.getName();
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
}
if (log.isDebugEnabled()) {
log.debug("Application keys are successfully saved in the database for application: " + application.getName() + " Client Id: " + oauthAppInfo.getClientId());
}
List<SubscriptionValidationData> subscriptionValidationData = getApiSubscriptionDAO().getAPISubscriptionsOfAppForValidation(applicationId, keyType);
if (subscriptionValidationData != null && !subscriptionValidationData.isEmpty()) {
getApiGateway().addAPISubscription(subscriptionValidationData);
}
return oauthAppInfo;
}
use of org.wso2.carbon.humantask.core.db.Database in project carbon-apimgt by wso2.
the class DAOIntegrationTestBase method setUp.
@BeforeMethod
public void setUp() throws Exception {
String sqlFilePath = null;
if (H2.equals(database)) {
((H2DataSource) dataSource).resetDB();
sqlFilePath = ".." + File.separator + ".." + File.separator + ".." + File.separator + "features" + File.separator + "apimgt" + File.separator + "org.wso2.carbon.apimgt.core.feature" + File.separator + "resources" + File.separator + "dbscripts" + File.separator + "h2.sql";
} else if (MYSQL.contains(database)) {
((MySQLDataSource) dataSource).resetDB();
sqlFilePath = ".." + File.separator + ".." + File.separator + ".." + File.separator + "features" + File.separator + "apimgt" + File.separator + "org.wso2.carbon.apimgt.core.feature" + File.separator + "resources" + File.separator + "dbscripts" + File.separator + "mysql.sql";
} else if (POSTGRES.contains(database)) {
((PostgreDataSource) dataSource).resetDB();
sqlFilePath = ".." + File.separator + ".." + File.separator + ".." + File.separator + "features" + File.separator + "apimgt" + File.separator + "org.wso2.carbon.apimgt.core.feature" + File.separator + "resources" + File.separator + "dbscripts" + File.separator + "postgres.sql";
} else if (MSSQL.contains(database)) {
((MSSQLDataSource) dataSource).resetDB();
sqlFilePath = ".." + File.separator + ".." + File.separator + ".." + File.separator + "features" + File.separator + "apimgt" + File.separator + "org.wso2.carbon.apimgt.core.feature" + File.separator + "resources" + File.separator + "dbscripts" + File.separator + "mssql.sql";
} else if (ORACLE.contains(database)) {
((OracleDataSource) dataSource).resetDB();
sqlFilePath = ".." + File.separator + ".." + File.separator + ".." + File.separator + "features" + File.separator + "apimgt" + File.separator + "org.wso2.carbon.apimgt.core.feature" + File.separator + "resources" + File.separator + "dbscripts" + File.separator + "oracle.sql";
}
DAOUtil.clearDataSource();
DAOUtil.initialize(dataSource);
try (Connection connection = DAOUtil.getConnection()) {
DBScriptRunnerUtil.executeSQLScript(sqlFilePath, connection);
}
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
SampleTestObjectCreator.createDefaultPolicy(policyDAO);
}
use of org.wso2.carbon.humantask.core.db.Database in project wso2-dss-connectors by wso2-attic.
the class MongoDBDataSource method init.
@Override
public void init(Map<String, String> params) throws DataServiceFault {
String serversParam = params.get(MongoDBDSConstants.SERVERS);
if (DBUtils.isEmptyString(serversParam)) {
throw new DataServiceFault("The data source param '" + MongoDBDSConstants.SERVERS + "' is required");
}
String[] servers = serversParam.split(",");
String database = params.get(MongoDBDSConstants.DATABASE);
if (DBUtils.isEmptyString(database)) {
throw new DataServiceFault("The data source param '" + MongoDBDSConstants.DATABASE + "' is required");
}
try {
this.mongo = new Mongo(this.createServerAddresses(servers), this.extractMongoOptions(params));
String writeConcern = params.get(MongoDBDSConstants.WRITE_CONCERN);
if (!DBUtils.isEmptyString(writeConcern)) {
this.getMongo().setWriteConcern(WriteConcern.valueOf(writeConcern));
}
String readPref = params.get(MongoDBDSConstants.READ_PREFERENCE);
if (!DBUtils.isEmptyString(readPref)) {
this.getMongo().setReadPreference(ReadPreference.valueOf(readPref));
}
this.jongo = new Jongo(this.getMongo().getDB(database));
} catch (Exception e) {
throw new DataServiceFault(e);
}
}
use of org.wso2.carbon.humantask.core.db.Database in project carbon-business-process by wso2.
the class TerminationTask method run.
@Override
public void run() {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
privilegedCarbonContext.setTenantId(tenantID, true);
try {
List<TaskProtocolHandler> taskProtocolHandlers = null;
try {
taskProtocolHandlers = getHTProtocolHandlerURLWithTasks(instanceID);
} catch (Exception e) {
log.error("Error occurred while retrieving coordination data", e);
}
String currentProtocolHandler = "";
ExitProtocolMessage currentExitMessage = null;
for (TaskProtocolHandler taskProtocolHandler : taskProtocolHandlers) {
// Task Protocol Handler and Task ID should be not null
if (taskProtocolHandler.getProtocolHandlerURL() != null && taskProtocolHandler.getTaskID() != null) {
if (!currentProtocolHandler.equals(taskProtocolHandler.getProtocolHandlerURL())) {
// found a new protocol handler URL, so invoking old exit message.
if (currentExitMessage != null) {
// To ignore initial condition, we do null check here.
invokeProtocolHandler(currentExitMessage);
}
currentExitMessage = new ExitProtocolMessage(taskProtocolHandler.getProtocolHandlerURL());
currentProtocolHandler = taskProtocolHandler.getProtocolHandlerURL();
}
currentExitMessage.getTaskIDs().add(taskProtocolHandler.getTaskID());
if (log.isDebugEnabled()) {
log.debug("building exit protocol message for task id:" + taskProtocolHandler.getTaskID());
}
}
}
if (currentExitMessage != null) {
// Here we do last invocation.
invokeProtocolHandler(currentExitMessage);
}
// Cleaning coordination data.
boolean deleted = false;
try {
deleted = deleteCoordinationData(instanceID);
} catch (Exception e) {
log.error("Error occurred while cleaning coordination data for process instance id " + instanceID, e);
}
if (deleted && log.isDebugEnabled()) {
log.debug("Coordination data are removed from database for process instance id " + instanceID);
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.humantask.core.db.Database in project carbon-business-process by wso2.
the class CoordinationController method initDataSource.
/**
* Initialize Database util class.
*
* @throws B4PCoordinationException
*/
private void initDataSource() throws B4PCoordinationException {
if (log.isDebugEnabled()) {
log.debug("Initialising B4P Coordination database");
}
dbUtil = new DatabaseUtil();
dbUtil.setTransactionManager(tnxManager);
try {
dbUtil.start();
} catch (DatabaseConfigurationException e) {
String errMsg = "B4P Coordination Database Initialization failed.";
log.error(errMsg);
throw new B4PCoordinationException(errMsg, e);
}
}
Aggregations