use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class ApiDAOImpl method getUriTemplates.
private Map<String, UriTemplate> getUriTemplates(Connection connection, String apiId) throws SQLException, IOException {
final String query = "SELECT operationMapping.OPERATION_ID AS OPERATION_ID,operationMapping.API_ID AS API_ID," + "operationMapping.HTTP_METHOD AS HTTP_METHOD,operationMapping.URL_PATTERN AS URL_PATTERN," + "operationMapping.AUTH_SCHEME AS AUTH_SCHEME,operationMapping.API_POLICY_ID AS API_POLICY_ID FROM " + "AM_API_OPERATION_MAPPING operationMapping WHERE operationMapping.API_ID = ?";
Map<String, UriTemplate> uriTemplateSet = new HashMap();
try (PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, apiId);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
while (rs.next()) {
UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder().uriTemplate(rs.getString("URL_PATTERN")).authType(rs.getString("AUTH_SCHEME")).httpVerb(rs.getString("HTTP_METHOD")).templateId(rs.getString("OPERATION_ID")).endpoint(getEndPointsForOperation(connection, apiId, rs.getString("OPERATION_ID")));
String apiPolicyId = rs.getString("API_POLICY_ID");
if (StringUtils.isNotEmpty(apiPolicyId)) {
uriTemplateBuilder.policy(getApiPolicyByUuid(connection, apiPolicyId));
}
uriTemplateSet.put(uriTemplateBuilder.build().getTemplateId(), uriTemplateBuilder.build());
}
}
}
return uriTemplateSet;
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class ApiDAOImpl method deleteEndpoint.
/**
* Delete an Endpoint
*
* @param endpointId UUID of the endpoint.
* @return Success of the delete operation.
* @throws APIMgtDAOException If failed to delete endpoint.
*/
@Override
public boolean deleteEndpoint(String endpointId) throws APIMgtDAOException {
try (Connection connection = DAOUtil.getConnection()) {
try {
connection.setAutoCommit(false);
deleteEndpoint(connection, endpointId);
connection.commit();
return true;
} catch (SQLException e) {
connection.rollback();
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting Endpoint: " + endpointId, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting Endpoint: " + endpointId, e);
}
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class ApiDAOImpl method getEndpoints.
/**
* get all Endpoints
*
* @return List of endpoints.
* @throws APIMgtDAOException If failed to retrieve endpoints.
*/
@Override
public List<Endpoint> getEndpoints() throws APIMgtDAOException {
final String query = "SELECT UUID,NAME,ENDPOINT_CONFIGURATION,TPS,TYPE,SECURITY_CONFIGURATION," + "APPLICABLE_LEVEL FROM AM_ENDPOINT WHERE APPLICABLE_LEVEL='" + APIMgtConstants.GLOBAL_ENDPOINT + "'";
List<Endpoint> endpointList = new ArrayList<>();
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query);
ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
endpointList.add(constructEndPointDetails(resultSet));
}
} catch (SQLException | IOException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting Endpoints", e);
}
return endpointList;
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class APIPublisherImpl method updateEndpoint.
/**
* Update and endpoint
*
* @param endpoint Endpoint object.
* @throws APIManagementException If failed to update endpoint.
*/
@Override
public void updateEndpoint(Endpoint endpoint) throws APIManagementException {
APIGateway gateway = getApiGateway();
gateway.updateEndpoint(endpoint);
String config = getGatewaySourceGenerator().getEndpointConfigStringFromTemplate(endpoint);
Endpoint updatedEndpoint = new Endpoint.Builder(endpoint).config(config).build();
try {
getApiDAO().updateEndpoint(updatedEndpoint);
} catch (APIMgtDAOException e) {
String msg = "Failed to update Endpoint : " + endpoint.getName();
log.error(msg, e);
throw new APIManagementException(msg, e, e.getErrorHandler());
}
// update endpoint config in gateway
}
use of org.wso2.carbon.apimgt.core.models.Endpoint in project carbon-apimgt by wso2.
the class APIPublisherImpl method searchAPIs.
/**
* @param limit Limit
* @param offset Offset
* @param query Search query
* @return List of APIS.
* @throws APIManagementException If failed to formatApiSearch APIs.
*/
@Override
public List<API> searchAPIs(Integer limit, Integer offset, String query) throws APIManagementException {
List<API> apiResults;
String user = getUsername();
Set<String> roles = new HashSet<>();
try {
// TODO: Need to validate users roles against results returned
if (!"admin".equals(user)) {
// Whenever call identity provider should convert pseudo name to actual name
String userId = getIdentityProvider().getIdOfUser(user);
roles = new HashSet<>(getIdentityProvider().getRoleIdsOfUser(userId));
}
if (query != null && !query.isEmpty()) {
String[] attributes = query.split(ATTRIBUTE_DELIMITER);
Map<String, String> attributeMap = new HashMap<>();
boolean isFullTextSearch = false;
String searchAttribute, searchValue;
if (!query.contains(KEY_VALUE_DELIMITER)) {
isFullTextSearch = true;
} else {
log.debug("Search query: " + query);
for (String attribute : attributes) {
searchAttribute = attribute.split(KEY_VALUE_DELIMITER)[0];
searchValue = attribute.split(KEY_VALUE_DELIMITER)[1];
log.debug(searchAttribute + KEY_VALUE_DELIMITER + searchValue);
attributeMap.put(searchAttribute, searchValue);
}
}
if (isFullTextSearch) {
apiResults = getApiDAO().searchAPIs(roles, user, query, offset, limit);
} else {
log.debug("Attributes:", attributeMap.toString());
apiResults = getApiDAO().attributeSearchAPIs(roles, user, attributeMap, offset, limit);
}
} else {
apiResults = getApiDAO().getAPIs(roles, user);
}
return apiResults;
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while Searching the API with query " + query;
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
} catch (IdentityProviderException e) {
String errorMsg = "Error occurred while calling SCIM endpoint to retrieve user " + user + "'s information";
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
}
}
Aggregations