Search in sources :

Example 21 with Add

use of org.wso2.siddhi.query.api.expression.math.Add in project siddhi by wso2.

the class SiddhiApp method defineTrigger.

public SiddhiApp defineTrigger(TriggerDefinition triggerDefinition) {
    if (triggerDefinition == null) {
        throw new SiddhiAppValidationException("Trigger Definition should not be null");
    } else if (triggerDefinition.getId() == null) {
        throw new SiddhiAppValidationException("Trigger Id should not be null for Trigger Definition", triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex());
    }
    StreamDefinition streamDefinition = StreamDefinition.id(triggerDefinition.getId()).attribute(SiddhiConstants.TRIGGERED_TIME, Attribute.Type.LONG);
    streamDefinition.setQueryContextStartIndex(triggerDefinition.getQueryContextStartIndex());
    streamDefinition.setQueryContextEndIndex(triggerDefinition.getQueryContextEndIndex());
    try {
        checkDuplicateDefinition(streamDefinition);
    } catch (DuplicateDefinitionException e) {
        throw new DuplicateDefinitionException("Trigger '" + triggerDefinition.getId() + "' cannot be defined as," + " " + e.getMessageWithOutContext(), e, triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex());
    }
    if (triggerDefinitionMap.containsKey(triggerDefinition.getId())) {
        throw new DuplicateDefinitionException("Trigger Definition with same Id '" + triggerDefinition.getId() + "' already exist '" + triggerDefinitionMap.get(triggerDefinition.getId()) + "', hence cannot add '" + triggerDefinition + "'", triggerDefinition.getQueryContextStartIndex(), triggerDefinition.getQueryContextEndIndex());
    }
    this.triggerDefinitionMap.put(triggerDefinition.getId(), triggerDefinition);
    this.streamDefinitionMap.put(streamDefinition.getId(), streamDefinition);
    return this;
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) DuplicateDefinitionException(org.wso2.siddhi.query.api.exception.DuplicateDefinitionException) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)

Example 22 with Add

use of org.wso2.siddhi.query.api.expression.math.Add in project siddhi by wso2.

the class SiddhiApp method addPartition.

public SiddhiApp addPartition(Partition partition) {
    if (partition == null) {
        throw new SiddhiAppValidationException("Partition should not be null");
    }
    String name = null;
    Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants.ANNOTATION_ELEMENT_NAME, partition.getAnnotations());
    if (element != null) {
        name = element.getValue();
    }
    if (name != null && executionElementNameList.contains(name)) {
        throw new SiddhiAppValidationException("Cannot add Partition as another Execution Element already " + "uses its name=" + name, element.getQueryContextStartIndex(), element.getQueryContextEndIndex());
    }
    executionElementNameList.add(name);
    this.executionElementList.add(partition);
    return this;
}
Also used : Element(org.wso2.siddhi.query.api.annotation.Element) ExecutionElement(org.wso2.siddhi.query.api.execution.ExecutionElement) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)

Example 23 with Add

use of org.wso2.siddhi.query.api.expression.math.Add in project siddhi by wso2.

the class SiddhiApp method addQuery.

public SiddhiApp addQuery(Query query) {
    if (query == null) {
        throw new SiddhiAppValidationException("Query should not be null");
    }
    String name = null;
    Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants.ANNOTATION_ELEMENT_NAME, query.getAnnotations());
    if (element != null) {
        name = element.getValue();
    }
    if (name != null && executionElementNameList.contains(name)) {
        throw new SiddhiAppValidationException("Cannot add Query as another Execution Element already uses " + "its name=" + name, element.getQueryContextStartIndex(), element.getQueryContextEndIndex());
    }
    executionElementNameList.add(name);
    this.executionElementList.add(query);
    return this;
}
Also used : Element(org.wso2.siddhi.query.api.annotation.Element) ExecutionElement(org.wso2.siddhi.query.api.execution.ExecutionElement) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)

Example 24 with Add

use of org.wso2.siddhi.query.api.expression.math.Add 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 25 with Add

use of org.wso2.siddhi.query.api.expression.math.Add 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

Test (org.testng.annotations.Test)134 API (org.wso2.carbon.apimgt.core.models.API)63 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)60 ArrayList (java.util.ArrayList)57 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)55 HashMap (java.util.HashMap)51 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)44 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)43 Application (org.wso2.carbon.apimgt.core.models.Application)37 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)35 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)33 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)30 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)29 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)26 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)26 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)25 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)23 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)22 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)22 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)22