Search in sources :

Example 21 with Parameter

use of org.wso2.carbon.identity.workflow.mgt.bean.Parameter in project carbon-apimgt by wso2.

the class JMSTaskManagerFactory method getTransactionality.

/**
 * @param svcMap JNDI context properties and other general property map
 * @param cfMap  properties defined on the JMS CF
 * @return value for the specific transactionality type
 */
private static int getTransactionality(Map<String, String> svcMap, Map<String, String> cfMap) {
    String key = BaseConstants.PARAM_TRANSACTIONALITY;
    String val = svcMap.get(key);
    if (val == null) {
        val = cfMap.get(key);
    }
    if (val == null) {
        return BaseConstants.TRANSACTION_NONE;
    } else {
        if (BaseConstants.STR_TRANSACTION_JTA.equalsIgnoreCase(val)) {
            return BaseConstants.TRANSACTION_JTA;
        } else if (BaseConstants.STR_TRANSACTION_LOCAL.equalsIgnoreCase(val)) {
            return BaseConstants.TRANSACTION_LOCAL;
        } else {
            throw new JmsRunTimeException("Invalid option : " + val + " for parameter : " + BaseConstants.STR_TRANSACTION_JTA);
        // TODO fix it
        // return 0;
        }
    }
}
Also used : JmsRunTimeException(org.wso2.carbon.apimgt.common.jms.JmsRunTimeException)

Example 22 with Parameter

use of org.wso2.carbon.identity.workflow.mgt.bean.Parameter in project carbon-apimgt by wso2.

the class ApiMgtDAO method setQueryParameterConditions.

/**
 * Add Query parameter conditions of pipeline with pipeline Id: <code>pipelineId</code> to a
 * provided {@link Condition} array
 *
 * @param pipelineId Id of the pipeline
 * @param conditions condition array to populate
 * @throws APIManagementException
 */
private void setQueryParameterConditions(int pipelineId, ArrayList<Condition> conditions) throws APIManagementException {
    Connection connection = null;
    PreparedStatement conditionsStatement = null;
    ResultSet resultSet = null;
    try {
        connection = APIMgtDBUtil.getConnection();
        conditionsStatement = connection.prepareStatement(SQLConstants.ThrottleSQLConstants.GET_QUERY_PARAMETER_CONDITIONS_SQL);
        conditionsStatement.setInt(1, pipelineId);
        resultSet = conditionsStatement.executeQuery();
        while (resultSet.next()) {
            QueryParameterCondition queryParameterCondition = new QueryParameterCondition();
            queryParameterCondition.setParameter(resultSet.getString(ThrottlePolicyConstants.COLUMN_PARAMETER_NAME));
            queryParameterCondition.setValue(resultSet.getString(ThrottlePolicyConstants.COLUMN_PARAMETER_VALUE));
            queryParameterCondition.setInvertCondition(resultSet.getBoolean(ThrottlePolicyConstants.COLUMN_IS_PARAM_MAPPING));
            conditions.add(queryParameterCondition);
        }
    } catch (SQLException e) {
        handleException("Failed to get query parameter conditions for pipelineId: " + pipelineId, e);
    } finally {
        APIMgtDBUtil.closeAllConnections(conditionsStatement, connection, resultSet);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryParameterCondition(org.wso2.carbon.apimgt.api.model.policy.QueryParameterCondition)

Example 23 with Parameter

use of org.wso2.carbon.identity.workflow.mgt.bean.Parameter in project carbon-apimgt by wso2.

the class CertificateMgtDAO method getCertificate.

/**
 * Method to retrieve certificate metadata from db for specific tenant which matches alias or endpoint.
 * From alias and endpoint, only one parameter is required.
 *
 * @param tenantId : The id of the tenant which the certificate belongs to.
 * @param alias    : Alias for the certificate. (Optional)
 * @param endpoint : The endpoint/ server url which the certificate is mapped to. (Optional)
 * @return : A CertificateMetadataDTO object if the certificate is retrieved successfully, null otherwise.
 */
public CertificateMetadataDTO getCertificate(String alias, String endpoint, int tenantId) throws CertificateManagementException {
    String getCertQuery;
    getCertQuery = SQLConstants.CertificateConstants.GET_CERTIFICATE_TENANT_ALIAS_ENDPOINT;
    try (Connection connection = APIMgtDBUtil.getConnection()) {
        try (PreparedStatement preparedStatement = connection.prepareStatement(getCertQuery)) {
            preparedStatement.setInt(1, tenantId);
            preparedStatement.setString(2, alias);
            preparedStatement.setString(3, endpoint);
            try (ResultSet resultSet = preparedStatement.executeQuery()) {
                if (resultSet.next()) {
                    CertificateMetadataDTO certificateMetadataDTO = new CertificateMetadataDTO();
                    certificateMetadataDTO.setAlias(resultSet.getString("ALIAS"));
                    certificateMetadataDTO.setEndpoint(resultSet.getString("END_POINT"));
                    try (InputStream certificate = resultSet.getBinaryStream("CERTIFICATE")) {
                        certificateMetadataDTO.setCertificate(APIMgtDBUtil.getStringFromInputStream(certificate));
                    }
                    return certificateMetadataDTO;
                }
            }
        }
    } catch (SQLException | IOException e) {
        handleException("Error while retrieving certificate metadata.", e);
    }
    throw new CertificateManagementException("Certificate didn't exist with alias" + alias);
}
Also used : CertificateMetadataDTO(org.wso2.carbon.apimgt.api.dto.CertificateMetadataDTO) SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) CertificateManagementException(org.wso2.carbon.apimgt.impl.certificatemgt.exceptions.CertificateManagementException) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException)

