Search in sources :

Example 36 with Database

use of org.wso2.carbon.humantask.core.db.Database in project carbon-apimgt by wso2.

the class AnalyticsDAOImpl method getSubscriptionCount.

/**
 * @see AnalyticsDAO#getSubscriptionCount(Instant, Instant, String)
 */
@Override
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
public List<SubscriptionCount> getSubscriptionCount(Instant fromTimestamp, Instant toTimestamp, String createdBy) throws APIMgtDAOException {
    final String query;
    if (StringUtils.isNotEmpty(createdBy)) {
        query = "SELECT COUNT(subs.UUID) AS COUNT, subs.CREATED_TIME AS time " + "FROM AM_SUBSCRIPTION subs, AM_API  api  " + "WHERE (subs.CREATED_TIME BETWEEN ? AND ?) " + "AND  subs.api_id=api.uuid " + "AND subs.CREATED_BY= ? " + "GROUP BY subs.CREATED_TIME ORDER BY subs.CREATED_TIME ASC";
    } else {
        query = "SELECT COUNT(subs.UUID) AS COUNT, subs.CREATED_TIME AS time " + "FROM AM_SUBSCRIPTION subs, AM_API  api  " + "WHERE (subs.CREATED_TIME BETWEEN ? AND ?) " + "AND  subs.api_id=api.uuid " + "GROUP BY subs.CREATED_TIME ORDER BY subs.CREATED_TIME ASC";
    }
    List<SubscriptionCount> subscriptionCountList = new ArrayList<>();
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setTimestamp(1, Timestamp.from(fromTimestamp));
        statement.setTimestamp(2, Timestamp.from(toTimestamp));
        if (StringUtils.isNotEmpty(createdBy)) {
            statement.setString(3, createdBy);
        }
        log.debug("Executing query: {} ", query);
        statement.execute();
        try (ResultSet rs = statement.getResultSet()) {
            while (rs.next()) {
                SubscriptionCount subscriptionCount = new SubscriptionCount();
                subscriptionCount.setTimestamp(rs.getTimestamp("TIME").getTime());
                subscriptionCount.setCount(rs.getInt("COUNT"));
                subscriptionCountList.add(subscriptionCount);
            }
        }
    } catch (SQLException e) {
        String errorMsg = "Error while creating database connection/prepared-statement";
        throw new APIMgtDAOException(errorMsg, e);
    }
    return subscriptionCountList;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount) SubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 37 with Database

use of org.wso2.carbon.humantask.core.db.Database in project carbon-apimgt by wso2.

the class AnalyticsDAOImpl method getAPISubscriptionCount.

/**
 * @see AnalyticsDAO#getAPISubscriptionCount(Instant, Instant, String)
 */
