Changes to DB queries

feature/appm-store/pbac
Chatura Dilan 8 years ago
parent c6263ae22d
commit f09905a2ec

@ -56,6 +56,7 @@ public class ApplicationManagementServiceImpl {
ApplicationList applications = applicationManager.getApplications(filter); ApplicationList applications = applicationManager.getApplications(filter);
return Response.status(Response.Status.OK).entity(applications).build(); return Response.status(Response.Status.OK).entity(applications).build();
} catch (Exception e) { } catch (Exception e) {
String msg = "Error occurred while getting the application list"; String msg = "Error occurred while getting the application list";
log.error(msg, e); log.error(msg, e);

@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.core.dto.Application; 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 org.wso2.carbon.device.application.mgt.core.dto.Category;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -39,6 +39,7 @@ public class ApplicationManagementDAOUtil {
private static final Log log = LogFactory.getLog(ApplicationManagementDAOUtil.class); private static final Log log = LogFactory.getLog(ApplicationManagementDAOUtil.class);
public static Application loadApplication(ResultSet rs , ResultSet rsProperties) throws SQLException, JSONException { public static Application loadApplication(ResultSet rs , ResultSet rsProperties) throws SQLException, JSONException {
Application application = new Application(); Application application = new Application();
application.setId(rs.getInt("ID")); application.setId(rs.getInt("ID"));
application.setName(rs.getString("NAME")); application.setName(rs.getString("NAME"));
@ -48,13 +49,12 @@ public class ApplicationManagementDAOUtil {
application.setBannerName(rs.getString("BANNER_NAME")); application.setBannerName(rs.getString("BANNER_NAME"));
application.setVideoName(rs.getString("VIDEO_NAME")); application.setVideoName(rs.getString("VIDEO_NAME"));
application.setScreenshots(jsonArrayStringToList(rs.getString("SCREENSHOTS"))); application.setScreenshots(jsonArrayStringToList(rs.getString("SCREENSHOTS")));
application.setTags(jsonArrayStringToList(rs.getString("TAGS")));
application.setCreatedAt(rs.getDate("CREATED_AT")); application.setCreatedAt(rs.getDate("CREATED_AT"));
application.setModifiedAt(rs.getDate("MODIFIED_AT")); application.setModifiedAt(rs.getDate("MODIFIED_AT"));
ApplicationType applicationType = new ApplicationType(); Platform applicationType = new Platform();
applicationType.setName(rs.getString("AT_NAME")); applicationType.setName(rs.getString("APL_NAME"));
applicationType.setCode(rs.getString("AT_CODE")); applicationType.setCode(rs.getString("APL_CODE"));
application.setApplicationType(applicationType); application.setApplicationType(applicationType);
Map<String, String> properties = new HashMap<>(); Map<String, String> properties = new HashMap<>();
@ -64,7 +64,7 @@ public class ApplicationManagementDAOUtil {
application.setProperties(properties); application.setProperties(properties);
Category category = new Category(); Category category = new Category();
category.setName(rs.getString("CT_NAME")); category.setName(rs.getString("CAT_NAME"));
application.setCategory(category); application.setCategory(category);
return application; return application;
} }

@ -64,12 +64,13 @@ public class GenericAppManagementDAO implements ApplicationManagementDAO {
conn = ConnectionManagerUtil.getCurrentConnection().get(); 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 += "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 AP "; sql += "FROM APPM_APPLICATION AS APP ";
sql += "INNER JOIN APPM_APPLICATION_TYPE AS AT ON AP.APPLICATION_TYPE_ID = AT.ID "; sql += "INNER JOIN APPM_PLATFORM_APPLICATION_MAPPING AS APM ON APP.PLATFORM_APPLICATION_MAPPING_ID = APM.ID ";
sql += "INNER JOIN APPM_APPLICATION_CATEGORY AS CT ON AP.CATEGORY_ID = CT.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())) { if (filter.getSearchQuery() != null || "".equals(filter.getSearchQuery())) {
sql += "WHERE AP.NAME LIKE ? "; sql += "WHERE APP.NAME LIKE ? ";
} }
sql += "LIMIT ? "; sql += "LIMIT ? ";
sql += "OFFSET ?;"; sql += "OFFSET ?;";
@ -95,7 +96,7 @@ public class GenericAppManagementDAO implements ApplicationManagementDAO {
while (rs.next()) { while (rs.next()) {
//Getting properties //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 = conn.prepareStatement(sql);
stmt.setInt(1, rs.getInt("ID")); stmt.setInt(1, rs.getInt("ID"));
ResultSet rsProperties = stmt.executeQuery(); ResultSet rsProperties = stmt.executeQuery();

@ -50,7 +50,7 @@ public class Application {
private Date modifiedAt; private Date modifiedAt;
private ApplicationType applicationType; private Platform platform;
private Category category; private Category category;
@ -147,12 +147,12 @@ public class Application {
this.modifiedAt = modifiedAt; this.modifiedAt = modifiedAt;
} }
public ApplicationType getApplicationType() { public Platform getPlatform() {
return applicationType; return platform;
} }
public void setApplicationType(ApplicationType applicationType) { public void setPlatform(Platform platform) {
this.applicationType = applicationType; this.platform = platform;
} }
public Category getCategory() { public Category getCategory() {

@ -20,16 +20,24 @@ package org.wso2.carbon.device.application.mgt.core.dto;
import org.wso2.carbon.device.application.mgt.core.jaxrs.Exclude; import org.wso2.carbon.device.application.mgt.core.jaxrs.Exclude;
public class ApplicationType { import java.util.List;
public class Platform {
@Exclude @Exclude
private int id; private int id;
private String name; private String name;
private String description;
private String code; private String code;
private String parameters; private String iconName;
private String properties;
private List<Application> applications;
public int getId() { public int getId() {
return id; return id;
@ -47,6 +55,14 @@ public class ApplicationType {
this.name = name; this.name = name;
} }
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCode() { public String getCode() {
return code; return code;
} }
@ -55,11 +71,27 @@ public class ApplicationType {
this.code = code; this.code = code;
} }
public String getParameters() { public String getIconName() {
return parameters; 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<Application> getApplications() {
return applications;
} }
public void setParameters(String parameters) { public void setApplications(List<Application> applications) {
this.parameters = parameters; this.applications = applications;
} }
} }
Loading…
Cancel
Save