com.formkiq.core.controller.admin.AdminController.java Source code

Java tutorial

Introduction

Here is the source code for com.formkiq.core.controller.admin.AdminController.java

Source

/*
 * 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.core.controller.admin;

import java.io.IOException;

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

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.formkiq.core.form.webflow.SingleFormFlowEventProcessor;
import com.formkiq.core.service.FolderService;
import com.formkiq.core.service.dto.License;
import com.formkiq.core.service.dto.SystemConfig;
import com.formkiq.core.service.workflow.FormFlowController;

/**
 * Admin Controller.
 *
 */
@Controller
@RequestMapping(value = "/admin")
public class AdminController {

    /** {@link FormFlowController}. */
    @Autowired
    private FormFlowController formFlowController;

    /** FolderService. */
    @Autowired
    private FolderService folderservice;

    /**
     * Admin Clients page.
     * @return {@link String}
     */
    @RequestMapping(value = "/clients", method = RequestMethod.GET)
    public String clients() {
        return "admin/clients";
    }

    /**
     * Download Form.
     * @param request {@link HttpServletRequest}
     * @param response {@link HttpServletResponse}
     * @param folder {@link String}
     * @param uuid {@link String}
     * @throws IOException IOException
     */
    @Transactional
    @RequestMapping("/download")
    public void download(final HttpServletRequest request, final HttpServletResponse response,
            @RequestParam(value = "folder", required = true) final String folder,
            @RequestParam(value = "uuid", required = true) final String uuid) throws IOException {

        byte[] data = this.folderservice.findFormData(folder, uuid).getLeft();

        response.setContentType("application/zip");
        response.setHeader("Content-disposition", "attachment; filename=" + uuid + ".zip");
        response.setContentLengthLong(data.length);
        IOUtils.write(data, response.getOutputStream());
    }

    /**
     * Admin Equifax page.
     * @return {@link String}
     */
    @RequestMapping(value = "/equifax", method = RequestMethod.GET)
    public String equifax() {
        return "admin/equifax";
    }

    /**
     * Admin Folders page.
     * @return {@link String}
     */
    @RequestMapping(value = "/folders", method = RequestMethod.GET)
    public String folders() {
        return "redirect:/admin/folders/index";
    }

    /**
     * Admin Forms page.
     * @param type {@link String}
     * @param client {@link String}
     * @param name {@link String}
     * @param uuid {@link String}
     * @return {@link String}
     */
    @RequestMapping(value = "/forms", method = RequestMethod.GET)
    public String forms(@RequestParam(value = "type", required = false) final String type,
            @RequestParam(value = "client", required = false) final String client,
            @RequestParam(value = "name", required = false) final String name,
            @RequestParam(value = "uuid", required = false) final String uuid) {

        if (StringUtils.isEmpty(type)) {
            return "redirect:/admin/index";
        }

        if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(uuid) && !StringUtils.isEmpty(client)) {
            return "admin/formdetails";
        }

        return "admin/forms";
    }

    /**
     * Admin Index.
     * @return {@link String}
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index() {
        return "redirect:/admin/users";
    }

    /**
     * License page.
     * @param request {@link HttpServletRequest}
     * @return {@link String}
     * @throws Exception Exception
     */
    @RequestMapping(value = "/license")
    public ModelAndView license(final HttpServletRequest request) throws Exception {
        return this.formFlowController.handle(request, SingleFormFlowEventProcessor.class, "admin/license",
                License.class);
    }

    /**
     * Admin OAuth page.
     * @return {@link String}
     */
    @RequestMapping(value = "/oauth", method = RequestMethod.GET)
    public String oauth() {
        return "admin/oauth";
    }

    /**
     * Admin System Properties page.
     * @param request {@link HttpServletRequest}
     * @return {@link String}
     * @throws Exception Exception
     */
    @RequestMapping(value = "/systemproperties")
    public ModelAndView systemproperties(final HttpServletRequest request) throws Exception {
        return this.formFlowController.handle(request, SingleFormFlowEventProcessor.class, "admin/systemproperties",
                SystemConfig.class);
    }

    /**
     * TODO remove
     * Admin System Properties page.
     * @return {@link String}
     */
    @RequestMapping(value = "/systempropertiesold", method = RequestMethod.GET)
    public String systempropertiesold() {
        return "admin/systempropertiesold";
    }

    /**
     * Admin Delete System Properties page.
     * @return {@link String}
     */
    @RequestMapping(value = "/systemproperties/delete", method = RequestMethod.GET)
    public String systempropertiesDelete() {
        return "admin/systemproperties/delete";
    }

    /**
     * Admin Edit System Properties page.
     * @return {@link String}
     */
    @RequestMapping(value = "/systemproperties/edit", method = RequestMethod.GET)
    public String systempropertiesEdit() {
        return "admin/systemproperties/edit";
    }

    /**
     * Admin Users page.
     * @return {@link String}
     */
    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public String users() {
        return "admin/users";
    }

    /**
     * Admin Workflows page.
     * @return {@link String}
     */
    @RequestMapping(value = "/workflows", method = RequestMethod.GET)
    public String workflows() {
        return "admin/workflows";
    }
}