1
22
23 package com.liferay.portal.verify;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.search.SearchEngineUtil;
28 import com.liferay.portal.kernel.util.GetterUtil;
29 import com.liferay.portal.kernel.util.PropsKeys;
30 import com.liferay.portal.service.persistence.BatchSessionUtil;
31 import com.liferay.portal.util.PropsUtil;
32
33
40 public class VerifyProcessUtil {
41
42 public static boolean verifyProcess(
43 boolean ranUpgradeProcess, boolean verified)
44 throws VerifyException {
45
46 boolean ranVerifyProcess = false;
47
48 int verifyFrequency = GetterUtil.getInteger(
49 PropsUtil.get(PropsKeys.VERIFY_FREQUENCY));
50
51 if ((verifyFrequency == VerifyProcess.ALWAYS) ||
52 ((verifyFrequency == VerifyProcess.ONCE) && !verified) ||
53 (ranUpgradeProcess)) {
54
55 if (ranUpgradeProcess) {
56 PropsUtil.set(
57 PropsKeys.INDEX_ON_STARTUP, Boolean.TRUE.toString());
58 }
59
60 String[] verifyProcessClassNames = PropsUtil.getArray(
61 PropsKeys.VERIFY_PROCESSES);
62
63 BatchSessionUtil.setEnabled(true);
64
65 boolean tempIndexReadOnly = SearchEngineUtil.isIndexReadOnly();
66
67 SearchEngineUtil.setIndexReadOnly(true);
68
69 try {
70 for (String verifyProcessClassName : verifyProcessClassNames) {
71 boolean tempRanVerifyProcess = _verifyProcess(
72 verifyProcessClassName);
73
74 if (tempRanVerifyProcess) {
75 ranVerifyProcess = true;
76 }
77 }
78 }
79 finally {
80 BatchSessionUtil.setEnabled(false);
81
82 SearchEngineUtil.setIndexReadOnly(tempIndexReadOnly);
83 }
84 }
85
86 return ranVerifyProcess;
87 }
88
89 private static boolean _verifyProcess(String verifyProcessClassName)
90 throws VerifyException {
91
92 if (_log.isDebugEnabled()) {
93 _log.debug("Initializing verification " + verifyProcessClassName);
94 }
95
96 try {
97 VerifyProcess verifyProcess = (VerifyProcess)Class.forName(
98 verifyProcessClassName).newInstance();
99
100 if (_log.isDebugEnabled()) {
101 _log.debug("Running verification " + verifyProcessClassName);
102 }
103
104 verifyProcess.verify();
105
106 if (_log.isDebugEnabled()) {
107 _log.debug("Finished verification " + verifyProcessClassName);
108 }
109
110 return true;
111 }
112 catch (ClassNotFoundException cnfe) {
113 _log.error(verifyProcessClassName + " cannot be found");
114 }
115 catch (IllegalAccessException iae) {
116 _log.error(verifyProcessClassName + " cannot be accessed");
117 }
118 catch (InstantiationException ie) {
119 _log.error(verifyProcessClassName + " cannot be initiated");
120 }
121
122 return false;
123 }
124
125 private static Log _log = LogFactoryUtil.getLog(VerifyProcessUtil.class);
126
127 }