use of org.wso2.carbon.apimgt.api.APIMgtDAOException 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.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApiFileDAOImpl method updateAPI.
/**
* @see ApiDAO#updateAPI(String apiID, API substituteAPI)
*/
@Override
public void updateAPI(String apiID, API substituteAPI) throws APIMgtDAOException {
API oldAPI = getAPI(apiID);
if (oldAPI == null) {
String errorMsg = "Error while updating API. Unable to find API with Id: " + apiID;
log.error(errorMsg);
throw new APIMgtDAOException(errorMsg, ExceptionCodes.API_NOT_FOUND);
}
// set immutable properties from old API
API updatedAPI = new API.APIBuilder(substituteAPI).id(apiID).provider(oldAPI.getProvider()).name(oldAPI.getName()).version(oldAPI.getVersion()).context(oldAPI.getContext()).createdTime(oldAPI.getCreatedTime()).createdBy(oldAPI.getCreatedBy()).lifecycleInstanceId(oldAPI.getLifecycleInstanceId()).lifeCycleStatus(oldAPI.getLifeCycleStatus()).copiedFromApiId(oldAPI.getCopiedFromApiId()).build();
// Adding the API override the existing files.
addAPI(updatedAPI);
}
use of org.wso2.carbon.apimgt.api.APIMgtDAOException 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;
}
use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApiFileDAOImpl method addAPI.
/**
* @see ApiDAO#addAPI(API api)
*/
@Override
public void addAPI(API api) throws APIMgtDAOException {
// Save API definition
FileApi fileApi = new FileApi(api);
String apiExportDirectory = APIFileUtils.getAPIBaseDirectory(storagePath, fileApi);
APIFileUtils.createDirectory(apiExportDirectory);
APIFileUtils.exportApiDefinitionToFileSystem(fileApi, apiExportDirectory);
// Export gateway config to file system
APIFileUtils.exportGatewayConfigToFileSystem(api.getGatewayConfig(), api, apiExportDirectory);
// Export swagger definition to file system.
APIFileUtils.exportSwaggerDefinitionToFileSystem(api.getApiDefinition(), api, apiExportDirectory);
}
use of org.wso2.carbon.apimgt.api.APIMgtDAOException in project carbon-apimgt by wso2.
the class ApiDAOImpl method getRatingByUUID.
@Override
public Rating getRatingByUUID(String apiId, String ratingId) throws APIMgtDAOException {
final String query = "SELECT UUID, API_ID, RATING, USER_IDENTIFIER, " + "CREATED_BY, CREATED_TIME, UPDATED_BY, LAST_UPDATED_TIME " + "FROM AM_API_RATINGS WHERE UUID = ? AND API_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
try {
statement.setString(1, ratingId);
statement.setString(2, apiId);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next()) {
return constructRatingFromResultSet(rs);
}
}
} catch (SQLException e) {
String errorMessage = "getting Rating: " + ratingId + " for API: " + apiId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
} catch (SQLException e) {
String errorMessage = "getting Rating: " + ratingId + " for API: " + apiId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
return null;
}
Aggregations