@Override
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
public List<APISubscriptionCount> getAPISubscriptionCount(Instant fromTime, Instant toTime, String apiId) throws APIMgtDAOException {
    final String query;
    if (StringUtils.isNotEmpty(apiId)) {
        query = "SELECT api.UUID,api.NAME,api.VERSION,api.PROVIDER,count(subs.UUID) as COUNT " + "FROM AM_SUBSCRIPTION subs,AM_API api " + "WHERE api.UUID=subs.API_ID " + "AND (subs.CREATED_TIME BETWEEN ? AND ?) " + "AND subs.SUB_STATUS = 'ACTIVE' " + "AND api.UUID=? " + "GROUP BY api.UUID,api.NAME,api.VERSION,api.PROVIDER";
    } else {
        query = "SELECT api.UUID,api.NAME,api.VERSION,api.PROVIDER,count(subs.UUID) as COUNT " + "FROM AM_SUBSCRIPTION subs,AM_API api " + "WHERE api.UUID=subs.API_ID " + "AND (subs.CREATED_TIME BETWEEN ? AND ?) " + "AND subs.SUB_STATUS = 'ACTIVE' " + "GROUP BY api.UUID,api.NAME,api.VERSION,api.PROVIDER";
    }
    List<APISubscriptionCount> apiSubscriptionCountList = new ArrayList<>();
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setTimestamp(1, Timestamp.from(fromTime));
        statement.setTimestamp(2, Timestamp.from(toTime));
        if (StringUtils.isNotEmpty(apiId)) {
            statement.setString(3, apiId);
        }
        log.debug("Executing query: {} ", query);
        statement.execute();
        try (ResultSet rs = statement.getResultSet()) {
            while (rs.next()) {
                APISubscriptionCount apiSubscriptionCount = new APISubscriptionCount();
                apiSubscriptionCount.setId(rs.getString("UUID"));
                apiSubscriptionCount.setName(rs.getString("NAME"));
                apiSubscriptionCount.setVersion(rs.getString("VERSION"));
                apiSubscriptionCount.setProvider(rs.getString("PROVIDER"));
                apiSubscriptionCount.setCount(rs.getInt("COUNT"));
                apiSubscriptionCountList.add(apiSubscriptionCount);
            }
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException("Error while creating database connection/prepared-statement", e);
    }
    return apiSubscriptionCountList;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APISubscriptionCount(org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 38 with Database

use of org.wso2.carbon.humantask.core.db.Database in project carbon-apimgt by wso2.

the class ApiDAOImpl method getCompositeAPISummary.

@Override
public CompositeAPI getCompositeAPISummary(String apiID) throws APIMgtDAOException {
    final String query = COMPOSITE_API_SUMMARY_SELECT + " WHERE UUID = ? AND API_TYPE_ID = " + "(SELECT TYPE_ID FROM AM_API_TYPES WHERE TYPE_NAME = ?)";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setString(1, apiID);
        statement.setString(2, ApiType.COMPOSITE.toString());
        List<CompositeAPI> apiResults = getCompositeAPISummaryList(connection, statement);
        if (apiResults.isEmpty()) {
            throw new APIMgtDAOException("API with ID " + apiID + " does not exist", ExceptionCodes.API_NOT_FOUND);
        }
        // there should be only 1 result from the database
        return apiResults.get(0);
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting Composite API: " + apiID, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) PreparedStatement(java.sql.PreparedStatement)

Example 39 with Database

use of org.wso2.carbon.humantask.core.db.Database in project carbon-apimgt by wso2.

the class AnalyticsDAOImpl method getSubscriptionInfo.

/**
 * @see AnalyticsDAO#getSubscriptionInfo(Instant, Instant, String)
 */
@Override
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
public List<SubscriptionInfo> getSubscriptionInfo(Instant fromTimestamp, Instant toTimestamp, String createdBy) throws APIMgtDAOException {
    final String query;
    if (StringUtils.isNotEmpty(createdBy)) {
        query = "SELECT sub.UUID, api.NAME as API_NAME, api.VERSION as API_VERSION, app.NAME " + "as APP_NAME, app.DESCRIPTION, sub.CREATED_TIME , policy.DISPLAY_NAME , sub.SUB_STATUS " + "FROM AM_API api, AM_SUBSCRIPTION sub, AM_APPLICATION app, AM_SUBSCRIPTION_POLICY policy " + "WHERE (sub.CREATED_TIME BETWEEN ? AND ?) " + "AND api.UUID = sub.API_ID " + "AND sub.APPLICATION_ID = app.UUID " + "AND sub.CREATED_BY= ? " + "AND sub.TIER_ID = policy.UUID ";
    } else {
        query = "SELECT sub.UUID, api.NAME as API_NAME, api.VERSION as API_VERSION, app.NAME " + "as APP_NAME, app.DESCRIPTION, sub.CREATED_TIME , policy.DISPLAY_NAME , sub.SUB_STATUS " + "FROM AM_API api, AM_SUBSCRIPTION sub, AM_APPLICATION app, AM_SUBSCRIPTION_POLICY policy " + "WHERE (sub.CREATED_TIME BETWEEN ? AND ?) " + "AND api.UUID = sub.API_ID " + "AND sub.APPLICATION_ID = app.UUID " + "AND sub.TIER_ID = policy.UUID ";
    }
    List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setTimestamp(1, Timestamp.from(fromTimestamp));
        statement.setTimestamp(2, Timestamp.from(toTimestamp));
        if (StringUtils.isNotEmpty(createdBy)) {
            statement.setString(3, createdBy);
        }
        log.debug("Executing query: {} ", query);
        statement.execute();
        try (ResultSet rs = statement.getResultSet()) {
            while (rs.next()) {
                SubscriptionInfo subscriptionInfo = new SubscriptionInfo();
                subscriptionInfo.setId(rs.getString("UUID"));
                subscriptionInfo.setName(rs.getString("API_NAME"));
                subscriptionInfo.setVersion(rs.getString("API_VERSION"));
                subscriptionInfo.setAppName(rs.getString("APP_NAME"));
                subscriptionInfo.setDescription(rs.getString("DESCRIPTION"));
                subscriptionInfo.setCreatedTime(rs.getTimestamp("CREATED_TIME").getTime());
                subscriptionInfo.setSubscriptionStatus(rs.getString("SUB_STATUS"));
                subscriptionInfo.setSubscriptionTier(rs.getString("DISPLAY_NAME"));
                subscriptionInfoList.add(subscriptionInfo);
            }
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException("Error while creating database connection/prepared-statement", e);
    }
    return subscriptionInfoList;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SubscriptionInfo(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo) PreparedStatement(java.sql.PreparedStatement) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 40 with Database

use of org.wso2.carbon.humantask.core.db.Database in project carbon-apimgt by wso2.

the class APIPublisherImpl method addAPIFromWSDLURL.

@Override
public String addAPIFromWSDLURL(API.APIBuilder apiBuilder, String wsdlUrl, boolean isHttpBinding) throws APIManagementException {
    WSDLProcessor processor = WSDLProcessFactory.getInstance().getWSDLProcessor(wsdlUrl);
    if (!processor.canProcess()) {
        throw new APIMgtWSDLException("Unable to process WSDL by the processor " + processor.getClass().getName(), ExceptionCodes.CANNOT_PROCESS_WSDL_CONTENT);
    }
    apiBuilder.uriTemplates(APIMWSDLUtils.getUriTemplatesForWSDLOperations(processor.getWsdlInfo().getHttpBindingOperations(), isHttpBinding));
    String uuid = addAPI(apiBuilder);
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the API. uuid: " + uuid);
    }
    byte[] wsdlContentBytes = processor.getWSDL();
    getApiDAO().addOrUpdateWSDL(uuid, wsdlContentBytes, getUsername());
    if (log.isDebugEnabled()) {
        log.debug("Successfully added the content of WSDL URL to database. WSDL URL: " + wsdlUrl);
    }
    if (APIMgtConstants.WSDLConstants.WSDL_VERSION_20.equals(processor.getWsdlInfo().getVersion())) {
        log.info("Extraction of HTTP Binding operations is not supported for WSDL 2.0.");
    }
    return uuid;
}
Also used : WSDLProcessor(org.wso2.carbon.apimgt.core.api.WSDLProcessor) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException)

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