/src/main/java/com/google/ie/web/controller/AuditController.java
Java | 112 lines | 53 code | 15 blank | 44 comment | 2 complexity | e2beb34230c9e58360b835c525fadf85 MD5 | raw file
1/* Copyright 2010 Google Inc. 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS. 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License 14 */ 15 16package com.google.ie.web.controller; 17 18import com.google.ie.business.domain.Audit; 19import com.google.ie.business.service.AuditService; 20import com.google.ie.dto.ViewStatus; 21 22import org.apache.log4j.Logger; 23import org.springframework.beans.factory.annotation.Autowired; 24import org.springframework.beans.propertyeditors.CustomBooleanEditor; 25import org.springframework.beans.propertyeditors.CustomDateEditor; 26import org.springframework.beans.propertyeditors.StringTrimmerEditor; 27import org.springframework.stereotype.Controller; 28import org.springframework.validation.BindingResult; 29import org.springframework.web.bind.WebDataBinder; 30import org.springframework.web.bind.annotation.InitBinder; 31import org.springframework.web.bind.annotation.ModelAttribute; 32import org.springframework.web.bind.annotation.RequestMapping; 33 34import java.text.DateFormat; 35import java.util.Date; 36import java.util.Map; 37 38/** 39 * A controller that handles request for Auditing.It store information regarding 40 * all the update operation. 41 * 42 * @author asirohi 43 * 44 */ 45 46@Controller 47public class AuditController { 48 /* Logger for logging system */ 49 private static Logger log = Logger.getLogger(AuditController.class); 50 51 /* Interface of audit service */ 52 @Autowired 53 private AuditService auditService; 54 55 /** 56 * Handles the request for saving Audit entity. 57 * This request is initiated by TaskQueue for auditing the user actions on 58 * the entity. 59 */ 60 @RequestMapping("/audits/save") 61 public String saveAudit(@ModelAttribute Audit audit, BindingResult result, 62 Map<String, Object> model) { 63 64 ViewStatus viewstStatus = new ViewStatus(); 65 66 if (result.hasErrors()) { 67 log.warn("Audit object has " + result.getErrorCount() + " validation errors"); 68 viewstStatus.setStatus(WebConstants.ERROR); 69 viewstStatus.addMessage(WebConstants.ERROR, "Audit object has validation errors"); 70 } else { 71 auditService.saveAudit(audit); 72 viewstStatus.setStatus(WebConstants.SUCCESS); 73 viewstStatus.addMessage(WebConstants.SUCCESS, "Auditing is successfully done."); 74 } 75 model.put(WebConstants.AUDIT, viewstStatus); 76 return "queue/queue"; 77 } 78 79 /** 80 * Register custom binders for Spring. Needed to run on app engine 81 * 82 * @param binder 83 * @param request 84 */ 85 @InitBinder 86 public void initBinder(WebDataBinder binder) { 87 binder.registerCustomEditor(Boolean.class, new CustomBooleanEditor(true)); 88 binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); 89 binder.registerCustomEditor(Date.class, new CustomDateEditor(DateFormat 90 .getDateTimeInstance(DateFormat.FULL, DateFormat.FULL), true)); 91 } 92 93 /** 94 * Getter for Audit Service. 95 * 96 * @return the auditService 97 */ 98 public AuditService getAuditService() { 99 return auditService; 100 } 101 102 /** 103 * Setter for audit service. 104 * 105 * @param auditService the auditService to set 106 */ 107 public void setAuditService(AuditService auditService) { 108 this.auditService = auditService; 109 } 110 111} 112