1 package org.kuali.ole.select.controller;
2
3 import org.kuali.ole.select.form.LocalGokbForm;
4 import org.kuali.ole.select.gokb.service.GokbLocalService;
5 import org.kuali.ole.select.gokb.service.GokbRdbmsService;
6 import org.kuali.ole.select.gokb.service.impl.GokbLocalServiceImpl;
7 import org.kuali.ole.select.gokb.service.impl.GokbRdbmsServiceImpl;
8 import org.kuali.ole.select.gokb.OleGokbUpdateLog;
9 import org.kuali.ole.select.gokb.service.impl.GokbThread;
10 import org.kuali.ole.select.gokb.util.OleGokbXmlUtil;
11 import org.kuali.rice.krad.service.BusinessObjectService;
12 import org.kuali.rice.krad.service.KRADServiceLocator;
13 import org.kuali.rice.krad.web.controller.UifControllerBase;
14 import org.kuali.rice.krad.web.form.UifFormBase;
15 import org.springframework.stereotype.Controller;
16 import org.springframework.validation.BindingResult;
17 import org.springframework.web.bind.annotation.ModelAttribute;
18 import org.springframework.web.bind.annotation.RequestMapping;
19 import org.springframework.web.servlet.ModelAndView;
20
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
23 import java.sql.Timestamp;
24 import java.util.*;
25
26
27
28
29
30 @Controller
31 @RequestMapping(value = "/localGokbController")
32 public class LocalGokbController extends UifControllerBase {
33 private GokbRdbmsService gokbRdbmsService;
34 private GokbLocalService gokbLocalService;
35 private BusinessObjectService businessObjectService;
36
37 @Override
38 protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
39 UifFormBase uifFormBase = null;
40 uifFormBase = new LocalGokbForm();
41 return uifFormBase;
42 }
43
44 public GokbRdbmsService getGokbRdbmsService() {
45 if (null == gokbRdbmsService) {
46 return new GokbRdbmsServiceImpl();
47 }
48 return gokbRdbmsService;
49 }
50
51 public GokbLocalService getGokbLocalService() {
52 if (null == gokbLocalService) {
53 return new GokbLocalServiceImpl();
54 }
55 return gokbLocalService;
56 }
57 public BusinessObjectService getBusinessObjectService() {
58 if (null == businessObjectService) {
59 businessObjectService = KRADServiceLocator.getBusinessObjectService();
60 }
61 return businessObjectService;
62 }
63
64
65
66 @Override
67 @RequestMapping(params = "methodToCall=start")
68 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
69 HttpServletRequest request, HttpServletResponse response) {
70 LocalGokbForm localGokbForm = (LocalGokbForm)form;
71 return getUIFModelAndView(localGokbForm);
72 }
73
74
75 @RequestMapping(params = "methodToCall=initOrUpdateLocalGokb")
76 public ModelAndView initOrUpdateLocalGokb(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
77 HttpServletRequest request, HttpServletResponse response) {
78 GokbThread gokbThread = new GokbThread();
79 gokbThread.start();
80 return getUIFModelAndView(getLocalGokbForm((LocalGokbForm) form));
81
82 }
83
84 @RequestMapping(params = "methodToCall=refreshStatus")
85 public ModelAndView refreshStatus(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
86 HttpServletRequest request, HttpServletResponse response) {
87 LocalGokbForm localGokbForm = getLocalGokbForm((LocalGokbForm) form);
88
89 return getUIFModelAndView(localGokbForm);
90
91 }
92
93 private LocalGokbForm getLocalGokbForm(LocalGokbForm form) {
94 LocalGokbForm localGokbForm = (LocalGokbForm)form;
95 List<OleGokbUpdateLog> oleGokbUpdateLogList = new ArrayList<OleGokbUpdateLog>();
96 List<OleGokbUpdateLog> oleGokbUpdateLogs = (List<OleGokbUpdateLog>) KRADServiceLocator.getBusinessObjectService().findAll(OleGokbUpdateLog.class);
97 for (OleGokbUpdateLog oleGokbUpdateLog : oleGokbUpdateLogs) {
98 if(oleGokbUpdateLog.getId() != null) {
99 localGokbForm.setId(oleGokbUpdateLog.getId().toString());
100 }
101 if(oleGokbUpdateLog.getNoOfPackages() != null){
102 localGokbForm.setNoOfPackages(oleGokbUpdateLog.getNoOfPackages().toString());
103 }
104 if(oleGokbUpdateLog.getNoOfTipps() != null){
105 localGokbForm.setNoOfTipps(oleGokbUpdateLog.getNoOfTipps().toString());
106 }
107 if(oleGokbUpdateLog.getNoOfTitles() != null) {
108 localGokbForm.setNoOfTitles(oleGokbUpdateLog.getNoOfTitles().toString());
109 }
110 if(oleGokbUpdateLog.getNoOfOrganization() != null) {
111 localGokbForm.setNoOfOrganization(oleGokbUpdateLog.getNoOfOrganization().toString());
112 }
113 if(oleGokbUpdateLog.getNoOfPlatforms() != null) {
114 localGokbForm.setNoOfPlatforms(oleGokbUpdateLog.getNoOfPlatforms().toString());
115 }
116 if(oleGokbUpdateLog.getStatus() != null) {
117 localGokbForm.setStatus(oleGokbUpdateLog.getStatus());
118 }
119 if(oleGokbUpdateLog.getStartTime() != null) {
120 localGokbForm.setStartTime(oleGokbUpdateLog.getStartTime());
121 }
122 if(oleGokbUpdateLog.getEndTime() != null) {
123 localGokbForm.setEndTime(oleGokbUpdateLog.getEndTime());
124 }
125 oleGokbUpdateLogList.add(oleGokbUpdateLog);
126 }
127 Collections.reverse(oleGokbUpdateLogList);
128 localGokbForm.setOleGokbUpdateLogList(oleGokbUpdateLogList);
129 return localGokbForm;
130 }
131
132
133 }