Fix billing issues

Co-authored-by: Oshani Silva <oshani@entgra.io>
Co-committed-by: Oshani Silva <oshani@entgra.io>
pull/116/head
Oshani Silva 1 year ago committed by Lasantha Dharmakeerthi
parent 00b2c06ec0
commit d7d28b1879

@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.metadata.mgt.MetadataManagementService; import org.wso2.carbon.device.mgt.common.metadata.mgt.MetadataManagementService;
import org.wso2.carbon.device.mgt.common.metadata.mgt.WhiteLabelTheme; import org.wso2.carbon.device.mgt.common.metadata.mgt.WhiteLabelTheme;
import org.wso2.carbon.device.mgt.common.metadata.mgt.WhiteLabelThemeCreateRequest; import org.wso2.carbon.device.mgt.common.metadata.mgt.WhiteLabelThemeCreateRequest;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.device.mgt.jaxrs.beans.MetadataList; import org.wso2.carbon.device.mgt.jaxrs.beans.MetadataList;
import org.wso2.carbon.device.mgt.jaxrs.service.api.MetadataService; import org.wso2.carbon.device.mgt.jaxrs.service.api.MetadataService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
@ -127,6 +128,7 @@ public class MetadataServiceImpl implements MetadataService {
RequestValidationUtil.validateMetadata(metadata); RequestValidationUtil.validateMetadata(metadata);
try { try {
Metadata updatedMetadata = DeviceMgtAPIUtils.getMetadataManagementService().updateMetadata(metadata); Metadata updatedMetadata = DeviceMgtAPIUtils.getMetadataManagementService().updateMetadata(metadata);
DeviceManagerUtil.removeBillingCache();
return Response.status(Response.Status.OK).entity(updatedMetadata).build(); return Response.status(Response.Status.OK).entity(updatedMetadata).build();
} catch (MetadataManagementException e) { } catch (MetadataManagementException e) {
String msg = "Error occurred while updating the metadata entry for metaKey:" + metadata.getMetaKey(); String msg = "Error occurred while updating the metadata entry for metaKey:" + metadata.getMetaKey();

@ -53,6 +53,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException; import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException;
import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.common.PaginationResult;
import org.wso2.carbon.device.mgt.common.metadata.mgt.Metadata;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;

@ -70,7 +70,7 @@ public class PostgreSQLGroupDAOImpl extends AbstractGroupDAOImpl {
"VALUES (?, ?, ?, ?) RETURNING ID"; "VALUES (?, ?, ?, ?) RETURNING ID";
} else { } else {
sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH, STATUS) " + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH, STATUS) " +
"VALUES (?, ?, ?, ?, ?) RETURNING ID"; "VALUES (?, ?, ?, ?, ?, ?) RETURNING ID";
hasStatus = true; hasStatus = true;
} }
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);

@ -239,8 +239,8 @@ public final class DeviceManagementDAOUtil {
Device device = new Device(); Device device = new Device();
device.setId(rs.getInt("DEVICE_ID")); device.setId(rs.getInt("DEVICE_ID"));
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
device.setName(rs.getString("DESCRIPTION")); device.setName(rs.getString("NAME"));
device.setDescription(rs.getString("NAME")); device.setDescription(rs.getString("DESCRIPTION"));
device.setEnrolmentInfo(loadEnrolmentBilling(rs)); device.setEnrolmentInfo(loadEnrolmentBilling(rs));
return device; return device;
} }

