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.coreprovided
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.application.mgt.core
+ provided
+ io.swaggerswagger-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
- 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.commonorg.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.swaggerswagger-annotationsprovided
- 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.coreorg.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 eb204af8907..3e4403169fc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,6 +41,7 @@
components/apimgt-extensionscomponents/policy-mgtcomponents/certificate-mgt
+ components/application-mgtcomponents/webapp-authenticator-frameworkcomponents/email-senderfeatures/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.devicemgtorg.wso2.carbon.policy.mgt.common