All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.formkiq.server.api.ExportsController Maven / Gradle / Ivy

/*
 * Copyright (C) 2016 FormKiQ Inc.
 *
 * 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
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.formkiq.server.api;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.formkiq.server.service.ExportService;
import com.formkiq.server.service.dto.FormJSON;

/**
 *
 * Rest Controller to convert data between formats.
 *
 */
@RestController
public class ExportsController extends AbstractRestController {

    /** Content Type for .XLS excel. */
    private static final String CONTENT_TYPE_XLS = "application/vnd.ms-excel";

    /** Content Type for .XLSX excel. */
    private static final String CONTENT_TYPE_XLSX =
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

    /** Export as XLS. */
    public static final String API_EXPORT_XLS = "/api/exports/xls";

    /** Export as XLSX. */
    public static final String API_EXPORT_XLSX = "/api/exports/xlsx";

    /** ExportService. */
    @Autowired
    private ExportService exportService;

    /**
     * Export to XLS format.
     * @param request {@link HttpServletRequest}
     * @param response {@link HttpServletResponse}
     * @param formJSON {@link FormJSON}
     * @throws IOException Exception
     */
    @RequestMapping(API_EXPORT_XLS)
    public void xls(final HttpServletRequest request,
            final HttpServletResponse response,
            @RequestBody final FormJSON formJSON) throws IOException {

        getApiVersion(request);

        response.setContentType(CONTENT_TYPE_XLS);
        this.exportService.writeToXLS(formJSON, response.getOutputStream());
    }

    /**
     * Export to XLSX format.
     * @param request {@link HttpServletRequest}
     * @param response {@link HttpServletResponse}
     * @param formJSON {@link FormJSON}
     * @throws IOException Exception
     */
    @RequestMapping(API_EXPORT_XLSX)
    public void xlsx(
            final HttpServletRequest request,
            final HttpServletResponse response,
            @RequestBody final FormJSON formJSON) throws IOException {

        getApiVersion(request);
        response.setContentType(CONTENT_TYPE_XLSX);
        this.exportService.writeToXLSX(formJSON, response.getOutputStream());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy