Package org.opentides.controller

Source Code of org.opentides.controller.ReportController

/*
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you 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 org.opentides.controller;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import org.apache.log4j.Logger;
import org.opentides.ControllerException;
import org.opentides.bean.DynamicReport;
import org.opentides.bean.FileInfo;
import org.opentides.bean.SystemCodes;
import org.opentides.editor.MultipartFileUploadEditor;
import org.opentides.editor.SystemCodeEditor;
import org.opentides.service.impl.ReportServiceImpl;
import org.springframework.validation.BindException;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.multipart.commons.CommonsMultipartFile;


/**
* This is the controller class for Report.
* Auto generated by high tides.
* @author hightides
*/

public class ReportController extends BaseCrudController<DynamicReport> {
  //-- Start custom codes. Do not delete this comment line.

  private static Logger _log = Logger.getLogger(ReportServiceImpl.class);

  public ReportController() {
    super();
    setMultipleUpload(false);
  }

  @SuppressWarnings("rawtypes")
  @Override
  protected Map referenceData(HttpServletRequest request) throws Exception {
    Map<String,Object> model = new HashMap<String,Object>();
    model.put("reportGroupList", getSystemCodesByCategory("REPORT_GROUP"));
    return model;
  }

  @Override
  protected void initBinder(HttpServletRequest request,
      ServletRequestDataBinder binder) throws Exception {
    binder.registerCustomEditor(CommonsMultipartFile.class, new MultipartFileUploadEditor());
    binder.registerCustomEditor(SystemCodes.class, new SystemCodeEditor(getSystemCodesService()));
  }

  @Override
  protected void preCreateAction(HttpServletRequest request,
      HttpServletResponse response, DynamicReport command, BindException errors) {
    uploadJasperFiles(request, response, command, errors);
  }

  @Override
  protected void preUpdateAction(HttpServletRequest request,
      HttpServletResponse response, DynamicReport command, BindException errors) {
    uploadJasperFiles(request, response, command, errors);
  }

  /**
   * Common method for file upload called during create and update form.
   * @param request
   * @param response
   * @param command
   * @param errors
   */
  private void uploadJasperFiles(HttpServletRequest request,
      HttpServletResponse response, DynamicReport command, BindException errors) {
    try {
      List<FileInfo> jasperFiles = processUpload(request, response,
          command, errors, "jasperFile");
      if (jasperFiles != null && !jasperFiles.isEmpty()) {
        FileInfo jasperFile = jasperFiles.get(0);
        File jasperPath = new File(jasperFile.getFullPath());
        command.setReportPath(jasperPath.getParent());
      }
    } catch (IOException e) {
      String message = "Unable to upload jasper file.";
      _log.error(message, e);
      errors.reject("jasperFile", null, message);
      throw new ControllerException(message, e);
    }
    try {
      processUpload(request, response, command, errors, "jrxmlFile");
    } catch (IOException e) {
      String message = "Unable to upload jrxml file.";
      _log.error(message, e);
      errors.reject("jrxmlFile", null, message);
      throw new ControllerException(message, e);
    }   
  }

  //-- End custom codes. Do not delete this comment line.
}
TOP

Related Classes of org.opentides.controller.ReportController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.