|
|
@ -51,27 +51,22 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addDeviceSubType(DeviceSubType deviceSubType)
|
|
|
|
public boolean addDeviceSubType(DeviceSubType deviceSubType) throws SubTypeMgtPluginException {
|
|
|
|
throws SubTypeMgtPluginException {
|
|
|
|
|
|
|
|
String msg = "";
|
|
|
|
String msg = "";
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
deviceSubType.setTenantId(tenantId);
|
|
|
|
deviceSubType.setTenantId(tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
//TODO This is done as a temporary... we need to implement addDeviceSubType method either with uuid
|
|
|
|
|
|
|
|
// or auto incrementing subtype id. In order to that we have to fix hardcoded subtype id in code level..
|
|
|
|
|
|
|
|
// ex: transport code level
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int maxSubTypeId = deviceSubTypeDAO.getMaxSubTypeId(deviceSubType.getDeviceType());
|
|
|
|
|
|
|
|
deviceSubType.setSubTypeId(maxSubTypeId + 1);
|
|
|
|
|
|
|
|
boolean result = deviceSubTypeDAO.addDeviceSubType(deviceSubType);
|
|
|
|
boolean result = deviceSubTypeDAO.addDeviceSubType(deviceSubType);
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
msg = "Device subtype added successfully,for " + deviceSubType.getDeviceType() + " subtype & subtype " +
|
|
|
|
msg = "Device subtype added successfully,for " + deviceSubType.getDeviceType() + " subtype & subtype " +
|
|
|
|
"Id: "
|
|
|
|
"Id: " + deviceSubType.getSubTypeId();
|
|
|
|
+ deviceSubType.getSubTypeId();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
msg = "Device subtype failed to add,for " + deviceSubType.getDeviceType() + " subtype & subtype Id: " +
|
|
|
|
msg = "Device subtype failed to add,for " + deviceSubType.getDeviceType() + " subtype & subtype Id: " +
|
|
|
|
deviceSubType.getSubTypeId();
|
|
|
|
deviceSubType.getSubTypeId();
|
|
|
|
throw new SubTypeMgtPluginException(msg);
|
|
|
|
throw new SubTypeMgtPluginException(msg);
|
|
|
@ -80,9 +75,6 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
|
|
|
|
String key = DeviceSubTypeMgtUtil.setDeviceSubTypeCacheKey(tenantId, deviceSubType.getSubTypeId(),
|
|
|
|
String key = DeviceSubTypeMgtUtil.setDeviceSubTypeCacheKey(tenantId, deviceSubType.getSubTypeId(),
|
|
|
|
deviceSubType.getDeviceType());
|
|
|
|
deviceSubType.getDeviceType());
|
|
|
|
deviceSubTypeCache.put(key, deviceSubType);
|
|
|
|
deviceSubTypeCache.put(key, deviceSubType);
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
msg = "Error occurred while obtaining the database connection to add device subtype for " +
|
|
|
|
msg = "Error occurred while obtaining the database connection to add device subtype for " +
|
|
|
@ -90,6 +82,7 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new SubTypeMgtPluginException(msg, e);
|
|
|
|
throw new SubTypeMgtPluginException(msg, e);
|
|
|
|
} catch (SubTypeMgtDAOException e) {
|
|
|
|
} catch (SubTypeMgtDAOException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
msg = "Error occurred in the database level while adding device subtype for " +
|
|
|
|
msg = "Error occurred in the database level while adding device subtype for " +
|
|
|
|
deviceSubType.getDeviceType() + " subtype & subtype Id: " + deviceSubType.getSubTypeId();
|
|
|
|
deviceSubType.getDeviceType() + " subtype & subtype Id: " + deviceSubType.getSubTypeId();
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -100,9 +93,9 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateDeviceSubType(int subTypeId, int tenantId, DeviceSubType.DeviceType deviceType,
|
|
|
|
public boolean updateDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType,
|
|
|
|
String subTypeName,
|
|
|
|
String subTypeName, String typeDefinition)
|
|
|
|
String typeDefinition) throws SubTypeMgtPluginException {
|
|
|
|
throws SubTypeMgtPluginException {
|
|
|
|
String msg = "";
|
|
|
|
String msg = "";
|
|
|
|
DeviceSubType deviceSubTypeOld = getDeviceSubType(subTypeId, tenantId, deviceType);
|
|
|
|
DeviceSubType deviceSubTypeOld = getDeviceSubType(subTypeId, tenantId, deviceType);
|
|
|
|
|
|
|
|
|
|
|
@ -117,14 +110,15 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
|
|
|
|
typeDefinition);
|
|
|
|
typeDefinition);
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
msg = "Device subtype updated successfully,for " + deviceType + " subtype & subtype Id: " + subTypeId;
|
|
|
|
msg = "Device subtype updated successfully,for " + deviceType + " subtype & subtype Id: " + subTypeId;
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
msg = "Device subtype failed to update,for " + deviceType + " subtype & subtype Id: " + subTypeId;
|
|
|
|
msg = "Device subtype failed to update,for " + deviceType + " subtype & subtype Id: " + subTypeId;
|
|
|
|
throw new SubTypeMgtPluginException(msg);
|
|
|
|
throw new SubTypeMgtPluginException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
msg = "Error occurred while obtaining the database connection to update device subtype for " + deviceType
|
|
|
|
msg = "Error occurred while obtaining the database connection to update device subtype for " + deviceType
|
|
|
@ -132,6 +126,7 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
|
throw new SubTypeMgtPluginException(msg, e);
|
|
|
|
throw new SubTypeMgtPluginException(msg, e);
|
|
|
|
} catch (SubTypeMgtDAOException e) {
|
|
|
|
} catch (SubTypeMgtDAOException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
msg = "Error occurred in the database level while updating device subtype for " + deviceType +
|
|
|
|
msg = "Error occurred in the database level while updating device subtype for " + deviceType +
|
|
|
|
" subtype & subtype Id: " + subTypeId;
|
|
|
|
" subtype & subtype Id: " + subTypeId;
|
|
|
|
log.error(msg);
|
|
|
|
log.error(msg);
|
|
|
@ -144,7 +139,7 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public DeviceSubType getDeviceSubType(int subTypeId, int tenantId, DeviceSubType.DeviceType deviceType)
|
|
|
|
public DeviceSubType getDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType)
|
|
|
|
throws SubTypeMgtPluginException {
|
|
|
|
throws SubTypeMgtPluginException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String key = DeviceSubTypeMgtUtil.setDeviceSubTypeCacheKey(tenantId, subTypeId, deviceType);
|
|
|
|
String key = DeviceSubTypeMgtUtil.setDeviceSubTypeCacheKey(tenantId, subTypeId, deviceType);
|
|
|
@ -188,7 +183,7 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
|
|
|
|
int result = deviceSubTypeDAO.getDeviceSubTypeCount(deviceType);
|
|
|
|
int result = deviceSubTypeDAO.getDeviceSubTypeCount(deviceType);
|
|
|
|
if (result <= 0) {
|
|
|
|
if (result <= 0) {
|
|
|
|
String msg = "There are no any subtypes for device type: " + deviceType;
|
|
|
|
String msg = "There are no any subtypes for device type: " + deviceType;
|
|
|
|
log.info(msg);
|
|
|
|
log.error(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
@ -228,5 +223,24 @@ public class DeviceSubTypeServiceImpl implements DeviceSubTypeService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType)
|
|
|
|
|
|
|
|
throws SubTypeMgtPluginException {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.openDBConnection();
|
|
|
|
|
|
|
|
return deviceSubTypeDAO.checkDeviceSubTypeExist(subTypeId, tenantId, deviceType);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while obtaining the database connection to check device subtype exist for " +
|
|
|
|
|
|
|
|
deviceType + " subtype & subtype id: " + subTypeId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new SubTypeMgtPluginException(msg, e);
|
|
|
|
|
|
|
|
} catch (SubTypeMgtDAOException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred in the database level while checking device subtype exist for " + deviceType
|
|
|
|
|
|
|
|
+ " subtype & subtype id: " + subTypeId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new SubTypeMgtPluginException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|