Fix billing issues

Co-authored-by: Oshani Silva <oshani@entgra.io>
Co-committed-by: Oshani Silva <oshani@entgra.io>
mssqloperationlogfix
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.WhiteLabelTheme;
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.service.api.MetadataService;
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
@ -127,6 +128,7 @@ public class MetadataServiceImpl implements MetadataService {
RequestValidationUtil.validateMetadata(metadata);
try {
Metadata updatedMetadata = DeviceMgtAPIUtils.getMetadataManagementService().updateMetadata(metadata);
DeviceManagerUtil.removeBillingCache();
return Response.status(Response.Status.OK).entity(updatedMetadata).build();
} catch (MetadataManagementException e) {
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.UserNotFoundException;
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.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;

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

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

@ -92,8 +92,8 @@ public class MetadataManagementServiceImpl implements MetadataManagementService
try {
MetadataManagementDAOFactory.openConnection();
int tenantId;
if (metaKey.equals("EVALUATE_TENANTS")){
// for getting evaluate tenant list to provide the live chat feature
if (metaKey.equals("EVALUATE_TENANTS") || metaKey.equals("PER_DEVICE_COST")){
// for getting per device cost and evaluate tenant list to provide the billing feature and live chat feature
tenantId = MultitenantConstants.SUPER_TENANT_ID;
} else {
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.HttpClients;
import org.apache.http.protocol.HTTP;
import org.opensaml.xmlsec.signature.P;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.CarbonContext;
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.UnauthorizedDeviceAccessException;
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.group.mgt.DeviceGroup;
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.LicenseManagementException;
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.Operation;
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.Properties;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService,
@ -1044,8 +1044,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
double totalCost = 0.0;
try {
MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(MultitenantConstants.SUPER_TENANT_ID, DeviceManagementConstants.META_KEY);
MetadataManagementService meta = DeviceManagementDataHolder
.getInstance().getMetadataManagementService();
Metadata metadata = meta.retrieveMetadata(DeviceManagementConstants.META_KEY);
Gson g = new Gson();
Collection<Cost> costData = null;
@ -1061,19 +1062,19 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
device.setDeviceStatusInfo(getDeviceStatusHistory(device, null, endDate, true));
List<DeviceStatus> deviceStatus = device.getDeviceStatusInfo();
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()) {
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();
}
} 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()) {
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();
}
}
@ -1095,16 +1096,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
String msg = "Error occurred calculating cost of devices";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (SQLException e) {
String msg = "Error when retrieving data";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (MetadataManagementDAOException e) {
} catch (MetadataManagementException e) {
String msg = "Error when retrieving metadata of billing feature";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
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
*/

Loading…
Cancel
Save