@ -92,8 +92,8 @@ public class MetadataManagementServiceImpl implements MetadataManagementService
try { try {
MetadataManagementDAOFactory.openConnection(); MetadataManagementDAOFactory.openConnection();
int tenantId; int tenantId;
if (metaKey.equals("EVALUATE_TENANTS")){ if (metaKey.equals("EVALUATE_TENANTS") || metaKey.equals("PER_DEVICE_COST")){
// for getting evaluate tenant list to provide the live chat feature // for getting per device cost and evaluate tenant list to provide the billing feature and live chat feature
tenantId = MultitenantConstants.SUPER_TENANT_ID; tenantId = MultitenantConstants.SUPER_TENANT_ID;
} else { } else {
tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);

@ -48,7 +48,6 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HTTP; import org.apache.http.protocol.HTTP;
import org.opensaml.xmlsec.signature.P;
import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -98,6 +97,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.UnauthorizedDeviceAccessException; import org.wso2.carbon.device.mgt.common.exceptions.UnauthorizedDeviceAccessException;
import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException; import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException;
import org.wso2.carbon.device.mgt.common.exceptions.MetadataManagementException;
import org.wso2.carbon.device.mgt.common.geo.service.GeoQuery; import org.wso2.carbon.device.mgt.common.geo.service.GeoQuery;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants;
@ -107,6 +107,7 @@ import org.wso2.carbon.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitati
import org.wso2.carbon.device.mgt.common.license.mgt.License; 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.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.metadata.mgt.Metadata; import org.wso2.carbon.device.mgt.common.metadata.mgt.Metadata;
import org.wso2.carbon.device.mgt.common.metadata.mgt.MetadataManagementService;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; 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.common.operation.mgt.OperationManagementException;
@ -183,7 +184,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService,
@ -1044,8 +1044,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
double totalCost = 0.0; double totalCost = 0.0;
try { try {
MetadataManagementDAOFactory.openConnection(); MetadataManagementService meta = DeviceManagementDataHolder
Metadata metadata = metadataDAO.getMetadata(MultitenantConstants.SUPER_TENANT_ID, DeviceManagementConstants.META_KEY); .getInstance().getMetadataManagementService();
Metadata metadata = meta.retrieveMetadata(DeviceManagementConstants.META_KEY);
Gson g = new Gson(); Gson g = new Gson();
Collection<Cost> costData = null; Collection<Cost> costData = null;
@ -1061,19 +1062,19 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
device.setDeviceStatusInfo(getDeviceStatusHistory(device, null, endDate, true)); device.setDeviceStatusInfo(getDeviceStatusHistory(device, null, endDate, true));
List<DeviceStatus> deviceStatus = device.getDeviceStatusInfo(); List<DeviceStatus> deviceStatus = device.getDeviceStatusInfo();
if (device.getEnrolmentInfo().getDateOfEnrolment() < startDate.getTime()) { if (device.getEnrolmentInfo().getDateOfEnrolment() < startDate.getTime()) {
if (!deviceStatus.isEmpty() && deviceStatus.get(0).getStatus().equals("REMOVED")) { if (!deviceStatus.isEmpty() && String.valueOf(deviceStatus.get(0).getStatus()).equals("REMOVED")) {
if (deviceStatus.get(0).getUpdateTime().getTime() >= startDate.getTime()) { if (deviceStatus.get(0).getUpdateTime().getTime() >= startDate.getTime()) {
dateDiff = deviceStatus.get(0).getUpdateTime().getTime() - startDate.getTime(); dateDiff = deviceStatus.get(0).getUpdateTime().getTime() - startDate.getTime();
} }
} else if (!deviceStatus.isEmpty() && !deviceStatus.get(0).getStatus().equals("REMOVED")) { } else if (!deviceStatus.isEmpty() && !String.valueOf(deviceStatus.get(0).getStatus()).equals("REMOVED")) {
dateDiff = endDate.getTime() - startDate.getTime(); dateDiff = endDate.getTime() - startDate.getTime();
} }
} else { } else {
if (!deviceStatus.isEmpty() && deviceStatus.get(0).getStatus().equals("REMOVED")) { if (!deviceStatus.isEmpty() && String.valueOf(deviceStatus.get(0).getStatus()).equals("REMOVED")) {
if (deviceStatus.get(0).getUpdateTime().getTime() >= device.getEnrolmentInfo().getDateOfEnrolment()) { if (deviceStatus.get(0).getUpdateTime().getTime() >= device.getEnrolmentInfo().getDateOfEnrolment()) {
dateDiff = deviceStatus.get(0).getUpdateTime().getTime() - device.getEnrolmentInfo().getDateOfEnrolment(); dateDiff = deviceStatus.get(0).getUpdateTime().getTime() - device.getEnrolmentInfo().getDateOfEnrolment();
} }
} else if (!deviceStatus.isEmpty() && !deviceStatus.get(0).getStatus().equals("REMOVED")) { } else if (!deviceStatus.isEmpty() && !String.valueOf(deviceStatus.get(0).getStatus()).equals("REMOVED")) {
dateDiff = endDate.getTime() - device.getEnrolmentInfo().getDateOfEnrolment(); dateDiff = endDate.getTime() - device.getEnrolmentInfo().getDateOfEnrolment();
} }
} }
@ -1095,16 +1096,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
String msg = "Error occurred calculating cost of devices"; String msg = "Error occurred calculating cost of devices";
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} catch (SQLException e) { } catch (MetadataManagementException e) {
String msg = "Error when retrieving data";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (MetadataManagementDAOException e) {
String msg = "Error when retrieving metadata of billing feature"; String msg = "Error when retrieving metadata of billing feature";
log.error(msg, e); log.error(msg, e);
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
} }
if (!deviceStatusNotAvailable.isEmpty()) { if (!deviceStatusNotAvailable.isEmpty()) {

@ -696,6 +696,14 @@ public final class DeviceManagerUtil {
} }
} }
/**
* Enable Billing caching according to the configurations provided by cdm-config.xml
*/
public static void removeBillingCache() {
CacheManager manager = getCacheManager();
manager.removeCache(DeviceManagementConstants.BILLING_CACHE);
}
/** /**
* Enable Geofence caching according to the configurations proviced by cdm-config.xml * Enable Geofence caching according to the configurations proviced by cdm-config.xml
*/ */

Loading…
Cancel
Save