|
|
@ -129,6 +129,7 @@ import org.wso2.carbon.email.sender.core.service.EmailSenderService;
|
|
|
|
import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
|
|
|
|
import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
|
|
|
|
import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService;
|
|
|
|
import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
import org.wso2.carbon.user.api.UserStoreException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
|
import javax.xml.bind.JAXBException;
|
|
|
@ -946,7 +947,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
PaginationResult paginationResult = new PaginationResult();
|
|
|
|
double totalCost = 0.0;
|
|
|
|
double totalCost = 0.0;
|
|
|
|
boolean allDevicesBilledDateIsValid = true;
|
|
|
|
boolean allDevicesBilledDateIsValid = true;
|
|
|
|
String lastBilledDates = "";
|
|
|
|
|
|
|
|
ArrayList<String> lastBilledDatesList = new ArrayList<>();
|
|
|
|
ArrayList<String> lastBilledDatesList = new ArrayList<>();
|
|
|
|
List<Billing> invalidDevices = new ArrayList<>();
|
|
|
|
List<Billing> invalidDevices = new ArrayList<>();
|
|
|
|
List<Device> removeBillingPeriodInvalidDevices = new ArrayList<>() ;
|
|
|
|
List<Device> removeBillingPeriodInvalidDevices = new ArrayList<>() ;
|
|
|
@ -954,7 +954,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
MetadataManagementDAOFactory.beginTransaction();
|
|
|
|
MetadataManagementDAOFactory.beginTransaction();
|
|
|
|
Metadata metadata = metadataDAO.getMetadata(-1234, DeviceManagementConstants.META_KEY);
|
|
|
|
Metadata metadata = metadataDAO.getMetadata(MultitenantConstants.SUPER_TENANT_ID, DeviceManagementConstants.META_KEY);
|
|
|
|
|
|
|
|
|
|
|
|
Gson g = new Gson();
|
|
|
|
Gson g = new Gson();
|
|
|
|
Collection<Cost> costData = null;
|
|
|
|
Collection<Cost> costData = null;
|
|
|
@ -970,7 +970,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
long dateDiff = 0;
|
|
|
|
long dateDiff = 0;
|
|
|
|
|
|
|
|
|
|
|
|
List<DeviceStatus> deviceStatus = device.getDeviceStatusInfo();
|
|
|
|
List<DeviceStatus> deviceStatus = device.getDeviceStatusInfo();
|
|
|
|
boolean lastBilledDate = false;
|
|
|
|
boolean firstDateBilled = false;
|
|
|
|
boolean deviceStatusIsValid = false;
|
|
|
|
boolean deviceStatusIsValid = false;
|
|
|
|
|
|
|
|
|
|
|
|
List<Billing> deviceBilling = billingDAO.getBilling(device.getId(), startDate, endDate);
|
|
|
|
List<Billing> deviceBilling = billingDAO.getBilling(device.getId(), startDate, endDate);
|
|
|
@ -992,10 +992,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
|
|
|
|
|
|
|
if (!billDateIsInvalid) {
|
|
|
|
if (!billDateIsInvalid) {
|
|
|
|
for (int i = 0; i < deviceStatus.size(); i++) {
|
|
|
|
for (int i = 0; i < deviceStatus.size(); i++) {
|
|
|
|
if (deviceStatus.get(i).getStatus().toString().equals("ACTIVE")) {
|
|
|
|
if (DeviceManagementConstants.ACTIVE_STATUS.equals(deviceStatus.get(i).getStatus().toString())) {
|
|
|
|
if (deviceStatus.size() > i + 1) {
|
|
|
|
if (deviceStatus.size() > i + 1) {
|
|
|
|
if (!lastBilledDate) {
|
|
|
|
if (!firstDateBilled) {
|
|
|
|
lastBilledDate = true;
|
|
|
|
firstDateBilled = true;
|
|
|
|
if (device.getEnrolmentInfo().getLastBilledDate() == 0) {
|
|
|
|
if (device.getEnrolmentInfo().getLastBilledDate() == 0) {
|
|
|
|
deviceStatusIsValid = true;
|
|
|
|
deviceStatusIsValid = true;
|
|
|
|
dateDiff = dateDiff + (deviceStatus.get(i + 1).getUpdateTime().getTime() - deviceStatus.get(i).getUpdateTime().getTime());
|
|
|
|
dateDiff = dateDiff + (deviceStatus.get(i + 1).getUpdateTime().getTime() - deviceStatus.get(i).getUpdateTime().getTime());
|
|
|
@ -1011,11 +1011,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
dateDiff = dateDiff + (deviceStatus.get(i + 1).getUpdateTime().getTime() - deviceStatus.get(i).getUpdateTime().getTime());
|
|
|
|
dateDiff = dateDiff + (deviceStatus.get(i + 1).getUpdateTime().getTime() - deviceStatus.get(i).getUpdateTime().getTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { // The last status update calculation is done in this block
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
// If only one status row is retrieved this block is executed
|
|
|
|
// If only one status row is retrieved this block is executed
|
|
|
|
if (!lastBilledDate) {
|
|
|
|
if (!firstDateBilled) {
|
|
|
|
lastBilledDate = true;
|
|
|
|
firstDateBilled = true;
|
|
|
|
// Is executed if there is no lastBilled date and if the updates time is before the enddate
|
|
|
|
|
|
|
|
|
|
|
|
// Is executed if there is no lastBilled date and if the updates time is before the end date
|
|
|
|
if (device.getEnrolmentInfo().getLastBilledDate() == 0) {
|
|
|
|
if (device.getEnrolmentInfo().getLastBilledDate() == 0) {
|
|
|
|
if (endDate.getTime() >= deviceStatus.get(i).getUpdateTime().getTime()) {
|
|
|
|
if (endDate.getTime() >= deviceStatus.get(i).getUpdateTime().getTime()) {
|
|
|
|
deviceStatusIsValid = true;
|
|
|
|
deviceStatusIsValid = true;
|
|
|
@ -1066,11 +1068,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
if (device.getEnrolmentInfo().getLastBilledDate() != 0) {
|
|
|
|
if (device.getEnrolmentInfo().getLastBilledDate() != 0) {
|
|
|
|
Date date = new Date(device.getEnrolmentInfo().getLastBilledDate());
|
|
|
|
Date date = new Date(device.getEnrolmentInfo().getLastBilledDate());
|
|
|
|
Format format = new SimpleDateFormat("yyyy MM dd");
|
|
|
|
Format format = new SimpleDateFormat("yyyy MM dd");
|
|
|
|
if (!lastBilledDatesList.contains(lastBilledDatesList.add(format.format(date)))) {
|
|
|
|
|
|
|
|
|
|
|
|
for (String lastBillDate : lastBilledDatesList) {
|
|
|
|
|
|
|
|
if (!lastBillDate.equals(format.format(date))) {
|
|
|
|
lastBilledDatesList.add(format.format(date));
|
|
|
|
lastBilledDatesList.add(format.format(date));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
lastBilledDates = lastBilledDates + ' ' + lastBilledDatesList;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeBillingPeriodInvalidDevices.add(device);
|
|
|
|
removeBillingPeriodInvalidDevices.add(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1098,14 +1101,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|
|
|
|
|
|
|
|
|
|
|
if(!removeBillingPeriodInvalidDevices.isEmpty() && removeBillingPeriodInvalidDevices.size() == allDevices.size()) {
|
|
|
|
if(!removeBillingPeriodInvalidDevices.isEmpty() && removeBillingPeriodInvalidDevices.size() == allDevices.size()) {
|
|
|
|
allDevicesBilledDateIsValid = false;
|
|
|
|
allDevicesBilledDateIsValid = false;
|
|
|
|
paginationResult.setMessage("Invalid bill period last billed dates of devices are " +lastBilledDates);
|
|
|
|
paginationResult.setMessage("Invalid bill period.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!removeStatusUpdateInvalidDevices.isEmpty() && removeStatusUpdateInvalidDevices.size() == allDevices.size()) {
|
|
|
|
if(!removeStatusUpdateInvalidDevices.isEmpty() && removeStatusUpdateInvalidDevices.size() == allDevices.size()) {
|
|
|
|
allDevicesBilledDateIsValid = false;
|
|
|
|
allDevicesBilledDateIsValid = false;
|
|
|
|
if (paginationResult.getMessage() != null){
|
|
|
|
if (paginationResult.getMessage() != null){
|
|
|
|
paginationResult.setMessage(paginationResult.getMessage() + " and no device updates within entered bill period.");
|
|
|
|
paginationResult.setMessage(paginationResult.getMessage() + " and no device updates within entered bill period.");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
paginationResult.setMessage("Devices have not been updated within the given period or entered end date comes before the last billed date");
|
|
|
|
paginationResult.setMessage("Devices have not been updated within the given period or entered end date comes before the " +
|
|
|
|
|
|
|
|
"last billed date.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|