public void handleRequest()

in src/main/java/com/amazonaws/partners/saasfactory/metering/billing/ProcessBillingEvent.java [128:182]


    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) {
        if (this.tableConfig.getTableName().isEmpty() || this.tableConfig.getIndexName().isEmpty()) {
            this.logger.error("{} or {} environment variable not set", TABLE_ENV_VARIABLE,CONFIG_INDEX_NAME_ENV_VARIABLE);
            return;
        }

        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
        EventBridgeBillingEvent event = null;
        try {
            event = gson.fromJson(reader, EventBridgeBillingEvent.class);
        } catch (JsonSyntaxException e) {
            this.logger.error("Unable to parse JSON input");
            throw e;
        }

        if (!validateEventFields(event)) {
            this.logger.error("The fields associated with the billing event are not valid");
            throw new ProcessBillingEventException("TenantID or Quantity key not found in event");
        }

        // Verify the existence of the tenant ID
        TenantConfiguration tenant = TenantConfiguration.getTenantConfiguration(
                event.getDetail().getTenantID(),
                this.tableConfig,
                this.ddb,
                this.logger);

        if (tenant.isEmpty()) {
            throw new TenantNotFoundException(String.format(
                    "Tenant with ID %s not found",
                    event.getDetail().getTenantID()));
        }

        this.logger.info("Found tenant ID {}", event.getDetail().getTenantID());

        BillingEvent billingEvent = BillingEvent.createBillingEvent(event);
        if (billingEvent == null) {
            this.logger.error("Billing event not created because a component of the billing event was missing.");
            throw new ProcessBillingEventException("Billing event not created because a component of the billing event was missing.");
        }
        this.logger.debug("Billing event time is: {}", event.getTime());
        boolean result = putEvent(billingEvent);
        if (result) {
            this.logger.info("{} | {} | {}",
                    billingEvent.getTenantID(),
                    billingEvent.getEventTime(),
                    billingEvent.getQuantity());
        } else {
            this.logger.error("{} | {} | {}",
                    billingEvent.getTenantID(),
                    billingEvent.getEventTime(),
                    billingEvent.getQuantity());
            throw new ProcessBillingEventException("Failure to put item into DyanmoDB");
        }
    }