Search in sources :

Example 1 with ApplicationList

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;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Application(org.wso2.carbon.apimgt.core.models.Application)

Example 2 with 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());
    }
}
Also used : ApplicationDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationDTO) ArrayList(java.util.ArrayList) Application(org.wso2.carbon.apimgt.core.models.Application) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Test(org.testng.annotations.Test)

Example 3 with ApplicationList

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");
}
Also used : ArrayList(java.util.ArrayList) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) Application(org.wso2.carbon.apimgt.core.models.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationListDTO) Test(org.junit.Test)

Example 4 with ApplicationList

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;
}
Also used : ApplicationDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationDTO) ArrayList(java.util.ArrayList) Application(org.wso2.carbon.apimgt.core.models.Application)

Example 5 with ApplicationList

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();
    }
}
Also used : HashMap(java.util.HashMap) APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) Application(org.wso2.carbon.apimgt.core.models.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationListDTO)

Aggregations

ArrayList (java.util.ArrayList)10 Application (org.wso2.carbon.apimgt.core.models.Application)8 Test (org.junit.Test)4 Response (javax.ws.rs.core.Response)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)2 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)2 ApplicationCreationResponse (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse)2 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)2 ApplicationDTO (org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationDTO)2 ApplicationListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationListDTO)2 ApplicationListDTO (org.wso2.carbon.apimgt.rest.api.gateway.dto.ApplicationListDTO)2 Request (org.wso2.msf4j.Request)2 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1