gauravpaliwal

Untitled

Jul 25th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. * http://license.openmrs.org
  6. *
  7. * Software distributed under the License is distributed on an "AS IS"
  8. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. * License for the specific language governing rights and limitations
  10. * under the License.
  11. *
  12. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  13. */
  14.  
  15. package org.openmrs.module.feedback.web;
  16.  
  17. import java.util.HashMap;
  18. import java.util.Map;
  19.  
  20. import javax.servlet.http.HttpServletRequest;
  21.  
  22. import org.apache.commons.logging.Log;
  23. import org.apache.commons.logging.LogFactory;
  24. import org.openmrs.api.context.Context;
  25. import org.openmrs.module.feedback.PredefinedSubject;
  26. import org.openmrs.module.feedback.FeedbackService;
  27. import org.springframework.util.StringUtils;
  28. import org.springframework.web.servlet.mvc.SimpleFormController;
  29.  
  30. public class PredefinedSubjectFormController extends SimpleFormController {
  31.  
  32. /** Logger for this class and subclasses */
  33. protected final Log log = LogFactory.getLog(getClass());
  34.  
  35. @Override
  36. protected String formBackingObject(HttpServletRequest request) throws Exception {
  37. Boolean feedbackMessage = false ;
  38. Object o = Context.getService(FeedbackService.class);
  39. FeedbackService service = (FeedbackService)o;
  40. String text = "";
  41. String predefinedsubjectid = request.getParameter("predefinedsubjectid") ;
  42.  
  43. if ( !StringUtils.hasLength(predefinedsubjectid) || service.getPredefinedSubject(Integer.parseInt(predefinedsubjectid)) == null )
  44. {
  45. /*Just log this for the statistics */
  46. System.out.println ("feedback.notification.predefinedSubject.deleted") ;
  47.  
  48. }
  49.  
  50. else if (predefinedsubjectid != null && "1".equals(request.getParameter("delete")) )
  51. {
  52. /*delete the element*/
  53. PredefinedSubject s = new PredefinedSubject() ;
  54. s = service.getPredefinedSubject(Integer.parseInt(predefinedsubjectid)) ;
  55. service.deletePredefinedSubject( s );
  56. text = predefinedsubjectid ;
  57. }
  58.  
  59. else if (predefinedsubjectid != null && "1".equals(request.getParameter("save")) )
  60. {
  61. /*save the element*/
  62. PredefinedSubject s = new PredefinedSubject() ;
  63. s = service.getPredefinedSubject(Integer.parseInt(predefinedsubjectid)) ;
  64.  
  65. /** This makes sure that the Predefined Subject value always remain less then or equal to 50*/
  66. s.setSubject(request.getParameter("predefinedsubject") ) ;
  67.  
  68. /*Service Method to save the data*/
  69. service.savePredefinedSubject(s) ;
  70. text = predefinedsubjectid ;
  71. }
  72.  
  73. log.debug("Returning hello world text: " + text);
  74.  
  75. return text ;
  76.  
  77. }
  78.  
  79. @Override
  80. protected Map referenceData(HttpServletRequest req) throws Exception {
  81.  
  82. Map<String, Object> map = new HashMap<String, Object>();
  83. Object o = Context.getService(FeedbackService.class);
  84. FeedbackService service = (FeedbackService)o;
  85. FeedbackService hService = (FeedbackService)Context.getService(FeedbackService.class);
  86. String predefinedsubjectid = req.getParameter("predefinedsubjectid") ;
  87.  
  88. /*Predefined Subject is deleted incase the subject with predefinedID is not found*/
  89. if ( !StringUtils.hasLength( predefinedsubjectid) || service.getPredefinedSubject(Integer.parseInt(predefinedsubjectid)) == null )
  90. {
  91. PredefinedSubject s = new PredefinedSubject() ;
  92. map.put("predefinedsubjects" , s ) ;
  93. map.put("feedbackPageMessage" , "feedback.notification.predefinedSubject.deleted") ;
  94. return map ;
  95. }
  96. /*Otherwise give the data about the predefined subject*/
  97. else
  98. {
  99. PredefinedSubject s = service.getPredefinedSubject(Integer.parseInt(predefinedsubjectid)) ;
  100. map.put("predefinedsubjects" , s ) ;
  101. map.put("feedbackPageMessage" , "") ;
  102. return map ;
  103. }
  104.  
  105.  
  106.  
  107. }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment