From f09905a2ecfe74903f9374a7b48d440f260a7871 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Fri, 12 May 2017 16:43:53 +0530 Subject: [PATCH] Changes to DB queries --- .../ApplicationManagementServiceImpl.java | 1 + .../dao/ApplicationManagementDAOUtil.java | 12 ++--- .../dao/impl/GenericAppManagementDAO.java | 13 +++--- .../application/mgt/core/dto/Application.java | 10 ++--- .../{ApplicationType.java => Platform.java} | 44 ++++++++++++++++--- 5 files changed, 57 insertions(+), 23 deletions(-) rename components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/{ApplicationType.java => Platform.java} (60%) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementServiceImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementServiceImpl.java index 87de7714b91..82fbcbefd4d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementServiceImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementServiceImpl.java @@ -56,6 +56,7 @@ public class ApplicationManagementServiceImpl { ApplicationList applications = applicationManager.getApplications(filter); return Response.status(Response.Status.OK).entity(applications).build(); + } catch (Exception e) { String msg = "Error occurred while getting the application list"; log.error(msg, e); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOUtil.java index 5b6ae3e72af..f68168d83fe 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOUtil.java @@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.json.JSONArray; import org.json.JSONException; import org.wso2.carbon.device.application.mgt.core.dto.Application; -import org.wso2.carbon.device.application.mgt.core.dto.ApplicationType; +import org.wso2.carbon.device.application.mgt.core.dto.Platform; import org.wso2.carbon.device.application.mgt.core.dto.Category; import java.sql.PreparedStatement; @@ -39,6 +39,7 @@ public class ApplicationManagementDAOUtil { private static final Log log = LogFactory.getLog(ApplicationManagementDAOUtil.class); public static Application loadApplication(ResultSet rs , ResultSet rsProperties) throws SQLException, JSONException { + Application application = new Application(); application.setId(rs.getInt("ID")); application.setName(rs.getString("NAME")); @@ -48,13 +49,12 @@ public class ApplicationManagementDAOUtil { application.setBannerName(rs.getString("BANNER_NAME")); application.setVideoName(rs.getString("VIDEO_NAME")); application.setScreenshots(jsonArrayStringToList(rs.getString("SCREENSHOTS"))); - application.setTags(jsonArrayStringToList(rs.getString("TAGS"))); application.setCreatedAt(rs.getDate("CREATED_AT")); application.setModifiedAt(rs.getDate("MODIFIED_AT")); - ApplicationType applicationType = new ApplicationType(); - applicationType.setName(rs.getString("AT_NAME")); - applicationType.setCode(rs.getString("AT_CODE")); + Platform applicationType = new Platform(); + applicationType.setName(rs.getString("APL_NAME")); + applicationType.setCode(rs.getString("APL_CODE")); application.setApplicationType(applicationType); Map properties = new HashMap<>(); @@ -64,7 +64,7 @@ public class ApplicationManagementDAOUtil { application.setProperties(properties); Category category = new Category(); - category.setName(rs.getString("CT_NAME")); + category.setName(rs.getString("CAT_NAME")); application.setCategory(category); return application; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/GenericAppManagementDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/GenericAppManagementDAO.java index bf2b5b67443..20412349c67 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/GenericAppManagementDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/GenericAppManagementDAO.java @@ -64,12 +64,13 @@ public class GenericAppManagementDAO implements ApplicationManagementDAO { conn = ConnectionManagerUtil.getCurrentConnection().get(); - sql += "SELECT SQL_CALC_FOUND_ROWS AP.*, AT.NAME AS AT_NAME, AT.CODE AS AT_CODE, CT.NAME AS CT_NAME "; - sql += "FROM APPM_APPLICATION AS AP "; - sql += "INNER JOIN APPM_APPLICATION_TYPE AS AT ON AP.APPLICATION_TYPE_ID = AT.ID "; - sql += "INNER JOIN APPM_APPLICATION_CATEGORY AS CT ON AP.CATEGORY_ID = CT.ID "; + sql += "SELECT SQL_CALC_FOUND_ROWS APP.*, APL.NAME AS APL_NAME, APL.CODE AS APL_CODE, CAT.NAME AS CAT_NAME "; + sql += "FROM APPM_APPLICATION AS APP "; + sql += "INNER JOIN APPM_PLATFORM_APPLICATION_MAPPING AS APM ON APP.PLATFORM_APPLICATION_MAPPING_ID = APM.ID "; + sql += "INNER JOIN APPM_PLATFORM AS APL ON APM.PLATFORM_ID = APL.ID "; + sql += "INNER JOIN APPM_APPLICATION_CATEGORY AS CAT ON APP.APPLICATION_CATEGORY_ID = CAT.ID "; if (filter.getSearchQuery() != null || "".equals(filter.getSearchQuery())) { - sql += "WHERE AP.NAME LIKE ? "; + sql += "WHERE APP.NAME LIKE ? "; } sql += "LIMIT ? "; sql += "OFFSET ?;"; @@ -95,7 +96,7 @@ public class GenericAppManagementDAO implements ApplicationManagementDAO { while (rs.next()) { //Getting properties - sql = "SELECT * FROM APPM_APPLICATION_PROPERTIES WHERE APPLICATION_ID=?"; + sql = "SELECT * FROM APPM_APPLICATION_PROPERTY WHERE APPLICATION_ID=?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, rs.getInt("ID")); ResultSet rsProperties = stmt.executeQuery(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Application.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Application.java index 56b45fa45b8..babac2321cd 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Application.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Application.java @@ -50,7 +50,7 @@ public class Application { private Date modifiedAt; - private ApplicationType applicationType; + private Platform platform; private Category category; @@ -147,12 +147,12 @@ public class Application { this.modifiedAt = modifiedAt; } - public ApplicationType getApplicationType() { - return applicationType; + public Platform getPlatform() { + return platform; } - public void setApplicationType(ApplicationType applicationType) { - this.applicationType = applicationType; + public void setPlatform(Platform platform) { + this.platform = platform; } public Category getCategory() { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/ApplicationType.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Platform.java similarity index 60% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/ApplicationType.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Platform.java index c6a9bb25ee3..18e876909ad 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/ApplicationType.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Platform.java @@ -20,16 +20,24 @@ package org.wso2.carbon.device.application.mgt.core.dto; import org.wso2.carbon.device.application.mgt.core.jaxrs.Exclude; -public class ApplicationType { +import java.util.List; + +public class Platform { @Exclude private int id; private String name; + private String description; + private String code; - private String parameters; + private String iconName; + + private String properties; + + private List applications; public int getId() { return id; @@ -47,6 +55,14 @@ public class ApplicationType { this.name = name; } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + public String getCode() { return code; } @@ -55,11 +71,27 @@ public class ApplicationType { this.code = code; } - public String getParameters() { - return parameters; + public String getIconName() { + return iconName; + } + + public void setIconName(String iconName) { + this.iconName = iconName; + } + + public String getProperties() { + return properties; + } + + public void setProperties(String properties) { + this.properties = properties; + } + + public List getApplications() { + return applications; } - public void setParameters(String parameters) { - this.parameters = parameters; + public void setApplications(List applications) { + this.applications = applications; } }