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