Validate billing cost

remotes/1731000850486189418/master
osh.silva 4 months ago
parent f585e37d61
commit 3112fd92a6

@ -23,6 +23,8 @@ import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpStatus;
import org.json.JSONArray;
import org.json.JSONObject;
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.Feature;
@ -821,6 +823,30 @@ public class RequestValidationUtil {
new ErrorResponse.ErrorResponseBuilder()
.setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
if (metadata.getMetaKey().equals("PER_DEVICE_COST")) {
String metaValue = metadata.getMetaValue();
JSONArray jsonArray = new JSONArray(metaValue);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
if (jsonObject.has("cost")) {
Object costObj = jsonObject.get("cost");
if (costObj == JSONObject.NULL || (costObj instanceof Number && ((Number) costObj).doubleValue() < 0)) {
String msg = "Billing cost cannot be a minus value or null.";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder()
.setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
} else {
String msg = "Billing cost is missing.";
log.error(msg);
throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder()
.setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
}
}
if (metadata.getMetaValue() == null) {
String msg = "Request parameter metaValue should be non empty.";
log.error(msg);

Loading…
Cancel
Save