/src/main/java/com/google/ie/web/controller/AuditController.java

http://thoughtsite.googlecode.com/ · 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. package com.google.ie.web.controller;
  16. import com.google.ie.business.domain.Audit;
  17. import com.google.ie.business.service.AuditService;
  18. import com.google.ie.dto.ViewStatus;
  19. import org.apache.log4j.Logger;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.propertyeditors.CustomBooleanEditor;
  22. import org.springframework.beans.propertyeditors.CustomDateEditor;
  23. import org.springframework.beans.propertyeditors.StringTrimmerEditor;
  24. import org.springframework.stereotype.Controller;
  25. import org.springframework.validation.BindingResult;
  26. import org.springframework.web.bind.WebDataBinder;
  27. import org.springframework.web.bind.annotation.InitBinder;
  28. import org.springframework.web.bind.annotation.ModelAttribute;
  29. import org.springframework.web.bind.annotation.RequestMapping;
  30. import java.text.DateFormat;
  31. import java.util.Date;
  32. import java.util.Map;
  33. /**
  34. * A controller that handles request for Auditing.It store information regarding
  35. * all the update operation.
  36. *
  37. * @author asirohi
  38. *
  39. */
  40. @Controller
  41. public class AuditController {
  42. /* Logger for logging system */
  43. private static Logger log = Logger.getLogger(AuditController.class);
  44. /* Interface of audit service */
  45. @Autowired
  46. private AuditService auditService;
  47. /**
  48. * Handles the request for saving Audit entity.
  49. * This request is initiated by TaskQueue for auditing the user actions on
  50. * the entity.
  51. */
  52. @RequestMapping("/audits/save")
  53. public String saveAudit(@ModelAttribute Audit audit, BindingResult result,
  54. Map<String, Object> model) {
  55. ViewStatus viewstStatus = new ViewStatus();
  56. if (result.hasErrors()) {
  57. log.warn("Audit object has " + result.getErrorCount() + " validation errors");
  58. viewstStatus.setStatus(WebConstants.ERROR);
  59. viewstStatus.addMessage(WebConstants.ERROR, "Audit object has validation errors");
  60. } else {
  61. auditService.saveAudit(audit);
  62. viewstStatus.setStatus(WebConstants.SUCCESS);
  63. viewstStatus.addMessage(WebConstants.SUCCESS, "Auditing is successfully done.");
  64. }
  65. model.put(WebConstants.AUDIT, viewstStatus);
  66. return "queue/queue";
  67. }
  68. /**
  69. * Register custom binders for Spring. Needed to run on app engine
  70. *
  71. * @param binder
  72. * @param request
  73. */
  74. @InitBinder
  75. public void initBinder(WebDataBinder binder) {
  76. binder.registerCustomEditor(Boolean.class, new CustomBooleanEditor(true));
  77. binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
  78. binder.registerCustomEditor(Date.class, new CustomDateEditor(DateFormat
  79. .getDateTimeInstance(DateFormat.FULL, DateFormat.FULL), true));
  80. }
  81. /**
  82. * Getter for Audit Service.
  83. *
  84. * @return the auditService
  85. */
  86. public AuditService getAuditService() {
  87. return auditService;
  88. }
  89. /**
  90. * Setter for audit service.
  91. *
  92. * @param auditService the auditService to set
  93. */
  94. public void setAuditService(AuditService auditService) {
  95. this.auditService = auditService;
  96. }
  97. }