From 1095151085a5a01eef48aa3c1927c6cbc7905bb2 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 2 May 2017 13:49:25 +0530 Subject: [PATCH] Added Response DTO --- .../pom.xml | 4 + .../mgt/api/dto/StoreApplication.java | 88 +++++++++++++++++++ .../responses/ApplicationsListResponse.java | 59 +++++++++++++ .../ApplicationManagementService.java | 61 +++---------- .../ApplicationManagementServiceImpl.java | 42 +++++---- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 12 ++- .../pom.xml | 5 ++ .../core/components/ApplicationManager.java | 3 +- .../impl/ApplicationManagerImpl.java | 5 +- .../core/dao/ApplicationManagementDAO.java | 5 +- .../dao/ApplicationManagementDAOImpl.java | 14 ++- .../dao/ApplicationManagementDAOUtil.java | 34 +++++-- .../application/mgt/core/dto/Application.java | 19 ++-- .../mgt/core/dto/ApplicationType.java | 6 +- .../mgt/core/dto/StoreApplication.java | 79 +++++++++++++++++ 15 files changed, 327 insertions(+), 109 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/dto/StoreApplication.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/responses/ApplicationsListResponse.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/StoreApplication.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml index 5a899715ee..7332606e59 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml @@ -132,6 +132,10 @@ commons-httpclient provided + + org.codehaus.jackson + jackson-jaxrs + javax.ws.rs jsr311-api diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/dto/StoreApplication.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/dto/StoreApplication.java new file mode 100644 index 0000000000..0eb39d13e8 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/dto/StoreApplication.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.application.mgt.api.dto; + +import org.codehaus.jackson.annotate.JsonIgnore; +import org.wso2.carbon.device.application.mgt.core.dto.Application; + +import java.util.List; + +public class StoreApplication { + + private int id; + + private String uuid; + + private String iconName; + + private String bannerName; + + private List screenshotNames; + + private Application application; + + @JsonIgnore + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getIconName() { + return iconName; + } + + public void setIconName(String iconName) { + this.iconName = iconName; + } + + public String getBannerName() { + return bannerName; + } + + public void setBannerName(String bannerName) { + this.bannerName = bannerName; + } + + public List getScreenshotNames() { + return screenshotNames; + } + + public void setScreenshotNames(List screenshotNames) { + this.screenshotNames = screenshotNames; + } + + public Application getApplication() { + return application; + } + + public void setApplication(Application application) { + this.application = application; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/responses/ApplicationsListResponse.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/responses/ApplicationsListResponse.java new file mode 100644 index 0000000000..de927e4706 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/responses/ApplicationsListResponse.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.application.mgt.api.responses; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; +import org.apache.commons.beanutils.BeanUtils; +import org.wso2.carbon.device.application.mgt.api.dto.StoreApplication; +import org.wso2.carbon.device.application.mgt.core.dto.Application; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +@XmlRootElement +public class ApplicationsListResponse { + + @ApiModelProperty(value = "List of applications types returned") + @JsonProperty("applications") + @XmlElement + private List applications; + + public ApplicationsListResponse(List applications) + throws InvocationTargetException, IllegalAccessException { + this.applications = new ArrayList<>(); + for(org.wso2.carbon.device.application.mgt.core.dto.StoreApplication applicationDTO : applications){ + StoreApplication application = new StoreApplication(); + BeanUtils.copyProperties(application, applicationDTO); + this.applications.add(application); + } + } + + public List getApplications() { + return applications; + } + + public void setApplications(List applications) { + this.applications = applications; + } + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementService.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementService.java index 1aeb0965cc..e74e42d2ca 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementService.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementService.java @@ -20,12 +20,13 @@ package org.wso2.carbon.device.application.mgt.api.services; import io.swagger.annotations.*; import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; +import org.wso2.carbon.device.application.mgt.api.responses.ApplicationsListResponse; +import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -@Path("/applications") @Api(value = "Application Management", description = "This API carries all device management related operations " + "such as get all the available devices, etc.") @Produces(MediaType.APPLICATION_JSON) @@ -34,53 +35,13 @@ public interface ApplicationManagementService { public final static String SCOPE = "scope"; - @POST - @Path("/") - @Produces(MediaType.TEXT_PLAIN) - @Consumes(MediaType.TEXT_PLAIN) - @ApiOperation( - consumes = MediaType.TEXT_PLAIN, - produces = MediaType.TEXT_PLAIN, - httpMethod = "POST", - value = "Creates new application", - notes = "This will create a new application", - tags = "Application Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:create-application") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully fetched the device location.", - response = String.class), - @ApiResponse( - code = 304, - message = "Not Modified. \n " + - "Empty body because the client already has the latest version of the requested resource."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while retrieving signed certificate.", - response = ErrorResponse.class) - }) - Response createApplication( - @ApiParam( - name = "If-Modified-Since", - value = "Validates if the requested variant has not been modified since the time specified", - required = false) - @HeaderParam("If-Modified-Since") String ifModifiedSince, - String name); - @GET - @Path("/") - @Produces(MediaType.TEXT_PLAIN) - @Consumes(MediaType.TEXT_PLAIN) + @Path("applications") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( - consumes = MediaType.TEXT_PLAIN, - produces = MediaType.TEXT_PLAIN, + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "get all applications", notes = "This will get all applications", @@ -96,7 +57,7 @@ public interface ApplicationManagementService { @ApiResponse( code = 200, message = "OK. \n Successfully got application list.", - response = String.class), + response = ApplicationsListResponse.class), @ApiResponse( code = 304, message = "Not Modified. \n " + @@ -106,8 +67,8 @@ public interface ApplicationManagementService { message = "Internal Server Error. \n Error occurred while getting the application list.", response = ErrorResponse.class) }) - Response getApplications( - @ApiParam( + ApplicationsListResponse getApplications(@Context final HttpServletResponse servletResponse, + @ApiParam( name = "If-Modified-Since", value = "Validates if the requested variant has not been modified since the time specified", required = false) 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 15ab68f938..f36a54218b 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 @@ -18,38 +18,46 @@ */ package org.wso2.carbon.device.application.mgt.api.services.impl; +import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; -import org.wso2.carbon.device.application.mgt.api.services.ApplicationManagementService; +import org.wso2.carbon.device.application.mgt.api.responses.ApplicationsListResponse; import org.wso2.carbon.device.application.mgt.core.components.ApplicationManager; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagerException; import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil; -import javax.ws.rs.POST; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.*; +import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; -public class ApplicationManagementServiceImpl implements ApplicationManagementService { +@Produces({ "application/json"}) +@Consumes({ "application/json"}) +public class ApplicationManagementServiceImpl { private static Log log = LogFactory.getLog(ApplicationManagementServiceImpl.class); - @POST - @Override - public Response createApplication(String ifModifiedSince, String name) { - ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManager(); - return null; - } - @Override - public Response getApplications(String ifModifiedSince) { + @GET + @Consumes("application/json") + @Path("applications") + public ApplicationsListResponse getApplications(@Context final HttpServletResponse servletResponse) { ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManager(); try { - return Response.ok().entity(applicationManager.getApplications()).build(); - } catch (ApplicationManagerException e) { - String msg = "Error occured while getting the application list"; + ApplicationsListResponse applicationsListResponse = + new ApplicationsListResponse(applicationManager.getApplications()); + return applicationsListResponse; + } catch (Exception e) { + String msg = "Error occurred while getting the application list"; log.error(msg, e); - return Response.serverError().entity( - new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + try { + servletResponse.sendError(Response.Status.NOT_FOUND.getStatusCode()); + } catch (IOException e1) { + log.error(msg, e1); + } + return null; } } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 3dd210b3b7..afe7616869 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -1,11 +1,11 @@ - +http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd +http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> @@ -13,12 +13,10 @@ - - - + \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml index 7c3e8f2fbe..c0a0759c7d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml @@ -82,6 +82,7 @@ org.wso2.carbon.context, org.jscep.transaction, org.w3c.dom, + org.json, org.xml.sax, javax.sql, @@ -187,6 +188,10 @@ slf4j-simple test + + org.json.wso2 + json + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/components/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/components/ApplicationManager.java index 31d02b7521..a7360f22d2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/components/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/components/ApplicationManager.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.application.mgt.core.components; import org.wso2.carbon.device.application.mgt.core.dto.Application; +import org.wso2.carbon.device.application.mgt.core.dto.StoreApplication; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagerException; import java.util.ArrayList; @@ -28,6 +29,6 @@ public interface ApplicationManager { public void createApplication(Application application) throws ApplicationManagerException; - public List getApplications() throws ApplicationManagerException; + public List getApplications() throws ApplicationManagerException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/components/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/components/impl/ApplicationManagerImpl.java index e48109eed0..3a03194d3f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/components/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/components/impl/ApplicationManagerImpl.java @@ -25,6 +25,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.ApplicationManagementDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationManagementDAOImpl; import org.wso2.carbon.device.application.mgt.core.dto.Application; +import org.wso2.carbon.device.application.mgt.core.dto.StoreApplication; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagerException; import org.wso2.carbon.device.application.mgt.core.internal.ApplicationManagementDataHolder; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; @@ -55,10 +56,10 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public List getApplications() throws ApplicationManagerException { + public List getApplications() throws ApplicationManagerException { ConnectionManagerUtil.openConnection(); ApplicationManagementDAO applicationManagementDAO = ApplicationManagementDataHolder.getInstance().getApplicationManagementDAO(); - List applications = null; + List applications = null; applications = applicationManagementDAO.getApplications(); ConnectionManagerUtil.closeConnection(); return applications; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAO.java index 9ca5ffbac9..cecdf2822f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAO.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.dao; import org.apache.axis2.databinding.types.Day; import org.wso2.carbon.device.application.mgt.core.dto.Application; +import org.wso2.carbon.device.application.mgt.core.dto.StoreApplication; import java.util.HashMap; import java.util.List; @@ -57,8 +58,8 @@ public interface ApplicationManagementDAO { } } - public void createApplication(Application application) throws ApplicationManagementDAOException; + public void createApplication(StoreApplication application) throws ApplicationManagementDAOException; - public List getApplications() throws ApplicationManagementDAOException; + public List getApplications() throws ApplicationManagementDAOException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOImpl.java index 83c56da6e4..4c69408e75 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOImpl.java @@ -20,7 +20,9 @@ package org.wso2.carbon.device.application.mgt.core.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.json.JSONException; import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig; +import org.wso2.carbon.device.application.mgt.core.dto.StoreApplication; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.dto.Application; @@ -37,6 +39,8 @@ public class ApplicationManagementDAOImpl implements ApplicationManagementDAO { private DatabaseType databaseType; private static DataSource dataSource; + private static final String TABLE_PREFIX = "APPM"; + private static final Log log = LogFactory.getLog(ApplicationManagementDAOImpl.class); public ApplicationManagementDAOImpl(DataSourceConfig dataSourceConfig) { @@ -52,25 +56,25 @@ public class ApplicationManagementDAOImpl implements ApplicationManagementDAO { } @Override - public void createApplication(Application application) throws ApplicationManagementDAOException { + public void createApplication(StoreApplication application) throws ApplicationManagementDAOException { } @Override - public List getApplications() throws ApplicationManagementDAOException { + public List getApplications() throws ApplicationManagementDAOException { Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; String sql = null; - List applications; + List applications; try { conn = ConnectionManagerUtil.getCurrentConnection().get(); switch (databaseType) { case H2: case MYSQL: - sql = "SELECT * FROM APPM_APPLICATION"; + sql = "SELECT * FROM APPM_STORE_APPLICATION"; } stmt = conn.prepareStatement(sql); @@ -82,6 +86,8 @@ public class ApplicationManagementDAOImpl implements ApplicationManagementDAO { } catch (SQLException e) { throw new ApplicationManagementDAOException("Error occurred while getting application List", e); + } catch (JSONException e) { + throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); } finally { ApplicationManagementDAOUtil.cleanupResources(stmt, rs); } 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 6bc3f4d124..7baa4380a3 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 @@ -20,26 +20,30 @@ package org.wso2.carbon.device.application.mgt.core.dao; import org.apache.commons.logging.Log; 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.StoreApplication; + import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class ApplicationManagementDAOUtil { private static final Log log = LogFactory.getLog(ApplicationManagementDAOUtil.class); - public static Application loadApplication(ResultSet rs) throws SQLException { + public static StoreApplication loadApplication(ResultSet rs) throws SQLException, JSONException { ApplicationType applicationType = new ApplicationType(); - Application application = new Application(); - application.setId(rs.getInt("ID")); - application.setName(rs.getString("NAME")); - application.setUuId(rs.getString("UUID")); - application.setDescription(rs.getString("DESCRIPTION")); - applicationType.setId(rs.getInt("APPLICATION_TYPE_ID")); - application.setApplicationType(applicationType); - return application; + StoreApplication storeApplication = new StoreApplication(); + storeApplication.setUuid(rs.getString("UUID")); + storeApplication.setIconName(rs.getString("ICON_NAME")); + storeApplication.setBannerName(rs.getString("BANNER_NAME")); + storeApplication.setScreenshotNames(jsonArrayStringToList(rs.getString("SCREENSHOTS"))); + return storeApplication; } public static void cleanupResources(PreparedStatement stmt, ResultSet rs) { @@ -58,4 +62,16 @@ public class ApplicationManagementDAOUtil { } } } + + public static List jsonArrayStringToList(String value) throws JSONException { + JSONArray jsonArray = new JSONArray(value); + List list = new ArrayList<>(); + if (jsonArray != null) { + int len = jsonArray.length(); + for (int i = 0; i < len; i++) { + list.add(jsonArray.get(i).toString()); + } + } + return list; + } } 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 125ee300ea..3fa3e4846f 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 @@ -18,16 +18,15 @@ */ package org.wso2.carbon.device.application.mgt.core.dto; -import java.util.List; +import java.util.Map; -public class Application{ +public class Application { private int id; - private String uuId; private String name; private String description; private ApplicationType applicationType; - private List properties; + private Map properties; public int getId() { @@ -38,14 +37,6 @@ public class Application{ this.id = id; } - public String getUuId() { - return uuId; - } - - public void setUuId(String uuId) { - this.uuId = uuId; - } - public String getName() { return name; } @@ -70,11 +61,11 @@ public class Application{ this.applicationType = applicationType; } - public List getProperties() { + public Map getProperties() { return properties; } - public void setProperties(List properties) { + public void setProperties(Map properties) { this.properties = properties; } } 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/ApplicationType.java index 79f4cbcfc0..153f9da89f 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/ApplicationType.java @@ -20,9 +20,9 @@ package org.wso2.carbon.device.application.mgt.core.dto; public class ApplicationType { - private int id; - private String name; - private String code; + protected int id; + protected String name; + protected String code; public int getId() { return id; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/StoreApplication.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/StoreApplication.java new file mode 100644 index 0000000000..6c1ed83326 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/StoreApplication.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.device.application.mgt.core.dto; + +import java.util.List; + +public class StoreApplication { + + private int id; + private String uuid; + private String iconName; + private String bannerName; + private List screenshotNames; + private Application application; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getIconName() { + return iconName; + } + + public void setIconName(String iconName) { + this.iconName = iconName; + } + + public String getBannerName() { + return bannerName; + } + + public void setBannerName(String bannerName) { + this.bannerName = bannerName; + } + + public List getScreenshotNames() { + return screenshotNames; + } + + public void setScreenshotNames(List screenshotNames) { + this.screenshotNames = screenshotNames; + } + + public Application getApplication() { + return application; + } + + public void setApplication(Application application) { + this.application = application; + } +}