revert-70aa11f8
charithag 9 years ago
commit 7b8c22a2e7

@ -72,4 +72,6 @@ public interface CertificateDAO {
* @return whether the certificate was removed or not.
*/
boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException;
public List<CertificateResponse> searchCertificate(String serialNumber) throws CertificateManagementDAOException;
}

@ -116,6 +116,44 @@ public class GenericCertificateDAOImpl implements CertificateDAO {
return certificateResponse;
}
@Override
public List<CertificateResponse> searchCertificate(String serialNumber)
throws CertificateManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet resultSet = null;
CertificateResponse certificateResponse = null;
List<CertificateResponse> certificates = new ArrayList<>();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
conn = this.getConnection();
String query =
"SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID FROM DM_DEVICE_CERTIFICATE WHERE SERIAL_NUMBER LIKE ?" +
" AND TENANT_ID = ? ";
stmt = conn.prepareStatement(query);
stmt.setString(1, "%" + serialNumber + "%");
stmt.setInt(2, tenantId);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
certificateResponse = new CertificateResponse();
byte [] certificateBytes = resultSet.getBytes("CERTIFICATE");
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
certificates.add(certificateResponse);
}
} catch (SQLException e) {
String errorMsg =
"Unable to get the read the certificate with serial" + serialNumber;
log.error(errorMsg, e);
throw new CertificateManagementDAOException(errorMsg, e);
} finally {
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
}
return certificates;
}
@Override
public PaginationResult getAllCertificates(PaginationRequest request) throws CertificateManagementDAOException {
PreparedStatement stmt = null;

@ -76,4 +76,6 @@ public interface CertificateManagementService {
boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException;
public List<CertificateResponse> getCertificates() throws CertificateManagementDAOException;
public List<CertificateResponse> searchCertificates(String serialNumber) throws CertificateManagementDAOException;
}

@ -17,6 +17,7 @@
*/
package org.wso2.carbon.certificate.mgt.core.service;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
@ -31,6 +32,7 @@ import org.wso2.carbon.certificate.mgt.core.impl.KeyStoreReader;
import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
import java.io.InputStream;
@ -165,11 +167,13 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe
@Override
public boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException {
try {
CertificateManagementDAOFactory.openConnection();
CertificateManagementDAOFactory.beginTransaction();
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
return certificateDAO.removeCertificate(serialNumber);
} catch (SQLException e) {
String errorMsg = "Error when opening connection";
Boolean status = certificateDAO.removeCertificate(serialNumber);
CertificateManagementDAOFactory.commitTransaction();
return status;
} catch (TransactionManagementException e) {
String errorMsg = "Error when deleting";
log.error(errorMsg, e);
throw new CertificateManagementDAOException(errorMsg, e);
} finally {
@ -192,4 +196,18 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe
}
}
@Override public List<CertificateResponse> searchCertificates(String serialNumber) throws CertificateManagementDAOException {
try {
CertificateManagementDAOFactory.openConnection();
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
return certificateDAO.searchCertificate(serialNumber);
} catch (SQLException e) {
String errorMsg = "Error when opening connection";
log.error(errorMsg, e);
throw new CertificateManagementDAOException(errorMsg, e);
} finally {
CertificateManagementDAOFactory.closeConnection();
}
}
}

@ -239,11 +239,11 @@
</dependency>
<!--<dependency>-->
<!--<groupId>com.google.code.gson</groupId>-->
<!--<artifactId>gson</artifactId>-->
<!--<version>1.7.1</version>-->
<!--</dependency>-->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>

