Package org.opentides.controller

Source Code of org.opentides.controller.WidgetController

/*
   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.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

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

import org.opentides.bean.Widget;
import org.opentides.bean.user.BaseUser;
import org.opentides.service.UserService;
import org.opentides.service.UserWidgetsService;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.validation.BindException;
import org.springframework.web.bind.ServletRequestDataBinder;


/**
* This is the controller class for Widget.
* Auto generated by high tides.
* @author hightides
*/
public class WidgetController extends BaseCrudController<Widget> {
 
  private UserService userService;
  private UserWidgetsService userWidgetsService;
 
  public WidgetController() {
    super();
    setMultipleUpload(false);
  }

  /*
   * (non-Javadoc)
   *
   * @see org.springframework.web.servlet.mvc.AbstractFormController#formBackingObject(javax.servlet.http.HttpServletRequest)
   */
  @Override
  protected Object formBackingObject(HttpServletRequest request)
      throws Exception {
    String action = getAction(request);
    if (READ.equals(action) || UPDATE.equals(action)) {
      return getService().load(request.getParameter(ID));
    } else {
      Widget object = new Widget();
      object.setCacheDuration(3600);
      object.setIsUserDefined(true);
      return object;
    }
  }
 
  @Override
  protected void postCreateAction(Widget command) {
    //after creating our widget, we must also check if that widget is automatically shown on our dashboard,
    //if the checkbox isShown was checked, then we need to add users to our USER_WIDGETS table in db...
    if (command.getIsShown()) {
      List<BaseUser> baseusers = userService.findAll();
      if (command.getAccessCode().equals("")) {
        //blank access code means all users will have this widget
        for (BaseUser baseuser : baseusers) {
          userWidgetsService.addUserWidgets(baseuser.getId(), command);
        }
      } else {
        for (BaseUser baseuser : baseusers) {
          if (baseuser.hasPermission(command.getAccessCode())) {
            userWidgetsService.addUserWidgets(baseuser.getId(), command);
          }
        }
      }
       
    }
   
   
  }
  /* (non-Javadoc)
   * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest, org.springframework.web.bind.ServletRequestDataBinder)
   */
  @Override
  protected void initBinder(HttpServletRequest request,
      ServletRequestDataBinder binder) throws Exception {
    binder.registerCustomEditor(Date.class, "lastCacheUpdate",
        new CustomDateEditor(new SimpleDateFormat("MMM dd, yyyy hh:mm:ss"), true));
  }

//-- Start custom codes. Do not delete this comment line.

  /* (non-Javadoc)
   * @see org.opentides.controller.BaseCrudController#preSearchAction(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.opentides.bean.BaseEntity, org.springframework.validation.BindException)
   */
  @Override
  protected void preSearchAction(HttpServletRequest request,
      HttpServletResponse response, Widget command, BindException errors) {
    command.setIsUserDefined(true);
  }

  public UserService getUserService() {
    return userService;
  }

  public void setUserService(UserService userService) {
    this.userService = userService;
  }

  public UserWidgetsService getUserWidgetsService() {
    return userWidgetsService;
  }

  public void setUserWidgetsService(UserWidgetsService userWidgetsService) {
    this.userWidgetsService = userWidgetsService;
  }
 
//-- End custom codes. Do not delete this comment line.
}
TOP

Related Classes of org.opentides.controller.WidgetController

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.