/**
 * Copyright 2014 Flipkart Internet Pvt. Ltd.
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.flipkart.foxtrot.server.resources;

import com.codahale.metrics.annotation.Timed;
import com.flipkart.foxtrot.common.Document;
import com.flipkart.foxtrot.core.exception.FoxtrotException;
import com.flipkart.foxtrot.core.querystore.QueryStore;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;
import java.util.List;

/**
 * User: Santanu Sinha (santanu.sinha@flipkart.com)
 * Date: 15/03/14
 * Time: 10:55 PM
 */
@Path("/v1/document/{table}")
@Produces(MediaType.APPLICATION_JSON)
public class DocumentResource {

    private final QueryStore queryStore;

    public DocumentResource(QueryStore queryStore) {
        this.queryStore = queryStore;
    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Timed
    public Response saveDocument(@PathParam("table") final String table, @Valid final Document document)
            throws FoxtrotException {
        queryStore.save(table, document);
        return Response.created(URI.create("/" + document.getId()))
                .build();
    }

    @POST
    @Path("/bulk")
    @Consumes(MediaType.APPLICATION_JSON)
    @Timed
    public Response saveDocuments(@PathParam("table") final String table, @Valid final List<Document> documents)
            throws FoxtrotException {
        queryStore.save(table, documents);
        return Response.created(URI.create("/" + table))
                .build();
    }

    @GET
    @Path("/{id}")
    @Timed
    public Response getDocument(@PathParam("table") final String table, @PathParam("id") @NotNull final String id)
            throws FoxtrotException {
        return Response.ok(queryStore.get(table, id))
                .build();
    }

    @GET
    @Timed
    public Response getDocuments(@PathParam("table") final String table,
                                 @QueryParam("id") @NotNull final List<String> ids) throws FoxtrotException {
        return Response.ok(queryStore.getAll(table, ids))
                .build();
    }
}

@@ -871,16 +871,73 @@
 ryStore;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -1339,16 +1339,106 @@
 urce %7B%0A%0A
+    private static final Logger LOGGER = LoggerFactory.getLogger(DocumentResource.class);%0A
     priv
@@ -2143,32 +2143,50 @@
 trotException %7B%0A
+        try %7B%0A    
         querySto
@@ -2208,24 +2208,136 @@
 documents);%0A
+        %7D catch (Exception e) %7B%0A            LOGGER.error(%22Error occurred in savingDocuments : %22 + e);%0A        %7D%0A
         retu

Print exception in document save bulk