use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.
the class CompositeAPIMappingUtilTestCase method testToCompositeAPIDTOAndViceVersa.
@Test
public void testToCompositeAPIDTOAndViceVersa() {
List<String> labels = new ArrayList<>();
labels.add("label1");
// Test compositeAPI to CompositeAPIDTO
CompositeAPI compositeAPI = SampleTestObjectCreator.createCompositeAPIModelBuilder().labels(labels).build();
CompositeAPIDTO compositeAPIDTO = CompositeAPIMappingUtil.toCompositeAPIDTO(compositeAPI);
assertEquals(compositeAPI.getId(), compositeAPIDTO.getId());
assertEquals(compositeAPI.getName(), compositeAPIDTO.getName());
assertEquals(compositeAPI.getProvider(), compositeAPIDTO.getProvider());
assertEquals(compositeAPI.getVersion(), compositeAPIDTO.getVersion());
assertEquals(compositeAPI.getContext(), compositeAPIDTO.getContext());
assertEquals(compositeAPI.getDescription(), compositeAPIDTO.getDescription());
assertEquals(compositeAPI.getLabels().size(), compositeAPIDTO.getLabels().size());
assertEquals(compositeAPI.getApplicationId(), compositeAPIDTO.getApplicationId());
// Test CompositeAPIDTO to compositeAPI
CompositeAPI compositeAPIGenerated = CompositeAPIMappingUtil.toAPI(compositeAPIDTO).build();
assertEquals(compositeAPIGenerated.getId(), compositeAPIDTO.getId());
assertEquals(compositeAPIGenerated.getName(), compositeAPIDTO.getName());
assertEquals(compositeAPIGenerated.getProvider(), compositeAPIDTO.getProvider());
assertEquals(compositeAPIGenerated.getVersion(), compositeAPIDTO.getVersion());
assertEquals(compositeAPIGenerated.getContext(), compositeAPIDTO.getContext());
assertEquals(compositeAPIGenerated.getDescription(), compositeAPIDTO.getDescription());
assertEquals(compositeAPIGenerated.getLabels().size(), compositeAPIDTO.getLabels().size());
assertEquals(compositeAPIGenerated.getApplicationId(), compositeAPIDTO.getApplicationId());
}
use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.
the class CompositeAPIMappingUtilTestCase method testToCompositeAPIListDTO.
@Test
public void testToCompositeAPIListDTO() {
List<CompositeAPI> apisResult = new ArrayList<>();
CompositeAPI comp1 = SampleTestObjectCreator.createCompositeAPIModelBuilder().name("newComp1").build();
CompositeAPI comp2 = SampleTestObjectCreator.createCompositeAPIModelBuilder().name("newComp2").build();
apisResult.add(comp1);
apisResult.add(comp2);
CompositeAPIListDTO compositeAPIListDTO = CompositeAPIMappingUtil.toCompositeAPIListDTO(apisResult);
assertEquals(compositeAPIListDTO.getCount(), (Integer) apisResult.size());
assertEquals(comp1.getId(), compositeAPIListDTO.getList().get(0).getId());
assertEquals(comp1.getName(), compositeAPIListDTO.getList().get(0).getName());
assertEquals(comp1.getProvider(), compositeAPIListDTO.getList().get(0).getProvider());
assertEquals(comp1.getVersion(), compositeAPIListDTO.getList().get(0).getVersion());
assertEquals(comp1.getContext(), compositeAPIListDTO.getList().get(0).getContext());
assertEquals(comp1.getDescription(), compositeAPIListDTO.getList().get(0).getDescription());
assertEquals(comp1.getApplicationId(), compositeAPIListDTO.getList().get(0).getApplicationId());
assertEquals(comp2.getId(), compositeAPIListDTO.getList().get(1).getId());
assertEquals(comp2.getName(), compositeAPIListDTO.getList().get(1).getName());
assertEquals(comp2.getProvider(), compositeAPIListDTO.getList().get(1).getProvider());
assertEquals(comp2.getVersion(), compositeAPIListDTO.getList().get(1).getVersion());
assertEquals(comp2.getContext(), compositeAPIListDTO.getList().get(1).getContext());
assertEquals(comp2.getDescription(), compositeAPIListDTO.getList().get(1).getDescription());
assertEquals(comp2.getApplicationId(), compositeAPIListDTO.getList().get(1).getApplicationId());
}
use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.
the class ApiDAOImpl method getCompositeAPI.
@Override
public CompositeAPI getCompositeAPI(String apiID) throws APIMgtDAOException {
final String query = "SELECT UUID, PROVIDER, NAME, CONTEXT, VERSION, DESCRIPTION, CREATED_BY, CREATED_TIME, " + "LAST_UPDATED_TIME, COPIED_FROM_API, UPDATED_BY, LC_WORKFLOW_STATUS " + "FROM AM_API WHERE UUID = ? AND API_TYPE_ID = (SELECT TYPE_ID FROM AM_API_TYPES WHERE TYPE_NAME = ?)";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, apiID);
statement.setString(2, ApiType.COMPOSITE.toString());
CompositeAPI api = getCompositeAPIFromResultSet(connection, statement);
if (api == null) {
throw new APIMgtDAOException("Composite API: " + apiID + " does not exist", ExceptionCodes.API_NOT_FOUND);
}
return api;
} catch (SQLException | IOException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting Composite API: " + apiID, e);
}
}
use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.
the class ApiDAOImpl method getCompositeAPISummaryList.
private List<CompositeAPI> getCompositeAPISummaryList(Connection connection, PreparedStatement statement) throws SQLException, APIMgtDAOException {
List<CompositeAPI> apiList = new ArrayList<>();
try (ResultSet rs = statement.executeQuery()) {
while (rs.next()) {
String apiPrimaryKey = rs.getString("UUID");
CompositeAPI apiSummary = new CompositeAPI.Builder().id(apiPrimaryKey).provider(rs.getString("PROVIDER")).name(rs.getString("NAME")).version(rs.getString("VERSION")).context(rs.getString("CONTEXT")).description(rs.getString("DESCRIPTION")).applicationId(getCompositeAPIApplicationId(connection, apiPrimaryKey)).workflowStatus(rs.getString("LC_WORKFLOW_STATUS")).threatProtectionPolicies(getThreatProtectionPolicies(connection, apiPrimaryKey)).build();
apiList.add(apiSummary);
}
}
return apiList;
}
use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.
the class ApiDAOImpl method getCompositeAPISummary.
@Override
public CompositeAPI getCompositeAPISummary(String apiID) throws APIMgtDAOException {
final String query = COMPOSITE_API_SUMMARY_SELECT + " WHERE UUID = ? AND API_TYPE_ID = " + "(SELECT TYPE_ID FROM AM_API_TYPES WHERE TYPE_NAME = ?)";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, apiID);
statement.setString(2, ApiType.COMPOSITE.toString());
List<CompositeAPI> apiResults = getCompositeAPISummaryList(connection, statement);
if (apiResults.isEmpty()) {
throw new APIMgtDAOException("API with ID " + apiID + " does not exist", ExceptionCodes.API_NOT_FOUND);
}
// there should be only 1 result from the database
return apiResults.get(0);
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting Composite API: " + apiID, e);
}
}
Aggregations