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)
throws OperationManagementDAOException;
}

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

@ -152,8 +152,8 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
}
@Override
public List<? extends Operation> getOperationsByDeviceAndStatus(
int enrolmentId, Operation.Status status) throws OperationManagementDAOException {
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
ConfigOperation configOperation;
@ -170,7 +170,6 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString());
rs = stmt.executeQuery();
while (rs.next()) {

@ -240,7 +240,7 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null;
ResultSet rs = null;
Operation operation;
List<Operation> operations = new ArrayList<>();
List<Operation> operations = new ArrayList<Operation>();
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
@ -281,7 +281,7 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null;
ResultSet rs = null;
Operation operation;
List<Operation> operations = new ArrayList<>();
List<Operation> operations = new ArrayList<Operation>();
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
@ -360,7 +360,7 @@ public class OperationDAOImpl implements OperationDAO {
PreparedStatement stmt = null;
ResultSet rs = null;
Operation operation;
List<Operation> operations = new ArrayList<>();
List<Operation> operations = new ArrayList<Operation>();
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +

@ -38,6 +38,10 @@
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
</dependency>
</dependencies>
<build>
@ -64,7 +68,9 @@
org.wso2.carbon.registry.api,
org.wso2.carbon.registry.core,
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>
</instructions>
</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.
*
*/
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.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.RegistryType;
@ -38,6 +38,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
@SuppressWarnings("unused")
public class RegistryBasedLicenseManager implements LicenseManager {
private Registry registry;
Loading…
Cancel
Save