Example 24 with Parameter

use of org.wso2.carbon.identity.workflow.mgt.bean.Parameter in project carbon-apimgt by wso2.

the class SystemApplicationDAO method getApplications.

/**
 * Method to retrieve all the system Applications for the given tenant
 *
 * @param tenantDomain required parameter
 * @return SystemApplicationDTO which hold the retrieved client credentials
 * @throws APIMgtDAOException
 */
public SystemApplicationDTO[] getApplications(String tenantDomain) throws APIMgtDAOException {
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    SystemApplicationDTO systemApplicationDTO = null;
    List<SystemApplicationDTO> systemApplicationDTOS = new ArrayList<>();
    String getCredentialsQuery = SQLConstants.SystemApplicationConstants.GET_APPLICATIONS;
    try {
        connection = APIMgtDBUtil.getConnection();
        connection.setAutoCommit(false);
        connection.commit();
        preparedStatement = connection.prepareStatement(getCredentialsQuery);
        preparedStatement.setString(1, tenantDomain);
        resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            systemApplicationDTO = new SystemApplicationDTO();
            systemApplicationDTO.setName(resultSet.getString("NAME"));
            systemApplicationDTO.setConsumerKey(resultSet.getString("CONSUMER_KEY"));
            systemApplicationDTO.setConsumerSecret(resultSet.getString("CONSUMER_SECRET"));
            systemApplicationDTOS.add(systemApplicationDTO);
        }
    } catch (SQLException e) {
        if (log.isDebugEnabled()) {
            log.debug("Error while retrieving system applications for tenant: " + tenantDomain);
        }
        handleException("Error while retrieving system applications for tenant: " + tenantDomain, e);
    } finally {
        APIMgtDBUtil.closeAllConnections(preparedStatement, connection, resultSet);
    }
    return systemApplicationDTOS.toArray(new SystemApplicationDTO[systemApplicationDTOS.size()]);
}
Also used : SQLException(java.sql.SQLException) SystemApplicationDTO(org.wso2.carbon.apimgt.impl.dto.SystemApplicationDTO) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Example 25 with Parameter

