forked from community/device-mgt-plugins
Merge branch 'master' of https://github.com/wso2/carbon-device-mgt-plugins
commit
66545c14c4
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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.mgt.mobile.impl.ios;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class IOSFeatureManager implements FeatureManager {
|
||||||
|
|
||||||
|
private FeatureDAO featureDAO;
|
||||||
|
|
||||||
|
public IOSFeatureManager() {
|
||||||
|
this.featureDAO = FeatureManagementDAOFactory.getFeatureDAO();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addFeature(Feature feature) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Feature getFeature(String s) throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Feature> getFeatures() throws DeviceManagementException {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeFeature(String s) throws DeviceManagementException {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* 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.mgt.mobile.impl.ios.dao;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface FeatureDAO {
|
||||||
|
|
||||||
|
void addFeature(Feature feature) throws FeatureManagementDAOException;
|
||||||
|
|
||||||
|
void removeFeature(String name) throws FeatureManagementDAOException;
|
||||||
|
|
||||||
|
Feature getFeature(String name) throws FeatureManagementDAOException;
|
||||||
|
|
||||||
|
List<Feature> getFeatures() throws FeatureManagementDAOException;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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.mgt.mobile.impl.ios.dao;
|
||||||
|
|
||||||
|
public class FeatureManagementDAOException extends Exception {
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
private static final long serialVersionUID = 2021891706072918865L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new MobileDeviceManagementDAOException with the specified detail message and
|
||||||
|
* nested exception.
|
||||||
|
*
|
||||||
|
* @param message error message
|
||||||
|
* @param nestedException exception
|
||||||
|
*/
|
||||||
|
public FeatureManagementDAOException(String message, Exception nestedException) {
|
||||||
|
super(message, nestedException);
|
||||||
|
setErrorMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new MobileDeviceManagementDAOException with the specified detail message
|
||||||
|
* and cause.
|
||||||
|
*
|
||||||
|
* @param message the detail message.
|
||||||
|
* @param cause the cause of this exception.
|
||||||
|
*/
|
||||||
|
public FeatureManagementDAOException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
setErrorMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new MobileDeviceManagementDAOException with the specified detail message.
|
||||||
|
*
|
||||||
|
* @param message the detail message.
|
||||||
|
*/
|
||||||
|
public FeatureManagementDAOException(String message) {
|
||||||
|
super(message);
|
||||||
|
setErrorMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new MobileDeviceManagementDAOException with the specified and cause.
|
||||||
|
*
|
||||||
|
* @param cause the cause of this exception.
|
||||||
|
*/
|
||||||
|
public FeatureManagementDAOException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String errorMessage) {
|
||||||
|
this.message = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* 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.mgt.mobile.impl.ios.dao;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.impl.FeatureDAOImpl;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class FeatureManagementDAOFactory {
|
||||||
|
|
||||||
|
private static DataSource dataSource;
|
||||||
|
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
|
||||||
|
private static final Log log = LogFactory.getLog(FeatureManagementDAOFactory.class);
|
||||||
|
|
||||||
|
public static FeatureDAO getFeatureDAO() {
|
||||||
|
return new FeatureDAOImpl();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init(DataSource dtSource) {
|
||||||
|
dataSource = dtSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void beginTransaction() throws FeatureManagementDAOException {
|
||||||
|
try {
|
||||||
|
Connection conn = dataSource.getConnection();
|
||||||
|
conn.setAutoCommit(false);
|
||||||
|
currentConnection.set(conn);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new FeatureManagementDAOException("Error occurred while retrieving datasource connection", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Connection getConnection() {
|
||||||
|
return currentConnection.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void commitTransaction() throws FeatureManagementDAOException {
|
||||||
|
try {
|
||||||
|
Connection conn = currentConnection.get();
|
||||||
|
if (conn != null) {
|
||||||
|
conn.commit();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Datasource connection associated with the current thread is null, hence commit " +
|
||||||
|
"has not been attempted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new FeatureManagementDAOException("Error occurred while committing the transaction", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void rollbackTransaction() throws FeatureManagementDAOException {
|
||||||
|
try {
|
||||||
|
Connection conn = currentConnection.get();
|
||||||
|
if (conn != null) {
|
||||||
|
conn.rollback();
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Datasource connection associated with the current thread is null, hence rollback " +
|
||||||
|
"has not been attempted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new FeatureManagementDAOException("Error occurred while rollbacking the transaction", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DataSource getDataSource() {
|
||||||
|
return dataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* 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.mgt.mobile.impl.ios.dao.impl;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureDAO;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException;
|
||||||
|
import org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOFactory;
|
||||||
|
|
||||||
|
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 FeatureDAOImpl implements FeatureDAO {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addFeature(Feature feature) throws FeatureManagementDAOException {
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
Connection conn = FeatureManagementDAOFactory.getConnection();
|
||||||
|
String sql = "INSERT INTO IOS_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setString(1, feature.getCode());
|
||||||
|
stmt.setString(2, feature.getName());
|
||||||
|
stmt.setString(3, feature.getDescription());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new FeatureManagementDAOException("Error occurred while adding feature '" +
|
||||||
|
feature.getName() + "' into the metadata repository", e);
|
||||||
|
} finally {
|
||||||
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeFeature(String code) throws FeatureManagementDAOException {
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
try {
|
||||||
|
Connection conn = FeatureManagementDAOFactory.getConnection();
|
||||||
|
String sql = "DELETE FROM IOS_FEATURE WHERE CODE = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setString(1, code);
|
||||||
|
stmt.execute();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new FeatureManagementDAOException("Error occurred while adding feature '" +
|
||||||
|
code + "' into the metadata repository", e);
|
||||||
|
} finally {
|
||||||
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Feature getFeature(String code) throws FeatureManagementDAOException {
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
Connection conn = FeatureManagementDAOFactory.getConnection();
|
||||||
|
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM IOS_FEATURE WHERE CODE = ?";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setString(1, code);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
Feature feature = null;
|
||||||
|
if (rs.next()) {
|
||||||
|
feature = new Feature();
|
||||||
|
feature.setId(rs.getInt("ID"));
|
||||||
|
feature.setCode(rs.getString("CODE"));
|
||||||
|
feature.setName(rs.getString("NAME"));
|
||||||
|
feature.setDescription(rs.getString("DESCRIPTION"));
|
||||||
|
}
|
||||||
|
return feature;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new FeatureManagementDAOException("Error occurred while retrieving feature metadata '" +
|
||||||
|
code + "' from the feature metadata repository", e);
|
||||||
|
} finally {
|
||||||
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Feature> getFeatures() throws FeatureManagementDAOException {
|
||||||
|
PreparedStatement stmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<Feature> features = new ArrayList<Feature>();
|
||||||
|
try {
|
||||||
|
Connection conn = FeatureManagementDAOFactory.getConnection();
|
||||||
|
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM IOS_FEATURE";
|
||||||
|
stmt = conn.prepareStatement(sql);
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
Feature feature = new Feature();
|
||||||
|
feature.setId(rs.getInt("ID"));
|
||||||
|
feature.setCode(rs.getString("CODE"));
|
||||||
|
feature.setName(rs.getString("NAME"));
|
||||||
|
feature.setDescription(rs.getString("DESCRIPTION"));
|
||||||
|
}
|
||||||
|
return features;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new FeatureManagementDAOException("Error occurred while retrieving all feature metadata from the " +
|
||||||
|
"feature metadata repository", e);
|
||||||
|
} finally {
|
||||||
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,47 +0,0 @@
|
|||||||
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java
|
|
||||||
index 719a38b..5a63eef 100644
|
|
||||||
--- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java
|
|
||||||
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/AbstractMobileOperationManager.java
|
|
||||||
@@ -28,15 +28,13 @@ import java.util.List;
|
|
||||||
public abstract class AbstractMobileOperationManager implements OperationManager {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
- public List<Operation> getOperations(DeviceIdentifier deviceIdentifier)
|
|
||||||
- throws OperationManagementException {
|
|
||||||
+ public List<Operation> getOperations(DeviceIdentifier deviceIdentifier) throws OperationManagementException {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean addOperation(Operation operation,
|
|
||||||
- List<DeviceIdentifier> devices)
|
|
||||||
- throws OperationManagementException {
|
|
||||||
+ List<DeviceIdentifier> devices) throws OperationManagementException {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java
|
|
||||||
index 17b347b..1aa3289 100644
|
|
||||||
--- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java
|
|
||||||
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/android/dao/FeatureDAO.java
|
|
||||||
@@ -19,7 +19,6 @@
|
|
||||||
package org.wso2.carbon.device.mgt.mobile.impl.android.dao;
|
|
||||||
|
|
||||||
import org.wso2.carbon.device.mgt.common.Feature;
|
|
||||||
-import org.wso2.carbon.device.mgt.common.FeatureManagementException;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java
|
|
||||||
index 38280e2..6607600 100644
|
|
||||||
--- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java
|
|
||||||
+++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/ios/IOSMobileOperationManager.java
|
|
||||||
@@ -20,8 +20,6 @@ package org.wso2.carbon.device.mgt.mobile.impl.ios;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
||||||
-import org.wso2.carbon.device.mgt.common.Feature;
|
|
||||||
-import org.wso2.carbon.device.mgt.common.FeatureManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.mobile.AbstractMobileOperationManager;
|
|
Loading…
Reference in new issue