lab3/order-service/src/main/java/com/amazon/aws/partners/saasfactory/OrderService.java [38:110]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class OrderService implements RequestHandler<Map<String, Object>, APIGatewayProxyResponseEvent> {

    private final static Logger LOGGER = LoggerFactory.getLogger(OrderService.class);
    private final static OrderServiceDAL DAL = new OrderServiceDAL();
    private final static ObjectMapper MAPPER = new ObjectMapper()
            .findAndRegisterModules()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    private final static Map<String, String> CORS = Stream
            .of(new AbstractMap.SimpleEntry<String, String>("Access-Control-Allow-Origin", "*"))
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

    public APIGatewayProxyResponseEvent handleRequest(Map<String, Object> event, Context context) {
        return getOrders(event, context);
    }

    public APIGatewayProxyResponseEvent getOrders(Map<String, Object> event, Context context) {
        LOGGER.info("OrderService::getOrders");
        List<Order> orders = DAL.getOrders(event);
        APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
                .withStatusCode(200)
                .withHeaders(CORS)
                .withBody(toJson(orders));
        return response;
    }

    public APIGatewayProxyResponseEvent getOrder(Map<String, Object> event, Context context) {
        Map<String, String> params = (Map) event.get("pathParameters");
        String orderId = params.get("id");
        LOGGER.info("OrderService::getOrder " + orderId);

        Order order = DAL.getOrder(event, orderId);
        APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
                .withStatusCode(200)
                .withHeaders(CORS)
                .withBody(toJson(order));
        return response;
    }

    public APIGatewayProxyResponseEvent updateOrder(Map<String, Object> event, Context context) {
        LOGGER.info("OrderService::updateOrder");
        APIGatewayProxyResponseEvent response = null;
        Map<String, String> params = (Map) event.get("pathParameters");
        String orderId = params.get("id");
        LOGGER.info("OrderService::updateOrder " + orderId);
        Order order = fromJson((String) event.get("body"));
        if (order == null) {
            response = new APIGatewayProxyResponseEvent()
                    .withStatusCode(400);
        } else {
            if (order.getId() == null || !order.getId().toString().equals(orderId)) {
                response = new APIGatewayProxyResponseEvent()
                        .withStatusCode(400);
            } else {
                order = DAL.updateOrder(event, order);
                response = new APIGatewayProxyResponseEvent()
                        .withStatusCode(200)
                        .withHeaders(CORS)
                        .withBody(toJson(order));
            }
        }
        return response;
    }

    public APIGatewayProxyResponseEvent insertOrder(Map<String, Object> event, Context context) {
        LOGGER.info("OrderService::insertOrder");

        APIGatewayProxyResponseEvent response = null;
        Order order = fromJson((String) event.get("body"));
        if (order == null) {
            response = new APIGatewayProxyResponseEvent()
                    .withStatusCode(400);
        } else {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



lab4/order-service/src/main/java/com/amazon/aws/partners/saasfactory/OrderService.java [38:110]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class OrderService implements RequestHandler<Map<String, Object>, APIGatewayProxyResponseEvent> {

    private final static Logger LOGGER = LoggerFactory.getLogger(OrderService.class);
    private final static OrderServiceDAL DAL = new OrderServiceDAL();
    private final static ObjectMapper MAPPER = new ObjectMapper()
            .findAndRegisterModules()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    private final static Map<String, String> CORS = Stream
            .of(new AbstractMap.SimpleEntry<String, String>("Access-Control-Allow-Origin", "*"))
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

    public APIGatewayProxyResponseEvent handleRequest(Map<String, Object> event, Context context) {
        return getOrders(event, context);
    }

    public APIGatewayProxyResponseEvent getOrders(Map<String, Object> event, Context context) {
        LOGGER.info("OrderService::getOrders");
        List<Order> orders = DAL.getOrders(event);
        APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
                .withStatusCode(200)
                .withHeaders(CORS)
                .withBody(toJson(orders));
        return response;
    }

    public APIGatewayProxyResponseEvent getOrder(Map<String, Object> event, Context context) {
        Map<String, String> params = (Map) event.get("pathParameters");
        String orderId = params.get("id");
        LOGGER.info("OrderService::getOrder " + orderId);

        Order order = DAL.getOrder(event, orderId);
        APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
                .withStatusCode(200)
                .withHeaders(CORS)
                .withBody(toJson(order));
        return response;
    }

    public APIGatewayProxyResponseEvent updateOrder(Map<String, Object> event, Context context) {
        LOGGER.info("OrderService::updateOrder");
        APIGatewayProxyResponseEvent response = null;
        Map<String, String> params = (Map) event.get("pathParameters");
        String orderId = params.get("id");
        LOGGER.info("OrderService::updateOrder " + orderId);
        Order order = fromJson((String) event.get("body"));
        if (order == null) {
            response = new APIGatewayProxyResponseEvent()
                    .withStatusCode(400);
        } else {
            if (order.getId() == null || !order.getId().toString().equals(orderId)) {
                response = new APIGatewayProxyResponseEvent()
                        .withStatusCode(400);
            } else {
                order = DAL.updateOrder(event, order);
                response = new APIGatewayProxyResponseEvent()
                        .withStatusCode(200)
                        .withHeaders(CORS)
                        .withBody(toJson(order));
            }
        }
        return response;
    }

    public APIGatewayProxyResponseEvent insertOrder(Map<String, Object> event, Context context) {
        LOGGER.info("OrderService::insertOrder");

        APIGatewayProxyResponseEvent response = null;
        Order order = fromJson((String) event.get("body"));
        if (order == null) {
            response = new APIGatewayProxyResponseEvent()
                    .withStatusCode(400);
        } else {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



