Search in sources :

Example 21 with User

use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.

the class ApiFileDAOImpl method getAPIs.

/**
 * @see ApiDAO#getAPIs(Set, String)
 */
@Override
public List<API> getAPIs(Set<String> roles, String user) throws APIMgtDAOException {
    File[] files = new File(storagePath).listFiles();
    List<API> apiList = new ArrayList<>();
    final FilenameFilter filenameFilter = (dir, name) -> (name.endsWith(APIMgtConstants.APIFileUtilConstants.JSON_EXTENSION) && name.contains(APIMgtConstants.APIFileUtilConstants.API_DEFINITION_FILE_PREFIX) && !dir.isHidden());
    if (files != null) {
        for (File file : files) {
            apiList.add((API) fetchObject(file, FileApi.class, filenameFilter));
        }
    }
    apiList.removeIf(Objects::isNull);
    return apiList;
}
Also used : FilenameFilter(java.io.FilenameFilter) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway) LoggerFactory(org.slf4j.LoggerFactory) Rating(org.wso2.carbon.apimgt.core.models.Rating) JsonReader(com.google.gson.stream.JsonReader) APIFileUtils(org.wso2.carbon.apimgt.core.util.APIFileUtils) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Map(java.util.Map) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIMgtConstants(org.wso2.carbon.apimgt.core.util.APIMgtConstants) Logger(org.slf4j.Logger) API(org.wso2.carbon.apimgt.core.models.API) Set(java.util.Set) ExceptionCodes(org.wso2.carbon.apimgt.core.exception.ExceptionCodes) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Comment(org.wso2.carbon.apimgt.core.models.Comment) Objects(java.util.Objects) List(java.util.List) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) FileApi(org.wso2.carbon.apimgt.core.models.FileApi) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) InputStream(java.io.InputStream) FilenameFilter(java.io.FilenameFilter) ArrayList(java.util.ArrayList) Objects(java.util.Objects) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) File(java.io.File)

Example 22 with User

use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.

the class FunctionDAOImpl method getUserDeployedFunctions.

/**
 * {@inheritDoc}
 */
@Override
public List<Function> getUserDeployedFunctions(String userName) throws APIMgtDAOException {
    if (userName == null) {
        throw new IllegalArgumentException("Username must not be null");
    }
    List<Function> functions = new ArrayList<>();
    final String sqlQuery = "SELECT FUNCTION_NAME, FUNCTION_URI " + "FROM AM_LAMBDA_FUNCTION " + "WHERE USER_NAME = ?";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
        preparedStatement.setString(1, userName);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                String functionName = resultSet.getString("FUNCTION_NAME");
                URI endpointURI = new URI(resultSet.getString("FUNCTION_URI"));
                functions.add(new Function(functionName, endpointURI));
            }
        } catch (URISyntaxException e) {
            throw new APIMgtDAOException("Not a URI", e);
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException("Error retrieving functions of user: " + userName, e);
    }
    return functions;
}
Also used : Function(org.wso2.carbon.apimgt.core.models.Function) 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) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 23 with User

use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.

the class FunctionDAOImpl method getUserFunctionsForEvent.

/**
 * {@inheritDoc}
 */
@Override
public List<Function> getUserFunctionsForEvent(String userName, Event event) throws APIMgtDAOException {
    if (userName == null) {
        throw new IllegalArgumentException("Username must not be null");
    }
    if (event == null) {
        throw new IllegalArgumentException("Event must not be null");
    }
    List<Function> functions = new ArrayList<>();
    final String sqlQuery = "SELECT FUNCTION_NAME, FUNCTION_URI " + "FROM AM_LAMBDA_FUNCTION JOIN AM_EVENT_FUNCTION_MAPPING " + "ON AM_LAMBDA_FUNCTION.FUNCTION_ID = AM_EVENT_FUNCTION_MAPPING.FUNCTION_ID " + "WHERE USER_NAME = ? AND EVENT = ?";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
        preparedStatement.setString(1, userName);
        preparedStatement.setString(2, event.getEventAsString());
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                String functionName = resultSet.getString("FUNCTION_NAME");
                URI endpointURI = new URI(resultSet.getString("FUNCTION_URI"));
                functions.add(new Function(functionName, endpointURI));
            }
        } catch (URISyntaxException e) {
            throw new APIMgtDAOException("Not a URI", e);
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException("Error retrieving functions for event: " + event + " of user: " + userName, e);
    }
    return functions;
}
Also used : Function(org.wso2.carbon.apimgt.core.models.Function) 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) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 24 with User

use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.

the class FunctionDAOImpl method deleteEventFunctionMapping.

/**
 * {@inheritDoc}
 */
@Override
public void deleteEventFunctionMapping(String userName, Event event, String functionName) throws APIMgtDAOException {
    if (userName == null) {
        throw new IllegalArgumentException("Username must not be null");
    }
    if (event == null) {
        throw new IllegalArgumentException("Event must not be null");
    }
    if (functionName == null) {
        throw new IllegalArgumentException("Function name must not be null");
    }
    final String sqlQuery = "DELETE FROM AM_EVENT_FUNCTION_MAPPING " + "WHERE EVENT = ? AND FUNCTION_ID = " + "(SELECT FUNCTION_ID " + "FROM AM_LAMBDA_FUNCTION " + "WHERE USER_NAME = ? AND FUNCTION_NAME = ?)";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
        preparedStatement.setString(1, event.getEventAsString());
        preparedStatement.setString(2, userName);
        preparedStatement.setString(3, functionName);
        preparedStatement.executeUpdate();
    } catch (SQLException e) {
        throw new APIMgtDAOException("Error deleting event function mapping -event: " + event + " -function: " + functionName + " -user: " + userName, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 25 with User

use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.

the class FunctionDAOImpl method getTriggersForUserFunction.

/**
 * {@inheritDoc}
 */
@Override
public List<Event> getTriggersForUserFunction(String userName, String functionName) throws APIMgtDAOException {
    if (userName == null) {
        throw new IllegalArgumentException("Username must not be null");
    }
    if (functionName == null) {
        throw new IllegalArgumentException("Function name must not be null");
    }
    List<Event> events = new ArrayList<>();
    final String sqlQuery = "SELECT EVENT " + "FROM AM_LAMBDA_FUNCTION JOIN AM_EVENT_FUNCTION_MAPPING " + "ON AM_LAMBDA_FUNCTION.FUNCTION_ID = AM_EVENT_FUNCTION_MAPPING.FUNCTION_ID " + "WHERE USER_NAME = ? AND FUNCTION_NAME = ?";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement preparedStatement = connection.prepareStatement(sqlQuery)) {
        preparedStatement.setString(1, userName);
        preparedStatement.setString(2, functionName);
        try (ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                events.add(Event.valueOf(resultSet.getString("EVENT")));
            }
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException("Error retrieving triggers for function: " + functionName + " of user: " + userName, e);
    }
    return events;
}
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) Event(org.wso2.carbon.apimgt.core.models.Event) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Test (org.junit.Test)225 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)225 Response (javax.ws.rs.core.Response)217 Test (org.testng.annotations.Test)150 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)130 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)114 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)112 Request (org.wso2.msf4j.Request)105 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)98 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)88 ArrayList (java.util.ArrayList)73 API (org.wso2.carbon.apimgt.core.models.API)73 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)65 HashMap (java.util.HashMap)59 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)51 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)51 Event (org.wso2.siddhi.core.event.Event)45 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)45 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)44 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)41