Code cleanup, adding file system based license manager, fixing some design issue in CommandOperationDAOImpl

revert-70aa11f8
prabathabey 10 years ago
parent c134cc7e25
commit 53302070e6

@ -46,4 +46,5 @@ public interface OperationDAO {
void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException; throws OperationManagementDAOException;
} }

@ -58,7 +58,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement( stmt = connection.prepareStatement(
"UPDATE DM_COMMAND_OPERATION O SET O.ENABLED=? WHERE O.OPERATION_ID=?"); "UPDATE DM_COMMAND_OPERATION O SET O.ENABLED = ? WHERE O.OPERATION_ID = ?");
stmt.setBoolean(1, operation.isEnabled()); stmt.setBoolean(1, operation.isEnabled());
stmt.setInt(2, operation.getId()); stmt.setInt(2, operation.getId());
stmt.executeUpdate(); stmt.executeUpdate();
@ -72,9 +72,10 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
@Override @Override
public void deleteOperation(int id) throws OperationManagementDAOException { public void deleteOperation(int id) throws OperationManagementDAOException {
super.deleteOperation(id);
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
super.deleteOperation(id);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID = ?"); stmt = connection.prepareStatement("DELETE DM_COMMAND_OPERATION WHERE OPERATION_ID = ?");
stmt.setInt(1, id); stmt.setInt(1, id);
@ -93,7 +94,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
CommandOperation commandOperation = null; CommandOperation commandOperation = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT OPERATION_ID, ENABLED FROM DM_COMMAND_OPERATION WHERE OPERATION_ID=?"; String sql = "SELECT OPERATION_ID, ENABLED FROM DM_COMMAND_OPERATION WHERE OPERATION_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, id); stmt.setInt(1, id);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -113,21 +114,19 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, public List<? extends Operation> getOperationsByDeviceAndStatus(
Operation.Status status) throws OperationManagementDAOException { int enrolmentId, Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation;
List<Operation> operations = new ArrayList<>();
List<CommandOperation> commandOperations = new ArrayList<>();
CommandOperation commandOperation; CommandOperation commandOperation;
List<CommandOperation> commandOperations = new ArrayList<>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT co.OPERATION_ID,ENABLED FROM DM_COMMAND_OPERATION co " + String sql = "SELECT o.ID, co1.ENABLED, co1.STATUS, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE FROM (SELECT co.OPERATION_ID, co.ENABLED FROM DM_COMMAND_OPERATION co " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " + "INNER JOIN (SELECT ENROLMENT_ID, OPERATION_ID, STATUS FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? " +
"AND STATUS=? ) dm ON dm.OPERATION_ID = co.OPERATION_ID"; "AND STATUS = ?) dm ON dm.OPERATION_ID = co.OPERATION_ID) co1 INNER JOIN OPERATION o ON co1.OPERATION_ID = o.ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
@ -137,15 +136,13 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
commandOperation = new CommandOperation(); commandOperation = new CommandOperation();
commandOperation.setEnabled(rs.getInt("ENABLED") != 0); commandOperation.setEnabled(rs.getInt("ENABLED") != 0);
commandOperation.setId(rs.getInt("OPERATION_ID")); commandOperation.setId(rs.getInt("OPERATION_ID"));
commandOperation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
commandOperation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
commandOperation.setCreatedTimeStamp(rs.getString("CREATED_TIMESTAMP"));
commandOperation.setReceivedTimeStamp(rs.getString("RECEIVED_TIMESTAMP"));
commandOperation.setCode(rs.getString("OPERATION_CODE"));
commandOperations.add(commandOperation); commandOperations.add(commandOperation);
} }
for(CommandOperation cmOperation : commandOperations){
operation = super.getOperation(cmOperation.getId());
operation.setEnabled(cmOperation.isEnabled());
operation.setStatus(status);
operations.add(operation);
}
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation available " + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation available " +
"for the device'" + enrolmentId + "' with status '" + status.toString(), e); "for the device'" + enrolmentId + "' with status '" + status.toString(), e);
@ -153,7 +150,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
return operations; return commandOperations;
} }
} }

