001package org.kuali.ole.select.controller; 002 003import org.kuali.ole.select.form.LocalGokbForm; 004import org.kuali.ole.select.gokb.service.GokbLocalService; 005import org.kuali.ole.select.gokb.service.GokbRdbmsService; 006import org.kuali.ole.select.gokb.service.impl.GokbLocalServiceImpl; 007import org.kuali.ole.select.gokb.service.impl.GokbRdbmsServiceImpl; 008import org.kuali.ole.select.gokb.OleGokbUpdateLog; 009import org.kuali.ole.select.gokb.service.impl.GokbThread; 010import org.kuali.ole.select.gokb.util.OleGokbXmlUtil; 011import org.kuali.rice.krad.service.BusinessObjectService; 012import org.kuali.rice.krad.service.KRADServiceLocator; 013import org.kuali.rice.krad.web.controller.UifControllerBase; 014import org.kuali.rice.krad.web.form.UifFormBase; 015import org.springframework.stereotype.Controller; 016import org.springframework.validation.BindingResult; 017import org.springframework.web.bind.annotation.ModelAttribute; 018import org.springframework.web.bind.annotation.RequestMapping; 019import org.springframework.web.servlet.ModelAndView; 020 021import javax.servlet.http.HttpServletRequest; 022import javax.servlet.http.HttpServletResponse; 023import java.sql.Timestamp; 024import java.util.*; 025 026 027/** 028 * Created by premkumarv on 12/18/14. 029 */ 030@Controller 031@RequestMapping(value = "/localGokbController") 032public class LocalGokbController extends UifControllerBase { 033 private GokbRdbmsService gokbRdbmsService; 034 private GokbLocalService gokbLocalService; 035 private BusinessObjectService businessObjectService; 036 037 @Override 038 protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) { 039 UifFormBase uifFormBase = null; 040 uifFormBase = new LocalGokbForm(); 041 return uifFormBase; 042 } 043 044 public GokbRdbmsService getGokbRdbmsService() { 045 if (null == gokbRdbmsService) { 046 return new GokbRdbmsServiceImpl(); 047 } 048 return gokbRdbmsService; 049 } 050 051 public GokbLocalService getGokbLocalService() { 052 if (null == gokbLocalService) { 053 return new GokbLocalServiceImpl(); 054 } 055 return gokbLocalService; 056 } 057 public BusinessObjectService getBusinessObjectService() { 058 if (null == businessObjectService) { 059 businessObjectService = KRADServiceLocator.getBusinessObjectService(); 060 } 061 return businessObjectService; 062 } 063 064 065 066 @Override 067 @RequestMapping(params = "methodToCall=start") 068 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 069 HttpServletRequest request, HttpServletResponse response) { 070 LocalGokbForm localGokbForm = (LocalGokbForm)form; 071 return getUIFModelAndView(localGokbForm); 072 } 073 074 075 @RequestMapping(params = "methodToCall=initOrUpdateLocalGokb") 076 public ModelAndView initOrUpdateLocalGokb(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 077 HttpServletRequest request, HttpServletResponse response) { 078 GokbThread gokbThread = new GokbThread(); 079 gokbThread.start(); 080 return getUIFModelAndView(getLocalGokbForm((LocalGokbForm) form)); 081 082 } 083 084 @RequestMapping(params = "methodToCall=refreshStatus") 085 public ModelAndView refreshStatus(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 086 HttpServletRequest request, HttpServletResponse response) { 087 LocalGokbForm localGokbForm = getLocalGokbForm((LocalGokbForm) form); 088 089 return getUIFModelAndView(localGokbForm); 090 091 } 092 093 private LocalGokbForm getLocalGokbForm(LocalGokbForm form) { 094 LocalGokbForm localGokbForm = (LocalGokbForm)form; 095 List<OleGokbUpdateLog> oleGokbUpdateLogList = new ArrayList<OleGokbUpdateLog>(); 096 List<OleGokbUpdateLog> oleGokbUpdateLogs = (List<OleGokbUpdateLog>) KRADServiceLocator.getBusinessObjectService().findAll(OleGokbUpdateLog.class); 097 Collections.reverse(oleGokbUpdateLogs); 098 for (OleGokbUpdateLog oleGokbUpdateLog : oleGokbUpdateLogs) { 099 if(oleGokbUpdateLog.getId() != null) { 100 localGokbForm.setId(oleGokbUpdateLog.getId().toString()); 101 } 102 if(oleGokbUpdateLog.getNoOfPackages() != null){ 103 localGokbForm.setNoOfPackages(oleGokbUpdateLog.getNoOfPackages().toString()); 104 } 105 if(oleGokbUpdateLog.getNoOfTipps() != null){ 106 localGokbForm.setNoOfTipps(oleGokbUpdateLog.getNoOfTipps().toString()); 107 } 108 if(oleGokbUpdateLog.getNoOfTitles() != null) { 109 localGokbForm.setNoOfTitles(oleGokbUpdateLog.getNoOfTitles().toString()); 110 } 111 if(oleGokbUpdateLog.getNoOfOrganization() != null) { 112 localGokbForm.setNoOfOrganization(oleGokbUpdateLog.getNoOfOrganization().toString()); 113 } 114 if(oleGokbUpdateLog.getNoOfPlatforms() != null) { 115 localGokbForm.setNoOfPlatforms(oleGokbUpdateLog.getNoOfPlatforms().toString()); 116 } 117 if(oleGokbUpdateLog.getStatus() != null) { 118 localGokbForm.setStatus(oleGokbUpdateLog.getStatus()); 119 } 120 if(oleGokbUpdateLog.getStartTime() != null) { 121 localGokbForm.setStartTime(oleGokbUpdateLog.getStartTime()); 122 } 123 if(oleGokbUpdateLog.getEndTime() != null) { 124 localGokbForm.setEndTime(oleGokbUpdateLog.getEndTime()); 125 } 126 break; 127 } 128 oleGokbUpdateLogList.addAll(oleGokbUpdateLogs); 129 localGokbForm.setOleGokbUpdateLogList(oleGokbUpdateLogList); 130 return localGokbForm; 131 } 132 133 134}