Search in sources :

Example 31 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitMonth_value.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public TimeConstant visitMonth_value(@NotNull SiddhiQLParser.Month_valueContext ctx) {
    TimeConstant timeConstant = Expression.Time.month(Long.parseLong(ctx.INT_LITERAL().getText().replaceFirst("[lL]", "")));
    populateQueryContext(timeConstant, ctx);
    return timeConstant;
}
Also used : TimeConstant(org.wso2.siddhi.query.api.expression.constant.TimeConstant)

Example 32 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class ApiDAOImpl method updateAPIWorkflowStatus.

/**
 * Update an existing API workflow state
 *
 * @param apiID          The {@link String} of the API that needs to be updated
 * @param workflowStatus workflow status
 * @throws APIMgtDAOException if error occurs while accessing data layer
 */
@Override
public void updateAPIWorkflowStatus(String apiID, APILCWorkflowStatus workflowStatus) throws APIMgtDAOException {
    final String query = "UPDATE AM_API SET LAST_UPDATED_TIME = ?, LC_WORKFLOW_STATUS=? WHERE UUID = ?";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(query)) {
        try {
            connection.setAutoCommit(false);
            statement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now()));
            statement.setString(2, workflowStatus.toString());
            statement.setString(3, apiID);
            statement.execute();
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String msg = "updating workflow status for API: " + apiID + " to Status: " + workflowStatus.name();
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String msg = "updating workflow status for API: " + apiID + " to Status: " + workflowStatus.name();
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 33 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class ApiDAOImpl method updateAPI.

/**
 * Update an existing API
 *
 * @param apiID         The {@link String} of the API that needs to be updated
 * @param substituteAPI Substitute {@link API} object that will replace the existing API
 * @throws APIMgtDAOException if error occurs while accessing data layer
 */
@Override
public void updateAPI(String apiID, API substituteAPI) throws APIMgtDAOException {
    final String query = "UPDATE AM_API SET CONTEXT = ?, IS_DEFAULT_VERSION = ?, DESCRIPTION = ?, VISIBILITY = ?, " + "IS_RESPONSE_CACHED = ?, CACHE_TIMEOUT = ?, TECHNICAL_OWNER = ?, TECHNICAL_EMAIL = ?, " + "BUSINESS_OWNER = ?, BUSINESS_EMAIL = ?, CORS_ENABLED = ?, CORS_ALLOW_ORIGINS = ?, " + "CORS_ALLOW_CREDENTIALS = ?, CORS_ALLOW_HEADERS = ?, CORS_ALLOW_METHODS = ?, LAST_UPDATED_TIME = ?," + "UPDATED_BY = ?, LC_WORKFLOW_STATUS = ?, SECURITY_SCHEME = ? WHERE UUID = ?";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(query)) {
        try {
            connection.setAutoCommit(false);
            statement.setString(1, substituteAPI.getContext());
            statement.setBoolean(2, substituteAPI.isDefaultVersion());
            statement.setString(3, substituteAPI.getDescription());
            statement.setString(4, substituteAPI.getVisibility().toString());
            statement.setBoolean(5, substituteAPI.isResponseCachingEnabled());
            statement.setInt(6, substituteAPI.getCacheTimeout());
            BusinessInformation businessInformation = substituteAPI.getBusinessInformation();
            statement.setString(7, businessInformation.getTechnicalOwner());
            statement.setString(8, businessInformation.getTechnicalOwnerEmail());
            statement.setString(9, businessInformation.getBusinessOwner());
            statement.setString(10, businessInformation.getBusinessOwnerEmail());
            CorsConfiguration corsConfiguration = substituteAPI.getCorsConfiguration();
            statement.setBoolean(11, corsConfiguration.isEnabled());
            statement.setString(12, String.join(",", corsConfiguration.getAllowOrigins()));
            statement.setBoolean(13, corsConfiguration.isAllowCredentials());
            statement.setString(14, String.join(",", corsConfiguration.getAllowHeaders()));
            statement.setString(15, String.join(",", corsConfiguration.getAllowMethods()));
            statement.setTimestamp(16, Timestamp.valueOf(LocalDateTime.now()));
            statement.setString(17, substituteAPI.getUpdatedBy());
            statement.setString(18, substituteAPI.getWorkflowStatus());
            statement.setInt(19, substituteAPI.getSecurityScheme());
            statement.setString(20, apiID);
            statement.execute();
            // Delete current visible roles if they exist
            deleteVisibleRoles(connection, apiID);
            if (API.Visibility.RESTRICTED == substituteAPI.getVisibility()) {
                addVisibleRole(connection, apiID, substituteAPI.getVisibleRoles());
            }
            deleteAPIPermission(connection, apiID);
            updateApiPermission(connection, substituteAPI.getPermissionMap(), apiID);
            deleteTransports(connection, apiID);
            addTransports(connection, apiID, substituteAPI.getTransport());
            deleteThreatProtectionPolicies(connection, apiID);
            if (substituteAPI.getThreatProtectionPolicies() != null) {
                addThreatProtectionPolicies(connection, apiID, substituteAPI.getThreatProtectionPolicies());
            }
            // Delete current tag mappings if they exist
            deleteTagsMapping(connection, apiID);
            addTagsMapping(connection, apiID, substituteAPI.getTags());
            deleteLabelsMapping(connection, apiID);
            addLabelMapping(connection, apiID, substituteAPI.getLabels());
            deleteSubscriptionPolicies(connection, apiID);
            addSubscriptionPolicies(connection, substituteAPI.getPolicies(), apiID);
            deleteEndPointsForApi(connection, apiID);
            addEndPointsForApi(connection, apiID, substituteAPI.getEndpoint());
            deleteEndPointsForOperation(connection, apiID);
            deleteUrlMappings(connection, apiID);
            addUrlMappings(connection, substituteAPI.getUriTemplates().values(), apiID);
            deleteApiPolicy(connection, apiID);
            if (substituteAPI.getApiPolicy() != null) {
                addApiPolicy(connection, substituteAPI.getApiPolicy().getUuid(), apiID);
            }
            connection.commit();
        } catch (SQLException | IOException e) {
            connection.rollback();
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating API: " + substituteAPI.getProvider() + " - " + substituteAPI.getName() + " - " + substituteAPI.getVersion(), e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "updating API: " + substituteAPI.getProvider() + " - " + substituteAPI.getName() + " - " + substituteAPI.getVersion(), e);
    }
}
Also used : BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) CorsConfiguration(org.wso2.carbon.apimgt.core.models.CorsConfiguration) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException)

