mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Added Response DTO
This commit is contained in:
parent
7f6b33a0c0
commit
1095151085
@ -132,6 +132,10 @@
|
|||||||
<artifactId>commons-httpclient</artifactId>
|
<artifactId>commons-httpclient</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.jackson</groupId>
|
||||||
|
<artifactId>jackson-jaxrs</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.ws.rs</groupId>
|
<groupId>javax.ws.rs</groupId>
|
||||||
<artifactId>jsr311-api</artifactId>
|
<artifactId>jsr311-api</artifactId>
|
||||||
|
|||||||
@ -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<String> 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<String> getScreenshotNames() {
|
||||||
|
return screenshotNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScreenshotNames(List<String> screenshotNames) {
|
||||||
|
this.screenshotNames = screenshotNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Application getApplication() {
|
||||||
|
return application;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplication(Application application) {
|
||||||
|
this.application = application;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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<StoreApplication> applications;
|
||||||
|
|
||||||
|
public ApplicationsListResponse(List<org.wso2.carbon.device.application.mgt.core.dto.StoreApplication> 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<StoreApplication> getApplications() {
|
||||||
|
return applications;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplications(List<StoreApplication> applications) {
|
||||||
|
this.applications = applications;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -20,12 +20,13 @@ package org.wso2.carbon.device.application.mgt.api.services;
|
|||||||
|
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
|
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.*;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
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 " +
|
@Api(value = "Application Management", description = "This API carries all device management related operations " +
|
||||||
"such as get all the available devices, etc.")
|
"such as get all the available devices, etc.")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@ -34,53 +35,13 @@ public interface ApplicationManagementService {
|
|||||||
|
|
||||||
public final static String SCOPE = "scope";
|
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
|
@GET
|
||||||
@Path("/")
|
@Path("applications")
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.TEXT_PLAIN)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
consumes = MediaType.TEXT_PLAIN,
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
produces = MediaType.TEXT_PLAIN,
|
produces = MediaType.APPLICATION_JSON,
|
||||||
httpMethod = "POST",
|
httpMethod = "POST",
|
||||||
value = "get all applications",
|
value = "get all applications",
|
||||||
notes = "This will get all applications",
|
notes = "This will get all applications",
|
||||||
@ -96,7 +57,7 @@ public interface ApplicationManagementService {
|
|||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 200,
|
code = 200,
|
||||||
message = "OK. \n Successfully got application list.",
|
message = "OK. \n Successfully got application list.",
|
||||||
response = String.class),
|
response = ApplicationsListResponse.class),
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
code = 304,
|
code = 304,
|
||||||
message = "Not Modified. \n " +
|
message = "Not Modified. \n " +
|
||||||
@ -106,8 +67,8 @@ public interface ApplicationManagementService {
|
|||||||
message = "Internal Server Error. \n Error occurred while getting the application list.",
|
message = "Internal Server Error. \n Error occurred while getting the application list.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
Response getApplications(
|
ApplicationsListResponse getApplications(@Context final HttpServletResponse servletResponse,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "If-Modified-Since",
|
name = "If-Modified-Since",
|
||||||
value = "Validates if the requested variant has not been modified since the time specified",
|
value = "Validates if the requested variant has not been modified since the time specified",
|
||||||
required = false)
|
required = false)
|
||||||
|
|||||||
@ -18,38 +18,46 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.application.mgt.api.services.impl;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse;
|
import org.wso2.carbon.device.application.mgt.api.responses.ApplicationsListResponse;
|
||||||
import org.wso2.carbon.device.application.mgt.api.services.ApplicationManagementService;
|
|
||||||
import org.wso2.carbon.device.application.mgt.core.components.ApplicationManager;
|
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.exception.ApplicationManagerException;
|
||||||
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
|
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 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);
|
private static Log log = LogFactory.getLog(ApplicationManagementServiceImpl.class);
|
||||||
|
|
||||||
@POST
|
|
||||||
@Override
|
|
||||||
public Response createApplication(String ifModifiedSince, String name) {
|
|
||||||
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManager();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@GET
|
||||||
public Response getApplications(String ifModifiedSince) {
|
@Consumes("application/json")
|
||||||
|
@Path("applications")
|
||||||
|
public ApplicationsListResponse getApplications(@Context final HttpServletResponse servletResponse) {
|
||||||
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManager();
|
ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManager();
|
||||||
try {
|
try {
|
||||||
return Response.ok().entity(applicationManager.getApplications()).build();
|
ApplicationsListResponse applicationsListResponse =
|
||||||
} catch (ApplicationManagerException e) {
|
new ApplicationsListResponse(applicationManager.getApplications());
|
||||||
String msg = "Error occured while getting the application list";
|
return applicationsListResponse;
|
||||||
|
} catch (Exception e) {
|
||||||
|
String msg = "Error occurred while getting the application list";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(
|
try {
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
servletResponse.sendError(Response.Status.NOT_FOUND.getStatusCode());
|
||||||
|
} catch (IOException e1) {
|
||||||
|
log.error(msg, e1);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
||||||
xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xsi:schemaLocation="
|
xsi:schemaLocation="
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
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">
|
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">
|
||||||
|
|
||||||
<jaxrs:server id="applicationMgtService" address="/">
|
<jaxrs:server id="applicationMgtService" address="/">
|
||||||
<jaxrs:serviceBeans>
|
<jaxrs:serviceBeans>
|
||||||
@ -13,12 +13,10 @@
|
|||||||
</jaxrs:serviceBeans>
|
</jaxrs:serviceBeans>
|
||||||
<jaxrs:providers>
|
<jaxrs:providers>
|
||||||
<ref bean="jsonProvider"/>
|
<ref bean="jsonProvider"/>
|
||||||
<ref bean="errorHandler"/>
|
|
||||||
</jaxrs:providers>
|
</jaxrs:providers>
|
||||||
</jaxrs:server>
|
</jaxrs:server>
|
||||||
|
|
||||||
<bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.api.services.impl.ApplicationManagementServiceImpl"/>
|
<bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.api.services.impl.ApplicationManagementServiceImpl"/>
|
||||||
<bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.api.common.GsonMessageBodyHandler"/>
|
<bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
|
||||||
<bean id="errorHandler" class="org.wso2.carbon.device.application.mgt.api.common.ErrorHandler"/>
|
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
@ -82,6 +82,7 @@
|
|||||||
org.wso2.carbon.context,
|
org.wso2.carbon.context,
|
||||||
org.jscep.transaction,
|
org.jscep.transaction,
|
||||||
org.w3c.dom,
|
org.w3c.dom,
|
||||||
|
org.json,
|
||||||
org.xml.sax,
|
org.xml.sax,
|
||||||
javax.sql,
|
javax.sql,
|
||||||
<!--javax.cache,-->
|
<!--javax.cache,-->
|
||||||
@ -187,6 +188,10 @@
|
|||||||
<artifactId>slf4j-simple</artifactId>
|
<artifactId>slf4j-simple</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json.wso2</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
package org.wso2.carbon.device.application.mgt.core.components;
|
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.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.exception.ApplicationManagerException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -28,6 +29,6 @@ public interface ApplicationManager {
|
|||||||
|
|
||||||
public void createApplication(Application application) throws ApplicationManagerException;
|
public void createApplication(Application application) throws ApplicationManagerException;
|
||||||
|
|
||||||
public List<Application> getApplications() throws ApplicationManagerException;
|
public List<StoreApplication> getApplications() throws ApplicationManagerException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.ApplicationManagementDAOException;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationManagementDAOImpl;
|
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.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.exception.ApplicationManagerException;
|
||||||
import org.wso2.carbon.device.application.mgt.core.internal.ApplicationManagementDataHolder;
|
import org.wso2.carbon.device.application.mgt.core.internal.ApplicationManagementDataHolder;
|
||||||
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
||||||
@ -55,10 +56,10 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Application> getApplications() throws ApplicationManagerException {
|
public List<StoreApplication> getApplications() throws ApplicationManagerException {
|
||||||
ConnectionManagerUtil.openConnection();
|
ConnectionManagerUtil.openConnection();
|
||||||
ApplicationManagementDAO applicationManagementDAO = ApplicationManagementDataHolder.getInstance().getApplicationManagementDAO();
|
ApplicationManagementDAO applicationManagementDAO = ApplicationManagementDataHolder.getInstance().getApplicationManagementDAO();
|
||||||
List<Application> applications = null;
|
List<StoreApplication> applications = null;
|
||||||
applications = applicationManagementDAO.getApplications();
|
applications = applicationManagementDAO.getApplications();
|
||||||
ConnectionManagerUtil.closeConnection();
|
ConnectionManagerUtil.closeConnection();
|
||||||
return applications;
|
return applications;
|
||||||
|
|||||||
@ -20,6 +20,7 @@ package org.wso2.carbon.device.application.mgt.core.dao;
|
|||||||
|
|
||||||
import org.apache.axis2.databinding.types.Day;
|
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.Application;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dto.StoreApplication;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
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<Application> getApplications() throws ApplicationManagementDAOException;
|
public List<StoreApplication> getApplications() throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,9 @@ package org.wso2.carbon.device.application.mgt.core.dao;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.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.util.ConnectionManagerUtil;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dto.Application;
|
import org.wso2.carbon.device.application.mgt.core.dto.Application;
|
||||||
|
|
||||||
@ -37,6 +39,8 @@ public class ApplicationManagementDAOImpl implements ApplicationManagementDAO {
|
|||||||
private DatabaseType databaseType;
|
private DatabaseType databaseType;
|
||||||
private static DataSource dataSource;
|
private static DataSource dataSource;
|
||||||
|
|
||||||
|
private static final String TABLE_PREFIX = "APPM";
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ApplicationManagementDAOImpl.class);
|
private static final Log log = LogFactory.getLog(ApplicationManagementDAOImpl.class);
|
||||||
|
|
||||||
public ApplicationManagementDAOImpl(DataSourceConfig dataSourceConfig) {
|
public ApplicationManagementDAOImpl(DataSourceConfig dataSourceConfig) {
|
||||||
@ -52,25 +56,25 @@ public class ApplicationManagementDAOImpl implements ApplicationManagementDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createApplication(Application application) throws ApplicationManagementDAOException {
|
public void createApplication(StoreApplication application) throws ApplicationManagementDAOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Application> getApplications() throws ApplicationManagementDAOException {
|
public List<StoreApplication> getApplications() throws ApplicationManagementDAOException {
|
||||||
|
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
String sql = null;
|
String sql = null;
|
||||||
List<Application> applications;
|
List<StoreApplication> applications;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = ConnectionManagerUtil.getCurrentConnection().get();
|
conn = ConnectionManagerUtil.getCurrentConnection().get();
|
||||||
switch (databaseType) {
|
switch (databaseType) {
|
||||||
case H2:
|
case H2:
|
||||||
case MYSQL:
|
case MYSQL:
|
||||||
sql = "SELECT * FROM APPM_APPLICATION";
|
sql = "SELECT * FROM APPM_STORE_APPLICATION";
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt = conn.prepareStatement(sql);
|
stmt = conn.prepareStatement(sql);
|
||||||
@ -82,6 +86,8 @@ public class ApplicationManagementDAOImpl implements ApplicationManagementDAO {
|
|||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new ApplicationManagementDAOException("Error occurred while getting application List", e);
|
throw new ApplicationManagementDAOException("Error occurred while getting application List", e);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e);
|
||||||
} finally {
|
} finally {
|
||||||
ApplicationManagementDAOUtil.cleanupResources(stmt, rs);
|
ApplicationManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,26 +20,30 @@ package org.wso2.carbon.device.application.mgt.core.dao;
|
|||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.Application;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dto.ApplicationType;
|
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.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ApplicationManagementDAOUtil {
|
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) throws SQLException {
|
public static StoreApplication loadApplication(ResultSet rs) throws SQLException, JSONException {
|
||||||
ApplicationType applicationType = new ApplicationType();
|
ApplicationType applicationType = new ApplicationType();
|
||||||
Application application = new Application();
|
StoreApplication storeApplication = new StoreApplication();
|
||||||
application.setId(rs.getInt("ID"));
|
storeApplication.setUuid(rs.getString("UUID"));
|
||||||
application.setName(rs.getString("NAME"));
|
storeApplication.setIconName(rs.getString("ICON_NAME"));
|
||||||
application.setUuId(rs.getString("UUID"));
|
storeApplication.setBannerName(rs.getString("BANNER_NAME"));
|
||||||
application.setDescription(rs.getString("DESCRIPTION"));
|
storeApplication.setScreenshotNames(jsonArrayStringToList(rs.getString("SCREENSHOTS")));
|
||||||
applicationType.setId(rs.getInt("APPLICATION_TYPE_ID"));
|
return storeApplication;
|
||||||
application.setApplicationType(applicationType);
|
|
||||||
return application;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanupResources(PreparedStatement stmt, ResultSet rs) {
|
public static void cleanupResources(PreparedStatement stmt, ResultSet rs) {
|
||||||
@ -58,4 +62,16 @@ public class ApplicationManagementDAOUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> jsonArrayStringToList(String value) throws JSONException {
|
||||||
|
JSONArray jsonArray = new JSONArray(value);
|
||||||
|
List<String> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,16 +18,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.application.mgt.core.dto;
|
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 int id;
|
||||||
private String uuId;
|
|
||||||
private String name;
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
private ApplicationType applicationType;
|
private ApplicationType applicationType;
|
||||||
private List<String> properties;
|
private Map<String, String> properties;
|
||||||
|
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@ -38,14 +37,6 @@ public class Application{
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUuId() {
|
|
||||||
return uuId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUuId(String uuId) {
|
|
||||||
this.uuId = uuId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -70,11 +61,11 @@ public class Application{
|
|||||||
this.applicationType = applicationType;
|
this.applicationType = applicationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getProperties() {
|
public Map<String, String> getProperties() {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProperties(List<String> properties) {
|
public void setProperties(Map<String, String> properties) {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,9 +20,9 @@ package org.wso2.carbon.device.application.mgt.core.dto;
|
|||||||
|
|
||||||
public class ApplicationType {
|
public class ApplicationType {
|
||||||
|
|
||||||
private int id;
|
protected int id;
|
||||||
private String name;
|
protected String name;
|
||||||
private String code;
|
protected String code;
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
|
|||||||
@ -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<String> 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<String> getScreenshotNames() {
|
||||||
|
return screenshotNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScreenshotNames(List<String> screenshotNames) {
|
||||||
|
this.screenshotNames = screenshotNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Application getApplication() {
|
||||||
|
return application;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplication(Application application) {
|
||||||
|
this.application = application;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user