use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.
the class ApiDAOImpl method constructAPISummaryList.
private List<API> constructAPISummaryList(Connection connection, PreparedStatement statement) throws SQLException {
List<API> apiList = new ArrayList<>();
try (ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
String apiPrimaryKey = rs.getString("UUID");
API apiSummary = new API.APIBuilder(rs.getString("PROVIDER"), rs.getString("NAME"), rs.getString("VERSION")).id(apiPrimaryKey).context(rs.getString("CONTEXT")).description(rs.getString("DESCRIPTION")).lifeCycleStatus(rs.getString("CURRENT_LC_STATUS")).lifecycleInstanceId(rs.getString("LIFECYCLE_INSTANCE_ID")).workflowStatus(rs.getString("LC_WORKFLOW_STATUS")).securityScheme(rs.getInt("SECURITY_SCHEME")).threatProtectionPolicies(getThreatProtectionPolicies(connection, apiPrimaryKey)).build();
apiList.add(apiSummary);
}
}
return apiList;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList 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.keymgt.model.entity.APIList in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method getAPIsByGatewayLabel.
@Override
public List<API> getAPIsByGatewayLabel(List<String> gatewayLabels) throws APIManagementException {
List<API> apiList;
try {
if (gatewayLabels != null) {
apiList = apiDAO.getAPIsByGatewayLabel(gatewayLabels);
} else {
String msg = "Gateway labels cannot be null";
log.error(msg);
throw new APIManagementException(msg, ExceptionCodes.GATEWAY_LABELS_CANNOT_BE_NULL);
}
} catch (APIMgtDAOException e) {
String msg = "Error occurred while getting the API list in given gateway labels";
log.error(msg, e);
throw new APIManagementException(msg, ExceptionCodes.APIMGT_DAO_EXCEPTION);
}
return apiList;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method getAPIsByStatus.
@Override
public List<API> getAPIsByStatus(List<String> gatewayLabels, String status) throws APIManagementException {
List<API> apiList;
try {
if (gatewayLabels != null && status != null) {
apiList = apiDAO.getAPIsByStatus(gatewayLabels, status);
} else {
if (gatewayLabels == null) {
String msg = "Gateway labels cannot be null";
log.error(msg);
throw new APIManagementException(msg, ExceptionCodes.GATEWAY_LABELS_CANNOT_BE_NULL);
} else {
String msg = "Status cannot be null";
log.error(msg);
throw new APIManagementException(msg, ExceptionCodes.STATUS_CANNOT_BE_NULL);
}
}
} catch (APIMgtDAOException e) {
String msg = "Error occurred while getting the API list in given states";
log.error(msg, e);
throw new APIManagementException(msg, ExceptionCodes.APIMGT_DAO_EXCEPTION);
}
return apiList;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testGetAPIsWhenUserRolesInAPIPermissionsWithoutREAD.
@Test(description = "Tests getting the APIs when the user roles are contained in the API permission list " + "but without READ permissions")
public void testGetAPIsWhenUserRolesInAPIPermissionsWithoutREAD() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
Set<String> rolesOfUser = new HashSet<>();
rolesOfUser.add(SampleTestObjectCreator.DEVELOPER_ROLE_ID);
// This user is not the provider of the API
List<API> apiList = apiDAO.getAPIs(rolesOfUser, ALTERNATIVE_USER);
Assert.assertTrue(apiList.isEmpty());
Map map = new HashMap();
map.put(SampleTestObjectCreator.DEVELOPER_ROLE_ID, 0);
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().permissionMap(map);
API api1 = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api1);
apiList = apiDAO.getAPIs(rolesOfUser, ALTERNATIVE_USER);
// Since the API has the role ID of the user but without READ permissions, it is not visible to this user
Assert.assertTrue(apiList.size() == 0);
}
Aggregations