From de8ad75be7a0ad1693a2170e4028385f8e2981c8 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Wed, 19 Apr 2017 16:17:51 +0530 Subject: [PATCH 01/11] Added aplication management component --- .../pom.xml | 303 +++++++++++++ .../api/ApplicationManagementService.java | 24 + .../ApplicationManagementServiceImpl.java | 25 ++ .../src/main/webapp/META-INF/permissions.xml | 420 ++++++++++++++++++ .../webapp/META-INF/webapp-classloading.xml | 35 ++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 66 +++ .../src/main/webapp/WEB-INF/web.xml | 119 +++++ .../pom.xml | 281 ++++++++++++ .../mgt/core/dao/ApplicationDAO.java | 27 ++ .../application/mgt/core/dto/Application.java | 64 +++ .../mgt/core/util/AppManagementPlugin.java | 30 ++ components/application-mgt/pom.xml | 41 ++ 12 files changed, 1435 insertions(+) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/api/ApplicationManagementService.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/impl/ApplicationManagementServiceImpl.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/META-INF/permissions.xml create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/META-INF/webapp-classloading.xml create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dao/ApplicationDAO.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dto/Application.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/util/AppManagementPlugin.java create mode 100644 components/application-mgt/pom.xml 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 new file mode 100644 index 00000000000..2d326b23883 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml @@ -0,0 +1,303 @@ + + + + + + + application-mgt + org.wso2.carbon.devicemgt + 2.0.45-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.application.mgt.api + war + WSO2 Carbon - Mobile Application Management API + WSO2 Carbon - Mobile Application Management API + http://wso2.org + + + + + maven-compiler-plugin + + 1.7 + 1.7 + + + + maven-war-plugin + + WEB-INF/lib/*cxf*.jar + api#application-mgt#v1.0 + + + + + + + + deploy + + compile + + + org.apache.maven.plugins + maven-antrun-plugin + 1.7 + + + compile + + run + + + + + + + + + + + + + + + + + + client + + test + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + test + + java + + + + + + + + + + + + org.apache.cxf + cxf-rt-frontend-jaxws + provided + + + org.apache.cxf + cxf-rt-frontend-jaxrs + provided + + + org.apache.cxf + cxf-rt-transports-http + provided + + + junit + junit + test + + + commons-httpclient.wso2 + commons-httpclient + provided + + + javax.ws.rs + jsr311-api + provided + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.user.mgt + provided + + + org.slf4j + slf4j-api + + + org.slf4j + jcl-over-slf4j + + + + + org.wso2.carbon + org.wso2.carbon.logging + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + provided + + + org.apache.axis2.wso2 + axis2-client + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.mgt.core + provided + + + org.apache.axis2.wso2 + axis2-client + + + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth.stub + provided + + + org.apache.axis2.wso2 + axis2-client + + + + + org.json.wso2 + json + + + commons-codec.wso2 + commons-codec + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.certificate.mgt.core + provided + + + io.swagger + swagger-annotations + + + io.swagger + swagger-core + + + com.fasterxml.jackson.module + jackson-module-jaxb-annotations + + + org.slf4j + slf4j-api + + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-core + + + + + io.swagger + swagger-jaxrs + + + com.fasterxml.jackson.module + jackson-module-jaxb-annotations + + + org.slf4j + slf4j-api + + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-core + + + + + javax.servlet + servlet-api + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics.dashboard + provided + + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-annotations + + + org.hibernate + hibernate-validator + + + javax.ws.rs + javax.ws.rs-api + + + org.wso2.carbon.commons + org.wso2.carbon.application.mgt.stub + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.identity.jwt.client.extension + provided + + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.user.store.count + ${carbon.identity.framework.version} + provided + + + + + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/api/ApplicationManagementService.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/api/ApplicationManagementService.java new file mode 100644 index 00000000000..3725cb0c304 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/api/ApplicationManagementService.java @@ -0,0 +1,24 @@ +/* + * 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.service.api; + +public interface ApplicationManagementService { + + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/impl/ApplicationManagementServiceImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/impl/ApplicationManagementServiceImpl.java new file mode 100644 index 00000000000..15263637812 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/impl/ApplicationManagementServiceImpl.java @@ -0,0 +1,25 @@ +/* + * 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.service.impl; + +import org.wso2.carbon.device.application.mgt.api.service.api.ApplicationManagementService; + +public class ApplicationManagementServiceImpl implements ApplicationManagementService { + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/META-INF/permissions.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/META-INF/permissions.xml new file mode 100644 index 00000000000..befabcd0977 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/META-INF/permissions.xml @@ -0,0 +1,420 @@ + + + + + + + + + Device Management + /device-mgt + / + GET + + + + Device Management Admin + /device-mgt/admin + / + GET + + + Devices + /device-mgt/devices + / + GET + + + + List devices + /device-mgt/devices/List + /devices + GET + + + Search devices + /device-mgt/devices/Search + /devices/search-devices + POST + + + View device + /device-mgt/devices/View + /devices/*/* + GET + + + View device info + /device-mgt/devices/View + /devices/*/*/info + GET + + + View device applications + /device-mgt/devices/View-Applications + /devices/*/*/applications + GET + + + View device effective-policy + /device-mgt/devices/View-Active-Policy + /devices/*/*/effective-policy + GET + + + View devices feature + /device-mgt/devices/View-Features + /devices/*/*/features + GET + + + View device operations + /device-mgt/devices/View-Operations + /devices/*/*/operations + GET + + + View Compliance Data + /device-mgt/devices/View-Compliance-Data + /devices/*/*/compliance-data + GET + + + List all devices + /device-mgt/devices/Admin-View + /admin/devices + GET + + + Verify device authorization + /device-mgt/devices + /admin/authorization + POST + + + View device types + /device-mgt/devices/Admin-DeviceType-View + /admin/device-types + GET + + + + Policies + /device-mgt/policies + / + GET + + + + List policies + /device-mgt/policies/List + /policies + GET + + + Add Policy + /device-mgt/policies/Add + /policies + POST + + + Activate policy + /device-mgt/policies/Activate-Policy + /policies/activate-policy + PUT + + + Deactivate Policy + /device-mgt/policies/Deactivate-Policy + /policies/deactivate-policy + PUT + + + Remove Policy + /device-mgt/policies/Remove + /policies/remove-policy + POST + + + View Policy + /device-mgt/policies/View + /policies/* + GET + + + Update Policy + /device-mgt/policies/Update + /policies/* + PUT + + + Update Policy + /device-mgt/policies/Update + /policies/apply-changes + PUT + + + Update Policy + /device-mgt/policies/Change-Priority + /policies/priorities + PUT + + + + Notifications + /device-mgt/notifications + / + GET + + + + View notifications + /device-mgt/notifications/View + /notifications + GET + + + Mark checked notifications + /device-mgt/notifications/View + /notifications/*/mark-checked + PUT + + + + Users + /device-mgt/users + / + GET + + + + List users + /device-mgt/users/List + /users + GET + + + Add user + /device-mgt/users/Add + /users + POST + + + List users + /device-mgt/users/Search + /users/search/usernames + GET + + + Remove user + /device-mgt/users/Remove + /users/* + DELETE + + + View user + /device-mgt/users/View + /users/* + GET + + + Update user + /device-mgt/users/Update + /users/* + PUT + + + Update user credentials + /device-mgt/users/Change-Password + /users/*/credentials + PUT + + + View assigned role + /device-mgt/roles/Assigned-Roles + /users/*/roles + GET + + + Change any user credentials + /device-mgt/users/Change-Password-Any + /admin/users/*/credentials + POST + + + Send invitation mail + /device-mgt/users/Send-invitations + /users/send-invitation + POST + + + + Roles + /device-mgt/roles + / + GET + + + + List roles + /device-mgt/roles/List + /roles + GET + + + Add role + /device-mgt/roles/Add + /roles + POST + + + Remove role + /device-mgt/roles/Remove + /roles/* + DELETE + + + View role + /device-mgt/roles/View + /roles/* + GET + + + Update role + /device-mgt/roles/Update + /roles/* + PUT + + + View role permissions + /device-mgt/roles/View-Permission + /roles/*/permissions + GET + + + Add Users to role + /device-mgt/roles/Add-Users + /roles/*/users + PUT + + + + Configurations + /device-mgt/general-configs + / + GET + + + + View configuration + /device-mgt/general-configuration/View + /configuration + GET + + + Update configuration + /device-mgt/general-configuration/Update + /configuration + PUT + + + + Activities + /device-mgt/activities + / + GET + + + + View Activities + /device-mgt/devices/owning/view + /activities + GET + + + View Activity Details + /device-mgt/devices/owning/view + /activities/* + GET + + + + Applications + /device-mgt/applications + / + GET + + + + Install Applications + /device-mgt/application/Install + /admin/applications/install-application + POST + + + Uninstall-Applications + /device-mgt/application/Uninstall + /admin/applications/uninstall-application + POST + + + + + + Device Management User + /device-mgt/user + / + GET + + + User Devices + /device-mgt/user/devices + / + GET + + + User Policies + /device-mgt/user/policies + / + GET + + + User Notifications + /device-mgt/user/notifications + / + GET + + + User Operations + /device-mgt/user/operations + / + GET + + + + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/META-INF/webapp-classloading.xml new file mode 100644 index 00000000000..ed2ed216247 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/META-INF/webapp-classloading.xml @@ -0,0 +1,35 @@ + + + + + + + + + false + + + CXF,Carbon + 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 new file mode 100644 index 00000000000..0dacf240841 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000000..351d3ac11ad --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,119 @@ + + + + Admin-Webapp + + JAX-WS/JAX-RS Application Management Endpoint + JAX-WS/JAX-RS Servlet + CXFServlet + + org.apache.cxf.transport.servlet.CXFServlet + + + + swagger.security.filter + ApiAuthorizationFilterImpl + + 1 + + + CXFServlet + /* + + + 60 + + + + doAuthentication + true + + + + + managed-api-enabled + true + + + managed-api-owner + admin + + + isSharedWithAllTenants + true + + + + + + ApplicationMgt-Admin + /* + + + CONFIDENTIAL + + + + + ApiOriginFilter + org.wso2.carbon.application.mgt.jaxrs.ApiOriginFilter + + + + HttpHeaderSecurityFilter + org.apache.catalina.filters.HttpHeaderSecurityFilter + + hstsEnabled + false + + + + + ContentTypeBasedCachePreventionFilter + org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter + + patterns + text/html" ,application/json" ,text/plain + + + filterAction + enforce + + + httpHeaders + Cache-Control: no-store, no-cache, must-revalidate, private + + + + + HttpHeaderSecurityFilter + /* + + + + ContentTypeBasedCachePreventionFilter + /* + + + + ApiOriginFilter + /* + + + 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 new file mode 100644 index 00000000000..b413dce4caf --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml @@ -0,0 +1,281 @@ + + + + + + + org.wso2.carbon.devicemgt + application-mgt + 2.0.45-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.application.mgt.core + bundle + WSO2 Carbon - Application Management Core + WSO2 Carbon - Application Management Core + http://wso2.org + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Device Management Core Bundle + org.wso2.carbon.application.mgt.core.internal + + org.apache.axis2.*;version="${axis2.osgi.version.range}", + org.apache.axiom.*; version="${axiom.osgi.version.range}", + org.osgi.framework, + org.osgi.service.component, + org.apache.commons.logging, + javax.naming, + javax.xml.*, + javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional, + javax.servlet.*, + org.xml.sax, + javax.sql.*, + org.wso2.carbon.context, + org.wso2.carbon.core, + org.wso2.carbon.utils.*, + org.wso2.carbon.application.mgt.common.*, + org.wso2.carbon.user.api, + org.wso2.carbon.user.core.*, + org.wso2.carbon.registry.core.service, + org.wso2.carbon.registry.core, + org.wso2.carbon.registry.core.exceptions, + org.wso2.carbon.registry.core.session, + org.wso2.carbon.registry.api, + org.w3c.dom, + org.wso2.carbon.identity.oauth.stub, + org.wso2.carbon.identity.oauth.stub.dto, + org.wso2.carbon.ndatasource.core, + org.wso2.carbon.ntask.core.*, + org.wso2.carbon.ntask.common, + org.apache.catalina, + org.apache.catalina.core, + org.apache.commons.collections, + org.wso2.carbon.email.sender.*, + io.swagger.annotations.*;resolution:=optional, + org.wso2.carbon, + org.wso2.carbon.base, + org.scannotation.* + + + !org.wso2.carbon.application.mgt.core.internal, + org.wso2.carbon.application.mgt.core.* + + + javax.ws.rs-api, + scribe;scope=compile|runtime;inline=false, + javassist;inline=false + + * + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + file:src/test/resources/log4j.properties + + + src/test/resources/testng.xml + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.wso2.orbit.org.scannotation + scannotation + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.wso2.carbon + org.wso2.carbon.utils + + + org.wso2.carbon + org.wso2.carbon.core + + + org.wso2.carbon + org.wso2.carbon.ndatasource.core + + + commons-lang + commons-lang + + + + + com.h2database.wso2 + h2-database-engine + test + + + org.testng + testng + + + org.wso2.carbon + org.wso2.carbon.user.core + + + org.wso2.carbon + org.wso2.carbon.user.api + + + org.wso2.carbon + org.wso2.carbon.registry.api + + + org.wso2.carbon + org.wso2.carbon.registry.core + + + org.apache.tomcat.wso2 + jdbc-pool + + + org.wso2.carbon + org.wso2.carbon.base + + + org.wso2.carbon.governance + org.wso2.carbon.governance.api + + + org.apache.axis2.transport + axis2-transport-mail + + + org.apache.ws.commons.axiom.wso2 + axiom + + + + org.apache.axis2.wso2 + axis2 + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth.stub + + + org.wso2.tomcat + tomcat + + + org.wso2.tomcat + tomcat-servlet-api + + + + + org.wso2.carbon.commons + org.wso2.carbon.ntask.core + + + + + commons-collections.wso2 + commons-collections + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.email.sender.core + + + + mysql + mysql-connector-java + test + + + + com.google.code.gson + gson + + + + io.swagger + swagger-annotations + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + + + + javax.ws.rs + javax.ws.rs-api + + + javax.ws.rs + jsr311-api + + + javassist + javassist + + + + + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dao/ApplicationDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dao/ApplicationDAO.java new file mode 100644 index 00000000000..74708532bac --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dao/ApplicationDAO.java @@ -0,0 +1,27 @@ +/* + * 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.application.mgt.core.dao; + +import org.wso2.carbon.application.mgt.core.dto.Application; + +public interface ApplicationDAO { + + public void createApplication(Application application); + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dto/Application.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dto/Application.java new file mode 100644 index 00000000000..0fd99cfb30b --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dto/Application.java @@ -0,0 +1,64 @@ +/* + * 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.application.mgt.core.dto; + +import java.util.List; + +public class Application{ + + private int id; + + private String uuId; + + private String type; + + private List properties; + + 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 getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public List getProperties() { + return properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/util/AppManagementPlugin.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/util/AppManagementPlugin.java new file mode 100644 index 00000000000..dcdbf077e4f --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/util/AppManagementPlugin.java @@ -0,0 +1,30 @@ +/* + * 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.application.mgt.core.util; + +public class AppManagementPlugin { + + public void registerPlugins(){ + + } + + public void unregisterPlugins(){ + + } +} diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml new file mode 100644 index 00000000000..2815c66c12d --- /dev/null +++ b/components/application-mgt/pom.xml @@ -0,0 +1,41 @@ + + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 2.0.45-SNAPSHOT + ../../pom.xml + + + 4.0.0 + application-mgt + org.wso2.carbon.devicemgt + pom + WSO2 Carbon - Device Application Management Component + WSO2 Carbon - Application Management Component + http://wso2.org + + + org.wso2.carbon.device.application.mgt.core + org.wso2.carbon.device.application.mgt.api + + From 021004158ba25a8fd9f3ae308fb85e1c4d0fe075 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 25 Apr 2017 15:18:32 +0530 Subject: [PATCH 02/11] Initialize application management DAOs --- .../pom.xml | 5 + .../mgt/api/beans/ErrorListItem.java | 79 +++++++ .../mgt/api/beans/ErrorResponse.java | 150 ++++++++++++ .../mgt/api/common/ErrorHandler.java | 33 +++ .../mgt/api/common/ErrorMessage.java | 42 ++++ .../api/common/GsonMessageBodyHandler.java | 91 +++++++ .../mgt/api/common/MDMAPIException.java | 59 +++++ .../ApplicationManagementService.java | 117 +++++++++ .../ApplicationManagementServiceImpl.java | 42 ++++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 70 ++---- .../src/main/webapp/WEB-INF/web.xml | 68 +----- .../pom.xml | 223 ++++++------------ .../core/components/ApplicationManager.java} | 11 +- .../impl/ApplicationManagerImpl.java | 75 ++++++ .../ApplicationConfigurationManager.java | 80 +++++++ .../ApplicationManagementConfigurations.java | 39 +++ .../ApplicationManagementRepository.java | 40 ++++ .../config/datasource/DataSourceConfig.java | 40 ++++ .../datasource/JNDILookupDefinition.java | 79 +++++++ .../core/dao/ApplicationManagementDAO.java | 64 +++++ .../ApplicationManagementDAOException.java} | 23 +- .../dao/ApplicationManagementDAOImpl.java | 90 +++++++ .../dao/ApplicationManagementDAOUtil.java | 61 +++++ .../application/mgt/core/dto/Application.java | 34 ++- .../mgt/core/dto/ApplicationType.java | 51 ++++ .../ApplicationManagerException.java} | 20 +- .../IllegalTransactionStateException.java | 44 ++++ .../mgt/core/exception/KeystoreException.java | 55 +++++ .../TransactionManagementException.java | 44 ++++ .../UnsupportedDatabaseEngineException.java | 48 ++++ .../ApplicationManagementDataHolder.java | 54 +++++ ...ApplicationManagementServiceComponent.java | 86 +++++++ .../core/util/ApplicationManagementUtil.java | 62 +++++ .../util/ApplicationManagerConstants.java} | 6 +- .../mgt/core/util/ConnectionManagerUtil.java | 209 ++++++++++++++++ components/application-mgt/pom.xml | 21 ++ pom.xml | 6 + 37 files changed, 2021 insertions(+), 300 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorListItem.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorResponse.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorHandler.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorMessage.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/MDMAPIException.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementService.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/ApplicationManagementServiceImpl.java rename components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/{application/mgt/core/dao/ApplicationDAO.java => device/application/mgt/core/components/ApplicationManager.java} (73%) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/components/impl/ApplicationManagerImpl.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationConfigurationManager.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationManagementConfigurations.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationManagementRepository.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/datasource/DataSourceConfig.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/datasource/JNDILookupDefinition.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAO.java rename components/application-mgt/{org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/impl/ApplicationManagementServiceImpl.java => org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOException.java} (58%) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOImpl.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOUtil.java rename components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/{ => device}/application/mgt/core/dto/Application.java (65%) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/ApplicationType.java rename components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/{application/mgt/core/util/AppManagementPlugin.java => device/application/mgt/core/exception/ApplicationManagerException.java} (60%) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/IllegalTransactionStateException.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/KeystoreException.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/TransactionManagementException.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/UnsupportedDatabaseEngineException.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementDataHolder.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java rename components/application-mgt/{org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/api/ApplicationManagementService.java => org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagerConstants.java} (79%) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.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 2d326b23883..5a899715ee2 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 @@ -214,6 +214,11 @@ org.wso2.carbon.certificate.mgt.core provided + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.application.mgt.core + provided + io.swagger swagger-annotations diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorListItem.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorListItem.java new file mode 100644 index 00000000000..e69f62c2cab --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorListItem.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2016, 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.beans; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import javax.validation.constraints.NotNull; + +@ApiModel(description = "Error List Item") +public class ErrorListItem { + + @NotNull + private String code = null; + @NotNull + private String message = null; + + @ApiModelProperty(required = true, value = "") + @JsonProperty("code") + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public ErrorListItem() { + } + + public ErrorListItem(String code, String msg) { + this.code = code; + this.message = msg; + } + + + /** + * Description about individual errors occurred + */ + @ApiModelProperty(required = true, value = "Description about individual errors occurred") + @JsonProperty("message") + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("errorItem {\n"); + + sb.append(" code: ").append(code).append("\n"); + sb.append(" message: ").append(message).append("\n"); + sb.append("}\n"); + return sb.toString(); + } + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorResponse.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorResponse.java new file mode 100644 index 00000000000..0b648b52c60 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/beans/ErrorResponse.java @@ -0,0 +1,150 @@ +/* + * 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.beans; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; + +@ApiModel(description = "Error Response") +public class ErrorResponse { + + private Long code = null; + private String message = null; + private String description = null; + private String moreInfo = null; + private List errorItems = new ArrayList<>(); + + private ErrorResponse() { + } + + @JsonProperty(value = "code") + @ApiModelProperty(required = true, value = "") + public Long getCode() { + return code; + } + + public void setCode(Long code) { + this.code = code; + } + + @JsonProperty(value = "message") + @ApiModelProperty(required = true, value = "ErrorResponse message.") + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @JsonProperty(value = "description") + @ApiModelProperty(value = "A detail description about the error message.") + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + @JsonProperty(value = "moreInfo") + @ApiModelProperty(value = "Preferably an url with more details about the error.") + public String getMoreInfo() { + return moreInfo; + } + + public void setMoreInfo(String moreInfo) { + this.moreInfo = moreInfo; + } + + public void addErrorListItem(ErrorListItem item) { + this.errorItems.add(item); + } + + /** + * If there are more than one error list them out. \nFor example, list out validation errors by each field. + */ + @JsonProperty(value = "errorItems") + @ApiModelProperty(value = "If there are more than one error list them out. \n" + + "For example, list out validation errors by each field.") + public List getErrorItems() { + return errorItems; + } + + public void setErrorItems(List error) { + this.errorItems = error; + } + + public static class ErrorResponseBuilder { + + private Long code = null; + private String message = null; + private String description = null; + private String moreInfo = null; + private List error; + + + public ErrorResponseBuilder() { + this.error = new ArrayList<>(); + } + + public ErrorResponseBuilder setCode(long code) { + this.code = code; + return this; + } + + public ErrorResponseBuilder setMessage(String message) { + this.message = message; + return this; + } + + public ErrorResponseBuilder setDescription(String description) { + this.description = description; + return this; + } + + public ErrorResponseBuilder setMoreInfo(String moreInfo) { + this.moreInfo = moreInfo; + return this; + } + + public ErrorResponseBuilder addErrorItem(String code, String msg) { + ErrorListItem item = new ErrorListItem(); + item.setCode(code); + item.setMessage(msg); + this.error.add(item); + return this; + } + + public ErrorResponse build() { + ErrorResponse errorResponse = new ErrorResponse(); + errorResponse.setCode(code); + errorResponse.setMessage(message); + errorResponse.setErrorItems(error); + errorResponse.setDescription(description); + errorResponse.setMoreInfo(moreInfo); + return errorResponse; + } + } + +} \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorHandler.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorHandler.java new file mode 100644 index 00000000000..0b921d5ec1c --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorHandler.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016, 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.common; + +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; + +@Produces({ "application/json", "application/xml" }) +public class ErrorHandler implements ExceptionMapper { + + public Response toResponse(MDMAPIException exception) { + ErrorMessage errorMessage = new ErrorMessage(); + errorMessage.setErrorMessage(exception.getErrorMessage()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorMessage).build(); + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorMessage.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorMessage.java new file mode 100644 index 00000000000..1856305ab64 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/ErrorMessage.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016, 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.common; + + +public class ErrorMessage { + + private String errorMessage; + private String errorCode; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java new file mode 100644 index 00000000000..d53e6fade2c --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2016, 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.common; + + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.ext.MessageBodyReader; +import javax.ws.rs.ext.MessageBodyWriter; +import javax.ws.rs.ext.Provider; +import java.io.*; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; + +@Provider +@Produces(APPLICATION_JSON) +@Consumes(APPLICATION_JSON) +public class GsonMessageBodyHandler implements MessageBodyWriter, MessageBodyReader { + + private Gson gson; + private static final String UTF_8 = "UTF-8"; + + public boolean isReadable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType) { + return true; + } + + private Gson getGson() { + if (gson == null) { + final GsonBuilder gsonBuilder = new GsonBuilder(); + gson = gsonBuilder.create(); + } + return gson; + } + + public Object readFrom(Class objectClass, Type type, Annotation[] annotations, MediaType mediaType, + MultivaluedMap stringStringMultivaluedMap, InputStream entityStream) + throws IOException, WebApplicationException { + + InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8"); + + try { + return getGson().fromJson(reader, type); + } finally { + reader.close(); + } + } + + public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType) { + return true; + } + + public long getSize(Object o, Class aClass, Type type, Annotation[] annotations, MediaType mediaType) { + return -1; + } + + public void writeTo(Object object, Class aClass, Type type, Annotation[] annotations, MediaType mediaType, + MultivaluedMap stringObjectMultivaluedMap, OutputStream entityStream) + throws IOException, WebApplicationException { + + OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8); + try { + getGson().toJson(object, type, writer); + } finally { + writer.close(); + } + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/MDMAPIException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/MDMAPIException.java new file mode 100644 index 00000000000..4637c6f3ecd --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/MDMAPIException.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2016, 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.common; + +/** + * Custom exception class for handling CDM API related exceptions. + */ +public class MDMAPIException extends Exception { + + private static final long serialVersionUID = 7950151650447893900L; + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public MDMAPIException(String msg, Exception e) { + super(msg, e); + setErrorMessage(msg); + } + + public MDMAPIException(String msg, Throwable cause) { + super(msg, cause); + setErrorMessage(msg); + } + + public MDMAPIException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public MDMAPIException() { + super(); + } + + public MDMAPIException(Throwable cause) { + super(cause); + } +} 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 new file mode 100644 index 00000000000..1aeb0965cc0 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/ApplicationManagementService.java @@ -0,0 +1,117 @@ +/* + * 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.services; + +import io.swagger.annotations.*; +import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; + +import javax.ws.rs.*; +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) +@Consumes(MediaType.APPLICATION_JSON) +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) + @ApiOperation( + consumes = MediaType.TEXT_PLAIN, + produces = MediaType.TEXT_PLAIN, + httpMethod = "POST", + value = "get all applications", + notes = "This will get all applications", + tags = "Application Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:get-application") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully got application list.", + 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 getting the application list.", + response = ErrorResponse.class) + }) + Response getApplications( + @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); + + +} 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 new file mode 100644 index 00000000000..a00a298eaef --- /dev/null +++ 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 @@ -0,0 +1,42 @@ +/* + * 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.services.impl; + +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.util.ApplicationManagementUtil; + +import javax.ws.rs.POST; +import javax.ws.rs.core.Response; + +public class ApplicationManagementServiceImpl implements ApplicationManagementService { + + @POST + @Override + public Response createApplication(String ifModifiedSince, String name) { + ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManager(); + return null; + } + + @Override + public Response getApplications(String ifModifiedSince) { + ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManager(); + return Response.ok().entity(applicationManager.getApplications().get(0).getName()).build(); + } +} 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 0dacf240841..3dd210b3b7a 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,66 +1,24 @@ - - - - + + + - - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - + \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml index 351d3ac11ad..984ef89837c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml @@ -17,7 +17,7 @@ ~ under the License. --> - Admin-Webapp + Application Management Webapp JAX-WS/JAX-RS Application Management Endpoint JAX-WS/JAX-RS Servlet @@ -25,12 +25,6 @@ org.apache.cxf.transport.servlet.CXFServlet - - - swagger.security.filter - ApiAuthorizationFilterImpl - - 1 CXFServlet @@ -39,10 +33,9 @@ 60 - doAuthentication - true + false @@ -59,61 +52,4 @@ true - - - - ApplicationMgt-Admin - /* - - - CONFIDENTIAL - - - - - ApiOriginFilter - org.wso2.carbon.application.mgt.jaxrs.ApiOriginFilter - - - - HttpHeaderSecurityFilter - org.apache.catalina.filters.HttpHeaderSecurityFilter - - hstsEnabled - false - - - - - ContentTypeBasedCachePreventionFilter - org.wso2.carbon.ui.filters.cache.ContentTypeBasedCachePreventionFilter - - patterns - text/html" ,application/json" ,text/plain - - - filterAction - enforce - - - httpHeaders - Cache-Control: no-store, no-cache, must-revalidate, private - - - - - HttpHeaderSecurityFilter - /* - - - - ContentTypeBasedCachePreventionFilter - /* - - - - ApiOriginFilter - /* - - 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 b413dce4caf..7c3e8f2fbed 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 @@ -18,7 +18,6 @@ --> - org.wso2.carbon.devicemgt application-mgt @@ -28,6 +27,7 @@ 4.0.0 org.wso2.carbon.device.application.mgt.core + 2.0.45-SNAPSHOT bundle WSO2 Carbon - Application Management Core WSO2 Carbon - Application Management Core @@ -42,6 +42,7 @@ org.apache.felix maven-bundle-plugin + 1.4.0 true @@ -49,61 +50,63 @@ ${project.artifactId} ${carbon.device.mgt.version} Device Management Core Bundle - org.wso2.carbon.application.mgt.core.internal + + org.wso2.carbon.device.application.mgt.core.internal + - org.apache.axis2.*;version="${axis2.osgi.version.range}", - org.apache.axiom.*; version="${axiom.osgi.version.range}", org.osgi.framework, org.osgi.service.component, org.apache.commons.logging, - javax.naming, + javax.security.auth.x500, javax.xml.*, javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}";resolution:=optional, - javax.servlet.*, - org.xml.sax, - javax.sql.*, - org.wso2.carbon.context, - org.wso2.carbon.core, - org.wso2.carbon.utils.*, - org.wso2.carbon.application.mgt.common.*, + org.apache.commons.codec.binary;version="${commons-codec.wso2.osgi.version.range}", + org.bouncycastle.asn1, + org.bouncycastle.asn1.x500, + org.bouncycastle.asn1.x509, + org.bouncycastle.asn1.pkcs, + org.bouncycastle.cert; version="${bcprov.wso2.version.range}", + org.bouncycastle.cert.jcajce; version="${bcprov.wso2.version.range}", + org.bouncycastle.cms, + org.bouncycastle.jce.provider, + org.bouncycastle.operator, + org.bouncycastle.operator.jcajce, + org.bouncycastle.asn1.x500.style, + org.bouncycastle.pkcs, + org.wso2.carbon.user.core.tenant, org.wso2.carbon.user.api, - org.wso2.carbon.user.core.*, - org.wso2.carbon.registry.core.service, - org.wso2.carbon.registry.core, - org.wso2.carbon.registry.core.exceptions, - org.wso2.carbon.registry.core.session, - org.wso2.carbon.registry.api, + org.wso2.carbon.user.core.service, + + org.bouncycastle.util, + org.jscep.message, + org.wso2.carbon.context, + org.jscep.transaction, org.w3c.dom, - org.wso2.carbon.identity.oauth.stub, - org.wso2.carbon.identity.oauth.stub.dto, - org.wso2.carbon.ndatasource.core, - org.wso2.carbon.ntask.core.*, - org.wso2.carbon.ntask.common, - org.apache.catalina, - org.apache.catalina.core, - org.apache.commons.collections, - org.wso2.carbon.email.sender.*, + org.xml.sax, + javax.sql, + + javax.naming, + javax.xml.bind.annotation, + javax.xml.bind, + org.wso2.carbon.utils.*, + org.wso2.carbon.device.mgt.common.*, io.swagger.annotations.*;resolution:=optional, - org.wso2.carbon, - org.wso2.carbon.base, - org.scannotation.* + org.wso2.carbon.device.mgt.core.*, + org.wso2.carbon.registry.indexing.*, + - !org.wso2.carbon.application.mgt.core.internal, - org.wso2.carbon.application.mgt.core.* + !org.wso2.carbon.device.application.mgt.core.internal.*, + org.wso2.carbon.device.application.mgt.core.* - - javax.ws.rs-api, - scribe;scope=compile|runtime;inline=false, - javassist;inline=false - - * + org.apache.maven.plugins maven-surefire-plugin + 2.18 file:src/test/resources/log4j.properties @@ -113,6 +116,7 @@ + @@ -122,43 +126,8 @@ org.eclipse.osgi - org.eclipse.osgi - org.eclipse.osgi.services - - - org.wso2.orbit.org.scannotation - scannotation - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.common - - - org.wso2.carbon - org.wso2.carbon.logging - - - org.wso2.carbon - org.wso2.carbon.utils - - - org.wso2.carbon - org.wso2.carbon.core - - - org.wso2.carbon - org.wso2.carbon.ndatasource.core - - - commons-lang - commons-lang - - - - - com.h2database.wso2 - h2-database-engine - test + org.eclipse.equinox + org.eclipse.equinox.common org.testng @@ -166,116 +135,58 @@ org.wso2.carbon - org.wso2.carbon.user.core - - - org.wso2.carbon - org.wso2.carbon.user.api - - - org.wso2.carbon - org.wso2.carbon.registry.api - - - org.wso2.carbon - org.wso2.carbon.registry.core - - - org.apache.tomcat.wso2 - jdbc-pool - - - org.wso2.carbon - org.wso2.carbon.base - - - org.wso2.carbon.governance - org.wso2.carbon.governance.api - - - org.apache.axis2.transport - axis2-transport-mail - - - org.apache.ws.commons.axiom.wso2 - axiom - - - - org.apache.axis2.wso2 - axis2 + org.wso2.orbit.org.bouncycastle + bcprov-jdk15on - org.wso2.carbon.identity.inbound.auth.oauth2 - org.wso2.carbon.identity.oauth.stub + org.wso2.orbit.org.bouncycastle + bcpkix-jdk15on - org.wso2.tomcat - tomcat + org.wso2.orbit.com.google.code.jscep + jscep - org.wso2.tomcat - tomcat-servlet-api + commons-codec.wso2 + commons-codec - - - org.wso2.carbon.commons - org.wso2.carbon.ntask.core + commons-io.wso2 + commons-io - - - commons-collections.wso2 - commons-collections + org.wso2.carbon + org.wso2.carbon.utils - org.wso2.carbon.devicemgt - org.wso2.carbon.email.sender.core + org.wso2.carbon.device.mgt.core - - - mysql - mysql-connector-java - test - - - com.google.code.gson - gson + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common - io.swagger swagger-annotations provided - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations + org.wso2.carbon + org.wso2.carbon.user.core - - javax.ws.rs - javax.ws.rs-api + org.wso2.carbon.registry + org.wso2.carbon.registry.indexing - javax.ws.rs - jsr311-api + org.slf4j + slf4j-simple + test - - javassist - javassist - - diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dao/ApplicationDAO.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 similarity index 73% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dao/ApplicationDAO.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/components/ApplicationManager.java index 74708532bac..7852e91d005 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dao/ApplicationDAO.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 @@ -16,12 +16,17 @@ * under the License. * */ -package org.wso2.carbon.application.mgt.core.dao; +package org.wso2.carbon.device.application.mgt.core.components; -import org.wso2.carbon.application.mgt.core.dto.Application; +import org.wso2.carbon.device.application.mgt.core.dto.Application; -public interface ApplicationDAO { +import java.util.ArrayList; +import java.util.List; + +public interface ApplicationManager { public void createApplication(Application application); + public List getApplications(); + } 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 new file mode 100644 index 00000000000..9f2873f4f2e --- /dev/null +++ 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 @@ -0,0 +1,75 @@ +/* + * 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.components.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.core.components.ApplicationManager; +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.internal.ApplicationManagementDataHolder; +import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class ApplicationManagerImpl implements ApplicationManager { + + private static final Log log = LogFactory.getLog(ApplicationManagerImpl.class); + + + private static ApplicationManagerImpl applicationManager = new ApplicationManagerImpl(); + + private ApplicationManagerImpl(){ + + } + + public static ApplicationManagerImpl getInstance(){ + return applicationManager; + } + + + @Override + public void createApplication(Application application) { + + } + + @Override + public List getApplications() { + ApplicationManagementDataHolder dataHolder = ApplicationManagementDataHolder.getInstance(); + try { + ConnectionManagerUtil.openConnection(); + } catch (SQLException e) { + e.printStackTrace(); + } + ApplicationManagementDAO applicationManagementDAO = dataHolder.getApplicationManagementDAO(); + List applications = null; + try { + applications = applicationManagementDAO.getApplications(); + } catch (ApplicationManagementDAOException e) { + log.error(e); + } + + 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/config/ApplicationConfigurationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationConfigurationManager.java new file mode 100644 index 00000000000..d0d7af42bf6 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationConfigurationManager.java @@ -0,0 +1,80 @@ +/* + * 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.config; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; +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.ApplicationManagerConstants; +import org.wso2.carbon.utils.CarbonUtils; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import java.io.File; + +public class ApplicationConfigurationManager { + + private final String applicationMgtConfigXMLPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + + ApplicationManagerConstants.APPLICATION_CONFIG_XML_FILE; + + private static final Log log = LogFactory.getLog(ApplicationConfigurationManager.class); + + private ApplicationManagementConfigurations applicationManagerConfiguration; + + + private static ApplicationConfigurationManager applicationConfigurationManager; + + private ApplicationConfigurationManager() { + + } + + public static ApplicationConfigurationManager getInstance() { + if (applicationConfigurationManager == null) { + applicationConfigurationManager = new ApplicationConfigurationManager(); + try { + applicationConfigurationManager.initConfig(); + } catch (ApplicationManagerException e) { + log.error(e); + } + } + + return applicationConfigurationManager; + } + + + public synchronized void initConfig() throws ApplicationManagerException { + try { + File appMgtConfig = new File(applicationMgtConfigXMLPath); + Document doc = ApplicationManagementUtil.convertToDocument(appMgtConfig); + + /* Un-marshaling Certificate Management configuration */ + JAXBContext jaxbContext = JAXBContext.newInstance(ApplicationManagementConfigurations.class); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + this.applicationManagerConfiguration = (ApplicationManagementConfigurations) unmarshaller.unmarshal(doc); + } catch (Exception e) { + throw new ApplicationManagerException("Error occurred while initializing application config"); + } + } + + public ApplicationManagementConfigurations getApplicationManagerConfiguration() { + return applicationManagerConfiguration; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationManagementConfigurations.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationManagementConfigurations.java new file mode 100644 index 00000000000..b56d8f206a7 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationManagementConfigurations.java @@ -0,0 +1,39 @@ +/* + * 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.config; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "ApplicationManagementConfigurations") +public class ApplicationManagementConfigurations { + + private ApplicationManagementRepository applicationManagerRepository; + + @XmlElement(name = "ManagementRepository", required = true) + public ApplicationManagementRepository getApplicationManagerRepository() { + return applicationManagerRepository; + } + + public void setApplicationManagerRepository(ApplicationManagementRepository applicationManagerRepository) { + this.applicationManagerRepository = applicationManagerRepository; + } +} + + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationManagementRepository.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationManagementRepository.java new file mode 100644 index 00000000000..52f257fd746 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationManagementRepository.java @@ -0,0 +1,40 @@ +/* + * 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.config; + + +import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "ManagementRepository") +public class ApplicationManagementRepository { + + private DataSourceConfig dataSourceConfig; + + @XmlElement(name = "DataSourceConfiguration", required = true) + public DataSourceConfig getDataSourceConfig() { + return dataSourceConfig; + } + + public void setDataSourceConfig(DataSourceConfig dataSourceConfig) { + this.dataSourceConfig = dataSourceConfig; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/datasource/DataSourceConfig.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/datasource/DataSourceConfig.java new file mode 100644 index 00000000000..6b6d9ff3e15 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/datasource/DataSourceConfig.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014, 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.config.datasource; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Class for holding data source configuration in cdm-config.xml at parsing with JAXB + */ +@XmlRootElement(name = "DataSourceConfiguration") +public class DataSourceConfig { + + private JNDILookupDefinition jndiLookupDefinition; + + @XmlElement(name = "JndiLookupDefinition", nillable = true) + public JNDILookupDefinition getJndiLookupDefinition() { + return jndiLookupDefinition; + } + + public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) { + this.jndiLookupDefinition = jndiLookupDefinition; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/datasource/JNDILookupDefinition.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/datasource/JNDILookupDefinition.java new file mode 100644 index 00000000000..600c9f1dafd --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/datasource/JNDILookupDefinition.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2014, 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.config.datasource; + +import javax.xml.bind.annotation.*; +import java.util.List; + +/** + * Class for hold JndiLookupDefinition of cdm-config.xml at parsing with JAXB + */ +@XmlRootElement(name = "JndiLookupDefinition") +public class JNDILookupDefinition { + + private String jndiName; + private List jndiProperties; + + @XmlElement(name = "Name", nillable = false) + public String getJndiName() { + return jndiName; + } + + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + @XmlElementWrapper(name = "Environment", nillable = false) + @XmlElement(name = "Property", nillable = false) + public List getJndiProperties() { + return jndiProperties; + } + + public void setJndiProperties(List jndiProperties) { + this.jndiProperties = jndiProperties; + } + + @XmlRootElement(name = "Property") + public static class JNDIProperty { + + private String name; + + private String value; + + @XmlAttribute(name = "Name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlValue + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + +} + 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 new file mode 100644 index 00000000000..9ca5ffbac92 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAO.java @@ -0,0 +1,64 @@ +/* + * 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.dao; + +import org.apache.axis2.databinding.types.Day; +import org.wso2.carbon.device.application.mgt.core.dto.Application; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public interface ApplicationManagementDAO { + + public enum DatabaseType { + + H2("H2"), + MYSQL("MySQL"), + ORACLE("Oracle"), + POSTGRESQL("PostgreSQL"), + MSSQL("Microsoft SQL Server"); + + private final String value; + private static final Map lookup = new HashMap(); + + static { + for (DatabaseType databaseType : DatabaseType.values()) { + lookup.put(databaseType.getValue(), databaseType); + } + } + + DatabaseType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static DatabaseType lookup(String value) { + return lookup.get(value); + } + } + + public void createApplication(Application application) throws ApplicationManagementDAOException; + + public List getApplications() throws ApplicationManagementDAOException; + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/impl/ApplicationManagementServiceImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOException.java similarity index 58% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/impl/ApplicationManagementServiceImpl.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOException.java index 15263637812..b800fb9d48c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/impl/ApplicationManagementServiceImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOException.java @@ -16,10 +16,27 @@ * under the License. * */ -package org.wso2.carbon.device.application.mgt.api.service.impl; +package org.wso2.carbon.device.application.mgt.core.dao; -import org.wso2.carbon.device.application.mgt.api.service.api.ApplicationManagementService; +public class ApplicationManagementDAOException extends Exception { -public class ApplicationManagementServiceImpl implements ApplicationManagementService { + String message; + public ApplicationManagementDAOException(String message){ + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return super.toString(); + } } 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 new file mode 100644 index 00000000000..431124565a5 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOImpl.java @@ -0,0 +1,90 @@ +/* + * 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.dao; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig; +import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; +import org.wso2.carbon.device.application.mgt.core.dto.Application; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class ApplicationManagementDAOImpl implements ApplicationManagementDAO { + + private DatabaseType databaseType; + private static DataSource dataSource; + + private static final Log log = LogFactory.getLog(ApplicationManagementDAOImpl.class); + + public ApplicationManagementDAOImpl(DataSourceConfig dataSourceConfig) { + dataSource = ConnectionManagerUtil.resolveDataSource(dataSourceConfig); + ConnectionManagerUtil.setDataSource(dataSource); + String databaseEngine = "H2"; + try { + databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); + } catch (SQLException e) { + log.error("Error occurred while retrieving config.datasource connection", e); + } + this.databaseType = DatabaseType.lookup(databaseEngine); + } + + @Override + public void createApplication(Application application) throws ApplicationManagementDAOException { + + } + + @Override + public List getApplications() throws ApplicationManagementDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + String sql = null; + List applications; + + try { + conn = ConnectionManagerUtil.getCurrentConnection().get(); + switch (databaseType) { + case H2: + case MYSQL: + sql = "SELECT * FROM APPM_APPLICATION"; + } + + stmt = conn.prepareStatement(sql); + rs = stmt.executeQuery(); + applications = new ArrayList<>(); + while (rs.next()) { + applications.add(ApplicationManagementDAOUtil.loadApplication(rs)); + } + + } catch (SQLException e) { + throw new ApplicationManagementDAOException("Error occurred while getting application List"); + } finally { + ApplicationManagementDAOUtil.cleanupResources(stmt, rs); + } + 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/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 new file mode 100644 index 00000000000..6bc3f4d1245 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOUtil.java @@ -0,0 +1,61 @@ +/* + * 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.dao; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.core.dto.Application; +import org.wso2.carbon.device.application.mgt.core.dto.ApplicationType; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class ApplicationManagementDAOUtil { + + private static final Log log = LogFactory.getLog(ApplicationManagementDAOUtil.class); + + public static Application loadApplication(ResultSet rs) throws SQLException { + 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; + } + + public static void cleanupResources(PreparedStatement stmt, ResultSet rs) { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing result set", e); + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing prepared statement", e); + } + } + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/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 similarity index 65% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/dto/Application.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Application.java index 0fd99cfb30b..125ee300ea3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/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 @@ -16,20 +16,20 @@ * under the License. * */ -package org.wso2.carbon.application.mgt.core.dto; +package org.wso2.carbon.device.application.mgt.core.dto; import java.util.List; public class Application{ private int id; - private String uuId; - - private String type; - + private String name; + private String description; + private ApplicationType applicationType; private List properties; + public int getId() { return id; } @@ -46,12 +46,28 @@ public class Application{ this.uuId = uuId; } - public String getType() { - return type; + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public ApplicationType getApplicationType() { + return applicationType; } - public void setType(String type) { - this.type = type; + public void setApplicationType(ApplicationType applicationType) { + this.applicationType = applicationType; } public List getProperties() { 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 new file mode 100644 index 00000000000..79f4cbcfc0b --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/ApplicationType.java @@ -0,0 +1,51 @@ +/* + * 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; + +public class ApplicationType { + + private int id; + private String name; + private String code; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/util/AppManagementPlugin.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagerException.java similarity index 60% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/util/AppManagementPlugin.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagerException.java index dcdbf077e4f..63727ff05fc 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/application/mgt/core/util/AppManagementPlugin.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagerException.java @@ -16,15 +16,27 @@ * under the License. * */ -package org.wso2.carbon.application.mgt.core.util; +package org.wso2.carbon.device.application.mgt.core.exception; -public class AppManagementPlugin { +public class ApplicationManagerException extends Exception { - public void registerPlugins(){ + String message; + public ApplicationManagerException(String message){ + this.message = message; } - public void unregisterPlugins(){ + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + @Override + public String toString() { + return super.toString(); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/IllegalTransactionStateException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/IllegalTransactionStateException.java new file mode 100644 index 00000000000..3cbb7f0f3e2 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/IllegalTransactionStateException.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016, 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.exception; + +public class IllegalTransactionStateException extends RuntimeException { + + private static final long serialVersionUID = -3151279331929070297L; + + public IllegalTransactionStateException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public IllegalTransactionStateException(String message, Throwable cause) { + super(message, cause); + } + + public IllegalTransactionStateException(String msg) { + super(msg); + } + + public IllegalTransactionStateException() { + super(); + } + + public IllegalTransactionStateException(Throwable cause) { + super(cause); + } + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/KeystoreException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/KeystoreException.java new file mode 100644 index 00000000000..15e1aec5bfb --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/KeystoreException.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2015, 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.exception; + +public class KeystoreException extends Exception { + + private static final long serialVersionUID = -8935640983869122660L; + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public KeystoreException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public KeystoreException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public KeystoreException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public KeystoreException() { + super(); + } + + public KeystoreException(Throwable cause) { + super(cause); + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/TransactionManagementException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/TransactionManagementException.java new file mode 100644 index 00000000000..bd5a6b503b7 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/TransactionManagementException.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016, 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.exception; + +public class TransactionManagementException extends Exception { + + private static final long serialVersionUID = -3151279321929070297L; + + public TransactionManagementException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public TransactionManagementException(String message, Throwable cause) { + super(message, cause); + } + + public TransactionManagementException(String msg) { + super(msg); + } + + public TransactionManagementException() { + super(); + } + + public TransactionManagementException(Throwable cause) { + super(cause); + } + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/UnsupportedDatabaseEngineException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/UnsupportedDatabaseEngineException.java new file mode 100644 index 00000000000..3ffff94290e --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/UnsupportedDatabaseEngineException.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016, 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.exception; + +/** + * This runtime exception will be thrown if the server has configured with unsupported DB engine. + */ +public class UnsupportedDatabaseEngineException extends RuntimeException { + + private static final long serialVersionUID = -3151279311929070297L; + + public UnsupportedDatabaseEngineException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public UnsupportedDatabaseEngineException(String message, Throwable cause) { + super(message, cause); + } + + public UnsupportedDatabaseEngineException(String msg) { + super(msg); + } + + public UnsupportedDatabaseEngineException() { + super(); + } + + public UnsupportedDatabaseEngineException(Throwable cause) { + super(cause); + } + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementDataHolder.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementDataHolder.java new file mode 100644 index 00000000000..82f629b5338 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementDataHolder.java @@ -0,0 +1,54 @@ +/* + * 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.internal; + +import org.wso2.carbon.device.application.mgt.core.dao.ApplicationManagementDAO; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; + +public class ApplicationManagementDataHolder { + + private DeviceManagementProviderService deviceManagementService; + private ApplicationManagementDAO applicationManagementDAO; + + private static final ApplicationManagementDataHolder applicationMgtDataHolder = new ApplicationManagementDataHolder(); + + private ApplicationManagementDataHolder(){ + + } + + public static ApplicationManagementDataHolder getInstance() { + return applicationMgtDataHolder; + } + + public DeviceManagementProviderService getDeviceManagementService() { + return deviceManagementService; + } + + public void setDeviceManagementService(DeviceManagementProviderService deviceManagementService) { + this.deviceManagementService = deviceManagementService; + } + + public ApplicationManagementDAO getApplicationManagementDAO() { + return applicationManagementDAO; + } + + public void setApplicationManagementDAO(ApplicationManagementDAO applicationManagementDAO) { + this.applicationManagementDAO = applicationManagementDAO; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java new file mode 100644 index 00000000000..daf29e8be15 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java @@ -0,0 +1,86 @@ +/* + * 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.internal; + +import org.apache.commons.logging.Log; +import org.osgi.service.component.ComponentContext; +import org.osgi.framework.BundleContext; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.core.components.ApplicationManager; +import org.wso2.carbon.device.application.mgt.core.components.impl.ApplicationManagerImpl; +import org.wso2.carbon.device.application.mgt.core.config.ApplicationConfigurationManager; +import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig; +import org.wso2.carbon.device.application.mgt.core.dao.ApplicationManagementDAO; +import org.wso2.carbon.device.application.mgt.core.dao.ApplicationManagementDAOImpl; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; + +import javax.naming.NamingException; + +/** + * @scr.component name="org.wso2.carbon.application.mgt" immediate="true" + * @scr.reference name="org.wso2.carbon.device.manager" + * interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService" + * cardinality="1..1" + * policy="dynamic" + * bind="setDeviceManagementService" + * unbind="unsetDeviceManagementService" + */ +public class ApplicationManagementServiceComponent { + + private static Log log = LogFactory.getLog(ApplicationManagementServiceComponent.class); + + + protected void activate(ComponentContext componentContext) throws NamingException { + BundleContext bundleContext = componentContext.getBundleContext(); + + bundleContext.registerService(ApplicationManager.class.getName(), + ApplicationManagerImpl.getInstance(), null); + + + DataSourceConfig dataSourceConfig = ApplicationConfigurationManager.getInstance() + .getApplicationManagerConfiguration().getApplicationManagerRepository().getDataSourceConfig(); + ApplicationManagementDAO applicationManagementDAO = new ApplicationManagementDAOImpl(dataSourceConfig); + ApplicationManagementDataHolder.getInstance() + .setApplicationManagementDAO(applicationManagementDAO); + + log.info("ApplicationManagement core bundle has been successfully initialized"); + + if (log.isDebugEnabled()) { + log.debug("ApplicationManagement core bundle has been successfully initialized"); + } + } + + protected void deactivate(ComponentContext componentContext) { + //do nothing + } + + protected void setDeviceManagementService(DeviceManagementProviderService deviceManagementProviderService) { + if (log.isDebugEnabled()) { + log.debug("Setting Application Management OSGI Service"); + } + ApplicationManagementDataHolder.getInstance().setDeviceManagementService(deviceManagementProviderService); + } + + protected void unsetDeviceManagementService(DeviceManagementProviderService deviceManagementProviderService) { + if (log.isDebugEnabled()) { + log.debug("Removing Application Management OSGI Service"); + } + ApplicationManagementDataHolder.getInstance().setDeviceManagementService(null); + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java new file mode 100644 index 00000000000..4a31cd93835 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java @@ -0,0 +1,62 @@ +/* + * 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.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.application.mgt.core.components.ApplicationManager; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagerException; + +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.File; + +public class ApplicationManagementUtil { + + private static Log log = LogFactory.getLog(ApplicationManagementUtil.class); + + public static ApplicationManager getApplicationManager() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ApplicationManager applicationManager = + (ApplicationManager) CarbonContext.getThreadLocalCarbonContext().getOSGiService(ApplicationManager.class, null); + if (applicationManager == null) { + String msg = "Application Management provider service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return applicationManager; + } + + public static Document convertToDocument(File file) throws ApplicationManagerException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + try { + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + return docBuilder.parse(file); + } catch (Exception e) { + throw new ApplicationManagerException("Error occurred while parsing file, while converting " + + "to a org.w3c.dom.Document : " + e.getMessage()); + } + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/api/ApplicationManagementService.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagerConstants.java similarity index 79% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/api/ApplicationManagementService.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagerConstants.java index 3725cb0c304..80c9c417bd5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/service/api/ApplicationManagementService.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagerConstants.java @@ -16,9 +16,9 @@ * under the License. * */ -package org.wso2.carbon.device.application.mgt.api.service.api; - -public interface ApplicationManagementService { +package org.wso2.carbon.device.application.mgt.core.util; +public class ApplicationManagerConstants { + public static final String APPLICATION_CONFIG_XML_FILE = "application-mgt.xml"; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java new file mode 100644 index 00000000000..6edc57547cc --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java @@ -0,0 +1,209 @@ +/* + * 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.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig; +import org.wso2.carbon.device.application.mgt.core.config.datasource.JNDILookupDefinition; +import org.wso2.carbon.device.application.mgt.core.exception.IllegalTransactionStateException; +import org.wso2.carbon.device.application.mgt.core.exception.TransactionManagementException; + +import javax.naming.InitialContext; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Hashtable; +import java.util.List; + +public class ConnectionManagerUtil { + + private static final Log log = LogFactory.getLog(ConnectionManagerUtil.class); + + private enum TxState { + CONNECTION_NOT_BORROWED, CONNECTION_BORROWED, CONNECTION_CLOSED + } + + private static final ThreadLocal currentConnection = new ThreadLocal<>(); + private static ThreadLocal currentTxState = new ThreadLocal<>(); + private static DataSource dataSource; + + public static void setDataSource(DataSource dataSource) { + ConnectionManagerUtil.dataSource = dataSource; + } + + public static ThreadLocal getCurrentConnection() { + return currentConnection; + } + + public static void openConnection() throws SQLException { + Connection conn = currentConnection.get(); + if (conn != null) { + throw new IllegalTransactionStateException("A transaction is already active within the context of " + + "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + + "transaction is already active is a sign of improper transaction handling"); + } + try { + conn = dataSource.getConnection(); + } catch (SQLException e) { + currentTxState.set(TxState.CONNECTION_NOT_BORROWED); + throw e; + } + currentConnection.set(conn); + currentTxState.set(TxState.CONNECTION_BORROWED); + } + + + public static void beginTransaction() throws TransactionManagementException { + Connection conn = currentConnection.get(); + if (conn != null) { + throw new IllegalTransactionStateException("A transaction is already active within the context of " + + "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + + "transaction is already active is a sign of improper transaction handling"); + } + try { + conn = dataSource.getConnection(); + } catch (SQLException e) { + throw new TransactionManagementException("Error occurred while retrieving a data source connection", e); + } + + try { + conn.setAutoCommit(false); + } catch (SQLException e) { + try { + conn.close(); + } catch (SQLException e1) { + log.warn("Error occurred while closing the borrowed connection. " + + "Transaction has ended pre-maturely", e1); + } + currentTxState.set(TxState.CONNECTION_CLOSED); + throw new TransactionManagementException("Error occurred while setting auto-commit to false", e); + } + currentConnection.set(conn); + currentTxState.set(TxState.CONNECTION_BORROWED); + } + + public static void commitTransaction() { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods"); + } + try { + conn.commit(); + } catch (SQLException e) { + log.error("Error occurred while committing the transaction", e); + } finally { + closeConnection(); + } + } + + public static void rollbackTransaction() { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods"); + } + try { + conn.rollback(); + } catch (SQLException e) { + log.warn("Error occurred while roll-backing the transaction", e); + } finally { + closeConnection(); + } + } + + public static void closeConnection() { + TxState txState = currentTxState.get(); + if (TxState.CONNECTION_NOT_BORROWED == txState) { + if (log.isDebugEnabled()) { + log.debug("No successful connection appears to have been borrowed to perform the underlying " + + "transaction even though the 'openConnection' method has been called. Therefore, " + + "'closeConnection' method is returning silently"); + } + currentTxState.remove(); + return; + } + + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods"); + } + try { + conn.close(); + } catch (SQLException e) { + log.warn("Error occurred while close the connection", e); + } + currentConnection.remove(); + currentTxState.remove(); + } + + + /** + * Resolve data source from the data source definition. + * + * @param config data source configuration + * @return data source resolved from the data source definition + */ + public static DataSource resolveDataSource(DataSourceConfig config) { + DataSource dataSource = null; + if (config == null) { + throw new RuntimeException( + "Application Management Repository data source configuration " + "is null and " + + "thus, is not initialized" + ); + } + JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); + if (jndiConfig != null) { + if (log.isDebugEnabled()) { + log.debug("Initializing Application Management Repository data source using the JNDI " + + "Lookup Definition"); + } + List jndiPropertyList = + jndiConfig.getJndiProperties(); + if (jndiPropertyList != null) { + Hashtable jndiProperties = new Hashtable(); + for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { + jndiProperties.put(prop.getName(), prop.getValue()); + } + dataSource = lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + } else { + dataSource = lookupDataSource(jndiConfig.getJndiName(), null); + } + } + return dataSource; + } + + + public static DataSource lookupDataSource(String dataSourceName, final Hashtable jndiProperties) { + try { + if (jndiProperties == null || jndiProperties.isEmpty()) { + return (DataSource) InitialContext.doLookup(dataSourceName); + } + final InitialContext context = new InitialContext(jndiProperties); + return (DataSource) context.doLookup(dataSourceName); + } catch (Exception e) { + throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); + } + } +} diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml index 2815c66c12d..1823e25fbb7 100644 --- a/components/application-mgt/pom.xml +++ b/components/application-mgt/pom.xml @@ -38,4 +38,25 @@ org.wso2.carbon.device.application.mgt.core org.wso2.carbon.device.application.mgt.api + + + + + + org.apache.felix + maven-scr-plugin + 1.7.2 + + + generate-scr-scrdescriptor + + scr + + + + + + + + diff --git a/pom.xml b/pom.xml index 4a42b1d576f..3fb6bd2fc15 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,7 @@ components/apimgt-extensions components/policy-mgt components/certificate-mgt + components/application-mgt components/webapp-authenticator-framework components/email-sender features/device-mgt @@ -170,6 +171,11 @@ org.wso2.carbon.certificate.mgt.core ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.application.mgt.core + ${carbon.device.mgt.version} + org.wso2.carbon.devicemgt org.wso2.carbon.policy.mgt.common From 7f6b33a0c0697547c145e4e46b116a0a27a7fe7d Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 25 Apr 2017 16:23:19 +0530 Subject: [PATCH 03/11] Fixes for Error handling --- .../ApplicationManagementServiceImpl.java | 15 +++++++++++- .../core/components/ApplicationManager.java | 5 ++-- .../impl/ApplicationManagerImpl.java | 23 ++++++------------- .../ApplicationConfigurationManager.java | 2 +- .../ApplicationManagementDAOException.java | 22 ++++-------------- .../dao/ApplicationManagementDAOImpl.java | 2 +- .../ApplicationManagerException.java | 10 +++----- .../core/util/ApplicationManagementUtil.java | 2 +- .../mgt/core/util/ConnectionManagerUtil.java | 12 +++++----- 9 files changed, 40 insertions(+), 53 deletions(-) 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 a00a298eaef..15ab68f9383 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,8 +18,12 @@ */ package org.wso2.carbon.device.application.mgt.api.services.impl; +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.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; @@ -27,6 +31,8 @@ import javax.ws.rs.core.Response; public class ApplicationManagementServiceImpl implements ApplicationManagementService { + private static Log log = LogFactory.getLog(ApplicationManagementServiceImpl.class); + @POST @Override public Response createApplication(String ifModifiedSince, String name) { @@ -37,6 +43,13 @@ public class ApplicationManagementServiceImpl implements ApplicationManagementSe @Override public Response getApplications(String ifModifiedSince) { ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManager(); - return Response.ok().entity(applicationManager.getApplications().get(0).getName()).build(); + try { + return Response.ok().entity(applicationManager.getApplications()).build(); + } catch (ApplicationManagerException e) { + String msg = "Error occured while getting the application list"; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } } } 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 7852e91d005..31d02b75211 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,14 +19,15 @@ 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.exception.ApplicationManagerException; import java.util.ArrayList; import java.util.List; public interface ApplicationManager { - public void createApplication(Application application); + public void createApplication(Application application) throws ApplicationManagerException; - public List getApplications(); + 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 9f2873f4f2e..e48109eed00 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.exception.ApplicationManagerException; import org.wso2.carbon.device.application.mgt.core.internal.ApplicationManagementDataHolder; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; @@ -39,11 +40,11 @@ public class ApplicationManagerImpl implements ApplicationManager { private static ApplicationManagerImpl applicationManager = new ApplicationManagerImpl(); - private ApplicationManagerImpl(){ + private ApplicationManagerImpl() { } - public static ApplicationManagerImpl getInstance(){ + public static ApplicationManagerImpl getInstance() { return applicationManager; } @@ -54,21 +55,11 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public List getApplications() { - ApplicationManagementDataHolder dataHolder = ApplicationManagementDataHolder.getInstance(); - try { - ConnectionManagerUtil.openConnection(); - } catch (SQLException e) { - e.printStackTrace(); - } - ApplicationManagementDAO applicationManagementDAO = dataHolder.getApplicationManagementDAO(); + public List getApplications() throws ApplicationManagerException { + ConnectionManagerUtil.openConnection(); + ApplicationManagementDAO applicationManagementDAO = ApplicationManagementDataHolder.getInstance().getApplicationManagementDAO(); List applications = null; - try { - applications = applicationManagementDAO.getApplications(); - } catch (ApplicationManagementDAOException e) { - log.error(e); - } - + 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/config/ApplicationConfigurationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationConfigurationManager.java index d0d7af42bf6..a0c6007dfda 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationConfigurationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ApplicationConfigurationManager.java @@ -70,7 +70,7 @@ public class ApplicationConfigurationManager { Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); this.applicationManagerConfiguration = (ApplicationManagementConfigurations) unmarshaller.unmarshal(doc); } catch (Exception e) { - throw new ApplicationManagerException("Error occurred while initializing application config"); + throw new ApplicationManagerException("Error occurred while initializing application config", 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/ApplicationManagementDAOException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOException.java index b800fb9d48c..40874b026d8 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOException.java @@ -18,25 +18,11 @@ */ package org.wso2.carbon.device.application.mgt.core.dao; -public class ApplicationManagementDAOException extends Exception { +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagerException; - String message; +public class ApplicationManagementDAOException extends ApplicationManagerException { - public ApplicationManagementDAOException(String message){ - this.message = message; - } - - @Override - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - @Override - public String toString() { - return super.toString(); + public ApplicationManagementDAOException(String message, Throwable throwable) { + super(message, throwable); } } 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 431124565a5..83c56da6e41 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 @@ -81,7 +81,7 @@ public class ApplicationManagementDAOImpl implements ApplicationManagementDAO { } } catch (SQLException e) { - throw new ApplicationManagementDAOException("Error occurred while getting application List"); + throw new ApplicationManagementDAOException("Error occurred while getting application List", 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/exception/ApplicationManagerException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagerException.java index 63727ff05fc..e937b86a5e4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagerException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/ApplicationManagerException.java @@ -22,8 +22,9 @@ public class ApplicationManagerException extends Exception { String message; - public ApplicationManagerException(String message){ - this.message = message; + public ApplicationManagerException(String message, Throwable throwable){ + super(message, throwable); + setMessage(message); } @Override @@ -34,9 +35,4 @@ public class ApplicationManagerException extends Exception { public void setMessage(String message) { this.message = message; } - - @Override - public String toString() { - return super.toString(); - } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java index 4a31cd93835..103cf97c7d6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationManagementUtil.java @@ -56,7 +56,7 @@ public class ApplicationManagementUtil { return docBuilder.parse(file); } catch (Exception e) { throw new ApplicationManagerException("Error occurred while parsing file, while converting " + - "to a org.w3c.dom.Document : " + e.getMessage()); + "to a org.w3c.dom.Document : ", e); } } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java index 6edc57547cc..1bac612e71d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java @@ -22,8 +22,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.application.mgt.core.config.datasource.JNDILookupDefinition; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagerException; import org.wso2.carbon.device.application.mgt.core.exception.IllegalTransactionStateException; -import org.wso2.carbon.device.application.mgt.core.exception.TransactionManagementException; import javax.naming.InitialContext; import javax.sql.DataSource; @@ -52,7 +52,7 @@ public class ConnectionManagerUtil { return currentConnection; } - public static void openConnection() throws SQLException { + public static void openConnection() throws ApplicationManagerException { Connection conn = currentConnection.get(); if (conn != null) { throw new IllegalTransactionStateException("A transaction is already active within the context of " + @@ -63,14 +63,14 @@ public class ConnectionManagerUtil { conn = dataSource.getConnection(); } catch (SQLException e) { currentTxState.set(TxState.CONNECTION_NOT_BORROWED); - throw e; + throw new ApplicationManagerException(e.getMessage(), e); } currentConnection.set(conn); currentTxState.set(TxState.CONNECTION_BORROWED); } - public static void beginTransaction() throws TransactionManagementException { + public static void beginTransaction() throws ApplicationManagerException { Connection conn = currentConnection.get(); if (conn != null) { throw new IllegalTransactionStateException("A transaction is already active within the context of " + @@ -80,7 +80,7 @@ public class ConnectionManagerUtil { try { conn = dataSource.getConnection(); } catch (SQLException e) { - throw new TransactionManagementException("Error occurred while retrieving a data source connection", e); + throw new ApplicationManagerException("Error occurred while retrieving a data source connection", e); } try { @@ -93,7 +93,7 @@ public class ConnectionManagerUtil { "Transaction has ended pre-maturely", e1); } currentTxState.set(TxState.CONNECTION_CLOSED); - throw new TransactionManagementException("Error occurred while setting auto-commit to false", e); + throw new ApplicationManagerException("Error occurred while setting auto-commit to false", e); } currentConnection.set(conn); currentTxState.set(TxState.CONNECTION_BORROWED); From 1095151085a5a01eef48aa3c1927c6cbc7905bb2 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 2 May 2017 13:49:25 +0530 Subject: [PATCH 04/11] 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 5a899715ee2..7332606e59a 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 00000000000..0eb39d13e87 --- /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 00000000000..de927e4706b --- /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 1aeb0965cc0..e74e42d2cac 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 15ab68f9383..f36a54218bb 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 3dd210b3b7a..afe76168696 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 7c3e8f2fbed..c0a0759c7d5 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 31d02b75211..a7360f22d2c 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 e48109eed00..3a03194d3fc 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 9ca5ffbac92..cecdf2822f3 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 83c56da6e41..4c69408e757 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 6bc3f4d1245..7baa4380a34 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 125ee300ea3..3fa3e4846ff 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 79f4cbcfc0b..153f9da89fc 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 00000000000..6c1ed83326a --- /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; + } +} From c53e5d5e703da3de85af21729aae88243777138d Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Thu, 4 May 2017 18:21:03 +0530 Subject: [PATCH 05/11] Added MySQL DAO --- .../src/main/resources/publisher-api.yaml | 2 +- .../src/main/resources/store-api.yaml | 2 +- .../api/common/GsonMessageBodyHandler.java | 3 +- .../mgt/api/dto/StoreApplication.java | 88 --------------- .../responses/ApplicationsListResponse.java | 59 ---------- .../ApplicationManagementService.java | 11 +- .../ApplicationManagementServiceImpl.java | 27 ++--- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- .../pom.xml | 2 + .../core/components/ApplicationManager.java | 5 +- .../impl/ApplicationManagerImpl.java | 11 +- .../core/dao/ApplicationManagementDAO.java | 7 +- .../dao/ApplicationManagementDAOFactory.java | 58 ++++++++++ .../dao/ApplicationManagementDAOImpl.java | 96 ----------------- .../dao/ApplicationManagementDAOUtil.java | 39 +++++-- .../dao/impl/GenericAppManagementDAO.java | 102 ++++++++++++++++++ .../application/mgt/core/dto/Application.java | 102 ++++++++++++++++++ .../mgt/core/dto/ApplicationList.java | 44 ++++++++ .../mgt/core/dto/ApplicationType.java | 20 +++- .../application/mgt/core/dto/Category.java | 55 ++++++++++ .../application/mgt/core/dto/Pagination.java | 62 +++++++++++ .../mgt/core/dto/StoreApplication.java | 79 -------------- ...ApplicationManagementServiceComponent.java | 5 +- .../jaxrs/AnnotationExclusionStrategy.java | 35 ++++++ .../application/mgt/core/jaxrs/Exclude.java | 29 +++++ .../carbon-home/repository/conf/carbon.xml | 2 +- .../repository/conf/etc/osgi-debug.options | 2 +- .../repository/conf/tomcat/web.xml | 6 +- .../app/pages/cdmf.page.devices/devices.hbs | 4 +- .../app/pages/cdmf.page.groups/groups.hbs | 2 +- .../public/less/theme-variables.less | 2 +- .../lib/theme-wso2_1.0/less/theme-wso2.less | 36 +++---- .../carbon-home/repository/conf/carbon.xml | 2 +- .../repository/conf/etc/osgi-debug.options | 2 +- .../repository/conf/tomcat/web.xml | 6 +- .../resources/conf/certificate-config.xml | 2 +- .../src/main/resources/conf/cdm-config.xml | 2 +- .../email/templates/user-enrollment.vm | 12 +-- .../email/templates/user-registration.vm | 16 +-- .../default-enrollment-invitation.vm | 12 +-- .../email/templates/user-enrollment.vm | 12 +-- .../email/templates/user-registration.vm | 16 +-- 42 files changed, 635 insertions(+), 446 deletions(-) delete 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 delete 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/dao/ApplicationManagementDAOFactory.java delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOImpl.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/GenericAppManagementDAO.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/ApplicationList.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/Category.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/Pagination.java delete 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 create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/jaxrs/AnnotationExclusionStrategy.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/jaxrs/Exclude.java diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/src/main/resources/publisher-api.yaml b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/src/main/resources/publisher-api.yaml index f213bd66524..e2d97583426 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/src/main/resources/publisher-api.yaml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/src/main/resources/publisher-api.yaml @@ -2009,7 +2009,7 @@ parameters: name: limit in: query description: | - Maximum size of resource array to return. + Maximum length of resource array to return. default: 25 type: integer diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/src/main/resources/store-api.yaml b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/src/main/resources/store-api.yaml index eed49e831e1..43c19533b7d 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/src/main/resources/store-api.yaml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.generated.client/src/main/resources/store-api.yaml @@ -1568,7 +1568,7 @@ parameters: name: limit in: query description: | - Maximum size of resource array to return. + Maximum length of resource array to return. default: 25 type: integer diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java index d53e6fade2c..fccfd66b19c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/common/GsonMessageBodyHandler.java @@ -21,6 +21,7 @@ package org.wso2.carbon.device.application.mgt.api.common; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import org.wso2.carbon.device.application.mgt.core.jaxrs.AnnotationExclusionStrategy; import javax.ws.rs.Consumes; import javax.ws.rs.Produces; @@ -50,7 +51,7 @@ public class GsonMessageBodyHandler implements MessageBodyWriter, Messag private Gson getGson() { if (gson == null) { - final GsonBuilder gsonBuilder = new GsonBuilder(); + final GsonBuilder gsonBuilder = new GsonBuilder().setExclusionStrategies(new AnnotationExclusionStrategy()); gson = gsonBuilder.create(); } return gson; 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 deleted file mode 100644 index 0eb39d13e87..00000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/dto/StoreApplication.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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 deleted file mode 100644 index de927e4706b..00000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/responses/ApplicationsListResponse.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 e74e42d2cac..48685d76b04 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,11 @@ 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 org.wso2.carbon.device.application.mgt.core.dto.ApplicationList; -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; @Api(value = "Application Management", description = "This API carries all device management related operations " + "such as get all the available devices, etc.") @@ -57,7 +56,7 @@ public interface ApplicationManagementService { @ApiResponse( code = 200, message = "OK. \n Successfully got application list.", - response = ApplicationsListResponse.class), + response = ApplicationList.class), @ApiResponse( code = 304, message = "Not Modified. \n " + @@ -67,8 +66,8 @@ public interface ApplicationManagementService { message = "Internal Server Error. \n Error occurred while getting the application list.", response = ErrorResponse.class) }) - ApplicationsListResponse getApplications(@Context final HttpServletResponse servletResponse, - @ApiParam( + Response getApplications( + @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 f36a54218bb..ef89c438c43 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,20 +18,17 @@ */ 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.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.dto.ApplicationList; import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.*; -import javax.ws.rs.core.Context; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; @Produces({ "application/json"}) @Consumes({ "application/json"}) @@ -43,21 +40,15 @@ public class ApplicationManagementServiceImpl { @GET @Consumes("application/json") @Path("applications") - public ApplicationsListResponse getApplications(@Context final HttpServletResponse servletResponse) { + public Response getApplications() { ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManager(); try { - ApplicationsListResponse applicationsListResponse = - new ApplicationsListResponse(applicationManager.getApplications()); - return applicationsListResponse; + ApplicationList applications = applicationManager.getApplications(); + 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); - try { - servletResponse.sendError(Response.Status.NOT_FOUND.getStatusCode()); - } catch (IOException e1) { - log.error(msg, e1); - } - return null; + return Response.status(Response.Status.NOT_FOUND).build(); } } } 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 afe76168696..65b5a921e7e 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 @@ -17,6 +17,6 @@ http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> - + \ 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 c0a0759c7d5..5a7933cd2da 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 @@ -85,6 +85,7 @@ org.json, org.xml.sax, javax.sql, + com.google.gson, javax.naming, javax.xml.bind.annotation, @@ -93,6 +94,7 @@ org.wso2.carbon.device.mgt.common.*, io.swagger.annotations.*;resolution:=optional, org.wso2.carbon.device.mgt.core.*, + org.wso2.carbon.device.mgt.core.utils.*, org.wso2.carbon.registry.indexing.*, 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 a7360f22d2c..26b58de04ef 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,16 +19,15 @@ 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.dto.ApplicationList; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagerException; -import java.util.ArrayList; import java.util.List; public interface ApplicationManager { public void createApplication(Application application) throws ApplicationManagerException; - public List getApplications() throws ApplicationManagerException; + public ApplicationList 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 3a03194d3fc..80161047d6b 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 @@ -22,16 +22,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.core.components.ApplicationManager; 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.dto.ApplicationList; 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; -import java.sql.SQLException; -import java.util.ArrayList; import java.util.List; public class ApplicationManagerImpl implements ApplicationManager { @@ -56,11 +52,10 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public List getApplications() throws ApplicationManagerException { + public ApplicationList getApplications() throws ApplicationManagerException { ConnectionManagerUtil.openConnection(); ApplicationManagementDAO applicationManagementDAO = ApplicationManagementDataHolder.getInstance().getApplicationManagementDAO(); - List applications = null; - applications = applicationManagementDAO.getApplications(); + ApplicationList 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 cecdf2822f3..9ab39c67ff3 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 @@ -18,9 +18,8 @@ */ 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 org.wso2.carbon.device.application.mgt.core.dto.ApplicationList; import java.util.HashMap; import java.util.List; @@ -58,8 +57,8 @@ public interface ApplicationManagementDAO { } } - public void createApplication(StoreApplication application) throws ApplicationManagementDAOException; + public void createApplication(Application application) throws ApplicationManagementDAOException; - public List getApplications() throws ApplicationManagementDAOException; + public ApplicationList 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/ApplicationManagementDAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOFactory.java new file mode 100644 index 00000000000..3ec8fdb1960 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOFactory.java @@ -0,0 +1,58 @@ +/* + * 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.dao; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig; +import org.wso2.carbon.device.application.mgt.core.dao.impl.GenericAppManagementDAO; +import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; + +import javax.sql.DataSource; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +public class ApplicationManagementDAOFactory { + + public static final String H2 = "H2"; + private ApplicationManagementDAO.DatabaseType databaseType; + private static DataSource dataSource; + + private static final Log log = LogFactory.getLog(ApplicationManagementDAOFactory.class); + + public ApplicationManagementDAOFactory(DataSourceConfig dataSourceConfig) { + dataSource = ConnectionManagerUtil.resolveDataSource(dataSourceConfig); + ConnectionManagerUtil.setDataSource(dataSource); + String databaseEngine = H2; + try { + databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); + } catch (SQLException e) { + log.error("Error occurred while retrieving config.datasource connection", e); + } + this.databaseType = ApplicationManagementDAO.DatabaseType.lookup(databaseEngine); + } + + public ApplicationManagementDAO getApplicationManagementDAO(){ + switch (databaseType) { + default: + return new GenericAppManagementDAO(); + } + } +} 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 deleted file mode 100644 index 4c69408e757..00000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationManagementDAOImpl.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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.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; - -import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -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) { - dataSource = ConnectionManagerUtil.resolveDataSource(dataSourceConfig); - ConnectionManagerUtil.setDataSource(dataSource); - String databaseEngine = "H2"; - try { - databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); - } catch (SQLException e) { - log.error("Error occurred while retrieving config.datasource connection", e); - } - this.databaseType = DatabaseType.lookup(databaseEngine); - } - - @Override - public void createApplication(StoreApplication application) throws ApplicationManagementDAOException { - - } - - @Override - public List getApplications() throws ApplicationManagementDAOException { - - Connection conn = null; - PreparedStatement stmt = null; - ResultSet rs = null; - String sql = null; - List applications; - - try { - conn = ConnectionManagerUtil.getCurrentConnection().get(); - switch (databaseType) { - case H2: - case MYSQL: - sql = "SELECT * FROM APPM_STORE_APPLICATION"; - } - - stmt = conn.prepareStatement(sql); - rs = stmt.executeQuery(); - applications = new ArrayList<>(); - while (rs.next()) { - applications.add(ApplicationManagementDAOUtil.loadApplication(rs)); - } - - } 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); - } - 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/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 7baa4380a34..5b6ae3e72af 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 @@ -24,26 +24,49 @@ 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 org.wso2.carbon.device.application.mgt.core.dto.Category; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class ApplicationManagementDAOUtil { private static final Log log = LogFactory.getLog(ApplicationManagementDAOUtil.class); - public static StoreApplication loadApplication(ResultSet rs) throws SQLException, JSONException { + 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")); + application.setUuid(rs.getString("UUID")); + application.setDescription(rs.getString("DESCRIPTION")); + application.setIconName(rs.getString("ICON_NAME")); + 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(); - 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; + applicationType.setName(rs.getString("AT_NAME")); + applicationType.setCode(rs.getString("AT_CODE")); + application.setApplicationType(applicationType); + + Map properties = new HashMap<>(); + while (rsProperties.next()){ + properties.put(rsProperties.getString("PROP_KEY"), rsProperties.getString("PROP_VAL")); + } + application.setProperties(properties); + + Category category = new Category(); + category.setName(rs.getString("CT_NAME")); + application.setCategory(category); + return application; } public static void cleanupResources(PreparedStatement stmt, ResultSet 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/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 new file mode 100644 index 00000000000..01c84551799 --- /dev/null +++ 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 @@ -0,0 +1,102 @@ +/* + * 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.dao.impl; + +import org.json.JSONException; +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.ApplicationManagementDAOUtil; +import org.wso2.carbon.device.application.mgt.core.dto.Application; +import org.wso2.carbon.device.application.mgt.core.dto.ApplicationList; +import org.wso2.carbon.device.application.mgt.core.dto.Pagination; +import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class GenericAppManagementDAO implements ApplicationManagementDAO { + + @Override + public void createApplication(Application application) throws ApplicationManagementDAOException { + + } + + @Override + public ApplicationList getApplications() throws ApplicationManagementDAOException { + + Connection conn = null; + PreparedStatement stmt = null; + ResultSet rs = null; + String sql = null; + ApplicationList applicationList = new ApplicationList(); + List applications = new ArrayList<>(); + Pagination pagination = new Pagination(); + + try { + + 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 " + + "FROM APPM_APPLICATION AS AP " + + "INNER JOIN APPM_APPLICATION_TYPE AS AT ON AP.APPLICATION_TYPE_ID = AT.ID " + + "INNER JOIN APPM_APPLICATION_CATEGORY AS CT ON AP.CATEGORY_ID = CT.ID;"; + + stmt = conn.prepareStatement(sql); + rs = stmt.executeQuery(); + + int length = 0; + sql = "SELECT FOUND_ROWS() AS COUNT;"; + stmt = conn.prepareStatement(sql); + ResultSet rsCount = stmt.executeQuery(); + if(rsCount.next()){ + pagination.setCount(rsCount.getInt("COUNT")); + } + + while (rs.next()) { + + //Getting properties + sql = "SELECT * FROM APPM_APPLICATION_PROPERTIES WHERE APPLICATION_ID=?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, rs.getInt("ID")); + ResultSet rsProperties = stmt.executeQuery(); + + applications.add(ApplicationManagementDAOUtil.loadApplication(rs, rsProperties)); + length++; + } + + pagination.setLength(length); + + applicationList.setApplications(applications); + applicationList.setPagination(pagination); + + } 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); + } + return applicationList; + + } +} 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 3fa3e4846ff..56b45fa45b8 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,46 @@ */ package org.wso2.carbon.device.application.mgt.core.dto; + +import org.wso2.carbon.device.application.mgt.core.jaxrs.Exclude; + +import java.util.Date; +import java.util.List; import java.util.Map; public class Application { + @Exclude private int id; + private String name; + + private String uuid; + private String description; + + private String iconName; + + private String bannerName; + + private String videoName; + + private List screenshots; + + private List tags; + + private Date createdAt; + + private Date modifiedAt; + private ApplicationType applicationType; + + private Category category; + private Map properties; + public Application() { + } public int getId() { return id; @@ -45,6 +75,14 @@ public class Application { this.name = name; } + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + public String getDescription() { return description; } @@ -53,6 +91,62 @@ public class Application { this.description = description; } + 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 String getVideoName() { + return videoName; + } + + public void setVideoName(String videoName) { + this.videoName = videoName; + } + + public List getScreenshots() { + return screenshots; + } + + public void setScreenshots(List screenshots) { + this.screenshots = screenshots; + } + + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getModifiedAt() { + return modifiedAt; + } + + public void setModifiedAt(Date modifiedAt) { + this.modifiedAt = modifiedAt; + } + public ApplicationType getApplicationType() { return applicationType; } @@ -61,6 +155,14 @@ public class Application { this.applicationType = applicationType; } + public Category getCategory() { + return category; + } + + public void setCategory(Category category) { + this.category = category; + } + public Map getProperties() { return 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/ApplicationList.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/ApplicationList.java new file mode 100644 index 00000000000..c089cbb3881 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/ApplicationList.java @@ -0,0 +1,44 @@ +/* + * 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 ApplicationList { + + private List applications; + + private Pagination pagination; + + public List getApplications() { + return applications; + } + + public void setApplications(List applications) { + this.applications = applications; + } + + public Pagination getPagination() { + return pagination; + } + + public void setPagination(Pagination pagination) { + this.pagination = pagination; + } +} 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 153f9da89fc..c6a9bb25ee3 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 @@ -18,11 +18,18 @@ */ package org.wso2.carbon.device.application.mgt.core.dto; +import org.wso2.carbon.device.application.mgt.core.jaxrs.Exclude; + public class ApplicationType { - protected int id; - protected String name; - protected String code; + @Exclude + private int id; + + private String name; + + private String code; + + private String parameters; public int getId() { return id; @@ -48,4 +55,11 @@ public class ApplicationType { this.code = code; } + public String getParameters() { + return parameters; + } + + public void setParameters(String parameters) { + this.parameters = parameters; + } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Category.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Category.java new file mode 100644 index 00000000000..4d79f071c7e --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Category.java @@ -0,0 +1,55 @@ +/* + * 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 org.wso2.carbon.device.application.mgt.core.jaxrs.Exclude; + +public class Category { + + @Exclude + private int id; + + private String name; + + private String description; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Pagination.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Pagination.java new file mode 100644 index 00000000000..34146acfe2f --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/Pagination.java @@ -0,0 +1,62 @@ +/* + * 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; + +public class Pagination { + + private int offset; + + private int limit; + + private int length; + + private int count; + + public int getOffset() { + return offset; + } + + public void setOffset(int offset) { + this.offset = offset; + } + + public int getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } + + public int getLength() { + return length; + } + + public void setLength(int length) { + this.length = length; + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } +} 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 deleted file mode 100644 index 6c1ed83326a..00000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dto/StoreApplication.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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; - } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java index daf29e8be15..a03667b425b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ApplicationManagementServiceComponent.java @@ -27,7 +27,7 @@ import org.wso2.carbon.device.application.mgt.core.components.impl.ApplicationMa import org.wso2.carbon.device.application.mgt.core.config.ApplicationConfigurationManager; import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationManagementDAO; -import org.wso2.carbon.device.application.mgt.core.dao.ApplicationManagementDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.ApplicationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import javax.naming.NamingException; @@ -55,7 +55,8 @@ public class ApplicationManagementServiceComponent { DataSourceConfig dataSourceConfig = ApplicationConfigurationManager.getInstance() .getApplicationManagerConfiguration().getApplicationManagerRepository().getDataSourceConfig(); - ApplicationManagementDAO applicationManagementDAO = new ApplicationManagementDAOImpl(dataSourceConfig); + ApplicationManagementDAO applicationManagementDAO = new ApplicationManagementDAOFactory(dataSourceConfig) + .getApplicationManagementDAO(); ApplicationManagementDataHolder.getInstance() .setApplicationManagementDAO(applicationManagementDAO); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/jaxrs/AnnotationExclusionStrategy.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/jaxrs/AnnotationExclusionStrategy.java new file mode 100644 index 00000000000..550f1e4cede --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/jaxrs/AnnotationExclusionStrategy.java @@ -0,0 +1,35 @@ +/* + * 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.jaxrs; + +import com.google.gson.ExclusionStrategy; +import com.google.gson.FieldAttributes; + +public class AnnotationExclusionStrategy implements ExclusionStrategy { + + @Override + public boolean shouldSkipField(FieldAttributes f) { + return f.getAnnotation(Exclude.class) != null; + } + + @Override + public boolean shouldSkipClass(Class clazz) { + return false; + } +} \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/jaxrs/Exclude.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/jaxrs/Exclude.java new file mode 100644 index 00000000000..af9c3c794d1 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/jaxrs/Exclude.java @@ -0,0 +1,29 @@ +/* + * 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.jaxrs; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Exclude { +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/carbon.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/carbon.xml index ca5863d18d9..97a1658aa34 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/carbon.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/carbon.xml @@ -468,7 +468,7 @@ --> 100 diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options index ba8e3c6c20f..80e56b83f2f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options @@ -62,7 +62,7 @@ org.eclipse.osgi/defaultprofile/logfilename = # requested. org.eclipse.osgi/defaultprofile/logsynchronously = false -# Specify the size of the default profile implementation log buffer. +# Specify the length of the default profile implementation log buffer. org.eclipse.osgi/defaultprofile/buffersize = 256 #### Monitoring settings diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml index d4241ef741a..b9f1e4a3e91 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/carbon-home/repository/conf/tomcat/web.xml @@ -47,7 +47,7 @@ - + @@ -56,7 +56,7 @@ - + @@ -67,7 +67,7 @@ - + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs index bdd2e9d39b3..d75cdedbad5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/devices.hbs @@ -383,7 +383,7 @@