use of org.wso2.carbon.identity.workflow.mgt.bean.Parameter in project carbon-apimgt by wso2.

the class CertificateMgtDAO method getCertificates.

/**
 * Method to retrieve certificate metadata from db for specific tenant which matches alias or endpoint.
 * From alias and endpoint, only one parameter is required.
 *
 * @param tenantId : The id of the tenant which the certificate belongs to.
 * @param alias    : Alias for the certificate. (Optional)
 * @param endpoint : The endpoint/ server url which the certificate is mapped to. (Optional)
 * @return : A CertificateMetadataDTO object if the certificate is retrieved successfully, null otherwise.
 */
public List<CertificateMetadataDTO> getCertificates(String alias, String endpoint, int tenantId) throws CertificateManagementException {
    String getCertQuery;
    CertificateMetadataDTO certificateMetadataDTO;
    List<CertificateMetadataDTO> certificateMetadataList = new ArrayList<>();
    if (StringUtils.isNotEmpty(alias) || StringUtils.isNotEmpty(endpoint)) {
        if (log.isDebugEnabled()) {
            log.debug("The alias and endpoint are not empty. Invoking the search query with parameters " + "alias = " + alias + " endpoint = " + endpoint);
        }
        getCertQuery = SQLConstants.CertificateConstants.GET_CERTIFICATE_TENANT;
    } else {
        if (log.isDebugEnabled()) {
            log.debug("The alias and endpoint are empty. Invoking the get all certificates for tenant " + tenantId);
        }
        getCertQuery = SQLConstants.CertificateConstants.GET_CERTIFICATES;
    }
    try (Connection connection = APIMgtDBUtil.getConnection()) {
        try (PreparedStatement preparedStatement = connection.prepareStatement(getCertQuery)) {
            preparedStatement.setInt(1, tenantId);
            if (StringUtils.isNotEmpty(alias) || StringUtils.isNotEmpty(endpoint)) {
                preparedStatement.setString(2, alias);
                preparedStatement.setString(3, endpoint);
            }
            try (ResultSet resultSet = preparedStatement.executeQuery()) {
                while (resultSet.next()) {
                    certificateMetadataDTO = new CertificateMetadataDTO();
                    certificateMetadataDTO.setAlias(resultSet.getString("ALIAS"));
                    certificateMetadataDTO.setEndpoint(resultSet.getString("END_POINT"));
                    try (InputStream certificate = resultSet.getBinaryStream("CERTIFICATE")) {
                        certificateMetadataDTO.setCertificate(APIMgtDBUtil.getStringFromInputStream(certificate));
                    }
                    certificateMetadataList.add(certificateMetadataDTO);
                }
            }
        }
    } catch (SQLException | IOException e) {
        handleException("Error while retrieving certificate metadata.", e);
    }
    return certificateMetadataList;
}
Also used : CertificateMetadataDTO(org.wso2.carbon.apimgt.api.dto.CertificateMetadataDTO) SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException)

Aggregations

HashMap (java.util.HashMap)74 ArrayList (java.util.ArrayList)65 Map (java.util.Map)29 Response (javax.ws.rs.core.Response)29 Operation (io.swagger.v3.oas.annotations.Operation)27 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)27 Parameter (org.apache.axis2.description.Parameter)27 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)26 OMElement (org.apache.axiom.om.OMElement)21 Test (org.testng.annotations.Test)19 IOException (java.io.IOException)17 List (java.util.List)17 QName (javax.xml.namespace.QName)15 CAppArtifacts (org.wso2.ei.dashboard.core.rest.model.CAppArtifacts)15 Method (java.lang.reflect.Method)14 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)14 Artifacts (org.wso2.ei.dashboard.core.rest.model.Artifacts)14 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)13 ResultSet (java.sql.ResultSet)12 PreparedStatement (java.sql.PreparedStatement)11