1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.web.struts.action;
17
18 import org.apache.struts.action.ActionForm;
19 import org.apache.struts.action.ActionForward;
20 import org.apache.struts.action.ActionMapping;
21 import org.kuali.rice.core.api.util.RiceConstants;
22 import org.kuali.rice.kim.api.role.RoleService;
23 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
24 import org.kuali.rice.kim.impl.data.DataIntegrityService;
25 import org.kuali.rice.kim.impl.services.KimImplServiceLocator;
26 import org.kuali.rice.kns.web.struts.action.KualiAction;
27 import org.kuali.rice.krad.exception.AuthorizationException;
28 import org.kuali.rice.krad.util.GlobalVariables;
29
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import java.util.Collections;
33 import java.util.HashMap;
34 import java.util.List;
35
36 public class DataIntegrityAction extends KualiAction {
37
38
39
40
41
42
43 protected void checkAuthorization( ActionForm form, String methodToCall) throws AuthorizationException
44 {
45 boolean authorized = false;
46 String principalId = GlobalVariables.getUserSession().getPrincipalId();
47 RoleService roleService = KimApiServiceLocator.getRoleService();
48 String roleId = roleService.getRoleIdByNamespaceCodeAndName("KR-SYS", "Technical Administrator");
49 if (roleId != null) {
50 authorized = roleService.principalHasRole(principalId, Collections.singletonList(roleId),
51 new HashMap<String, String>(), true);
52 }
53
54 if (!authorized) {
55 throw new AuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalName(),
56 methodToCall,
57 this.getClass().getSimpleName());
58 }
59 }
60
61 public ActionForward check(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
62 List<String> messages = getDataIntegrityService().checkIntegrity();
63 if (messages.isEmpty()) {
64 messages = Collections.singletonList("No data integrity issues found.");
65 }
66 request.setAttribute("checkMessages", messages);
67 return mapping.findForward(RiceConstants.MAPPING_BASIC);
68 }
69
70 public ActionForward repair(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
71 List<String> messages = getDataIntegrityService().repair();
72 if (messages.isEmpty()) {
73 messages = Collections.singletonList("No data repair was necessary.");
74 }
75 request.setAttribute("repairMessages", messages);
76 return mapping.findForward(RiceConstants.MAPPING_BASIC);
77 }
78
79 public DataIntegrityService getDataIntegrityService() {
80 return KimImplServiceLocator.getDataIntegrityService();
81 }
82
83 }