Search in sources :

Example 41 with Database

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;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) OAuthAppRequest(org.wso2.carbon.apimgt.core.models.OAuthAppRequest) OAuthApplicationInfo(org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) Application(org.wso2.carbon.apimgt.core.models.Application)

Example 42 with Database

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);
}
Also used : Connection(java.sql.Connection) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 43 with Database

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);
    }
}
Also used : Mongo(com.mongodb.Mongo) Jongo(org.jongo.Jongo) DataServiceFault(org.wso2.carbon.dataservices.core.DataServiceFault)

Example 44 with Database

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();
    }
}
Also used : ExitProtocolMessage(org.wso2.carbon.bpel.b4p.coordination.context.ExitProtocolMessage) TaskProtocolHandler(org.wso2.carbon.bpel.b4p.coordination.dao.TaskProtocolHandler) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 45 with Database

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);
    }
}
Also used : DatabaseConfigurationException(org.wso2.carbon.bpel.b4p.coordination.db.DatabaseConfigurationException) DatabaseUtil(org.wso2.carbon.bpel.b4p.coordination.db.DatabaseUtil)

Aggregations

SQLException (java.sql.SQLException)29 PreparedStatement (java.sql.PreparedStatement)28 Connection (java.sql.Connection)24 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)23 ResultSet (java.sql.ResultSet)16 ArrayList (java.util.ArrayList)13 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)12 Map (java.util.Map)6 DeviceMgtPluginException (org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException)6 HashMap (java.util.HashMap)5 BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)5 File (java.io.File)4 InstanceFilter (org.apache.ode.bpel.common.InstanceFilter)4 BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)4 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)4 Device (org.wso2.carbon.device.mgt.common.Device)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 DataSource (javax.sql.DataSource)3 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)3