Example 34 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class ApiDAOImpl method addDocumentInfo.

/**
 * Add artifact resource meta data to an API
 *
 * @param apiId        UUID of API
 * @param documentInfo {@link DocumentInfo}
 * @throws APIMgtDAOException if error occurs while accessing data layer
 */
@Override
public void addDocumentInfo(String apiId, DocumentInfo documentInfo) throws APIMgtDAOException {
    try (Connection connection = DAOUtil.getConnection()) {
        try {
            connection.setAutoCommit(false);
            ApiResourceDAO.addResourceWithoutValue(connection, apiId, documentInfo.getId(), ResourceCategory.DOC);
            DocMetaDataDAO.addDocumentInfo(connection, documentInfo);
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String msg = "adding Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName();
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String msg = "adding Document Info for API: " + apiId + " , Document Name: " + documentInfo.getName();
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + msg, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Example 35 with Link

use of org.wso2.carbon.bpel.ui.bpel2svg.Link in project carbon-apimgt by wso2.

the class ApplicationDAOImpl method addApplication.

/**
 * Add a new instance of an Application
 *
 * @param application The {@link Application} object to be added
 * @throws APIMgtDAOException   If failed to add application.
 */
@Override
public void addApplication(Application application) throws APIMgtDAOException {
    final String addAppQuery = "INSERT INTO AM_APPLICATION (UUID, NAME, APPLICATION_POLICY_ID, " + "DESCRIPTION, APPLICATION_STATUS, CREATED_BY, CREATED_TIME, UPDATED_BY, " + "LAST_UPDATED_TIME) VALUES (?, ?,?,?,?,?,?,?,?)";
    try (Connection conn = DAOUtil.getConnection()) {
        conn.setAutoCommit(false);
        try (PreparedStatement ps = conn.prepareStatement(addAppQuery)) {
            ps.setString(1, application.getId());
            ps.setString(2, application.getName());
            ps.setString(3, application.getPolicy().getUuid());
            ps.setString(4, application.getDescription());
            if (APIMgtConstants.DEFAULT_APPLICATION_NAME.equals(application.getName())) {
                ps.setString(5, APIMgtConstants.ApplicationStatus.APPLICATION_APPROVED);
            } else {
                ps.setString(5, APIMgtConstants.ApplicationStatus.APPLICATION_CREATED);
            }
            ps.setString(6, application.getCreatedUser());
            ps.setTimestamp(7, Timestamp.valueOf(application.getCreatedTime()));
            ps.setString(8, application.getCreatedUser());
            ps.setTimestamp(9, Timestamp.valueOf(application.getCreatedTime()));
            ps.executeUpdate();
            addApplicationPermission(conn, application.getPermissionMap(), application.getId());
            conn.commit();
        } catch (SQLException ex) {
            conn.rollback();
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "adding application: " + application.getId(), ex);
        } finally {
            conn.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException ex) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "adding application: " + application.getId(), ex);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

PreparedStatement (java.sql.PreparedStatement)47 ArrayList (java.util.ArrayList)47 Connection (java.sql.Connection)43 SQLException (java.sql.SQLException)41 ResultSet (java.sql.ResultSet)37 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)26 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)18 HashSet (java.util.HashSet)16 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)15 IOException (java.io.IOException)14 HashMap (java.util.HashMap)14 List (java.util.List)13 Map (java.util.Map)13 Expression (org.wso2.siddhi.query.api.expression.Expression)13 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)12 TimeConstant (org.wso2.siddhi.query.api.expression.constant.TimeConstant)12 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)11 API (org.wso2.carbon.apimgt.core.models.API)11 UserStoreException (org.wso2.carbon.user.api.UserStoreException)10 SiddhiQLParser (org.wso2.siddhi.query.compiler.SiddhiQLParser)10