@ -63,7 +63,7 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE DM_CONFIG_OPERATION WHERE OPERATION_ID = ?"); stmt = connection.prepareStatement("DELETE DM_CONFIG_OPERATION WHERE OPERATION_ID = ?") ;
stmt.setInt(1, id); stmt.setInt(1, id);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
@ -152,8 +152,8 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus( public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
int enrolmentId, Operation.Status status) throws OperationManagementDAOException { Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
ConfigOperation configOperation; ConfigOperation configOperation;
@ -170,7 +170,6 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {

@ -70,8 +70,8 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP = ? " + stmt = connection.prepareStatement("UPDATE DM_OPERATION O SET O.RECEIVED_TIMESTAMP=? " +
"WHERE O.ID = ?"); "WHERE O.ID=?");
stmt.setTimestamp(1, new Timestamp(new Date().getTime())); stmt.setTimestamp(1, new Timestamp(new Date().getTime()));
stmt.setInt(2, operation.getId()); stmt.setInt(2, operation.getId());
stmt.executeUpdate(); stmt.executeUpdate();
@ -87,8 +87,8 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OPERATION_MAPPING O SET O.STATUS = ? " + stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OPERATION_MAPPING O SET O.STATUS=? " +
"WHERE O.ENROLMENT_ID = ? and O.OPERATION_ID = ?"); "WHERE O.ENROLMENT_ID=? and O.OPERATION_ID=?");
stmt.setString(1, status.toString()); stmt.setString(1, status.toString());
stmt.setInt(2, enrolmentId); stmt.setInt(2, enrolmentId);
stmt.setInt(3, operationId); stmt.setInt(3, operationId);
@ -110,7 +110,7 @@ public class OperationDAOImpl implements OperationDAO {
ObjectOutputStream oos = null; ObjectOutputStream oos = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, DEVICE_ID, " + stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,DEVICE_ID," +
"OPERATION_RESPONSE) VALUES(?, ?, ?)"); "OPERATION_RESPONSE) VALUES(?, ?, ?)");
bao = new ByteArrayOutputStream(); bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao); oos = new ObjectOutputStream(bao);
@ -240,7 +240,7 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
@ -281,7 +281,7 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
@ -360,7 +360,7 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +

@ -38,6 +38,10 @@
<groupId>org.apache.ws.commons.axiom</groupId> <groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId> <artifactId>axiom-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -64,7 +68,9 @@
org.wso2.carbon.registry.api, org.wso2.carbon.registry.api,
org.wso2.carbon.registry.core, org.wso2.carbon.registry.core,
org.wso2.carbon.registry.core.exceptions, org.wso2.carbon.registry.core.exceptions,
org.wso2.carbon.registry.core.session org.wso2.carbon.registry.core.session,
javax.xml.bind,
org.wso2.carbon.utils
</Import-Package> </Import-Package>
</instructions> </instructions>
</configuration> </configuration>

@ -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.extensions.license.mgt.file;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.utils.CarbonUtils;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.File;
public class FileSystemBasedLicenseManager implements LicenseManager {
private static final String PATH_MOBILE_PLUGIN_CONF_DIR =
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugins";
@Override
public License getLicense(String deviceType, String languageCode) throws LicenseManagementException {
try {
String licenseConfigPath =
PATH_MOBILE_PLUGIN_CONF_DIR + File.separator + deviceType + File.separator + "license.xml";
File licenseConfig = new File(licenseConfigPath);
JAXBContext context = JAXBContext.newInstance(License.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
return (License) unmarshaller.unmarshal(licenseConfig);
} catch (JAXBException e) {
throw new LicenseManagementException("Error occurred while un-marshalling license configuration " +
"used for '" + deviceType + "' platform from file system", e);
}
}
@Override
public void addLicense(String deviceType, License license) throws LicenseManagementException {
throw new UnsupportedOperationException("'addLicense' method is not supported in " +
"FileSystemBasedLicenseManager");
}
}

@ -16,7 +16,7 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.mgt.extensions.license.mgt; package org.wso2.carbon.device.mgt.extensions.license.mgt.registry;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;

@ -17,7 +17,7 @@
* *
*/ */
package org.wso2.carbon.device.mgt.extensions.license.mgt; package org.wso2.carbon.device.mgt.extensions.license.mgt.registry;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.context.RegistryType;
@ -38,6 +38,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Locale; import java.util.Locale;
@SuppressWarnings("unused")
public class RegistryBasedLicenseManager implements LicenseManager { public class RegistryBasedLicenseManager implements LicenseManager {
private Registry registry; private Registry registry;
Loading…
Cancel
Save