@ -47,31 +47,27 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
try {
conn = this.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_DETAIL (DEVICE_ID, IMEI, IMSI, DEVICE_MODEL, " +
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_DETAIL (DEVICE_ID, DEVICE_MODEL, " +
"VENDOR, OS_VERSION, BATTERY_LEVEL, INTERNAL_TOTAL_MEMORY, INTERNAL_AVAILABLE_MEMORY, " +
"EXTERNAL_TOTAL_MEMORY, EXTERNAL_AVAILABLE_MEMORY, OPERATOR, CONNECTION_TYPE, " +
"MOBILE_SIGNAL_STRENGTH, SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?,? ); ");
"EXTERNAL_TOTAL_MEMORY, EXTERNAL_AVAILABLE_MEMORY, CONNECTION_TYPE, " +
"SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN) " +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
stmt.setInt(1, deviceInfo.getDeviceId());
stmt.setString(2, deviceInfo.getIMEI());
stmt.setString(3, deviceInfo.getIMSI());
stmt.setString(4, deviceInfo.getDeviceModel());
stmt.setString(5, deviceInfo.getVendor());
stmt.setString(6, deviceInfo.getOsVersion());
stmt.setDouble(7, deviceInfo.getBatteryLevel());
stmt.setDouble(8, deviceInfo.getInternalTotalMemory());
stmt.setDouble(9, deviceInfo.getInternalAvailableMemory());
stmt.setDouble(10, deviceInfo.getExternalTotalMemory());
stmt.setDouble(11, deviceInfo.getExternalAvailableMemory());
stmt.setString(12, deviceInfo.getOperator());
stmt.setString(13, deviceInfo.getConnectionType());
stmt.setDouble(14, deviceInfo.getMobileSignalStrength());
stmt.setString(15, deviceInfo.getSsid());
stmt.setDouble(16, deviceInfo.getCpuUsage());
stmt.setDouble(17, deviceInfo.getTotalRAMMemory());
stmt.setDouble(18, deviceInfo.getAvailableRAMMemory());
stmt.setBoolean(19, deviceInfo.isPluggedIn());
stmt.setString(2, deviceInfo.getDeviceModel());
stmt.setString(3, deviceInfo.getVendor());
stmt.setString(4, deviceInfo.getOsVersion());
stmt.setDouble(5, deviceInfo.getBatteryLevel());
stmt.setDouble(6, deviceInfo.getInternalTotalMemory());
stmt.setDouble(7, deviceInfo.getInternalAvailableMemory());
stmt.setDouble(8, deviceInfo.getExternalTotalMemory());
stmt.setDouble(9, deviceInfo.getExternalAvailableMemory());
stmt.setString(10, deviceInfo.getConnectionType());
stmt.setString(11, deviceInfo.getSsid());
stmt.setDouble(12, deviceInfo.getCpuUsage());
stmt.setDouble(13, deviceInfo.getTotalRAMMemory());
stmt.setDouble(14, deviceInfo.getAvailableRAMMemory());
stmt.setBoolean(15, deviceInfo.isPluggedIn());
stmt.execute();
@ -128,8 +124,8 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
while (rs.next()) {
deviceInfo.setDeviceId(rs.getInt("DEVICE_ID"));
deviceInfo.setIMEI(rs.getString("IMEI"));
deviceInfo.setIMSI(rs.getString("IMSI"));
// deviceInfo.setIMEI(rs.getString("IMEI"));
// deviceInfo.setIMSI(rs.getString("IMSI"));
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setVendor(rs.getString("VENDOR"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
@ -138,9 +134,9 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setOperator(rs.getString("OPERATOR"));
// deviceInfo.setOperator(rs.getString("OPERATOR"));
deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE"));
deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
deviceInfo.setSsid(rs.getString("SSID"));
deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE"));
deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY"));

@ -78,12 +78,12 @@ public class SearchDAOImpl implements SearchDAO {
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setIMEI(rs.getString("IMEI"));
deviceInfo.setIMSI(rs.getString("IMSI"));
// deviceInfo.setIMEI(rs.getString("IMEI"));
// deviceInfo.setIMSI(rs.getString("IMSI"));
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
deviceInfo.setOperator(rs.getString("OPERATOR"));
// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
// deviceInfo.setOperator(rs.getString("OPERATOR"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
deviceInfo.setSsid(rs.getString("SSID"));
@ -143,7 +143,7 @@ public class SearchDAOImpl implements SearchDAO {
Device device = new Device();
device.setId(rs.getInt("ID"));
device.setDescription(rs.getString("DESCRIPTION"));
device.setName("NAME");
device.setName(rs.getString("NAME"));
device.setType(rs.getString("DEVICE_TYPE_NAME"));
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
@ -160,12 +160,12 @@ public class SearchDAOImpl implements SearchDAO {
deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL"));
deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setIMEI(rs.getString("IMEI"));
deviceInfo.setIMSI(rs.getString("IMSI"));
// deviceInfo.setIMEI(rs.getString("IMEI"));
// deviceInfo.setIMSI(rs.getString("IMSI"));
deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY"));
deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY"));
deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
deviceInfo.setOperator(rs.getString("OPERATOR"));
// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH"));
// deviceInfo.setOperator(rs.getString("OPERATOR"));
deviceInfo.setOsVersion(rs.getString("OS_VERSION"));
deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN"));
deviceInfo.setSsid(rs.getString("SSID"));

@ -50,8 +50,8 @@ public class QueryBuilderImpl implements QueryBuilder {
if (conditions.get(0).getKey().equalsIgnoreCase(Constants.LOCATION)) {
locConditon = conditions.get(0);
} else if (Utils.getDeviceDetailsColumnNames().containsKey(conditions.get(0)) ||
Utils.getDeviceLocationColumnNames().containsKey(conditions.get(0))) {
} else if (Utils.getDeviceDetailsColumnNames().containsKey(conditions.get(0).getKey()) ||
Utils.getDeviceLocationColumnNames().containsKey(conditions.get(0).getKey())) {
andColumns.add(conditions.get(0));
} else {
otherANDColumns.add(conditions.get(0));
@ -82,11 +82,19 @@ public class QueryBuilderImpl implements QueryBuilder {
}
Map<String, List<String>> queries = new HashMap<>();
queries.put(Constants.GENERAL, Utils.convertStringToList(this.getGenericQueryPart() + this.processAND(andColumns) +
this.processOR(orColumns)));
queries.put(Constants.PROP_AND, this.processANDProperties(otherANDColumns));
queries.put(Constants.PROP_OR, this.processORProperties(otherORColumns));
queries.put(Constants.LOCATION, this.processLocation(locConditon));
if ((!andColumns.isEmpty()) || (!orColumns.isEmpty())) {
queries.put(Constants.GENERAL, Utils.convertStringToList(this.getGenericQueryPart() + this.processAND(andColumns) +
this.processOR(orColumns)));
}
if (!otherANDColumns.isEmpty()) {
queries.put(Constants.PROP_AND, this.processANDProperties(otherANDColumns));
}
if (!otherORColumns.isEmpty()) {
queries.put(Constants.PROP_OR, this.processORProperties(otherORColumns));
}
if (locConditon != null && locConditon.getValue() != null) {
queries.put(Constants.LOCATION, this.processLocation(locConditon));
}
if (log.isDebugEnabled()) {
log.debug("General Query : " + queries.get(Constants.GENERAL));
@ -164,12 +172,12 @@ public class QueryBuilderImpl implements QueryBuilder {
private String buildLocationQuery(String location) {
String query = this.getGenericQueryPart();
query = query + " OR STREET1 LIKE \'%" + location + "%\'";
query = query + " OR STREET2 LIKE \'%" + location + "%\'";
query = query + " OR CITY LIKE \'%" + location + "%\'";
query = query + " OR STATE LIKE \'%" + location + "%\'";
query = query + " OR COUNTRY LIKE \'%" + location + "%\'";
query = query + " OR ZIP LIKE \'%" + location + "%\'";
query = query + " AND DL.STREET1 LIKE \'%" + location + "%\'";
query = query + " OR DL.STREET2 LIKE \'%" + location + "%\'";
query = query + " OR DL.CITY LIKE \'%" + location + "%\'";
query = query + " OR DL.STATE LIKE \'%" + location + "%\'";
query = query + " OR DL.COUNTRY LIKE \'%" + location + "%\'";
query = query + " OR DL.ZIP LIKE \'%" + location + "%\'";
return query;
}
@ -177,13 +185,13 @@ public class QueryBuilderImpl implements QueryBuilder {
return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" +
" D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \n" +
"DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.IMEI, DD.IMSI, DD.DEVICE_MODEL, DD.VENDOR, \n" +
"DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.DEVICE_MODEL, DD.VENDOR, \n" +
"DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" +
"DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.OPERATOR, DD.CONNECTION_TYPE, \n" +
"DD.MOBILE_SIGNAL_STRENGTH, DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" +
"DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" +
"DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" +
"DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" +
"DL.STATE, DL.COUNTRY FROM DM_DEVICE_DETAIL AS DD, DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, " +
"DM_DEVICE_TYPE AS DT WHERE D.TENANT_ID = " +
"DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " +
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -193,14 +201,14 @@ public class QueryBuilderImpl implements QueryBuilder {
return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" +
" D.DEVICE_TYPE_ID, D.DEVICE_IDENTIFICATION, DT.ID AS DEVICE_TYPE_ID, \n" +
"DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.IMEI, DD.IMSI, DD.DEVICE_MODEL, DD.VENDOR, \n" +
"DT.NAME AS DEVICE_TYPE_NAME, DD.DEVICE_ID, DD.DEVICE_MODEL, DD.VENDOR, \n" +
"DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" +
"DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.OPERATOR, DD.CONNECTION_TYPE, \n" +
"DD.MOBILE_SIGNAL_STRENGTH, DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" +
"DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" +
"DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" +
"DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" +
"DL.STATE, DL.COUNTRY, DI.KEY_FIELD, DI.VALUE_FIELD FROM DM_DEVICE_DETAIL AS DD, " +
"DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, \n" +
"DM_DEVICE_INFO AS DI, DM_DEVICE_TYPE AS DT WHERE D.TENANT_ID = " +
"DM_DEVICE_INFO AS DI, DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " +
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
}

@ -23,10 +23,7 @@ import org.wso2.carbon.device.mgt.common.device.details.DeviceWrapper;
import org.wso2.carbon.device.mgt.core.search.mgt.Constants;
import org.wso2.carbon.device.mgt.core.search.mgt.ResultSetAggregator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class ResultSetAggregatorImpl implements ResultSetAggregator {
@ -37,24 +34,36 @@ public class ResultSetAggregatorImpl implements ResultSetAggregator {
Map<Integer, DeviceWrapper> andMap = this.convertToMap(deviceWrappers.get(Constants.PROP_AND));
Map<Integer, DeviceWrapper> orMap = this.convertToMap(deviceWrappers.get(Constants.PROP_OR));
Map<Integer, DeviceWrapper> locationMap = this.convertToMap(deviceWrappers.get(Constants.LOCATION));
Map<Integer, DeviceWrapper> finalMap = new HashMap<>();
List<DeviceWrapper> finalResult = new ArrayList<>();
for (Integer a : andMap.keySet()) {
if (generalQueryMap.containsKey(a)) {
if (!finalResult.contains(a)) {
if (andMap.isEmpty()) {
finalMap = generalQueryMap;
finalResult = this.convertDeviceMapToList(generalQueryMap);
} else {
for (Integer a : andMap.keySet()) {
if (generalQueryMap.isEmpty()) {
finalResult.add(andMap.get(a));
finalMap.put(a, andMap.get(a));
} else if (generalQueryMap.containsKey(a)) {
if (!finalMap.containsKey(a)) {
finalResult.add(andMap.get(a));
finalMap.put(a, andMap.get(a));
}
}
}
}
for (Integer a : orMap.keySet()) {
if (!finalResult.contains(a)) {
if (!finalMap.containsKey(a)) {
finalResult.add(orMap.get(a));
finalMap.put(a, orMap.get(a));
}
}
for (Integer a : locationMap.keySet()) {
if (!finalResult.contains(a)) {
if (!finalMap.containsKey(a)) {
finalResult.add(locationMap.get(a));
finalMap.put(a, locationMap.get(a));
}
}
@ -72,4 +81,13 @@ public class ResultSetAggregatorImpl implements ResultSetAggregator {
}
return deviceWrapperMap;
}
private List<DeviceWrapper> convertDeviceMapToList(Map<Integer, DeviceWrapper> map) {
List<DeviceWrapper> list = new ArrayList<>();
for (Integer a : map.keySet()) {
list.add(map.get(a));
}
return list;
}
}

@ -32,8 +32,6 @@ public class Utils {
Map<String, String> colonmsMap = new HashMap<>();
colonmsMap.put("IMEI", "IMEI");
colonmsMap.put("IMSI", "IMSI");
colonmsMap.put("deviceModel", "DEVICE_MODEL");
colonmsMap.put("vendor", "VENDOR");
colonmsMap.put("osVersion", "OS_VERSION");
@ -42,9 +40,7 @@ public class Utils {
colonmsMap.put("internalAvailableMemory", "INTERNAL_AVAILABLE_MEMORY");
colonmsMap.put("externalTotalMemory", "EXTERNAL_TOTAL_MEMORY");
colonmsMap.put("externalAvailableMemory", "EXTERNAL_AVAILABLE_MEMORY");
colonmsMap.put("operator", "OPERATOR");
colonmsMap.put("connectionType", "CONNECTION_TYPE");
colonmsMap.put("mobileSignalStrength", "MOBILE_SIGNAL_STRENGTH");
colonmsMap.put("ssid", "SSID");
colonmsMap.put("cpuUsage", "CPU_USAGE");
colonmsMap.put("totalRAMMemory", "TOTAL_RAM_MEMORY");

@ -215,6 +215,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
DeviceManager deviceManager = this.getDeviceManager(device.getType());
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
if (deviceManager == null) {
if (log.isDebugEnabled()) {
log.debug("Device Manager associated with the device type '" + device.getType() + "' is null. " +
@ -226,7 +227,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try {
int tenantId = this.getTenantId();
DeviceManagementDAOFactory.beginTransaction();
DeviceType type = deviceTypeDAO.getDeviceType(device.getType(), tenantId);
Device currentDevice = deviceDAO.getDevice(deviceIdentifier, tenantId);
device.setId(currentDevice.getId());
device.getEnrolmentInfo().setId(currentDevice.getEnrolmentInfo().getId());
deviceDAO.updateDevice(type.getId(), device, tenantId);
enrollmentDAO.updateEnrollment(device.getEnrolmentInfo());
DeviceManagementDAOFactory.commitTransaction();

@ -19,6 +19,7 @@
package org.wso2.carbon.device.mgt.core.search;
import com.google.gson.Gson;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass;
@ -61,36 +62,93 @@ public class SearchDevice extends BaseDeviceManagementTest {
cond.setState(Condition.State.AND);
conditions.add(cond);
Condition cond2 = new Condition();
cond2.setKey("CPU_USAGE");
cond2.setOperator(">");
cond2.setValue("40");
cond2.setState(Condition.State.OR);
conditions.add(cond2);
Condition cond3 = new Condition();
cond3.setKey("LOCATION");
cond3.setOperator("=");
cond3.setValue("Colombo");
cond3.setState(Condition.State.AND);
conditions.add(cond3);
// Condition cond2 = new Condition();
// cond2.setKey("CPU_USAGE");
// cond2.setOperator(">");
// cond2.setValue("40");
// cond2.setState(Condition.State.OR);
// conditions.add(cond2);
//
// Condition cond3 = new Condition();
// cond3.setKey("LOCATION");
// cond3.setOperator("=");
// cond3.setValue("Colombo");
// cond3.setState(Condition.State.AND);
// conditions.add(cond3);
context.setConditions(conditions);
// Gson gson = new Gson();
//
// String aaa = gson.toJson(context);
//
// log.info(aaa);
SearchManagerService service = new SearchManagerServiceImpl();
List<DeviceWrapper> deviceWrappers = service.search(context);
Gson gson = new Gson();
String bbbb = gson.toJson(deviceWrappers);
log.info(bbbb);
for (DeviceWrapper dw : deviceWrappers) {
log.debug(dw.getDevice().getDescription());
log.debug(dw.getDevice().getDeviceIdentifier());
}
}
// @Test
// public void doValidLocationSearch() throws Exception{
//
// SearchContext context = new SearchContext();
// List<Condition> conditions = new ArrayList<>();
//
// Condition cond = new Condition();
// cond.setKey("LOCATION");
// cond.setOperator("=");
// cond.setValue("Karan");
// cond.setState(Condition.State.AND);
// conditions.add(cond);
//
// context.setConditions(conditions);
//
// SearchManagerService service = new SearchManagerServiceImpl();
// List<DeviceWrapper> deviceWrappers = service.search(context);
//
// Gson gson = new Gson();
// String bbbb = gson.toJson(deviceWrappers);
// log.info("Valid Search " + bbbb);
//
//
// for (DeviceWrapper dw : deviceWrappers) {
// log.debug(dw.getDevice().getDescription());
// log.debug(dw.getDevice().getDeviceIdentifier());
// }
// }
//
// @Test
// public void doInvalidLocationSearch() throws Exception{
//
// SearchContext context = new SearchContext();
// List<Condition> conditions = new ArrayList<>();
//
// Condition cond = new Condition();
// cond.setKey("LOCATION");
// cond.setOperator("=");
// cond.setValue("Colombo");
// cond.setState(Condition.State.AND);
// conditions.add(cond);
//
// context.setConditions(conditions);
//
// SearchManagerService service = new SearchManagerServiceImpl();
// List<DeviceWrapper> deviceWrappers = service.search(context);
//
// Gson gson = new Gson();
// String bbbb = gson.toJson(deviceWrappers);
// log.info("Invalid Search " + bbbb);
//
//
// for (DeviceWrapper dw : deviceWrappers) {
// log.debug(dw.getDevice().getDescription());
// log.debug(dw.getDevice().getDeviceIdentifier());
// }
// }
}

@ -462,23 +462,19 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
IMEI VARCHAR(100) NULL,
IMSI VARCHAR(100) NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
BATTERY_LEVEL DECIMAL(4) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL,
OPERATOR VARCHAR(45) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
CONNECTION_TYPE VARCHAR(10) NULL,
MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL,
SSID VARCHAR(45) NULL,
CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(5) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE

@ -463,23 +463,19 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
IMEI VARCHAR(100) NULL,
IMSI VARCHAR(100) NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
BATTERY_LEVEL DECIMAL(4) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL,
OPERATOR VARCHAR(45) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
CONNECTION_TYPE VARCHAR(10) NULL,
MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL,
SSID VARCHAR(45) NULL,
CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(5) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE

@ -434,23 +434,19 @@ DROP TABLE IF EXISTS DM_DEVICE_DETAIL ;
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
IMEI VARCHAR(100) NULL,
IMSI VARCHAR(100) NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
BATTERY_LEVEL DECIMAL(4) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL,
OPERATOR VARCHAR(45) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
CONNECTION_TYPE VARCHAR(10) NULL,
MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL,
SSID VARCHAR(45) NULL,
CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(5) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL,
PRIMARY KEY (ID),
INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC),

@ -447,23 +447,19 @@ DROP TABLE IF EXISTS DM_DEVICE_DETAIL ;
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
IMEI VARCHAR(100) NULL,
IMSI VARCHAR(100) NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
BATTERY_LEVEL DECIMAL(4) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL,
OPERATOR VARCHAR(45) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
CONNECTION_TYPE VARCHAR(10) NULL,
MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL,
SSID VARCHAR(45) NULL,
CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(5) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT(1) NULL,
PRIMARY KEY (ID),
INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC),

@ -747,23 +747,19 @@ END;
CREATE TABLE DM_DEVICE_DETAIL (
ID NUMBER(10) NOT NULL,
DEVICE_ID NUMBER(10) NOT NULL,
IMEI VARCHAR2(100) NULL,
IMSI VARCHAR2(100) NULL,
DEVICE_MODEL VARCHAR2(45) NULL,
VENDOR VARCHAR2(45) NULL,
OS_VERSION VARCHAR2(45) NULL,
BATTERY_LEVEL NUMBER(4) NULL,
INTERNAL_TOTAL_MEMORY NUMBER(5) NULL,
INTERNAL_AVAILABLE_MEMORY NUMBER(5) NULL,
EXTERNAL_TOTAL_MEMORY NUMBER(5) NULL,
EXTERNAL_AVAILABLE_MEMORY NUMBER(5) NULL,
OPERATOR VARCHAR2(45) NULL,
INTERNAL_TOTAL_MEMORY NUMBER(30) NULL,
INTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL,
EXTERNAL_TOTAL_MEMORY NUMBER(30) NULL,
EXTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL,
CONNECTION_TYPE VARCHAR2(10) NULL,
MOBILE_SIGNAL_STRENGTH NUMBER(5) NULL,
SSID VARCHAR2(45) NULL,
CPU_USAGE NUMBER(5) NULL,
TOTAL_RAM_MEMORY NUMBER(5) NULL,
AVAILABLE_RAM_MEMORY NUMBER(5) NULL,
TOTAL_RAM_MEMORY NUMBER(30) NULL,
AVAILABLE_RAM_MEMORY NUMBER(30) NULL,
PLUGGED_IN NUMBER(10) NULL,
PRIMARY KEY (ID)
,

@ -393,23 +393,19 @@ CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC)
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_DETAIL_seq'),
DEVICE_ID INT NOT NULL,
IMEI VARCHAR(100) NULL,
IMSI VARCHAR(100) NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
BATTERY_LEVEL DECIMAL(4) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL,
OPERATOR VARCHAR(45) NULL,
INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL,
EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL,
CONNECTION_TYPE VARCHAR(10) NULL,
MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL,
SSID VARCHAR(45) NULL,
CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(5) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT NULL,
PRIMARY KEY (ID) ,
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE

Loading…
Cancel
Save