use of org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList in project carbon-apimgt by wso2.
the class ApplicationDAOImpl method getAllApplications.
@Override
public List<Application> getAllApplications() throws APIMgtDAOException {
List<Application> applicationList = new ArrayList<>();
try (Connection conn = DAOUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(GET_APPS_QUERY)) {
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
String createdUser = rs.getString("CREATED_BY");
Application application = new Application(rs.getString("NAME"), createdUser);
application.setId(rs.getString("UUID"));
application.setStatus(rs.getString("APPLICATION_STATUS"));
application.setPolicy(new ApplicationPolicy(rs.getString("APPLICATION_POLICY_ID"), ""));
applicationList.add(application);
}
}
} catch (SQLException ex) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting all applications", ex);
}
return applicationList;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList in project carbon-apimgt by wso2.
the class MappingUtilTestCase method convertToApplicationDtoListTest.
@Test
public void convertToApplicationDtoListTest() {
List<Application> applicationList = new ArrayList<>();
applicationList.add(SampleTestObjectCreator.createRandomApplication());
applicationList.add(SampleTestObjectCreator.createRandomApplication());
applicationList.add(SampleTestObjectCreator.createRandomApplication());
List<ApplicationDTO> applicationDTOList = MappingUtil.convertToApplicationDtoList(applicationList);
Assert.assertEquals(applicationList.size(), applicationDTOList.size());
for (int i = 0; i < applicationList.size(); i++) {
Assert.assertEquals(applicationList.get(i).getName(), applicationDTOList.get(i).getName());
Assert.assertEquals(applicationList.get(i).getId(), applicationDTOList.get(i).getApplicationId());
Assert.assertEquals(applicationList.get(i).getPolicy().getUuid(), applicationDTOList.get(i).getThrottlingTier());
Assert.assertEquals(applicationList.get(i).getCreatedUser(), applicationDTOList.get(i).getSubscriber());
}
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList in project carbon-apimgt by wso2.
the class ApplicationMappingUtilTestCase method testFromApplicationsToDTO.
@Test
public void testFromApplicationsToDTO() {
Application application1 = new Application("application1", "user1");
application1.setId(UUID.randomUUID().toString());
application1.setDescription("application 1");
application1.setStatus("ACTIVE");
application1.setPolicy(new APIPolicy("GOLD"));
Application application2 = new Application("application2", "user1");
application2.setId(UUID.randomUUID().toString());
application2.setDescription("application 2");
application2.setStatus("ACTIVE");
application2.setPolicy(new APIPolicy("GOLD"));
Application application3 = new Application("application3", "user1");
application3.setId(UUID.randomUUID().toString());
application3.setDescription("application 3");
application3.setStatus("ACTIVE");
application3.setPolicy(new APIPolicy("GOLD"));
List<Application> applicationList = new ArrayList<>();
applicationList.add(application1);
applicationList.add(application2);
applicationList.add(application3);
ApplicationMappingUtil applicationMappingUtil = new ApplicationMappingUtil();
ApplicationListDTO applicationListDTO = applicationMappingUtil.fromApplicationsToDTO(applicationList, 10, 0);
Assert.assertEquals(applicationListDTO.getList().get(0).getName(), "application1");
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList in project carbon-apimgt by wso2.
the class MappingUtil method convertToApplicationDtoList.
/**
* convert {@link ApplicationDTO} to {@link Application}
*
* @param applicationList List of {@link Application}
* @return ApplicationEvent list
*/
public static List<ApplicationDTO> convertToApplicationDtoList(List<Application> applicationList) {
List<ApplicationDTO> applicationDTOList = new ArrayList<>();
for (Application application : applicationList) {
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setName(application.getName());
applicationDTO.setApplicationId(application.getId());
applicationDTO.setThrottlingTier(application.getPolicy().getUuid());
applicationDTO.setSubscriber(application.getCreatedUser());
applicationDTOList.add(applicationDTO);
}
return applicationDTOList;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImpl method applicationsGet.
@Override
public Response applicationsGet(String accept, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
List<Application> applicationList = apiMgtAdminService.getAllApplications();
ApplicationListDTO applicationListDTO = new ApplicationListDTO();
applicationListDTO.setList(MappingUtil.convertToApplicationDtoList(applicationList));
return Response.ok(applicationListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving Applications.";
HashMap<String, String> paramList = new HashMap<String, String>();
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations